@lark-apaas/openclaw-scripts-diagnose-cli 0.1.15-alpha.15 → 0.1.15-alpha.16

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 +87 -36
  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.15-alpha.15";
55
+ return "0.1.15-alpha.16";
56
56
  }
57
57
  //#endregion
58
58
  //#region src/rule-engine/base.ts
@@ -4180,9 +4180,10 @@ let FeishuBotChannelConfigRule = class FeishuBotChannelConfigRule extends Diagno
4180
4180
  };
4181
4181
  }
4182
4182
  /** Check a single bot entry (either an account object or the feishu channel itself).
4183
- * appSecret is validated based on its current type:
4184
4183
  * - object → must match canonical provider-ref
4185
4184
  * - string → must match larkApps plaintext
4185
+ * - undefined/null → missing
4186
+ * - other → unexpected type
4186
4187
  */
4187
4188
  checkBot(label, bot, larkApp, issues) {
4188
4189
  const creatorOpenID = larkApp.creatorOpenID;
@@ -4195,7 +4196,8 @@ let FeishuBotChannelConfigRule = class FeishuBotChannelConfigRule extends Diagno
4195
4196
  if (!matchMap(secret, DEFAULT_FEISHU_APP_SECRET)) issues.push(`${label} appSecret is a provider-ref but not the canonical one`);
4196
4197
  } else if (typeof secret === "string") {
4197
4198
  if (secret !== larkApp.appSecret) issues.push(`${label} appSecret plaintext mismatch`);
4198
- } else issues.push(`${label} appSecret has unexpected type ${typeof secret}`);
4199
+ } else if (secret === void 0 || secret === null) issues.push(`${label} appSecret is missing`);
4200
+ else issues.push(`${label} appSecret has unexpected type ${typeof secret}`);
4199
4201
  }
4200
4202
  repair(ctx) {
4201
4203
  const larkApps = ctx.vars.larkApps;
@@ -4219,9 +4221,8 @@ let FeishuBotChannelConfigRule = class FeishuBotChannelConfigRule extends Diagno
4219
4221
  }
4220
4222
  }
4221
4223
  /** Fix a single bot entry in-place.
4222
- * appSecret is repaired based on its current type:
4223
- * - object → fix to canonical provider-ref
4224
- * - string → fix to larkApps plaintext
4224
+ * - object (provider-ref) fix to canonical
4225
+ * - otherwise → fix to larkApps plaintext
4225
4226
  */
4226
4227
  fixBot(bot, larkApp) {
4227
4228
  const creatorOpenID = larkApp.creatorOpenID;
@@ -4235,9 +4236,7 @@ let FeishuBotChannelConfigRule = class FeishuBotChannelConfigRule extends Diagno
4235
4236
  const secret = bot.appSecret;
4236
4237
  if (typeof secret === "object" && secret !== null && !Array.isArray(secret)) {
4237
4238
  if (!matchMap(secret, DEFAULT_FEISHU_APP_SECRET)) bot.appSecret = { ...DEFAULT_FEISHU_APP_SECRET };
4238
- } else if (typeof secret === "string") {
4239
- if (secret !== larkApp.appSecret) bot.appSecret = larkApp.appSecret;
4240
- }
4239
+ } else if (secret !== larkApp.appSecret) bot.appSecret = larkApp.appSecret;
4241
4240
  }
4242
4241
  };
