@lark-apaas/openclaw-scripts-diagnose-cli 0.1.6-alpha.3 → 0.1.6-alpha.5
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 +26 -120
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -53,7 +53,7 @@ let json_diff = require("json-diff");
|
|
|
53
53
|
* it terse and parseable.
|
|
54
54
|
*/
|
|
55
55
|
function getVersion() {
|
|
56
|
-
return "0.1.6-alpha.
|
|
56
|
+
return "0.1.6-alpha.5";
|
|
57
57
|
}
|
|
58
58
|
//#endregion
|
|
59
59
|
//#region src/rule-engine/base.ts
|
|
@@ -4212,40 +4212,8 @@ function finalize(results, aborted) {
|
|
|
4212
4212
|
//#endregion
|
|
4213
4213
|
//#region src/lark-cli-init.ts
|
|
4214
4214
|
const LARK_PLUGIN_NAMES = ["openclaw-lark", "feishu-openclaw-plugin"];
|
|
4215
|
-
const PE_XML_TAG = "lark-pe";
|
|
4216
|
-
|
|
4217
|
-
<${PE_XML_TAG}>
|
|
4218
|
-
# 飞书操作铁律(最高优先级)
|
|
4219
|
-
【Critical】所有飞书相关操作(消息、文档、日历、搜索、群、文件等)**必须通过 lark-cli**,禁止使用 \`feishu_im_*\` / \`feishu_chat\` / \`feishu_search_doc_wiki\` / \`feishu_fetch_doc\` / \`feishu_create_doc\` / \`feishu_update_doc\` 等同名工具。
|
|
4220
|
-
lark-cli 是飞书所有能力的唯一入口。
|
|
4221
|
-
## 调用规范
|
|
4222
|
-
【必读】开始任何飞书操作前,先读对应 SKILL.md:
|
|
4223
|
-
- 系统自动根据任务匹配 skills,读取对应 SKILL.md
|
|
4224
|
-
- 匹配到相关 skill 后,严格按照 SKILL.md 的规范执行
|
|
4225
|
-
- 需要时用 \`lark-cli --help\` 或 \`lark-cli <sub> --help\` 查看可用命令,不要猜测参数格式
|
|
4226
|
-
## 命令格式
|
|
4227
|
-
\`\`\`
|
|
4228
|
-
lark-cli --profile <appId> [--as bot] <子命令> <子命令参数>
|
|
4229
|
-
\`\`\`
|
|
4230
|
-
### --profile 参数(必填)
|
|
4231
|
-
\`--profile\` 传入的是飞书 App ID(格式:\`cli_xxx\`),**不是** \`account_id\`(\`bot-cli_xxx\`)。
|
|
4232
|
-
**如何找到当前 Agent 的 appId**:
|
|
4233
|
-
1. **获取 account_id**:从入站上下文元数据的 \`account_id\` 字段读取(格式:\`bot-cli_xxx\`)
|
|
4234
|
-
2. **查 appId**:调用 \`gateway config.get\` 查询 \`channels.feishu.accounts[account_id].appId\`
|
|
4235
|
-
3. **兜底**:如果 accounts 里查不到,直接查 \`channels.feishu.appId\`
|
|
4236
|
-
\`\`\`bash
|
|
4237
|
-
# 示例:account_id = bot-cli_a977eb4fc239dbd7
|
|
4238
|
-
# 查询配置获取 appId
|
|
4239
|
-
gateway config.get channels.feishu.accounts
|
|
4240
|
-
# → appId: cli_a977eb4fc239dbd7
|
|
4241
|
-
# 正确用法
|
|
4242
|
-
lark-cli --profile cli_a977eb4fc239dbd7 --as bot im +chat-messages-list ...
|
|
4243
|
-
\`\`\`
|
|
4244
|
-
### --as bot 参数(必填)
|
|
4245
|
-
当前账号 \`uat.enabled: false\`,**必须显式加 \`--as bot\`**。
|
|
4246
|
-
\`--as user\` 仅在 \`uat.enabled: true\` 且需要以用户身份操作时使用。
|
|
4247
|
-
</${PE_XML_TAG}>
|
|
4248
|
-
`;
|
|
4215
|
+
const PE_XML_TAG = "lark-cli-pe";
|
|
4216
|
+
`${PE_XML_TAG}${PE_XML_TAG}`;
|
|
4249
4217
|
function isLarkPluginInstalled(configPath) {
|
|
4250
4218
|
const extDir = getExtensionsDir(configPath);
|
|
4251
4219
|
return LARK_PLUGIN_NAMES.some((name) => {
|
|
@@ -4303,7 +4271,7 @@ function resolveAppSecret(appId, config, feishuAppSecret) {
|
|
|
4303
4271
|
if (accounts) for (const [, val] of Object.entries(accounts)) {
|
|
4304
4272
|
const account = asRecord(val);
|
|
4305
4273
|
if (account?.appId === appId) {
|
|
4306
|
-
rawSecret = account.appSecret;
|
|
4274
|
+
rawSecret = account.appSecret ?? feishu.appSecret;
|
|
4307
4275
|
break;
|
|
4308
4276
|
}
|
|
4309
4277
|
}
|
|
@@ -4312,67 +4280,6 @@ function resolveAppSecret(appId, config, feishuAppSecret) {
|
|
|
4312
4280
|
if (rawSecret != null && typeof rawSecret === "object") return feishuAppSecret ?? null;
|
|
4313
4281
|
return null;
|
|
4314
4282
|
}
|
|
4315
|
-
/**
|
|
4316
|
-
* Resolve the agents.md path for the given appId from the openclaw config.
|
|
4317
|
-
*
|
|
4318
|
-
* Case 1: appId matches channels.feishu.appId (single-agent path)
|
|
4319
|
-
* → WORKSPACE_DIR/AGENTS.md
|
|
4320
|
-
*
|
|
4321
|
-
* Case 2: appId found in channels.feishu.accounts (multi-agent path)
|
|
4322
|
-
* → find account key where account.appId === appId
|
|
4323
|
-
* → find binding where match.channel=feishu && match.accountId=that key
|
|
4324
|
-
* → if agentId === 'main' → WORKSPACE_DIR/agents.md
|
|
4325
|
-
* → else find agent in agents.list by id → agent.workspace/agents.md
|
|
4326
|
-
*
|
|
4327
|
-
* Returns null when the path cannot be determined.
|
|
4328
|
-
*/
|
|
4329
|
-
function resolveAgentsMdPath(appId, config) {
|
|
4330
|
-
const feishu = getNestedMap(config, "channels", "feishu");
|
|
4331
|
-
if (!feishu) return null;
|
|
4332
|
-
if (typeof feishu.appId === "string" && feishu.appId === appId) return node_path.default.join(WORKSPACE_DIR, "AGENTS.md");
|
|
4333
|
-
const accounts = asRecord(feishu.accounts);
|
|
4334
|
-
if (!accounts) return null;
|
|
4335
|
-
let accountId;
|
|
4336
|
-
for (const [key, val] of Object.entries(accounts)) if (asRecord(val)?.appId === appId) {
|
|
4337
|
-
accountId = key;
|
|
4338
|
-
break;
|
|
4339
|
-
}
|
|
4340
|
-
if (!accountId) return null;
|
|
4341
|
-
const bindings = Array.isArray(config.bindings) ? config.bindings : [];
|
|
4342
|
-
let agentId;
|
|
4343
|
-
for (const b of bindings) {
|
|
4344
|
-
const binding = asRecord(b);
|
|
4345
|
-
if (!binding) continue;
|
|
4346
|
-
const match = asRecord(binding.match);
|
|
4347
|
-
if (match?.channel === "feishu" && match?.accountId === accountId) {
|
|
4348
|
-
if (typeof binding.agentId === "string") {
|
|
4349
|
-
agentId = binding.agentId;
|
|
4350
|
-
break;
|
|
4351
|
-
}
|
|
4352
|
-
}
|
|
4353
|
-
}
|
|
4354
|
-
if (!agentId) return null;
|
|
4355
|
-
if (agentId === "main") return node_path.default.join(WORKSPACE_DIR, "agents.md");
|
|
4356
|
-
const agentsObj = asRecord(config.agents);
|
|
4357
|
-
const list = Array.isArray(agentsObj?.list) ? agentsObj.list : [];
|
|
4358
|
-
for (const a of list) {
|
|
4359
|
-
const agent = asRecord(a);
|
|
4360
|
-
if (agent?.id === agentId && typeof agent.workspace === "string") return node_path.default.join(agent.workspace, "agents.md");
|
|
4361
|
-
}
|
|
4362
|
-
return null;
|
|
4363
|
-
}
|
|
4364
|
-
function appendPeToAgentsMd(agentsMdPath) {
|
|
4365
|
-
const dir = node_path.default.dirname(agentsMdPath);
|
|
4366
|
-
if (!node_fs.default.existsSync(dir)) node_fs.default.mkdirSync(dir, { recursive: true });
|
|
4367
|
-
const existing = node_fs.default.existsSync(agentsMdPath) ? node_fs.default.readFileSync(agentsMdPath, "utf-8") : "";
|
|
4368
|
-
if (existing.includes(`<${PE_XML_TAG}>`)) {
|
|
4369
|
-
console.error(`lark-cli-init: <${PE_XML_TAG}> already present in ${agentsMdPath}, skipping`);
|
|
4370
|
-
return;
|
|
4371
|
-
}
|
|
4372
|
-
const sep = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
|
|
4373
|
-
node_fs.default.appendFileSync(agentsMdPath, `${sep}${PE_PLACEHOLDER}`, "utf-8");
|
|
4374
|
-
console.error(`lark-cli-init: appended PE placeholder to ${agentsMdPath}`);
|
|
4375
|
-
}
|
|
4376
4283
|
function runLarkCliInit(opts) {
|
|
4377
4284
|
const configPath = opts.configPath ?? CONFIG_PATH;
|
|
4378
4285
|
if (!isLarkPluginInstalled(configPath)) {
|
|
@@ -4396,18 +4303,12 @@ function runLarkCliInit(opts) {
|
|
|
4396
4303
|
ok: false,
|
|
4397
4304
|
error: `could not read config at ${configPath}`
|
|
4398
4305
|
};
|
|
4399
|
-
const agentsMdPath = opts.agentsMdPath ?? resolveAgentsMdPath(opts.appId, config);
|
|
4400
|
-
if (!agentsMdPath) return {
|
|
4401
|
-
ok: false,
|
|
4402
|
-
error: `could not resolve agents.md path for appId=${opts.appId}`
|
|
4403
|
-
};
|
|
4404
|
-
console.error(`lark-cli-init: agents.md path=${agentsMdPath}`);
|
|
4405
4306
|
const appSecret = resolveAppSecret(opts.appId, config, opts.feishuAppSecret);
|
|
4406
4307
|
if (!appSecret) return {
|
|
4407
4308
|
ok: false,
|
|
4408
4309
|
error: `could not resolve appSecret for appId=${opts.appId}`
|
|
4409
4310
|
};
|
|
4410
|
-
console.error(`lark-cli-init: running lark-cli config init --app-id
|
|
4311
|
+
console.error(`lark-cli-init: running lark-cli config init --name ${opts.appId} --app-id ${opts.appId} --brand feishu --app-secret-stdin --force-init`);
|
|
4411
4312
|
const initRes = (0, node_child_process.spawnSync)("lark-cli", [
|
|
4412
4313
|
"config",
|
|
4413
4314
|
"init",
|
|
@@ -4417,7 +4318,8 @@ function runLarkCliInit(opts) {
|
|
|
4417
4318
|
opts.appId,
|
|
4418
4319
|
"--brand",
|
|
4419
4320
|
"feishu",
|
|
4420
|
-
"--app-secret-stdin"
|
|
4321
|
+
"--app-secret-stdin",
|
|
4322
|
+
"--force-init"
|
|
4421
4323
|
], {
|
|
4422
4324
|
stdio: [
|
|
4423
4325
|
"pipe",
|
|
@@ -4427,22 +4329,26 @@ function runLarkCliInit(opts) {
|
|
|
4427
4329
|
encoding: "utf-8",
|
|
4428
4330
|
input: appSecret
|
|
4429
4331
|
});
|
|
4430
|
-
|
|
4431
|
-
|
|
4332
|
+
const configInitStdout = initRes.stdout?.trim() || void 0;
|
|
4333
|
+
const configInitStderr = initRes.stderr?.trim() || void 0;
|
|
4334
|
+
if (configInitStdout) console.error(`lark-cli config init stdout: ${configInitStdout}`);
|
|
4335
|
+
if (configInitStderr) console.error(`lark-cli config init stderr: ${configInitStderr}`);
|
|
4432
4336
|
if (initRes.error) return {
|
|
4433
4337
|
ok: false,
|
|
4338
|
+
configInitStdout,
|
|
4339
|
+
configInitStderr,
|
|
4434
4340
|
error: `lark-cli config init spawn error: ${initRes.error.message}`
|
|
4435
4341
|
};
|
|
4436
4342
|
if (initRes.status !== 0) return {
|
|
4437
4343
|
ok: false,
|
|
4438
4344
|
configInitExitCode: initRes.status ?? void 0,
|
|
4345
|
+
configInitStdout,
|
|
4346
|
+
configInitStderr,
|
|
4439
4347
|
error: `lark-cli config init exited with code ${initRes.status}`
|
|
4440
4348
|
};
|
|
4441
|
-
appendPeToAgentsMd(agentsMdPath);
|
|
4442
4349
|
return {
|
|
4443
4350
|
ok: true,
|
|
4444
|
-
configInitExitCode: 0
|
|
4445
|
-
agentsMdPath
|
|
4351
|
+
configInitExitCode: 0
|
|
4446
4352
|
};
|
|
4447
4353
|
}
|
|
4448
4354
|
//#endregion
|
|
@@ -4525,7 +4431,7 @@ async function reportCliRun(opts) {
|
|
|
4525
4431
|
//#region src/help.ts
|
|
4526
4432
|
const BIN = "mclaw-diagnose";
|
|
4527
4433
|
function versionBanner() {
|
|
4528
|
-
return `v0.1.6-alpha.
|
|
4434
|
+
return `v0.1.6-alpha.5`;
|
|
4529
4435
|
}
|
|
4530
4436
|
const COMMANDS = [
|
|
4531
4437
|
{
|
|
@@ -4741,7 +4647,7 @@ OPTIONS
|
|
|
4741
4647
|
hidden: false,
|
|
4742
4648
|
summary: "Initialize lark-cli bot config and append PE to agents.md",
|
|
4743
4649
|
help: `USAGE
|
|
4744
|
-
${BIN} lark-cli-init --app-id=<app-id> [--feishu-app-secret=<secret>]
|
|
4650
|
+
${BIN} lark-cli-init --app-id=<app-id> [--feishu-app-secret=<secret>]
|
|
4745
4651
|
|
|
4746
4652
|
DESCRIPTION
|
|
4747
4653
|
Two-step initialization for a Lark (Feishu) bot when prerequisites are met:
|
|
@@ -4772,16 +4678,13 @@ DESCRIPTION
|
|
|
4772
4678
|
agents.md path resolution:
|
|
4773
4679
|
- channels.feishu.appId === appId → WORKSPACE/AGENTS.md (single-agent)
|
|
4774
4680
|
- accounts[key].appId === appId → look up binding by accountId:
|
|
4775
|
-
agentId === 'main' → WORKSPACE/
|
|
4776
|
-
otherwise → agents.list[agentId].workspace/
|
|
4681
|
+
agentId === 'main' → WORKSPACE/AGENTS.md
|
|
4682
|
+
otherwise → agents.list[agentId].workspace/AGENTS.md
|
|
4777
4683
|
|
|
4778
4684
|
ARGUMENTS
|
|
4779
4685
|
--app-id=<app-id> Required. Bot app ID, e.g. cli_a9659e1f0ab89ccd.
|
|
4780
4686
|
|
|
4781
4687
|
OPTIONS
|
|
4782
|
-
--feishu-app-secret=<secret> Required when config stores appSecret as a
|
|
4783
|
-
provider-ref object (ctx.vars.feishuAppSecret).
|
|
4784
|
-
--agents-md=<path> Override the resolved agents.md path.
|
|
4785
4688
|
|
|
4786
4689
|
EXIT CODES
|
|
4787
4690
|
0 Success or skipped (prerequisites not met).
|
|
@@ -5268,13 +5171,16 @@ async function main() {
|
|
|
5268
5171
|
case "lark-cli-init": {
|
|
5269
5172
|
const appId = getFlag(args, "app-id");
|
|
5270
5173
|
if (!appId) {
|
|
5271
|
-
console.error("Usage: lark-cli-init --app-id=<app-id>
|
|
5174
|
+
console.error("Usage: lark-cli-init --app-id=<app-id>");
|
|
5272
5175
|
node_process.default.exit(1);
|
|
5273
5176
|
}
|
|
5274
5177
|
const result = runLarkCliInit({
|
|
5275
5178
|
appId,
|
|
5276
|
-
|
|
5277
|
-
|
|
5179
|
+
feishuAppSecret: normalizeCtx(await fetchCtxViaInnerApi({
|
|
5180
|
+
populate: { app: ["feishuAppSecret"] },
|
|
5181
|
+
caller: rc.caller,
|
|
5182
|
+
traceId: rc.traceId
|
|
5183
|
+
})).app.feishuAppSecret || void 0
|
|
5278
5184
|
});
|
|
5279
5185
|
console.log(JSON.stringify(result));
|
|
5280
5186
|
await reportRun("lark-cli-init", rc, void 0, args.join(" "), Date.now() - t0, {
|