@lark-apaas/openclaw-scripts-diagnose-cli 0.1.14-alpha.5 → 0.1.14-alpha.6
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 +225 -778
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -52,7 +52,7 @@ node_assert = __toESM(node_assert);
|
|
|
52
52
|
* it terse and parseable.
|
|
53
53
|
*/
|
|
54
54
|
function getVersion() {
|
|
55
|
-
return "0.1.14-alpha.
|
|
55
|
+
return "0.1.14-alpha.6";
|
|
56
56
|
}
|
|
57
57
|
//#endregion
|
|
58
58
|
//#region src/rule-engine/base.ts
|
|
@@ -3347,6 +3347,7 @@ function resolveUpgradeDirection(installed, ocCur, recommendedOc, isLegacy) {
|
|
|
3347
3347
|
/** 提取公共前置上下文;任何前置条件不满足时返回 null(规则 pass)。 */
|
|
3348
3348
|
function resolveCompatContext(ctx) {
|
|
3349
3349
|
const recommendedOc = ctx.vars.recommendedOpenclawTag;
|
|
3350
|
+
if (!recommendedOc) return null;
|
|
3350
3351
|
const ocCur = getOcVersion();
|
|
3351
3352
|
if (!ocCur) return null;
|
|
3352
3353
|
const installed = getInstalledPlugin(ctx);
|
|
@@ -3367,7 +3368,6 @@ let FeishuPluginOpenclawUpgradeRule = class FeishuPluginOpenclawUpgradeRule exte
|
|
|
3367
3368
|
validate(ctx) {
|
|
3368
3369
|
const cc = resolveCompatContext(ctx);
|
|
3369
3370
|
if (!cc) return { pass: true };
|
|
3370
|
-
if (!cc.recommendedOc) return { pass: true };
|
|
3371
3371
|
const { ocCur, recommendedOc, installed, isLegacy } = cc;
|
|
3372
3372
|
if (isForkPlugin(installed)) return validateForkPlugin(installed, ocCur, recommendedOc);
|
|
3373
3373
|
if (resolveUpgradeDirection(installed, ocCur, recommendedOc, isLegacy) !== "openclaw") return { pass: true };
|
|
@@ -3397,14 +3397,6 @@ let FeishuPluginLarkUpgradeRule = class FeishuPluginLarkUpgradeRule extends Diag
|
|
|
3397
3397
|
if (!cc) return { pass: true };
|
|
3398
3398
|
const { ocCur, recommendedOc, installed, isLegacy } = cc;
|
|
3399
3399
|
if (isForkPlugin(installed)) return { pass: true };
|
|
3400
|
-
if (!recommendedOc) {
|
|
3401
|
-
if (isLegacy || !isVersionCompatible(installed, ocCur)) return {
|
|
3402
|
-
pass: false,
|
|
3403
|
-
action: "upgrade_lark",
|
|
3404
|
-
message: `${buildCompatPrefix(installed, ocCur, isLegacy)};建议升级飞书插件至兼容版本`
|
|
3405
|
-
};
|
|
3406
|
-
return { pass: true };
|
|
3407
|
-
}
|
|
3408
3400
|
if (resolveUpgradeDirection(installed, ocCur, recommendedOc, isLegacy) !== "lark") return { pass: true };
|
|
3409
3401
|
return {
|
|
3410
3402
|
pass: false,
|
|
@@ -3513,176 +3505,6 @@ function extractScopedNameFromSpec$1(spec) {
|
|
|
3513
3505
|
const at = spec.indexOf("@", 1);
|
|
3514
3506
|
return at === -1 ? spec : spec.slice(0, at);
|
|
3515
3507
|
}
|
|
3516
|
-
/**
|
|
3517
|
-
* Returns true if the installed feishu plugin is version-incompatible with
|
|
3518
|
-
* the current openclaw (or is a legacy plugin that must be replaced).
|
|
3519
|
-
* Used by the upgrade_lark_needed rule and the upgrade-lark pre-check gate.
|
|
3520
|
-
*/
|
|
3521
|
-
function needsLarkUpgrade(ctx) {
|
|
3522
|
-
const cc = resolveCompatContext(ctx);
|
|
3523
|
-
if (!cc) return false;
|
|
3524
|
-
const { ocCur, recommendedOc, installed, isLegacy } = cc;
|
|
3525
|
-
if (isForkPlugin(installed)) return false;
|
|
3526
|
-
if (recommendedOc) return resolveUpgradeDirection(installed, ocCur, recommendedOc, isLegacy) === "lark";
|
|
3527
|
-
return isLegacy || !isVersionCompatible(installed, ocCur);
|
|
3528
|
-
}
|
|
3529
|
-
//#endregion
|
|
3530
|
-
//#region src/channels-probe.ts
|
|
3531
|
-
const FEISHU_INVALID_CONFIG_MSG = "channels.feishu: invalid config: must NOT have additional properties";
|
|
3532
|
-
const CHANNEL_LINE_RE = /^-\s+Feishu\s+([^:]+):\s+(.+)$/;
|
|
3533
|
-
/**
|
|
3534
|
-
* Port of Python `_account_is_working` from the feishu-channel-success-rate skill.
|
|
3535
|
-
*
|
|
3536
|
-
* Strips colon-prefixed key:value bits (dm:, bot:, in:, out:, token:, allow:,
|
|
3537
|
-
* intents:, groups:, health:) and evaluates the canonical health formula.
|
|
3538
|
-
*/
|
|
3539
|
-
function accountIsWorking(bits) {
|
|
3540
|
-
const bitTokens = /* @__PURE__ */ new Set();
|
|
3541
|
-
let hasError = false;
|
|
3542
|
-
let hasProbeFailed = false;
|
|
3543
|
-
for (const raw of bits) {
|
|
3544
|
-
const b = raw.trim();
|
|
3545
|
-
if (!b) continue;
|
|
3546
|
-
if (b.startsWith("error:")) {
|
|
3547
|
-
hasError = true;
|
|
3548
|
-
continue;
|
|
3549
|
-
}
|
|
3550
|
-
if (b === "probe failed") {
|
|
3551
|
-
hasProbeFailed = true;
|
|
3552
|
-
continue;
|
|
3553
|
-
}
|
|
3554
|
-
bitTokens.add(b.split(":")[0]);
|
|
3555
|
-
}
|
|
3556
|
-
if (!bitTokens.has("enabled") || !bitTokens.has("configured")) return false;
|
|
3557
|
-
if (bitTokens.has("works")) return true;
|
|
3558
|
-
if (bitTokens.has("running") && !hasError && !hasProbeFailed) return true;
|
|
3559
|
-
return false;
|
|
3560
|
-
}
|
|
3561
|
-
/**
|
|
3562
|
-
* Parse the raw stdout of `openclaw channels status --probe`.
|
|
3563
|
-
* Port of Python `extract_channels_probe` from the feishu-channel-success-rate skill.
|
|
3564
|
-
*/
|
|
3565
|
-
function parseChannelsProbeOutput(text) {
|
|
3566
|
-
const gatewayReachable = text.includes("Gateway reachable");
|
|
3567
|
-
const feishuConfigInvalid = text.includes(FEISHU_INVALID_CONFIG_MSG);
|
|
3568
|
-
const accounts = [];
|
|
3569
|
-
let anyAccountWorking = false;
|
|
3570
|
-
for (const line of text.split("\n")) {
|
|
3571
|
-
const m = CHANNEL_LINE_RE.exec(line.trim());
|
|
3572
|
-
if (!m) continue;
|
|
3573
|
-
const [, acct, rest] = m;
|
|
3574
|
-
const bits = rest.split(",").map((b) => b.trim());
|
|
3575
|
-
const isWorking = accountIsWorking(bits);
|
|
3576
|
-
if (isWorking) anyAccountWorking = true;
|
|
3577
|
-
accounts.push({
|
|
3578
|
-
id: acct.trim(),
|
|
3579
|
-
bits,
|
|
3580
|
-
isWorking,
|
|
3581
|
-
raw: line.trim()
|
|
3582
|
-
});
|
|
3583
|
-
}
|
|
3584
|
-
return {
|
|
3585
|
-
gatewayReachable,
|
|
3586
|
-
feishuConfigInvalid,
|
|
3587
|
-
accounts,
|
|
3588
|
-
anyAccountWorking
|
|
3589
|
-
};
|
|
3590
|
-
}
|
|
3591
|
-
/**
|
|
3592
|
-
* Run `openclaw channels status --probe` and return a structured result.
|
|
3593
|
-
*
|
|
3594
|
-
* The command may exit non-zero when some bot accounts fail their probe — that
|
|
3595
|
-
* is still useful output. We therefore try to parse stdout even when the
|
|
3596
|
-
* process exits with a non-zero code, falling back to an unavailable result
|
|
3597
|
-
* only when there is genuinely no output to parse.
|
|
3598
|
-
*
|
|
3599
|
-
* @param timeoutMs Maximum wait time. Default is 60 s because v2026.4.x
|
|
3600
|
-
* lacks a per-request HTTP timeout and can block indefinitely.
|
|
3601
|
-
*/
|
|
3602
|
-
function runChannelsProbe(timeoutMs = 6e4) {
|
|
3603
|
-
let stdout = "";
|
|
3604
|
-
let execError;
|
|
3605
|
-
try {
|
|
3606
|
-
stdout = (0, node_child_process.execSync)("openclaw channels status --probe", {
|
|
3607
|
-
encoding: "utf-8",
|
|
3608
|
-
timeout: timeoutMs,
|
|
3609
|
-
stdio: [
|
|
3610
|
-
"ignore",
|
|
3611
|
-
"pipe",
|
|
3612
|
-
"pipe"
|
|
3613
|
-
]
|
|
3614
|
-
});
|
|
3615
|
-
} catch (e) {
|
|
3616
|
-
const err = e;
|
|
3617
|
-
stdout = err.stdout ?? "";
|
|
3618
|
-
execError = err.message;
|
|
3619
|
-
const stderrRaw = err.stderr;
|
|
3620
|
-
const stderr = (typeof stderrRaw === "string" ? stderrRaw : stderrRaw?.toString("utf-8") ?? "").trim();
|
|
3621
|
-
if (stderr) console.error(`channels-probe: stderr from CLI: ${stderr}`);
|
|
3622
|
-
}
|
|
3623
|
-
if (stdout.trim()) return {
|
|
3624
|
-
available: true,
|
|
3625
|
-
...parseChannelsProbeOutput(stdout)
|
|
3626
|
-
};
|
|
3627
|
-
return {
|
|
3628
|
-
available: false,
|
|
3629
|
-
gatewayReachable: false,
|
|
3630
|
-
feishuConfigInvalid: false,
|
|
3631
|
-
accounts: [],
|
|
3632
|
-
anyAccountWorking: false,
|
|
3633
|
-
error: execError ?? "no output from openclaw channels status --probe"
|
|
3634
|
-
};
|
|
3635
|
-
}
|
|
3636
|
-
//#endregion
|
|
3637
|
-
//#region src/rules/upgrade-lark-needed.ts
|
|
3638
|
-
/**
|
|
3639
|
-
* Detects the condition that warrants running `upgrade-lark`:
|
|
3640
|
-
* - feishu plugin version incompatible with current openclaw, OR
|
|
3641
|
-
* - openclaw channels status --probe reports feishu channel config invalid; AND
|
|
3642
|
-
* - channels are not working.
|
|
3643
|
-
*
|
|
3644
|
-
* Both conditions must be true simultaneously. If version is compatible and
|
|
3645
|
-
* feishu config is valid, or channels are working, the rule passes (no action needed).
|
|
3646
|
-
*
|
|
3647
|
-
* feishuConfigInvalid is read from the channels probe output rather than running a
|
|
3648
|
-
* separate `openclaw status` call, since only `openclaw channels status --probe`
|
|
3649
|
-
* reliably surfaces the schema validation error.
|
|
3650
|
-
*
|
|
3651
|
-
* profile: experimental — runs only in full sweep mode, not in standard doctor.
|
|
3652
|
-
* level: silent — telemetry/sweep-only, does not trigger page-level repair UI.
|
|
3653
|
-
*/
|
|
3654
|
-
let UpgradeLarkNeededRule = class UpgradeLarkNeededRule extends DiagnoseRule {
|
|
3655
|
-
validate(ctx) {
|
|
3656
|
-
let versionIncompatible = false;
|
|
3657
|
-
try {
|
|
3658
|
-
versionIncompatible = needsLarkUpgrade(ctx);
|
|
3659
|
-
} catch {
|
|
3660
|
-
versionIncompatible = true;
|
|
3661
|
-
}
|
|
3662
|
-
let probeResult;
|
|
3663
|
-
try {
|
|
3664
|
-
probeResult = runChannelsProbe(3e4);
|
|
3665
|
-
} catch {
|
|
3666
|
-
return { pass: true };
|
|
3667
|
-
}
|
|
3668
|
-
const feishuConfigInvalid = probeResult.feishuConfigInvalid;
|
|
3669
|
-
if (!(versionIncompatible || feishuConfigInvalid)) return { pass: true };
|
|
3670
|
-
if (probeResult.anyAccountWorking) return { pass: true };
|
|
3671
|
-
return {
|
|
3672
|
-
pass: false,
|
|
3673
|
-
action: "upgrade_lark",
|
|
3674
|
-
message: `飞书插件需要升级且 channels 不可用(版本不兼容=${versionIncompatible}, feishu配置无效=${feishuConfigInvalid}),建议执行 upgrade-lark 命令升级飞书插件`
|
|
3675
|
-
};
|
|
3676
|
-
}
|
|
3677
|
-
};
|
|
3678
|
-
UpgradeLarkNeededRule = __decorate([Rule({
|
|
3679
|
-
key: "upgrade_lark_needed",
|
|
3680
|
-
description: "检测飞书插件版本不兼容且 channels 不可用,判断是否需要执行 upgrade-lark 升级",
|
|
3681
|
-
repairMode: "check-only",
|
|
3682
|
-
level: "silent",
|
|
3683
|
-
profile: "experimental",
|
|
3684
|
-
usesVars: ["recommendedOpenclawTag"]
|
|
3685
|
-
})], UpgradeLarkNeededRule);
|
|
3686
3508
|
//#endregion
|
|
3687
3509
|
//#region src/rules/cleanup-install-backup-dirs.ts
|
|
3688
3510
|
const DIR_PREFIX = ".openclaw-install-";
|
|
@@ -3828,6 +3650,117 @@ LarkCliMissingForInstalledLarkPluginRule = __decorate([Rule({
|
|
|
3828
3650
|
usesVars: ["recommendedOpenclawTag"]
|
|
3829
3651
|
})], LarkCliMissingForInstalledLarkPluginRule);
|
|
3830
3652
|
//#endregion
|
|
3653
|
+
//#region src/rules/feishu-bot-channel-config.ts
|
|
3654
|
+
/**
|
|
3655
|
+
* Ensures each bot account's channel config is correct:
|
|
3656
|
+
* 1. `allowFrom` contains its own `creatorOpenID` from larkApps
|
|
3657
|
+
* 2. `appSecret` is either the canonical provider-ref or matches larkApps plaintext
|
|
3658
|
+
*
|
|
3659
|
+
* Covers both multi-account (channels.feishu.accounts) and single-account
|
|
3660
|
+
* (channels.feishu.appId + allowFrom at top level) layouts.
|
|
3661
|
+
*/
|
|
3662
|
+
let FeishuBotChannelConfigRule = class FeishuBotChannelConfigRule extends DiagnoseRule {
|
|
3663
|
+
validate(ctx) {
|
|
3664
|
+
const larkApps = ctx.vars.larkApps;
|
|
3665
|
+
if (!larkApps || larkApps.length === 0) return { pass: true };
|
|
3666
|
+
const feishu = asRecord(getNestedMap(ctx.config, "channels", "feishu"));
|
|
3667
|
+
if (!feishu) return { pass: true };
|
|
3668
|
+
const issues = [];
|
|
3669
|
+
const accounts = asRecord(feishu.accounts);
|
|
3670
|
+
if (accounts) for (const [accountId, account] of Object.entries(accounts)) {
|
|
3671
|
+
const bot = asRecord(account);
|
|
3672
|
+
if (!bot) continue;
|
|
3673
|
+
const appId = bot.appId;
|
|
3674
|
+
if (typeof appId !== "string" || !appId.startsWith("cli_")) continue;
|
|
3675
|
+
const larkApp = larkApps.find((e) => e.larkAppID === appId);
|
|
3676
|
+
if (!larkApp) continue;
|
|
3677
|
+
this.checkBot(accountId, bot, larkApp, issues);
|
|
3678
|
+
}
|
|
3679
|
+
const singleAppId = feishu.appId;
|
|
3680
|
+
if (typeof singleAppId === "string" && singleAppId.startsWith("cli_") && !accounts) {
|
|
3681
|
+
const larkApp = larkApps.find((e) => e.larkAppID === singleAppId);
|
|
3682
|
+
if (larkApp) this.checkBot("feishu", feishu, larkApp, issues);
|
|
3683
|
+
}
|
|
3684
|
+
if (issues.length === 0) return { pass: true };
|
|
3685
|
+
return {
|
|
3686
|
+
pass: false,
|
|
3687
|
+
message: issues.join("; ")
|
|
3688
|
+
};
|
|
3689
|
+
}
|
|
3690
|
+
/** Check a single bot entry (either an account object or the feishu channel itself).
|
|
3691
|
+
* appSecret is validated based on its current type:
|
|
3692
|
+
* - object → must match canonical provider-ref
|
|
3693
|
+
* - string → must match larkApps plaintext
|
|
3694
|
+
*/
|
|
3695
|
+
checkBot(label, bot, larkApp, issues) {
|
|
3696
|
+
const creatorOpenID = larkApp.creatorOpenID;
|
|
3697
|
+
const allowFrom = Array.isArray(bot.allowFrom) ? bot.allowFrom : [];
|
|
3698
|
+
if (typeof creatorOpenID === "string" && creatorOpenID !== "") {
|
|
3699
|
+
if (!allowFrom.includes(creatorOpenID)) issues.push(`${label} allowFrom missing creatorOpenID ${creatorOpenID.length > 8 ? creatorOpenID.slice(0, 4) + "***" + creatorOpenID.slice(-4) : "***"}`);
|
|
3700
|
+
} else if (allowFrom.length === 0) issues.push(`${label} allowFrom is empty (creatorOpenID unavailable, cannot auto-fix)`);
|
|
3701
|
+
const secret = bot.appSecret;
|
|
3702
|
+
if (typeof secret === "object" && secret !== null && !Array.isArray(secret)) {
|
|
3703
|
+
if (!matchMap(secret, DEFAULT_FEISHU_APP_SECRET)) issues.push(`${label} appSecret is a provider-ref but not the canonical one`);
|
|
3704
|
+
} else if (typeof secret === "string") {
|
|
3705
|
+
if (secret !== larkApp.appSecret) issues.push(`${label} appSecret plaintext mismatch`);
|
|
3706
|
+
} else issues.push(`${label} appSecret has unexpected type ${typeof secret}`);
|
|
3707
|
+
}
|
|
3708
|
+
repair(ctx) {
|
|
3709
|
+
const larkApps = ctx.vars.larkApps;
|
|
3710
|
+
if (!larkApps || larkApps.length === 0) return;
|
|
3711
|
+
const feishu = asRecord(getNestedMap(ctx.config, "channels", "feishu"));
|
|
3712
|
+
if (!feishu) return;
|
|
3713
|
+
const accounts = asRecord(feishu.accounts);
|
|
3714
|
+
if (accounts) for (const [, account] of Object.entries(accounts)) {
|
|
3715
|
+
const bot = asRecord(account);
|
|
3716
|
+
if (!bot) continue;
|
|
3717
|
+
const appId = bot.appId;
|
|
3718
|
+
if (typeof appId !== "string" || !appId.startsWith("cli_")) continue;
|
|
3719
|
+
const larkApp = larkApps.find((e) => e.larkAppID === appId);
|
|
3720
|
+
if (!larkApp) continue;
|
|
3721
|
+
this.fixBot(bot, larkApp);
|
|
3722
|
+
}
|
|
3723
|
+
const singleAppId = feishu.appId;
|
|
3724
|
+
if (typeof singleAppId === "string" && singleAppId.startsWith("cli_") && !accounts) {
|
|
3725
|
+
const larkApp = larkApps.find((e) => e.larkAppID === singleAppId);
|
|
3726
|
+
if (larkApp) this.fixBot(feishu, larkApp);
|
|
3727
|
+
}
|
|
3728
|
+
}
|
|
3729
|
+
/** Fix a single bot entry in-place.
|
|
3730
|
+
* appSecret is repaired based on its current type:
|
|
3731
|
+
* - object → canonical provider-ref
|
|
3732
|
+
* - string → plaintext from larkApps
|
|
3733
|
+
*/
|
|
3734
|
+
fixBot(bot, larkApp) {
|
|
3735
|
+
const creatorOpenID = larkApp.creatorOpenID;
|
|
3736
|
+
if (typeof creatorOpenID === "string" && creatorOpenID !== "") {
|
|
3737
|
+
const allowFrom = Array.isArray(bot.allowFrom) ? [...bot.allowFrom] : [];
|
|
3738
|
+
if (!allowFrom.includes(creatorOpenID)) {
|
|
3739
|
+
allowFrom.push(creatorOpenID);
|
|
3740
|
+
bot.allowFrom = allowFrom;
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
const secret = bot.appSecret;
|
|
3744
|
+
if (typeof secret === "object" && secret !== null && !Array.isArray(secret)) {
|
|
3745
|
+
if (!matchMap(secret, DEFAULT_FEISHU_APP_SECRET)) bot.appSecret = { ...DEFAULT_FEISHU_APP_SECRET };
|
|
3746
|
+
} else if (typeof secret === "string") {
|
|
3747
|
+
if (secret !== larkApp.appSecret) bot.appSecret = larkApp.appSecret;
|
|
3748
|
+
} else bot.appSecret = { ...DEFAULT_FEISHU_APP_SECRET };
|
|
3749
|
+
}
|
|
3750
|
+
};
|
|
3751
|
+
FeishuBotChannelConfigRule = __decorate([Rule({
|
|
3752
|
+
key: "feishu_bot_channel_config",
|
|
3753
|
+
description: "确保飞书配置中 bot 账号的 allowFrom 包含其创建者 openID 且 appSecret 值正确",
|
|
3754
|
+
dependsOn: [
|
|
3755
|
+
"config_syntax_check",
|
|
3756
|
+
"feishu_default_account",
|
|
3757
|
+
"feishu_bot_id"
|
|
3758
|
+
],
|
|
3759
|
+
repairMode: "standard",
|
|
3760
|
+
usesVars: ["larkApps"],
|
|
3761
|
+
level: "critical"
|
|
3762
|
+
})], FeishuBotChannelConfigRule);
|
|
3763
|
+
//#endregion
|
|
3831
3764
|
//#region src/check.ts
|
|
3832
3765
|
/** Telemetry-aware entry: returns both the legacy CheckResult (for stdout)
|
|
3833
3766
|
* AND a DoctorReport-shape payload (for `openclaw.report_cli_run`). The
|
|
@@ -4291,9 +4224,6 @@ const PROVIDER_FILE_PATH = "/home/gem/workspace/.force/openclaw/miaoda-provider-
|
|
|
4291
4224
|
const SECRETS_FILE_PATH = "/home/gem/workspace/.force/openclaw/miaoda-openclaw-secrets.json";
|
|
4292
4225
|
/** Absolute path to the openclaw config JSON. */
|
|
4293
4226
|
const CONFIG_PATH = `${WORKSPACE_DIR}/openclaw.json`;
|
|
4294
|
-
function upgradeLarkLogFile(runId) {
|
|
4295
|
-
return `${DIAGNOSE_DIR}/upgrade-lark-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace(/:/g, "-")}-${runId.slice(0, 8)}.log`;
|
|
4296
|
-
}
|
|
4297
4227
|
//#endregion
|
|
4298
4228
|
//#region src/run-log.ts
|
|
4299
4229
|
let currentRunContext;
|
|
@@ -4430,9 +4360,10 @@ function makeLogger(logFile) {
|
|
|
4430
4360
|
/**
|
|
4431
4361
|
* Start an async reset task: spawn a detached child process and return the taskId.
|
|
4432
4362
|
*
|
|
4433
|
-
* The child process runs: node cli.js reset --worker --task-id=xxx
|
|
4363
|
+
* The child process runs: node cli.js reset --worker --task-id=xxx
|
|
4364
|
+
* The worker fetches ctx from innerApi itself — no --ctx passthrough.
|
|
4434
4365
|
*/
|
|
4435
|
-
function startAsyncReset(
|
|
4366
|
+
function startAsyncReset() {
|
|
4436
4367
|
const taskId = (0, node_crypto.randomUUID)();
|
|
4437
4368
|
const resultFile = resetResultFile(taskId);
|
|
4438
4369
|
const log = makeLogger(resetLogFile(taskId));
|
|
@@ -4456,8 +4387,7 @@ function startAsyncReset(ctxBase64) {
|
|
|
4456
4387
|
process.argv[1],
|
|
4457
4388
|
"reset",
|
|
4458
4389
|
"--worker",
|
|
4459
|
-
`--task-id=${taskId}
|
|
4460
|
-
`--ctx=${ctxBase64}`
|
|
4390
|
+
`--task-id=${taskId}`
|
|
4461
4391
|
], {
|
|
4462
4392
|
detached: true,
|
|
4463
4393
|
stdio: "ignore",
|
|
@@ -6971,6 +6901,60 @@ function mergeCoreBackupAndOrigins(configPath, vars, resetData, log) {
|
|
|
6971
6901
|
log(`allowedOrigins: added ${added.length} (${JSON.stringify(added)}), total now ${mergedOrigins.length}`);
|
|
6972
6902
|
}
|
|
6973
6903
|
/**
|
|
6904
|
+
* Fix bot account allowFrom and appSecret using larkApps from innerApi.
|
|
6905
|
+
*
|
|
6906
|
+
* For each bot account (key starts with `bot-cli_`):
|
|
6907
|
+
* - allowFrom must contain the bot's own creatorOpenID from larkApps
|
|
6908
|
+
* - appSecret must be either the canonical provider-ref or match larkApps plaintext
|
|
6909
|
+
*
|
|
6910
|
+
* Runs after mergeCoreBackupAndOrigins so it operates on the final config state.
|
|
6911
|
+
*/
|
|
6912
|
+
function fixBotChannelConfig(configPath, larkApps, log) {
|
|
6913
|
+
if (!larkApps || larkApps.length === 0) {
|
|
6914
|
+
log("no larkApps data, skip bot channel config fix");
|
|
6915
|
+
return;
|
|
6916
|
+
}
|
|
6917
|
+
const config = loadJSON5().parse(node_fs.default.readFileSync(configPath, "utf-8"));
|
|
6918
|
+
const accounts = asRecord(getNestedMap(config, "channels", "feishu")?.accounts);
|
|
6919
|
+
if (!accounts) {
|
|
6920
|
+
log("no feishu accounts in config, skip bot channel config fix");
|
|
6921
|
+
return;
|
|
6922
|
+
}
|
|
6923
|
+
let fixCount = 0;
|
|
6924
|
+
for (const [, account] of Object.entries(accounts)) {
|
|
6925
|
+
const bot = asRecord(account);
|
|
6926
|
+
if (!bot) continue;
|
|
6927
|
+
const appId = bot.appId;
|
|
6928
|
+
if (typeof appId !== "string" || !appId.startsWith("cli_")) continue;
|
|
6929
|
+
const larkApp = larkApps.find((e) => e.larkAppID === appId);
|
|
6930
|
+
if (!larkApp) continue;
|
|
6931
|
+
const creatorOpenID = larkApp.creatorOpenID;
|
|
6932
|
+
if (typeof creatorOpenID === "string" && creatorOpenID !== "") {
|
|
6933
|
+
const allowFrom = Array.isArray(bot.allowFrom) ? [...bot.allowFrom] : [];
|
|
6934
|
+
if (!allowFrom.includes(creatorOpenID)) {
|
|
6935
|
+
allowFrom.push(creatorOpenID);
|
|
6936
|
+
bot.allowFrom = allowFrom;
|
|
6937
|
+
fixCount++;
|
|
6938
|
+
}
|
|
6939
|
+
}
|
|
6940
|
+
const secret = bot.appSecret;
|
|
6941
|
+
let needsFix = false;
|
|
6942
|
+
if (typeof secret === "object" && secret !== null && !Array.isArray(secret)) {
|
|
6943
|
+
if (!matchMap(secret, DEFAULT_FEISHU_APP_SECRET)) needsFix = true;
|
|
6944
|
+
} else if (typeof secret === "string") {
|
|
6945
|
+
if (secret !== larkApp.appSecret) needsFix = true;
|
|
6946
|
+
} else needsFix = true;
|
|
6947
|
+
if (needsFix) {
|
|
6948
|
+
bot.appSecret = { ...DEFAULT_FEISHU_APP_SECRET };
|
|
6949
|
+
fixCount++;
|
|
6950
|
+
}
|
|
6951
|
+
}
|
|
6952
|
+
if (fixCount > 0) {
|
|
6953
|
+
node_fs.default.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
6954
|
+
log(`fixed ${fixCount} bot channel config issue(s) (allowFrom/appSecret)`);
|
|
6955
|
+
} else log("bot channel config ok, no fixes needed");
|
|
6956
|
+
}
|
|
6957
|
+
/**
|
|
6974
6958
|
* Step 7: Verify startup scripts landed in configDir/scripts/.
|
|
6975
6959
|
*
|
|
6976
6960
|
* Scripts are extracted directly to configDir/scripts/ during stageTemplate —
|
|
@@ -7115,6 +7099,7 @@ async function runReset(input, taskId, resultFile) {
|
|
|
7115
7099
|
await step5InstallOpenclaw(openclawTag, ossFileMap, log);
|
|
7116
7100
|
step(6);
|
|
7117
7101
|
mergeCoreBackupAndOrigins(configPath, vars, resetData, log);
|
|
7102
|
+
fixBotChannelConfig(configPath, vars.larkApps, log);
|
|
7118
7103
|
step(7);
|
|
7119
7104
|
verifyStartupScripts(configDir, log);
|
|
7120
7105
|
step(8);
|
|
@@ -7913,7 +7898,8 @@ function normalizeCtx(raw) {
|
|
|
7913
7898
|
reset: {
|
|
7914
7899
|
templateVars: r.reset.templateVars ?? {},
|
|
7915
7900
|
coreBackup: r.reset.coreBackup
|
|
7916
|
-
}
|
|
7901
|
+
},
|
|
7902
|
+
larkApps: Array.isArray(r.larkApps) ? r.larkApps : []
|
|
7917
7903
|
};
|
|
7918
7904
|
}
|
|
7919
7905
|
const vars = r.vars ?? {};
|
|
@@ -7938,7 +7924,8 @@ function normalizeCtx(raw) {
|
|
|
7938
7924
|
reset: {
|
|
7939
7925
|
templateVars: resetData.templateVars ?? {},
|
|
7940
7926
|
coreBackup: resetData.coreBackup
|
|
7941
|
-
}
|
|
7927
|
+
},
|
|
7928
|
+
larkApps: Array.isArray(r.larkApps) ? r.larkApps : []
|
|
7942
7929
|
};
|
|
7943
7930
|
}
|
|
7944
7931
|
function fillApp(src) {
|
|
@@ -8003,7 +7990,8 @@ function buildCheckInput(raw, configPathOverride) {
|
|
|
8003
7990
|
providerFilePath: PROVIDER_FILE_PATH,
|
|
8004
7991
|
secretsFilePath: SECRETS_FILE_PATH,
|
|
8005
7992
|
templateVars: ctx.app.templateVars,
|
|
8006
|
-
recommendedOpenclawTag: ctx.app.recommendedOpenclawTag
|
|
7993
|
+
recommendedOpenclawTag: ctx.app.recommendedOpenclawTag,
|
|
7994
|
+
larkApps: ctx.larkApps
|
|
8007
7995
|
},
|
|
8008
7996
|
templateVars: ctx.app.templateVars
|
|
8009
7997
|
};
|
|
@@ -8035,7 +8023,8 @@ function buildRepairInput(raw, configPathOverride) {
|
|
|
8035
8023
|
providerFilePath: PROVIDER_FILE_PATH,
|
|
8036
8024
|
secretsFilePath: SECRETS_FILE_PATH,
|
|
8037
8025
|
templateVars: ctx.app.templateVars,
|
|
8038
|
-
recommendedOpenclawTag: ctx.app.recommendedOpenclawTag
|
|
8026
|
+
recommendedOpenclawTag: ctx.app.recommendedOpenclawTag,
|
|
8027
|
+
larkApps: ctx.larkApps
|
|
8039
8028
|
},
|
|
8040
8029
|
repairData: {
|
|
8041
8030
|
secretsContent: ctx.secrets.secretsContent,
|
|
@@ -8071,7 +8060,8 @@ function buildResetInput(raw, configPathOverride) {
|
|
|
8071
8060
|
providerFilePath: PROVIDER_FILE_PATH,
|
|
8072
8061
|
secretsFilePath: SECRETS_FILE_PATH,
|
|
8073
8062
|
templateVars: ctx.app.templateVars,
|
|
8074
|
-
recommendedOpenclawTag: ctx.app.recommendedOpenclawTag
|
|
8063
|
+
recommendedOpenclawTag: ctx.app.recommendedOpenclawTag,
|
|
8064
|
+
larkApps: ctx.larkApps
|
|
8075
8065
|
},
|
|
8076
8066
|
resetData: {
|
|
8077
8067
|
templateVars: ctx.reset.templateVars,
|
|
@@ -10381,7 +10371,7 @@ async function reportCliRun(opts) {
|
|
|
10381
10371
|
//#region src/help.ts
|
|
10382
10372
|
const BIN = "mclaw-diagnose";
|
|
10383
10373
|
function versionBanner() {
|
|
10384
|
-
return `v0.1.14-alpha.
|
|
10374
|
+
return `v0.1.14-alpha.6`;
|
|
10385
10375
|
}
|
|
10386
10376
|
const COMMANDS = [
|
|
10387
10377
|
{
|
|
@@ -10485,16 +10475,12 @@ EXIT CODES
|
|
|
10485
10475
|
hidden: true,
|
|
10486
10476
|
summary: "Run rule-engine check only",
|
|
10487
10477
|
help: `USAGE
|
|
10488
|
-
${BIN} check
|
|
10478
|
+
${BIN} check
|
|
10489
10479
|
|
|
10490
10480
|
DESCRIPTION
|
|
10491
10481
|
Runs the rule engine against the sandbox's current openclaw config and
|
|
10492
|
-
returns { failedRules }.
|
|
10493
|
-
|
|
10494
|
-
|
|
10495
|
-
OPTIONS
|
|
10496
|
-
--ctx=<base64> Opaque ctx JSON (base64). When absent, fetched from
|
|
10497
|
-
innerapi (same path as doctor).
|
|
10482
|
+
returns { failedRules }. Ctx is fetched from innerapi automatically.
|
|
10483
|
+
End-users should prefer \`doctor\`.
|
|
10498
10484
|
`
|
|
10499
10485
|
},
|
|
10500
10486
|
{
|
|
@@ -10502,16 +10488,11 @@ OPTIONS
|
|
|
10502
10488
|
hidden: true,
|
|
10503
10489
|
summary: "Apply standard-mode repairs",
|
|
10504
10490
|
help: `USAGE
|
|
10505
|
-
${BIN} repair
|
|
10491
|
+
${BIN} repair
|
|
10506
10492
|
|
|
10507
10493
|
DESCRIPTION
|
|
10508
|
-
Runs repair for the failing rules
|
|
10509
|
-
|
|
10510
|
-
\`doctor --fix\` instead.
|
|
10511
|
-
|
|
10512
|
-
OPTIONS
|
|
10513
|
-
--ctx=<base64> Opaque ctx JSON (base64). When absent, fetched from
|
|
10514
|
-
innerapi.
|
|
10494
|
+
Runs repair for the failing rules. Ctx is fetched from innerapi
|
|
10495
|
+
automatically. End-users should use \`doctor --fix\` instead.
|
|
10515
10496
|
`
|
|
10516
10497
|
},
|
|
10517
10498
|
{
|
|
@@ -10519,14 +10500,15 @@ OPTIONS
|
|
|
10519
10500
|
hidden: true,
|
|
10520
10501
|
summary: "Re-initialize sandbox via the 9-step reset pipeline",
|
|
10521
10502
|
help: `USAGE
|
|
10522
|
-
${BIN} reset --async
|
|
10523
|
-
${BIN} reset --worker --task-id=<id>
|
|
10503
|
+
${BIN} reset --async
|
|
10504
|
+
${BIN} reset --worker --task-id=<id>
|
|
10524
10505
|
|
|
10525
10506
|
DESCRIPTION
|
|
10526
10507
|
Two-phase pipeline driven asynchronously: the --async invocation spawns
|
|
10527
10508
|
a detached worker and returns { taskId } immediately; the --worker
|
|
10528
10509
|
invocation (spawned by --async) runs the actual 9 steps and writes
|
|
10529
10510
|
progress to /tmp/openclaw-diagnose/reset-<taskId>.json.
|
|
10511
|
+
Ctx is fetched from innerapi automatically.
|
|
10530
10512
|
|
|
10531
10513
|
Poll progress with \`${BIN} get_reset_task --task-id=<id>\`.
|
|
10532
10514
|
|
|
@@ -10534,7 +10516,6 @@ OPTIONS
|
|
|
10534
10516
|
--async Start a detached worker and return taskId on stdout.
|
|
10535
10517
|
--worker Internal — run the 9-step pipeline (launched by --async).
|
|
10536
10518
|
--task-id=<id> Required with --worker; identifies the progress file.
|
|
10537
|
-
--ctx=<base64> Opaque ctx JSON; fetched from innerapi when absent.
|
|
10538
10519
|
`
|
|
10539
10520
|
},
|
|
10540
10521
|
{
|
|
@@ -10557,7 +10538,7 @@ OPTIONS
|
|
|
10557
10538
|
hidden: true,
|
|
10558
10539
|
summary: "Download + install the openclaw tarball",
|
|
10559
10540
|
help: `USAGE
|
|
10560
|
-
${BIN} install-openclaw <tag> [--
|
|
10541
|
+
${BIN} install-openclaw <tag> [--oss_file_map=<base64>]
|
|
10561
10542
|
|
|
10562
10543
|
DESCRIPTION
|
|
10563
10544
|
Downloads the openclaw@<tag> tgz via the signed OSS URL found in the
|
|
@@ -10569,9 +10550,9 @@ ARGUMENTS
|
|
|
10569
10550
|
<tag> Openclaw version tag, e.g. 2026.4.11.
|
|
10570
10551
|
|
|
10571
10552
|
OPTIONS
|
|
10572
|
-
--ctx=<base64> Opaque ctx; ossFileMap is extracted from it.
|
|
10573
10553
|
--oss_file_map=... Pre-built OSS URL map (base64 JSON); skips innerapi
|
|
10574
|
-
entirely.
|
|
10554
|
+
entirely. When absent, ossFileMap is fetched from
|
|
10555
|
+
innerapi automatically.
|
|
10575
10556
|
`
|
|
10576
10557
|
},
|
|
10577
10558
|
{
|
|
@@ -10597,8 +10578,7 @@ OPTIONS
|
|
|
10597
10578
|
--home_base=<dir> Override the /home/gem base (tests).
|
|
10598
10579
|
--config_path=<p> Override the openclaw.json path (tests).
|
|
10599
10580
|
--skip-config-update Leave plugins.installs in openclaw.json untouched.
|
|
10600
|
-
--
|
|
10601
|
-
--oss_file_map=... Pre-built OSS URL map (base64 JSON).
|
|
10581
|
+
--oss_file_map=... Pre-built OSS URL map (base64 JSON); skips innerapi.
|
|
10602
10582
|
`
|
|
10603
10583
|
},
|
|
10604
10584
|
{
|
|
@@ -10625,7 +10605,6 @@ OPTIONS
|
|
|
10625
10605
|
--cli=<name> CLI package to install by short name or scoped
|
|
10626
10606
|
packageName (repeatable, at least one required).
|
|
10627
10607
|
--home_base=<dir> Override the /home/gem base (tests).
|
|
10628
|
-
--ctx=<base64> Opaque ctx; ossFileMap is extracted from it.
|
|
10629
10608
|
--oss_file_map=... Pre-built OSS URL map (base64 JSON); skips innerapi.
|
|
10630
10609
|
|
|
10631
10610
|
EXAMPLES
|
|
@@ -10679,46 +10658,6 @@ OPTIONS
|
|
|
10679
10658
|
EXIT CODES
|
|
10680
10659
|
0 Success or skipped (prerequisites not met).
|
|
10681
10660
|
1 Secret/path unresolvable, lark-cli failed, or config unreadable.
|
|
10682
|
-
`
|
|
10683
|
-
},
|
|
10684
|
-
{
|
|
10685
|
-
name: "upgrade-lark",
|
|
10686
|
-
hidden: false,
|
|
10687
|
-
summary: "Upgrade the Feishu/Lark plugin via @larksuite/openclaw-lark-tools",
|
|
10688
|
-
help: `USAGE
|
|
10689
|
-
${BIN} upgrade-lark [--scene=<scene>] [--caller=<n>] [--trace-id=<id>]
|
|
10690
|
-
|
|
10691
|
-
DESCRIPTION
|
|
10692
|
-
Upgrades the Feishu/Lark plugin by running:
|
|
10693
|
-
npx -y @larksuite/openclaw-lark-tools update --use-existing
|
|
10694
|
-
|
|
10695
|
-
Before the upgrade, the following files are backed up:
|
|
10696
|
-
- openclaw.json
|
|
10697
|
-
- extensions/openclaw-lark/ (if present)
|
|
10698
|
-
- extensions/feishu-openclaw-plugin/ (if present)
|
|
10699
|
-
After the upgrade, the result is validated:
|
|
10700
|
-
- feishu.accounts bot count must not decrease
|
|
10701
|
-
- gateway config structure must remain valid (port/mode/bind/auth/trustedProxies)
|
|
10702
|
-
If the upgrade command fails, or validation fails, the backed-up files are
|
|
10703
|
-
restored to roll back the changes.
|
|
10704
|
-
|
|
10705
|
-
Execution is logged to /tmp/openclaw-diagnose/upgrade-lark-<runId>.log.
|
|
10706
|
-
|
|
10707
|
-
Output is a single JSON object on stdout:
|
|
10708
|
-
{ "ok": true, "stdout": "...", "stderr": "...", "logFile": "..." }
|
|
10709
|
-
{ "ok": false, "error": "...", "stderr": "...", "exitCode": 1,
|
|
10710
|
-
"rollbackOk": true, "validationError": "...", "logFile": "..." }
|
|
10711
|
-
|
|
10712
|
-
OPTIONS
|
|
10713
|
-
--scene=<scene> Telemetry label forwarded to Slardar only.
|
|
10714
|
-
Known values: PageUpgradeLark, etc. Custom strings accepted.
|
|
10715
|
-
--caller=<name> Optional metadata passed to innerapi.
|
|
10716
|
-
--trace-id=<id> Optional log-correlation id.
|
|
10717
|
-
|
|
10718
|
-
EXIT CODES
|
|
10719
|
-
0 Success: upgrade ran and all validations passed.
|
|
10720
|
-
1 Failure: npx error, validation failed, or git commit failed.
|
|
10721
|
-
File rollback was attempted (see rollbackOk in the JSON output).
|
|
10722
10661
|
`
|
|
10723
10662
|
},
|
|
10724
10663
|
{
|
|
@@ -10752,41 +10691,6 @@ EXAMPLES
|
|
|
10752
10691
|
${BIN} rules # all rules
|
|
10753
10692
|
${BIN} rules --rule=gateway # single rule
|
|
10754
10693
|
${BIN} rules --rule=gateway --rule=feishu_channel # multiple rules
|
|
10755
|
-
`
|
|
10756
|
-
},
|
|
10757
|
-
{
|
|
10758
|
-
name: "channels-probe",
|
|
10759
|
-
hidden: true,
|
|
10760
|
-
summary: "Check feishu channel health via openclaw channels status --probe",
|
|
10761
|
-
help: `USAGE
|
|
10762
|
-
${BIN} channels-probe [--timeout=<ms>]
|
|
10763
|
-
|
|
10764
|
-
DESCRIPTION
|
|
10765
|
-
Runs \`openclaw channels status --probe\` and returns a structured JSON
|
|
10766
|
-
summary of whether the current environment's feishu channels are
|
|
10767
|
-
configured and working correctly.
|
|
10768
|
-
|
|
10769
|
-
Output:
|
|
10770
|
-
{
|
|
10771
|
-
"available": true,
|
|
10772
|
-
"gatewayReachable": true,
|
|
10773
|
-
"accounts": [
|
|
10774
|
-
{ "id": "default", "bits": ["enabled","configured","running","works"],
|
|
10775
|
-
"isWorking": true, "raw": "- Feishu default: ..." }
|
|
10776
|
-
],
|
|
10777
|
-
"anyAccountWorking": true
|
|
10778
|
-
}
|
|
10779
|
-
|
|
10780
|
-
An account is considered working when:
|
|
10781
|
-
enabled ∧ configured ∧ ( works ∨ ( running ∧ no error: ∧ no probe failed ) )
|
|
10782
|
-
|
|
10783
|
-
"available": false means the CLI invocation itself failed (openclaw not
|
|
10784
|
-
found, gateway unreachable, or no parseable output returned).
|
|
10785
|
-
|
|
10786
|
-
OPTIONS
|
|
10787
|
-
--timeout=<ms> Max wait in milliseconds (default: 60000). The probe
|
|
10788
|
-
can hang indefinitely on openclaw v2026.4.x due to a
|
|
10789
|
-
missing per-request HTTP timeout — set this accordingly.
|
|
10790
10694
|
`
|
|
10791
10695
|
},
|
|
10792
10696
|
{
|
|
@@ -10807,8 +10711,7 @@ OPTIONS
|
|
|
10807
10711
|
--role=<role> Package role (e.g. template, config).
|
|
10808
10712
|
--name=<name> Package name within the role.
|
|
10809
10713
|
--dir=<dir> Target dir (defaults to dirname(pkg.installPath)).
|
|
10810
|
-
--
|
|
10811
|
-
--oss_file_map=... Pre-built OSS URL map (base64 JSON).
|
|
10714
|
+
--oss_file_map=... Pre-built OSS URL map (base64 JSON); skips innerapi.
|
|
10812
10715
|
`
|
|
10813
10716
|
}
|
|
10814
10717
|
];
|
|
@@ -10884,31 +10787,31 @@ function planVarsFields(opts = {}) {
|
|
|
10884
10787
|
*
|
|
10885
10788
|
* Per-command group needs:
|
|
10886
10789
|
*
|
|
10887
|
-
* doctor / check app
|
|
10888
|
-
* repair app + secrets
|
|
10889
|
-
* reset app + secrets + install + reset
|
|
10790
|
+
* doctor / check app + larkApps
|
|
10791
|
+
* repair app + secrets + larkApps
|
|
10792
|
+
* reset app + secrets + install + reset + larkApps
|
|
10890
10793
|
* install-* install only
|
|
10891
10794
|
*
|
|
10892
10795
|
* Empty result (`{}`) means "no group needed" — the CLI can skip the
|
|
10893
10796
|
* `fetchCtxViaInnerApi` call entirely and run with a synthetic empty ctx.
|
|
10894
|
-
* Happens e.g. when the user pinned `--rule=<key>` to a vars-free rule on
|
|
10895
|
-
* `doctor`.
|
|
10896
10797
|
*/
|
|
10897
10798
|
function planCtxPopulate(opts) {
|
|
10898
10799
|
if (opts.command === "install") return { install: true };
|
|
10899
10800
|
const populate = {};
|
|
10900
|
-
|
|
10801
|
+
if (planVarsFields({
|
|
10901
10802
|
disabled: opts.disabled,
|
|
10902
10803
|
onlyRules: opts.onlyRules,
|
|
10903
10804
|
profile: opts.profile
|
|
10904
|
-
});
|
|
10905
|
-
if (
|
|
10906
|
-
|
|
10907
|
-
|
|
10805
|
+
}).length > 0) populate.app = true;
|
|
10806
|
+
if (opts.command === "repair") {
|
|
10807
|
+
populate.secrets = true;
|
|
10808
|
+
populate.larkApps = true;
|
|
10809
|
+
} else if (opts.command === "reset") {
|
|
10908
10810
|
populate.secrets = true;
|
|
10909
10811
|
populate.install = true;
|
|
10910
10812
|
populate.reset = true;
|
|
10911
|
-
|
|
10813
|
+
populate.larkApps = true;
|
|
10814
|
+
} else if (opts.command === "doctor" || opts.command === "check") populate.larkApps = true;
|
|
10912
10815
|
return populate;
|
|
10913
10816
|
}
|
|
10914
10817
|
//#endregion
|
|
@@ -10962,411 +10865,11 @@ function reportDoctorRunToSlardar(opts) {
|
|
|
10962
10865
|
}
|
|
10963
10866
|
});
|
|
10964
10867
|
}
|
|
10965
|
-
function readLogFile(filePath) {
|
|
10966
|
-
try {
|
|
10967
|
-
return node_fs.default.readFileSync(filePath, "utf-8");
|
|
10968
|
-
} catch {
|
|
10969
|
-
return "";
|
|
10970
|
-
}
|
|
10971
|
-
}
|
|
10972
|
-
function reportUpgradeLarkToSlardar(opts) {
|
|
10973
|
-
console.error(`[slardar] upgrade_lark_run scene=${opts.scene ?? ""} success=${opts.success} exitCode=${opts.exitCode ?? ""} rollbackOk=${opts.rollbackOk ?? ""}`);
|
|
10974
|
-
const logContent = readLogFile(opts.logFile);
|
|
10975
|
-
reportTask({
|
|
10976
|
-
eventName: "upgrade_lark_run",
|
|
10977
|
-
durationMs: opts.durationMs,
|
|
10978
|
-
status: opts.success ? "success" : "failed",
|
|
10979
|
-
extraCategories: {
|
|
10980
|
-
scene: opts.scene ?? "",
|
|
10981
|
-
exit_code: String(opts.exitCode ?? ""),
|
|
10982
|
-
rollback_ok: opts.rollbackOk != null ? String(opts.rollbackOk) : "",
|
|
10983
|
-
validation_error: opts.validationError ?? "",
|
|
10984
|
-
error_msg: opts.error ?? "",
|
|
10985
|
-
log_content: logContent
|
|
10986
|
-
}
|
|
10987
|
-
});
|
|
10988
|
-
}
|
|
10989
|
-
//#endregion
|
|
10990
|
-
//#region src/upgrade-lark.ts
|
|
10991
|
-
/** Plugin directories under extensions/ that are backed up before upgrade */
|
|
10992
|
-
const FEISHU_PLUGIN_DIRS = ["openclaw-lark", "feishu-openclaw-plugin"];
|
|
10993
|
-
/** Version compat rule keys checked in the doctor output after install */
|
|
10994
|
-
const VERSION_COMPAT_RULE_KEYS = ["feishu_plugin_version_compat_lark", "feishu_plugin_version_compat_openclaw"];
|
|
10995
|
-
function backupFiles(opts) {
|
|
10996
|
-
const { workspaceDir, configPath, backupDir, log } = opts;
|
|
10997
|
-
try {
|
|
10998
|
-
node_fs.default.mkdirSync(backupDir, { recursive: true });
|
|
10999
|
-
log(`backup dir: ${backupDir}`);
|
|
11000
|
-
if (node_fs.default.existsSync(configPath)) {
|
|
11001
|
-
const stat = node_fs.default.statSync(configPath);
|
|
11002
|
-
node_fs.default.copyFileSync(configPath, node_path.default.join(backupDir, "openclaw.json"));
|
|
11003
|
-
log(` backed up: openclaw.json (${stat.size} bytes)`);
|
|
11004
|
-
} else log(` skipped: openclaw.json (not found)`);
|
|
11005
|
-
const extSrc = node_path.default.join(workspaceDir, "extensions");
|
|
11006
|
-
for (const pluginDir of FEISHU_PLUGIN_DIRS) {
|
|
11007
|
-
const src = node_path.default.join(extSrc, pluginDir);
|
|
11008
|
-
if (node_fs.default.existsSync(src)) {
|
|
11009
|
-
const dst = node_path.default.join(backupDir, "extensions", pluginDir);
|
|
11010
|
-
node_fs.default.cpSync(src, dst, { recursive: true });
|
|
11011
|
-
const version = readPkgVersion(node_path.default.join(src, "package.json"));
|
|
11012
|
-
log(` backed up: extensions/${pluginDir}${version ? ` (version: ${version})` : ""}`);
|
|
11013
|
-
} else log(` skipped: extensions/${pluginDir} (not found)`);
|
|
11014
|
-
}
|
|
11015
|
-
return { ok: true };
|
|
11016
|
-
} catch (e) {
|
|
11017
|
-
return {
|
|
11018
|
-
ok: false,
|
|
11019
|
-
error: `backup failed: ${e.message}`
|
|
11020
|
-
};
|
|
11021
|
-
}
|
|
11022
|
-
}
|
|
11023
|
-
function restoreFiles(opts) {
|
|
11024
|
-
const { workspaceDir, configPath, backupDir, log } = opts;
|
|
11025
|
-
try {
|
|
11026
|
-
const configBackup = node_path.default.join(backupDir, "openclaw.json");
|
|
11027
|
-
if (node_fs.default.existsSync(configBackup)) {
|
|
11028
|
-
node_fs.default.copyFileSync(configBackup, configPath);
|
|
11029
|
-
log(` restored: openclaw.json`);
|
|
11030
|
-
}
|
|
11031
|
-
const extDst = node_path.default.join(workspaceDir, "extensions");
|
|
11032
|
-
for (const pluginDir of FEISHU_PLUGIN_DIRS) {
|
|
11033
|
-
const backupSrc = node_path.default.join(backupDir, "extensions", pluginDir);
|
|
11034
|
-
if (node_fs.default.existsSync(backupSrc)) {
|
|
11035
|
-
const dst = node_path.default.join(extDst, pluginDir);
|
|
11036
|
-
if (node_fs.default.existsSync(dst)) node_fs.default.rmSync(dst, {
|
|
11037
|
-
recursive: true,
|
|
11038
|
-
force: true
|
|
11039
|
-
});
|
|
11040
|
-
node_fs.default.cpSync(backupSrc, dst, { recursive: true });
|
|
11041
|
-
log(` restored: extensions/${pluginDir}`);
|
|
11042
|
-
}
|
|
11043
|
-
}
|
|
11044
|
-
return true;
|
|
11045
|
-
} catch (e) {
|
|
11046
|
-
log(` restore error: ${e.message}`);
|
|
11047
|
-
return false;
|
|
11048
|
-
}
|
|
11049
|
-
}
|
|
11050
|
-
function readPkgVersion(pkgPath) {
|
|
11051
|
-
try {
|
|
11052
|
-
const pkg = JSON.parse(node_fs.default.readFileSync(pkgPath, "utf-8"));
|
|
11053
|
-
return typeof pkg.version === "string" ? pkg.version : null;
|
|
11054
|
-
} catch {
|
|
11055
|
-
return null;
|
|
11056
|
-
}
|
|
11057
|
-
}
|
|
11058
|
-
function snapshotVersions(cwd, log) {
|
|
11059
|
-
const ocResult = (0, node_child_process.spawnSync)("openclaw", ["--version"], {
|
|
11060
|
-
cwd,
|
|
11061
|
-
encoding: "utf-8",
|
|
11062
|
-
stdio: [
|
|
11063
|
-
"ignore",
|
|
11064
|
-
"pipe",
|
|
11065
|
-
"pipe"
|
|
11066
|
-
],
|
|
11067
|
-
timeout: 5e3
|
|
11068
|
-
});
|
|
11069
|
-
const ocRaw = (ocResult.stdout ?? "").trim() || (ocResult.stderr ?? "").trim();
|
|
11070
|
-
const extDir = node_path.default.join(cwd, "extensions");
|
|
11071
|
-
const larkPkg = node_path.default.join(extDir, "openclaw-lark", "package.json");
|
|
11072
|
-
const feishuPkg = node_path.default.join(extDir, "feishu-openclaw-plugin", "package.json");
|
|
11073
|
-
log(` version-check paths: ${larkPkg} [${node_fs.default.existsSync(larkPkg) ? "exists" : "missing"}]`);
|
|
11074
|
-
log(` version-check paths: ${feishuPkg} [${node_fs.default.existsSync(feishuPkg) ? "exists" : "missing"}]`);
|
|
11075
|
-
return {
|
|
11076
|
-
openclaw: ocRaw || null,
|
|
11077
|
-
openclawLark: readPkgVersion(larkPkg),
|
|
11078
|
-
feishuOpenclawPlugin: readPkgVersion(feishuPkg)
|
|
11079
|
-
};
|
|
11080
|
-
}
|
|
11081
|
-
function logVersionSnapshot(label, v, log) {
|
|
11082
|
-
log(`${label}: openclaw=${v.openclaw ?? "n/a"} openclaw-lark=${v.openclawLark ?? "n/a"} feishu-openclaw-plugin=${v.feishuOpenclawPlugin ?? "n/a"}`);
|
|
11083
|
-
}
|
|
11084
|
-
function countFeishuBots(configPath) {
|
|
11085
|
-
try {
|
|
11086
|
-
const raw = node_fs.default.readFileSync(configPath, "utf-8");
|
|
11087
|
-
const config = loadJSON5().parse(raw);
|
|
11088
|
-
const accounts = getNestedMap(config, "channels", "feishu", "accounts");
|
|
11089
|
-
if (accounts) return Object.keys(accounts).length;
|
|
11090
|
-
const feishu = getNestedMap(config, "channels", "feishu");
|
|
11091
|
-
return typeof feishu?.appId === "string" && feishu.appId ? 1 : 0;
|
|
11092
|
-
} catch {
|
|
11093
|
-
return 0;
|
|
11094
|
-
}
|
|
11095
|
-
}
|
|
11096
|
-
/**
|
|
11097
|
-
* Parse doctor stdout (first JSON line) and return an error string if any
|
|
11098
|
-
* version compat rule failed. Returns null on parse failure so a broken doctor
|
|
11099
|
-
* output does not block the install.
|
|
11100
|
-
*/
|
|
11101
|
-
function checkVersionCompatFromDoctorOutput(stdout, log) {
|
|
11102
|
-
const firstLine = stdout.split("\n")[0]?.trim();
|
|
11103
|
-
if (!firstLine) {
|
|
11104
|
-
log(" doctor(compat): empty output, skipping version compat check");
|
|
11105
|
-
return null;
|
|
11106
|
-
}
|
|
11107
|
-
try {
|
|
11108
|
-
const report = JSON.parse(firstLine);
|
|
11109
|
-
for (const outcome of report.results) if (VERSION_COMPAT_RULE_KEYS.includes(outcome.rule)) {
|
|
11110
|
-
if (outcome.status === "failed" || outcome.status === "still-broken" || outcome.status === "error") return `version compat rule ${outcome.rule} ${outcome.status}: ${outcome.message ?? "(no message)"}`;
|
|
11111
|
-
}
|
|
11112
|
-
return null;
|
|
11113
|
-
} catch (e) {
|
|
11114
|
-
log(` doctor(compat): failed to parse output — ${e.message}`);
|
|
11115
|
-
return null;
|
|
11116
|
-
}
|
|
11117
|
-
}
|
|
11118
|
-
/** Run channels probe, log results, and return the result. Never throws. */
|
|
11119
|
-
function probeChannels(label, log, timeoutMs) {
|
|
11120
|
-
try {
|
|
11121
|
-
const r = runChannelsProbe(timeoutMs);
|
|
11122
|
-
log(` ${label} available=${r.available} anyAccountWorking=${r.anyAccountWorking}`);
|
|
11123
|
-
if (r.error) log(` ${label} error: ${r.error}`);
|
|
11124
|
-
if (r.gatewayReachable != null) log(` ${label} gatewayReachable: ${r.gatewayReachable}`);
|
|
11125
|
-
for (const acct of r.accounts ?? []) log(` ${label} account ${acct.id}: isWorking=${acct.isWorking} bits=[${acct.bits.join(",")}]`);
|
|
11126
|
-
return r;
|
|
11127
|
-
} catch (e) {
|
|
11128
|
-
log(` ${label} channels probe threw: ${e.message}`);
|
|
11129
|
-
return {
|
|
11130
|
-
available: false,
|
|
11131
|
-
accounts: [],
|
|
11132
|
-
anyAccountWorking: false
|
|
11133
|
-
};
|
|
11134
|
-
}
|
|
11135
|
-
}
|
|
11136
|
-
function runUpgradeLark(opts) {
|
|
11137
|
-
const cwd = opts.cwd ?? "/home/gem/workspace/agent";
|
|
11138
|
-
const configPath = opts.configPath ?? CONFIG_PATH;
|
|
11139
|
-
const logFile = upgradeLarkLogFile(opts.runId);
|
|
11140
|
-
const log = makeLogger(logFile);
|
|
11141
|
-
const fsOpts = {
|
|
11142
|
-
workspaceDir: cwd,
|
|
11143
|
-
configPath,
|
|
11144
|
-
backupDir: node_path.default.join(opts.backupBaseDir ?? "/tmp/openclaw-diagnose", `upgrade-lark-backup-${opts.runId}`),
|
|
11145
|
-
log
|
|
11146
|
-
};
|
|
11147
|
-
const cliScript = opts.cliScript ?? process.argv[1];
|
|
11148
|
-
const statusCheckDelayMs = opts.statusCheckDelayMs ?? 5e3;
|
|
11149
|
-
log(`${"=".repeat(60)}`);
|
|
11150
|
-
log(`upgrade-lark started runId=${opts.runId}`);
|
|
11151
|
-
log(` cwd : ${cwd}`);
|
|
11152
|
-
log(` configPath : ${configPath}`);
|
|
11153
|
-
log(`${"=".repeat(60)}`);
|
|
11154
|
-
log("");
|
|
11155
|
-
log("── [Pre-check A] channels probe(升级前)────────────────");
|
|
11156
|
-
const beforeChannels = probeChannels("before", log, 3e4);
|
|
11157
|
-
log("");
|
|
11158
|
-
log("── [Pre-check B] 版本兼容预检 ───────────────────────────");
|
|
11159
|
-
let versionIncompatible = false;
|
|
11160
|
-
try {
|
|
11161
|
-
const rawConfig = node_fs.default.readFileSync(configPath, "utf-8");
|
|
11162
|
-
versionIncompatible = needsLarkUpgrade({
|
|
11163
|
-
config: loadJSON5().parse(rawConfig),
|
|
11164
|
-
configPath,
|
|
11165
|
-
vars: {},
|
|
11166
|
-
providerDeps: {
|
|
11167
|
-
usesMiaodaProvider: false,
|
|
11168
|
-
usesMiaodaSecretProvider: false
|
|
11169
|
-
}
|
|
11170
|
-
});
|
|
11171
|
-
log(` version-compat pre-check: ${versionIncompatible ? "NEEDS_UPGRADE" : "ok"}`);
|
|
11172
|
-
} catch (e) {
|
|
11173
|
-
log(` version-compat pre-check error: ${e.message} — treating as needs-upgrade`);
|
|
11174
|
-
versionIncompatible = true;
|
|
11175
|
-
}
|
|
11176
|
-
const feishuConfigInvalid = beforeChannels.feishuConfigInvalid;
|
|
11177
|
-
log(` feishu config invalid : ${feishuConfigInvalid}`);
|
|
11178
|
-
log("");
|
|
11179
|
-
log("── [Gate] 升级前置条件检查 ───────────────────────────────");
|
|
11180
|
-
log(` versionIncompatible : ${versionIncompatible}`);
|
|
11181
|
-
log(` feishuConfigInvalid : ${feishuConfigInvalid}`);
|
|
11182
|
-
log(` channels working before: ${beforeChannels.anyAccountWorking}`);
|
|
11183
|
-
if (!(versionIncompatible || feishuConfigInvalid)) {
|
|
11184
|
-
const reason = "version compatible and feishu channel config valid — upgrade not needed";
|
|
11185
|
-
log(` SKIP: ${reason}`);
|
|
11186
|
-
log(`${"=".repeat(60)}`);
|
|
11187
|
-
log("upgrade-lark skipped (pre-check gate)");
|
|
11188
|
-
log(`${"=".repeat(60)}`);
|
|
11189
|
-
return {
|
|
11190
|
-
ok: true,
|
|
11191
|
-
skipped: true,
|
|
11192
|
-
skipReason: reason,
|
|
11193
|
-
logFile
|
|
11194
|
-
};
|
|
11195
|
-
}
|
|
11196
|
-
if (beforeChannels.anyAccountWorking) {
|
|
11197
|
-
const reason = "channels are working — upgrade not needed (issue detected but system is functional)";
|
|
11198
|
-
log(` SKIP: ${reason}`);
|
|
11199
|
-
log(`${"=".repeat(60)}`);
|
|
11200
|
-
log("upgrade-lark skipped (pre-check gate)");
|
|
11201
|
-
log(`${"=".repeat(60)}`);
|
|
11202
|
-
return {
|
|
11203
|
-
ok: true,
|
|
11204
|
-
skipped: true,
|
|
11205
|
-
skipReason: reason,
|
|
11206
|
-
logFile
|
|
11207
|
-
};
|
|
11208
|
-
}
|
|
11209
|
-
log(` PROCEED: requiresLarkUpgrade=true (version=${versionIncompatible}, feishuConfig=${feishuConfigInvalid}) AND channels not working → running upgrade`);
|
|
11210
|
-
log("");
|
|
11211
|
-
log("── [1/6] 文件备份 ────────────────────────────────────────");
|
|
11212
|
-
log(`before-state: botCount=${countFeishuBots(configPath)}`);
|
|
11213
|
-
const backup = backupFiles(fsOpts);
|
|
11214
|
-
if (!backup.ok) {
|
|
11215
|
-
log(`ERROR: ${backup.error}`);
|
|
11216
|
-
return {
|
|
11217
|
-
ok: false,
|
|
11218
|
-
error: backup.error,
|
|
11219
|
-
logFile
|
|
11220
|
-
};
|
|
11221
|
-
}
|
|
11222
|
-
log("backup: ok");
|
|
11223
|
-
logVersionSnapshot("before-versions", snapshotVersions(cwd, log), log);
|
|
11224
|
-
log("");
|
|
11225
|
-
log("── [2/6] 清理本地 openclaw shim ─────────────────────────");
|
|
11226
|
-
const localOpenclawBin = node_path.default.join(cwd, "node_modules", ".bin", "openclaw");
|
|
11227
|
-
if (node_fs.default.existsSync(localOpenclawBin)) try {
|
|
11228
|
-
node_fs.default.rmSync(localOpenclawBin);
|
|
11229
|
-
log(` removed: ${localOpenclawBin}`);
|
|
11230
|
-
} catch (e) {
|
|
11231
|
-
log(` WARN: failed to remove ${localOpenclawBin}: ${e.message}`);
|
|
11232
|
-
}
|
|
11233
|
-
else log(` skipped: ${localOpenclawBin} (not found)`);
|
|
11234
|
-
log("");
|
|
11235
|
-
log("── [3/6] npx install (@larksuite/openclaw-lark-tools update) ──");
|
|
11236
|
-
const npxResult = (0, node_child_process.spawnSync)("npx", [
|
|
11237
|
-
"-y",
|
|
11238
|
-
"@larksuite/openclaw-lark-tools",
|
|
11239
|
-
"update"
|
|
11240
|
-
], {
|
|
11241
|
-
cwd,
|
|
11242
|
-
encoding: "utf-8",
|
|
11243
|
-
stdio: [
|
|
11244
|
-
"ignore",
|
|
11245
|
-
"pipe",
|
|
11246
|
-
"pipe"
|
|
11247
|
-
],
|
|
11248
|
-
timeout: 12e4
|
|
11249
|
-
});
|
|
11250
|
-
const npxStdout = npxResult.stdout?.trim() ?? "";
|
|
11251
|
-
const npxStderr = npxResult.stderr?.trim() ?? "";
|
|
11252
|
-
const npxExitCode = npxResult.status ?? 1;
|
|
11253
|
-
if (npxStdout) log(`npx stdout:\n${npxStdout}`);
|
|
11254
|
-
if (npxStderr) log(`npx stderr:\n${npxStderr}`);
|
|
11255
|
-
log(`npx exit: ${npxExitCode}${npxResult.error ? ` error: ${npxResult.error.message}` : ""}`);
|
|
11256
|
-
if (statusCheckDelayMs > 0) {
|
|
11257
|
-
log("");
|
|
11258
|
-
log(`── 等待 ${statusCheckDelayMs / 1e3}s(让 openclaw 服务完成重启) ─────────────`);
|
|
11259
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, statusCheckDelayMs);
|
|
11260
|
-
log("wait done");
|
|
11261
|
-
}
|
|
11262
|
-
const doRollback = (reason) => {
|
|
11263
|
-
log(`ERROR: ${reason}`);
|
|
11264
|
-
const rollbackOk = restoreFiles(fsOpts);
|
|
11265
|
-
log(`rollback: ${rollbackOk ? "ok" : "FAILED"}`);
|
|
11266
|
-
return {
|
|
11267
|
-
ok: false,
|
|
11268
|
-
error: reason,
|
|
11269
|
-
validationError: reason,
|
|
11270
|
-
stdout: npxStdout,
|
|
11271
|
-
stderr: npxStderr,
|
|
11272
|
-
exitCode: npxExitCode,
|
|
11273
|
-
rollbackOk,
|
|
11274
|
-
logFile
|
|
11275
|
-
};
|
|
11276
|
-
};
|
|
11277
|
-
log("");
|
|
11278
|
-
log("── [4/6] 插件安装检查 + 版本兼容校验 ───────────────────");
|
|
11279
|
-
const larkExtDir = node_path.default.join(cwd, "extensions", "openclaw-lark");
|
|
11280
|
-
const larkVersion = readPkgVersion(node_path.default.join(larkExtDir, "package.json"));
|
|
11281
|
-
log(` extensions/openclaw-lark: ${node_fs.default.existsSync(larkExtDir) ? "exists" : "missing"}, version=${larkVersion ?? "n/a"}`);
|
|
11282
|
-
if (!node_fs.default.existsSync(larkExtDir)) return doRollback("extensions/openclaw-lark not found after install");
|
|
11283
|
-
if (!larkVersion) return doRollback("extensions/openclaw-lark/package.json has no valid version after install");
|
|
11284
|
-
log(" running doctor version compat check...");
|
|
11285
|
-
const compatArgs = ["doctor"];
|
|
11286
|
-
if (opts.scene) compatArgs.push(`--scene=${opts.scene}`);
|
|
11287
|
-
const compatResult = (0, node_child_process.spawnSync)(process.execPath, [cliScript, ...compatArgs], {
|
|
11288
|
-
cwd,
|
|
11289
|
-
encoding: "utf-8",
|
|
11290
|
-
stdio: [
|
|
11291
|
-
"ignore",
|
|
11292
|
-
"pipe",
|
|
11293
|
-
"pipe"
|
|
11294
|
-
],
|
|
11295
|
-
timeout: 6e4,
|
|
11296
|
-
env: process.env
|
|
11297
|
-
});
|
|
11298
|
-
if (compatResult.stdout?.trim()) log(`doctor(compat) stdout:\n${compatResult.stdout.trim()}`);
|
|
11299
|
-
if (compatResult.stderr?.trim()) log(`doctor(compat) stderr:\n${compatResult.stderr.trim()}`);
|
|
11300
|
-
log(`doctor(compat) exit: ${compatResult.status ?? "null"}${compatResult.error ? ` error: ${compatResult.error.message}` : ""}`);
|
|
11301
|
-
const compatError = checkVersionCompatFromDoctorOutput(compatResult.stdout?.trim() ?? "", log);
|
|
11302
|
-
if (compatError) return doRollback(compatError);
|
|
11303
|
-
log(" version compat: ok");
|
|
11304
|
-
logVersionSnapshot("after-versions", snapshotVersions(cwd, log), log);
|
|
11305
|
-
log("");
|
|
11306
|
-
log("── [5/6] channels probe(升级后)────────────────────────");
|
|
11307
|
-
if (!probeChannels("after", log, 3e4).anyAccountWorking) {
|
|
11308
|
-
log(" channels: not working before or after install — pre-existing issue, skipping rollback");
|
|
11309
|
-
return {
|
|
11310
|
-
ok: false,
|
|
11311
|
-
error: "channels probe: no working account (pre-existing issue, not caused by install)",
|
|
11312
|
-
validationError: "channels probe: no working account (pre-existing)",
|
|
11313
|
-
stdout: npxStdout,
|
|
11314
|
-
stderr: npxStderr,
|
|
11315
|
-
exitCode: npxExitCode,
|
|
11316
|
-
logFile
|
|
11317
|
-
};
|
|
11318
|
-
}
|
|
11319
|
-
log(" channels: ok (recovered after install)");
|
|
11320
|
-
log("");
|
|
11321
|
-
log("── [6/6] doctor --fix ────────────────────────────────────");
|
|
11322
|
-
const fixArgs = ["doctor", "--fix"];
|
|
11323
|
-
if (opts.scene) fixArgs.push(`--scene=${opts.scene}`);
|
|
11324
|
-
const fixResult = (0, node_child_process.spawnSync)(process.execPath, [cliScript, ...fixArgs], {
|
|
11325
|
-
cwd,
|
|
11326
|
-
encoding: "utf-8",
|
|
11327
|
-
stdio: [
|
|
11328
|
-
"ignore",
|
|
11329
|
-
"pipe",
|
|
11330
|
-
"pipe"
|
|
11331
|
-
],
|
|
11332
|
-
timeout: 6e4,
|
|
11333
|
-
env: process.env
|
|
11334
|
-
});
|
|
11335
|
-
if (fixResult.stdout?.trim()) log(`doctor(fix) stdout:\n${fixResult.stdout.trim()}`);
|
|
11336
|
-
if (fixResult.stderr?.trim()) log(`doctor(fix) stderr:\n${fixResult.stderr.trim()}`);
|
|
11337
|
-
log(`doctor(fix) exit: ${fixResult.status ?? "null"}${fixResult.error ? ` error: ${fixResult.error.message}` : ""}`);
|
|
11338
|
-
log("");
|
|
11339
|
-
log(`${"=".repeat(60)}`);
|
|
11340
|
-
log("upgrade-lark completed successfully");
|
|
11341
|
-
log(`${"=".repeat(60)}`);
|
|
11342
|
-
return {
|
|
11343
|
-
ok: true,
|
|
11344
|
-
stdout: npxStdout,
|
|
11345
|
-
stderr: npxStderr,
|
|
11346
|
-
exitCode: npxExitCode,
|
|
11347
|
-
logFile
|
|
11348
|
-
};
|
|
11349
|
-
}
|
|
11350
10868
|
//#endregion
|
|
11351
10869
|
//#region src/index.ts
|
|
11352
10870
|
const args = node_process.default.argv.slice(2);
|
|
11353
10871
|
const mode = args.find((a) => !a.startsWith("-"));
|
|
11354
10872
|
/**
|
|
11355
|
-
* Decode `--ctx=<base64>` into an opaque JSON object. Returns undefined when
|
|
11356
|
-
* the flag isn't present — the caller decides whether to fall back to the
|
|
11357
|
-
* innerapi or to error out.
|
|
11358
|
-
*
|
|
11359
|
-
* The object's shape is not enforced here; downstream code consumes it via
|
|
11360
|
-
* either `normalizeCtx()` (new path) or direct field access for the legacy
|
|
11361
|
-
* check/repair/reset contract still used by sandbox_console push.
|
|
11362
|
-
*/
|
|
11363
|
-
function parseCtxFlag(args) {
|
|
11364
|
-
const ctxArg = args.find((a) => a.startsWith("--ctx="));
|
|
11365
|
-
if (!ctxArg) return void 0;
|
|
11366
|
-
const b64 = ctxArg.slice(6);
|
|
11367
|
-
return JSON.parse(Buffer.from(b64, "base64").toString("utf-8"));
|
|
11368
|
-
}
|
|
11369
|
-
/**
|
|
11370
10873
|
* Pull the first non-flag positional after the mode name.
|
|
11371
10874
|
* (The mode itself is args[0] in the filtered set, so we skip index 0.)
|
|
11372
10875
|
*/
|
|
@@ -11394,8 +10897,8 @@ function getMultiFlag(args, name) {
|
|
|
11394
10897
|
* case but is no longer consulted.
|
|
11395
10898
|
*/
|
|
11396
10899
|
async function reportRun(command, rc, _raw, invocation, durationMs, outcome, slardar = {
|
|
11397
|
-
scene,
|
|
11398
|
-
profile,
|
|
10900
|
+
scene: void 0,
|
|
10901
|
+
profile: "standard",
|
|
11399
10902
|
fix: false
|
|
11400
10903
|
}) {
|
|
11401
10904
|
console.error(`${command}: telemetry calling report_cli_run`);
|
|
@@ -11459,7 +10962,7 @@ async function main() {
|
|
|
11459
10962
|
console.error(`${mode}: begin argv=[${args.join(" ")}] version=${getVersion()} traceId=${traceId ?? "-"} caller=${caller ?? "-"} runIdGenerated=${rc.generated}`);
|
|
11460
10963
|
switch (mode) {
|
|
11461
10964
|
case "check": {
|
|
11462
|
-
const raw =
|
|
10965
|
+
const raw = await fetchCtxViaInnerApi({
|
|
11463
10966
|
populate: planCtxPopulate({
|
|
11464
10967
|
command: "check",
|
|
11465
10968
|
profile
|
|
@@ -11484,7 +10987,7 @@ async function main() {
|
|
|
11484
10987
|
break;
|
|
11485
10988
|
}
|
|
11486
10989
|
case "repair": {
|
|
11487
|
-
const raw =
|
|
10990
|
+
const raw = await fetchCtxViaInnerApi({
|
|
11488
10991
|
populate: planCtxPopulate({
|
|
11489
10992
|
command: "repair",
|
|
11490
10993
|
profile
|
|
@@ -11555,27 +11058,15 @@ async function main() {
|
|
|
11555
11058
|
break;
|
|
11556
11059
|
}
|
|
11557
11060
|
case "reset":
|
|
11558
|
-
if (args.includes("--async"))
|
|
11559
|
-
|
|
11560
|
-
let ctxBase64;
|
|
11561
|
-
if (ctxArg) ctxBase64 = ctxArg.slice(6);
|
|
11562
|
-
else {
|
|
11563
|
-
const fetched = await fetchCtxViaInnerApi({
|
|
11564
|
-
populate: planCtxPopulate({ command: "reset" }),
|
|
11565
|
-
caller,
|
|
11566
|
-
traceId
|
|
11567
|
-
});
|
|
11568
|
-
ctxBase64 = Buffer.from(JSON.stringify(fetched), "utf-8").toString("base64");
|
|
11569
|
-
}
|
|
11570
|
-
console.log(JSON.stringify(startAsyncReset(ctxBase64)));
|
|
11571
|
-
} else if (args.includes("--worker")) {
|
|
11061
|
+
if (args.includes("--async")) console.log(JSON.stringify(startAsyncReset()));
|
|
11062
|
+
else if (args.includes("--worker")) {
|
|
11572
11063
|
const taskId = args.find((a) => a.startsWith("--task-id="))?.slice(10);
|
|
11573
11064
|
if (!taskId) {
|
|
11574
11065
|
console.error("Error: --task-id=<id> is required for worker");
|
|
11575
11066
|
node_process.default.exit(1);
|
|
11576
11067
|
}
|
|
11577
11068
|
const resultFile = resetResultFile(taskId);
|
|
11578
|
-
const raw =
|
|
11069
|
+
const raw = await fetchCtxViaInnerApi({
|
|
11579
11070
|
populate: planCtxPopulate({ command: "reset" }),
|
|
11580
11071
|
caller,
|
|
11581
11072
|
traceId
|
|
@@ -11599,7 +11090,7 @@ async function main() {
|
|
|
11599
11090
|
return;
|
|
11600
11091
|
}
|
|
11601
11092
|
} else {
|
|
11602
|
-
console.error("Usage: reset --async
|
|
11093
|
+
console.error("Usage: reset --async | reset --worker --task-id=<id>");
|
|
11603
11094
|
node_process.default.exit(1);
|
|
11604
11095
|
}
|
|
11605
11096
|
break;
|
|
@@ -11615,14 +11106,14 @@ async function main() {
|
|
|
11615
11106
|
case "install-openclaw": {
|
|
11616
11107
|
const tag = getPositionalTag(args, "install-openclaw");
|
|
11617
11108
|
if (!tag) {
|
|
11618
|
-
console.error("Usage: install-openclaw <tag> [--
|
|
11109
|
+
console.error("Usage: install-openclaw <tag> [--oss_file_map=<base64>]");
|
|
11619
11110
|
node_process.default.exit(1);
|
|
11620
11111
|
}
|
|
11621
11112
|
const ossFileMapFlag = getFlag(args, "oss_file_map");
|
|
11622
11113
|
let installOssFileMap;
|
|
11623
11114
|
let rawForTelemetry;
|
|
11624
11115
|
if (!ossFileMapFlag) {
|
|
11625
|
-
rawForTelemetry =
|
|
11116
|
+
rawForTelemetry = await fetchCtxViaInnerApi({
|
|
11626
11117
|
populate: planCtxPopulate({ command: "install" }),
|
|
11627
11118
|
caller,
|
|
11628
11119
|
traceId
|
|
@@ -11657,7 +11148,7 @@ async function main() {
|
|
|
11657
11148
|
case "install-extension": {
|
|
11658
11149
|
const tag = getPositionalTag(args, "install-extension");
|
|
11659
11150
|
if (!tag) {
|
|
11660
|
-
console.error("Usage: install-extension <tag> (--all | --extension=<name>...) [--home_base=<dir>] [--config_path=<path>] [--skip-config-update] [--
|
|
11151
|
+
console.error("Usage: install-extension <tag> (--all | --extension=<name>...) [--home_base=<dir>] [--config_path=<path>] [--skip-config-update] [--oss_file_map=<base64>]");
|
|
11661
11152
|
node_process.default.exit(1);
|
|
11662
11153
|
}
|
|
11663
11154
|
const all = args.includes("--all");
|
|
@@ -11669,7 +11160,7 @@ async function main() {
|
|
|
11669
11160
|
let installOssFileMap;
|
|
11670
11161
|
let rawForTelemetry;
|
|
11671
11162
|
if (!ossFileMapFlag) {
|
|
11672
|
-
rawForTelemetry =
|
|
11163
|
+
rawForTelemetry = await fetchCtxViaInnerApi({
|
|
11673
11164
|
populate: planCtxPopulate({ command: "install" }),
|
|
11674
11165
|
caller,
|
|
11675
11166
|
traceId
|
|
@@ -11715,12 +11206,12 @@ async function main() {
|
|
|
11715
11206
|
case "install-cli": {
|
|
11716
11207
|
const tag = getPositionalTag(args, "install-cli");
|
|
11717
11208
|
if (!tag) {
|
|
11718
|
-
console.error("Usage: install-cli <tag> --cli=<name>... [--home_base=<dir>] [--
|
|
11209
|
+
console.error("Usage: install-cli <tag> --cli=<name>... [--home_base=<dir>] [--oss_file_map=<base64>]");
|
|
11719
11210
|
node_process.default.exit(1);
|
|
11720
11211
|
}
|
|
11721
11212
|
const names = getMultiFlag(args, "cli");
|
|
11722
11213
|
if (names.length === 0) {
|
|
11723
|
-
console.error("Usage: install-cli <tag> --cli=<name>... [--home_base=<dir>] [--
|
|
11214
|
+
console.error("Usage: install-cli <tag> --cli=<name>... [--home_base=<dir>] [--oss_file_map=<base64>]");
|
|
11724
11215
|
node_process.default.exit(1);
|
|
11725
11216
|
}
|
|
11726
11217
|
const homeBase = getFlag(args, "home_base");
|
|
@@ -11728,7 +11219,7 @@ async function main() {
|
|
|
11728
11219
|
let installOssFileMap;
|
|
11729
11220
|
let rawForTelemetry;
|
|
11730
11221
|
if (!ossFileMapFlag) {
|
|
11731
|
-
rawForTelemetry =
|
|
11222
|
+
rawForTelemetry = await fetchCtxViaInnerApi({
|
|
11732
11223
|
populate: planCtxPopulate({ command: "install" }),
|
|
11733
11224
|
caller,
|
|
11734
11225
|
traceId
|
|
@@ -11776,7 +11267,7 @@ async function main() {
|
|
|
11776
11267
|
case "download-resource": {
|
|
11777
11268
|
const tag = getPositionalTag(args, "download-resource");
|
|
11778
11269
|
if (!tag) {
|
|
11779
|
-
console.error("Usage: download-resource <tag> --role=<role> --name=<name> [--dir=<dir>] [--
|
|
11270
|
+
console.error("Usage: download-resource <tag> --role=<role> --name=<name> [--dir=<dir>] [--oss_file_map=<base64>]");
|
|
11780
11271
|
node_process.default.exit(1);
|
|
11781
11272
|
}
|
|
11782
11273
|
const role = getFlag(args, "role");
|
|
@@ -11790,7 +11281,7 @@ async function main() {
|
|
|
11790
11281
|
let installOssFileMap;
|
|
11791
11282
|
let rawForTelemetry;
|
|
11792
11283
|
if (!ossFileMapFlag) {
|
|
11793
|
-
rawForTelemetry =
|
|
11284
|
+
rawForTelemetry = await fetchCtxViaInnerApi({
|
|
11794
11285
|
populate: planCtxPopulate({ command: "install" }),
|
|
11795
11286
|
caller,
|
|
11796
11287
|
traceId
|
|
@@ -11864,50 +11355,6 @@ async function main() {
|
|
|
11864
11355
|
if (!result.ok) node_process.default.exit(1);
|
|
11865
11356
|
break;
|
|
11866
11357
|
}
|
|
11867
|
-
case "upgrade-lark": {
|
|
11868
|
-
const result = runUpgradeLark({
|
|
11869
|
-
runId: rc.runId,
|
|
11870
|
-
scene
|
|
11871
|
-
});
|
|
11872
|
-
const upgradeDurationMs = Date.now() - t0;
|
|
11873
|
-
console.log(JSON.stringify(result));
|
|
11874
|
-
reportUpgradeLarkToSlardar({
|
|
11875
|
-
scene,
|
|
11876
|
-
durationMs: upgradeDurationMs,
|
|
11877
|
-
success: result.ok,
|
|
11878
|
-
logFile: result.logFile,
|
|
11879
|
-
exitCode: result.exitCode,
|
|
11880
|
-
rollbackOk: result.rollbackOk,
|
|
11881
|
-
validationError: result.validationError,
|
|
11882
|
-
error: result.error
|
|
11883
|
-
});
|
|
11884
|
-
try {
|
|
11885
|
-
await reportCliRun({
|
|
11886
|
-
command: "upgrade-lark",
|
|
11887
|
-
runId: rc.runId,
|
|
11888
|
-
version: getVersion(),
|
|
11889
|
-
invocation: args.join(" "),
|
|
11890
|
-
durationMs: upgradeDurationMs,
|
|
11891
|
-
caller: rc.caller,
|
|
11892
|
-
traceId: rc.traceId,
|
|
11893
|
-
success: result.ok,
|
|
11894
|
-
result,
|
|
11895
|
-
error: result.ok ? void 0 : { message: result.error ?? "upgrade-lark failed" }
|
|
11896
|
-
});
|
|
11897
|
-
} catch (e) {
|
|
11898
|
-
console.error(`[telemetry] reportCliRun failed: ${e.message}`);
|
|
11899
|
-
}
|
|
11900
|
-
if (!result.ok) {
|
|
11901
|
-
node_process.default.exitCode = 1;
|
|
11902
|
-
return;
|
|
11903
|
-
}
|
|
11904
|
-
break;
|
|
11905
|
-
}
|
|
11906
|
-
case "channels-probe": {
|
|
11907
|
-
const result = runChannelsProbe(getFlag(args, "timeout") ? Number(getFlag(args, "timeout")) : void 0);
|
|
11908
|
-
console.log(JSON.stringify(result));
|
|
11909
|
-
break;
|
|
11910
|
-
}
|
|
11911
11358
|
default:
|
|
11912
11359
|
node_process.default.stderr.write(`Unknown command: ${mode}\n\n`);
|
|
11913
11360
|
node_process.default.stderr.write(formatTopLevelHelp(helpFlags.expert));
|
package/package.json
CHANGED