4243
4242
  FeishuBotChannelConfigRule = __decorate([Rule({
@@ -7123,45 +7122,56 @@ function fixBotChannelConfig(configPath, larkApps, log) {
7123
7122
  return;
7124
7123
  }
7125
7124
  const config = loadJSON5().parse(node_fs.default.readFileSync(configPath, "utf-8"));
7126
- const accounts = asRecord(getNestedMap(config, "channels", "feishu")?.accounts);
7127
- if (!accounts) {
7128
- log("no feishu accounts in config, skip bot channel config fix");
7125
+ const feishu = asRecord(getNestedMap(config, "channels", "feishu"));
7126
+ if (!feishu) {
7127
+ log("no feishu channel in config, skip bot channel config fix");
7129
7128
  return;
7130
7129
  }
7131
7130
  let fixCount = 0;
7132
- for (const [, account] of Object.entries(accounts)) {
7131
+ const accounts = asRecord(feishu.accounts);
7132
+ if (accounts) for (const [, account] of Object.entries(accounts)) {
7133
7133
  const bot = asRecord(account);
7134
7134
  if (!bot) continue;
7135
7135
  const appId = bot.appId;
7136
7136
  if (typeof appId !== "string" || !appId.startsWith("cli_")) continue;
7137
7137
  const larkApp = larkApps.find((e) => e.larkAppID === appId);
7138
7138
  if (!larkApp) continue;
7139
- const creatorOpenID = larkApp.creatorOpenID;
7140
- if (typeof creatorOpenID === "string" && creatorOpenID !== "") {
7141
- const allowFrom = Array.isArray(bot.allowFrom) ? [...bot.allowFrom] : [];
7142
- if (!allowFrom.includes(creatorOpenID)) {
7143
- allowFrom.push(creatorOpenID);
7144
- bot.allowFrom = allowFrom;
7145
- fixCount++;
7146
- }
7147
- }
7148
- const secret = bot.appSecret;
7149
- let needsFix = false;
7150
- if (typeof secret === "object" && secret !== null && !Array.isArray(secret)) {
7151
- if (!matchMap(secret, DEFAULT_FEISHU_APP_SECRET)) needsFix = true;
7152
- } else if (typeof secret === "string") {
7153
- if (secret !== larkApp.appSecret) needsFix = true;
7154
- } else needsFix = true;
7155
- if (needsFix) {
7156
- bot.appSecret = { ...DEFAULT_FEISHU_APP_SECRET };
7157
- fixCount++;
7158
- }
7139
+ fixCount += fixBot(bot, larkApp);
7140
+ }
7141
+ const singleAppId = feishu.appId;
7142
+ if (typeof singleAppId === "string" && singleAppId.startsWith("cli_") && !accounts) {
7143
+ const larkApp = larkApps.find((e) => e.larkAppID === singleAppId);
7144
+ if (larkApp) fixCount += fixBot(feishu, larkApp);
7159
7145
  }
7160
7146
  if (fixCount > 0) {
7161
7147
  node_fs.default.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
7162
7148
  log(`fixed ${fixCount} bot channel config issue(s) (allowFrom/appSecret)`);
7163
7149
  } else log("bot channel config ok, no fixes needed");
7164
7150
  }
7151
+ /** Fix a single bot entry in-place. Returns number of fixes applied. */
7152
+ function fixBot(bot, larkApp) {
7153
+ let fixCount = 0;
7154
+ const creatorOpenID = larkApp.creatorOpenID;
7155
+ if (typeof creatorOpenID === "string" && creatorOpenID !== "") {
7156
+ const allowFrom = Array.isArray(bot.allowFrom) ? [...bot.allowFrom] : [];
7157
+ if (!allowFrom.includes(creatorOpenID)) {
7158
+ allowFrom.push(creatorOpenID);
7159
+ bot.allowFrom = allowFrom;
7160
+ fixCount++;
7161
+ }
7162
+ }
7163
+ const secret = bot.appSecret;
7164
+ if (typeof secret === "object" && secret !== null && !Array.isArray(secret)) {
7165
+ if (!matchMap(secret, DEFAULT_FEISHU_APP_SECRET)) {
7166
+ bot.appSecret = { ...DEFAULT_FEISHU_APP_SECRET };
7167
+ fixCount++;
7168
+ }
7169
+ } else if (secret !== larkApp.appSecret) {
7170
+ bot.appSecret = larkApp.appSecret;
7171
+ fixCount++;
7172
+ }
7173
+ return fixCount;
7174
+ }
7165
7175
  /**
7166
7176
  * Step 7: Verify startup scripts landed in configDir/scripts/.
7167
7177
  *
@@ -10704,7 +10714,7 @@ async function reportCliRun(opts) {
10704
10714
  //#region src/help.ts
10705
10715
  const BIN = "mclaw-diagnose";
10706
10716
  function versionBanner() {
10707
- return `v0.1.15-alpha.15`;
10717
+ return `v0.1.15-alpha.16`;
10708
10718
  }
10709
10719
  const COMMANDS = [
10710
10720
  {
@@ -11958,6 +11968,8 @@ function releaseInstallLock() {
11958
11968
  //#region src/index.ts
11959
11969
  const args = node_process.default.argv.slice(2);
11960
11970
  const mode = args.find((a) => !a.startsWith("-"));
11971
+ const t0 = Date.now();
11972
+ const scene = getFlag(args, "scene");
11961
11973
  /**
11962
11974
  * Pull the first non-flag positional after the mode name.
11963
11975
  * (The mode itself is args[0] in the filtered set, so we skip index 0.)
@@ -12041,13 +12053,11 @@ async function main() {
12041
12053
  }
12042
12054
  const caller = getFlag(args, "caller");
12043
12055
  const traceId = getFlag(args, "trace-id");
12044
- const scene = getFlag(args, "scene");
12045
12056
  const profile = getFlag(args, "profile") === "experimental" ? "experimental" : "standard";
12046
12057
  const rc = setRunContext({
12047
12058
  caller,
12048
12059
  traceId
12049
12060
  });
12050
- const t0 = Date.now();
12051
12061
  console.error(`${mode}: begin argv=[${args.join(" ")}] version=${getVersion()} traceId=${traceId ?? "-"} caller=${caller ?? "-"} runIdGenerated=${rc.generated}`);
12052
12062
  switch (mode) {
12053
12063
  case "check": {
@@ -12516,6 +12526,47 @@ main().catch((err) => {
12516
12526
  const msg = err instanceof Error ? err.message : String(err);
12517
12527
  console.error(`${mode ?? "<no-mode>"}: error message=${msg}`);
12518
12528
  node_process.default.stderr.write(`Error: ${msg}\n`);
12529
+ if (mode) {
12530
+ const durationMs = Date.now() - t0;
12531
+ if (mode === "upgrade-lark") {
12532
+ const checkOnly = args.includes("--check");
12533
+ const fixStatus = computeFixStatus(scene, "failed");
12534
+ const failResult = {
12535
+ status: "failed",
12536
+ error: msg,
12537
+ logFile: "",
12538
+ fixStatus
12539
+ };
12540
+ if (fixStatus !== void 0) writeFixStatusEvent(fixStatus, failResult, console.error);
12541
+ console.log(JSON.stringify(failResult));
12542
+ reportUpgradeLarkToSlardar({
12543
+ scene,
12544
+ checkOnly,
12545
+ durationMs,
12546
+ resultStatus: "failed",
12547
+ error: msg,
12548
+ logFile: "",
12549
+ resultSummary: buildUpgradeLarkResultSummary(failResult, checkOnly)
12550
+ });
12551
+ } else if ([
12552
+ "doctor",
12553
+ "check",
12554
+ "repair",
12555
+ "install-openclaw",
12556
+ "install-extension",
12557
+ "install-cli",
12558
+ "download-resource",
12559
+ "reset",
12560
+ "lark-cli-init"
12561
+ ].includes(mode)) reportDoctorRunToSlardar({
12562
+ command: mode,
12563
+ scene,
12564
+ profile: getFlag(args, "profile") === "experimental" ? "experimental" : "standard",
12565
+ fix: args.includes("--fix"),
12566
+ durationMs,
12567
+ success: false
12568
+ });
12569
+ }
12519
12570
  node_process.default.exitCode = 1;
12520
12571
  });
12521
12572
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/openclaw-scripts-diagnose-cli",
3
- "version": "0.1.15-alpha.15",
3
+ "version": "0.1.15-alpha.16",
4
4
  "description": "CLI for OpenClaw config diagnose and repair with JSON5 support",
5
5
  "main": "dist/index.cjs",
6
6
  "bin": {