@lark-apaas/openclaw-scripts-diagnose-cli 0.1.13-alpha.7 → 0.1.13-alpha.8

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.
Files changed (2) hide show
  1. package/dist/index.cjs +58 -34
  2. 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.13-alpha.7";
55
+ return "0.1.13-alpha.8";
56
56
  }
57
57
  //#endregion
58
58
  //#region src/rule-engine/base.ts
@@ -3560,31 +3560,31 @@ CleanupInstallBackupDirsRule = __decorate([Rule({
3560
3560
  * Ensures each bot account's channel config is correct:
3561
3561
  * 1. `allowFrom` contains its own `creatorOpenID` from larkApps
3562
3562
  * 2. `appSecret` is either the canonical provider-ref or matches larkApps plaintext
3563
+ *
3564
+ * Covers both multi-account (channels.feishu.accounts) and single-account
3565
+ * (channels.feishu.appId + allowFrom at top level) layouts.
3563
3566
  */
3564
3567
  let FeishuBotChannelConfigRule = class FeishuBotChannelConfigRule extends DiagnoseRule {
3565
3568
  validate(ctx) {
3566
3569
  const larkApps = ctx.vars.larkApps;
3567
3570
  if (!larkApps || larkApps.length === 0) return { pass: true };
3568
- const accounts = asRecord(getNestedMap(ctx.config, "channels", "feishu")?.accounts);
3569
- if (!accounts) return { pass: true };
3571
+ const feishu = asRecord(getNestedMap(ctx.config, "channels", "feishu"));
3572
+ if (!feishu) return { pass: true };
3570
3573
  const issues = [];
3571
- for (const [accountId, account] of Object.entries(accounts)) {
3574
+ const accounts = asRecord(feishu.accounts);
3575
+ if (accounts) for (const [accountId, account] of Object.entries(accounts)) {
3572
3576
  const bot = asRecord(account);
3573
3577
  if (!bot) continue;
3574
3578
  const appId = bot.appId;
3575
3579
  if (typeof appId !== "string" || !appId.startsWith("cli_")) continue;
3576
3580
  const larkApp = larkApps.find((e) => e.larkAppID === appId);
3577
3581
  if (!larkApp) continue;
3578
- const creatorOpenID = larkApp.creatorOpenID;
3579
- if (typeof creatorOpenID === "string" && creatorOpenID !== "") {
3580
- if (!(Array.isArray(bot.allowFrom) ? bot.allowFrom : []).includes(creatorOpenID)) issues.push(`${accountId} allowFrom missing creatorOpenID ${creatorOpenID.length > 8 ? creatorOpenID.slice(0, 4) + "***" + creatorOpenID.slice(-4) : "***"}`);
3581
- }
3582
- const secret = bot.appSecret;
3583
- if (typeof secret === "object" && secret !== null && !Array.isArray(secret)) {
3584
- if (!matchMap(secret, DEFAULT_FEISHU_APP_SECRET)) issues.push(`${accountId} appSecret is a provider-ref but not the canonical one`);
3585
- } else if (typeof secret === "string") {
3586
- if (secret !== larkApp.appSecret) issues.push(`${accountId} appSecret plaintext mismatch`);
3587
- } else issues.push(`${accountId} appSecret has unexpected type`);
3582
+ this.checkBot(accountId, bot, larkApp, issues);
3583
+ }
3584
+ const singleAppId = feishu.appId;
3585
+ if (typeof singleAppId === "string" && singleAppId.startsWith("cli_") && !accounts) {
3586
+ const larkApp = larkApps.find((e) => e.larkAppID === singleAppId);
3587
+ if (larkApp) this.checkBot("feishu", feishu, larkApp, issues);
3588
3588
  }
3589
3589
  if (issues.length === 0) return { pass: true };
3590
3590
  return {
@@ -3592,40 +3592,64 @@ let FeishuBotChannelConfigRule = class FeishuBotChannelConfigRule extends Diagno
3592
3592
  message: issues.join("; ")
3593
3593
  };
3594
3594
  }
3595
+ /** Check a single bot entry (either an account object or the feishu channel itself). */
3596
+ checkBot(label, bot, larkApp, issues) {
3597
+ const creatorOpenID = larkApp.creatorOpenID;
3598
+ const allowFrom = Array.isArray(bot.allowFrom) ? bot.allowFrom : [];
3599
+ if (typeof creatorOpenID === "string" && creatorOpenID !== "") {
3600
+ if (!allowFrom.includes(creatorOpenID)) issues.push(`${label} allowFrom missing creatorOpenID ${creatorOpenID.length > 8 ? creatorOpenID.slice(0, 4) + "***" + creatorOpenID.slice(-4) : "***"}`);
3601
+ } else if (allowFrom.length === 0) issues.push(`${label} allowFrom is empty (creatorOpenID unavailable, cannot auto-fix)`);
3602
+ const secret = bot.appSecret;
3603
+ if (typeof secret === "object" && secret !== null && !Array.isArray(secret)) {
3604
+ if (!matchMap(secret, DEFAULT_FEISHU_APP_SECRET)) issues.push(`${label} appSecret is a provider-ref but not the canonical one`);
3605
+ } else if (typeof secret === "string") {
3606
+ if (secret !== larkApp.appSecret) issues.push(`${label} appSecret plaintext mismatch`);
3607
+ } else issues.push(`${label} appSecret has unexpected type`);
3608
+ }
3595
3609
  repair(ctx) {
3596
3610
  const larkApps = ctx.vars.larkApps;
3597
3611
  if (!larkApps || larkApps.length === 0) return;
3598
- const accounts = asRecord(getNestedMap(ctx.config, "channels", "feishu")?.accounts);
3599
- if (!accounts) return;
3600
- for (const [, account] of Object.entries(accounts)) {
3612
+ const feishu = asRecord(getNestedMap(ctx.config, "channels", "feishu"));
3613
+ if (!feishu) return;
3614
+ const accounts = asRecord(feishu.accounts);
3615
+ if (accounts) for (const [, account] of Object.entries(accounts)) {
3601
3616
  const bot = asRecord(account);
3602
3617
  if (!bot) continue;
3603
3618
  const appId = bot.appId;
3604
3619
  if (typeof appId !== "string" || !appId.startsWith("cli_")) continue;
3605
3620
  const larkApp = larkApps.find((e) => e.larkAppID === appId);
3606
3621
  if (!larkApp) continue;
3607
- const creatorOpenID = larkApp.creatorOpenID;
3608
- if (typeof creatorOpenID === "string" && creatorOpenID !== "") {
3609
- const allowFrom = Array.isArray(bot.allowFrom) ? [...bot.allowFrom] : [];
3610
- if (!allowFrom.includes(creatorOpenID)) {
3611
- allowFrom.push(creatorOpenID);
3612
- bot.allowFrom = allowFrom;
3613
- }
3622
+ this.fixBot(bot, larkApp);
3623
+ }
3624
+ const singleAppId = feishu.appId;
3625
+ if (typeof singleAppId === "string" && singleAppId.startsWith("cli_") && !accounts) {
3626
+ const larkApp = larkApps.find((e) => e.larkAppID === singleAppId);
3627
+ if (larkApp) this.fixBot(feishu, larkApp);
3628
+ }
3629
+ }
3630
+ /** Fix a single bot entry in-place. */
3631
+ fixBot(bot, larkApp) {
3632
+ const creatorOpenID = larkApp.creatorOpenID;
3633
+ if (typeof creatorOpenID === "string" && creatorOpenID !== "") {
3634
+ const allowFrom = Array.isArray(bot.allowFrom) ? [...bot.allowFrom] : [];
3635
+ if (!allowFrom.includes(creatorOpenID)) {
3636
+ allowFrom.push(creatorOpenID);
3637
+ bot.allowFrom = allowFrom;
3614
3638
  }
3615
- const secret = bot.appSecret;
3616
- let needsFix = false;
3617
- if (typeof secret === "object" && secret !== null && !Array.isArray(secret)) {
3618
- if (!matchMap(secret, DEFAULT_FEISHU_APP_SECRET)) needsFix = true;
3619
- } else if (typeof secret === "string") {
3620
- if (secret !== larkApp.appSecret) needsFix = true;
3621
- } else needsFix = true;
3622
- if (needsFix) bot.appSecret = { ...DEFAULT_FEISHU_APP_SECRET };
3623
3639
  }
3640
+ const secret = bot.appSecret;
3641
+ let needsFix = false;
3642
+ if (typeof secret === "object" && secret !== null && !Array.isArray(secret)) {
3643
+ if (!matchMap(secret, DEFAULT_FEISHU_APP_SECRET)) needsFix = true;
3644
+ } else if (typeof secret === "string") {
3645
+ if (secret !== larkApp.appSecret) needsFix = true;
3646
+ } else needsFix = true;
3647
+ if (needsFix) bot.appSecret = { ...DEFAULT_FEISHU_APP_SECRET };
3624
3648
  }
3625
3649
  };
3626
3650
  FeishuBotChannelConfigRule = __decorate([Rule({
3627
3651
  key: "feishu_bot_channel_config",
3628
- description: "确保多账号飞书配置中每个 bot 账号的 allowFrom 包含其创建者 openID 且 appSecret 值正确",
3652
+ description: "确保飞书配置中 bot 账号的 allowFrom 包含其创建者 openID 且 appSecret 值正确",
3629
3653
  dependsOn: [
3630
3654
  "config_syntax_check",
3631
3655
  "feishu_default_account",
@@ -10246,7 +10270,7 @@ async function reportCliRun(opts) {
10246
10270
  //#region src/help.ts
10247
10271
  const BIN = "mclaw-diagnose";
10248
10272
  function versionBanner() {
10249
- return `v0.1.13-alpha.7`;
10273
+ return `v0.1.13-alpha.8`;
10250
10274
  }
10251
10275
  const COMMANDS = [
10252
10276
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/openclaw-scripts-diagnose-cli",
3
- "version": "0.1.13-alpha.7",
3
+ "version": "0.1.13-alpha.8",
4
4
  "description": "CLI for OpenClaw config diagnose and repair with JSON5 support",
5
5
  "main": "dist/index.cjs",
6
6
  "bin": {