Skip to content

Commit 5d1b7aa

Browse files
committed
Merge branch 'main' into feat/cli-skill-sync
2 parents 5007b9b + 2389681 commit 5d1b7aa

24 files changed

Lines changed: 511 additions & 595 deletions

File tree

README.md

Lines changed: 71 additions & 135 deletions
Large diffs are not rendered by default.

README.zh.md

Lines changed: 71 additions & 136 deletions
Large diffs are not rendered by default.

docs/agents/auth-change.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defineCommand({ auth }) → runtime/authStage → ctx.client → command.run(ctx
2525
当前 command 鉴权域(`AuthRequirement`):
2626

2727
- `apiKey` — DashScope / OpenAI-compatible 模型域,用 API key 与 model base URL
28-
- `console` — Bailian Console Gateway,用 console access token + region/site/switchAgent/workspace
28+
- `console` — Bailian Console Gateway,用 console access token + region/site/switchAgent;`workspace_id` 是独立的 Settings 作用域,不属于 credential
2929
- `openapi` — 阿里云 OpenAPI 签名域,用 AccessKey ID/Secret 调用 Token Plan 等 OpenAPI
3030
- `none` — 本地命令、登录/配置类命令、无需 credential 的命令
3131

@@ -35,7 +35,7 @@ defineCommand({ auth }) → runtime/authStage → ctx.client → command.run(ctx
3535

3636
- `bl auth login --api-key ...` 只更新 `api_key` / `base_url`
3737
- `bl auth login --console` 只更新 `access_token` 以及回调携带的 console 作用域字段
38-
- `bl auth login --open-api ...` 只更新 `access_key_id` / `access_key_secret`
38+
- `bl auth login --open-api ...` 更新 `access_key_id` / `access_key_secret`,同时会调用 OpenAPI 生成 CLI `access_token` 并一并写入;即一次 `--open-api` 登录同时产生 `openapi``console` 域凭证
3939
- `bl auth logout --console` 只清 `access_token`
4040
- `bl auth logout --open-api` 只清 `access_key_id` / `access_key_secret` / `security_token`
4141
- `bl auth logout``api_key` + `base_url` + `access_token` + `access_key_*`
@@ -78,6 +78,9 @@ defineCommand({ auth }) → runtime/authStage → ctx.client → command.run(ctx
7878
- 如新增鉴权域,扩展 `AuthRequirement`
7979
- 更新 `credentialFlagDefs()` 暴露该域可见的 flag
8080
- 必要时新增 `*_AUTH_FLAGS`
81+
- `workspace_id` 是作用域字段而非 credential,不要把它放进 `ConsoleCredential`;读取方式按命令 `auth` 域区分:
82+
- `auth: "console"` 命令通过 `CONSOLE_AUTH_FLAGS` 自动获得 `--workspace-id`,由 `buildSettings()` 解析到 `settings.workspaceId`,命令统一从 `settings.workspaceId` 读取
83+
- `auth: "apiKey"`/`"openapi"`/`"none"` 命令如需 `--workspace-id`,必须自声明 flag;因它不会进入 credential/global flags,命令从 `ctx.flags.workspaceId` 读取(可回退到 `settings.workspaceId`)
8184
- [ ] `packages/core/src/auth/types.ts`:
8285
- 新增 credential 类型 / source / scope 字段
8386
- [ ] `packages/core/src/auth/resolver.ts`:
@@ -131,6 +134,8 @@ defineCommand({ auth }) → runtime/authStage → ctx.client → command.run(ctx
131134

132135
## 完成后自查
133136

137+
本仓库同时存在 `bl`(packages/cli) 与 `kscli`(packages/kscli) 两个入口,二者共享 core/runtime 鉴权链路,但暴露的命令不同。如果改动会影响两个入口共用的命令或错误提示,再分别验证它们各自实际暴露的路径;不要假设 `kscli` 也有 `bl auth *` 命令。
138+
134139
```sh
135140
# 各种凭证组合
136141
unset DASHSCOPE_API_KEY ALIBABA_CLOUD_ACCESS_KEY_ID ALIBABA_CLOUD_ACCESS_KEY_SECRET
@@ -150,9 +155,11 @@ Console 登录/网关相关改动:
150155

151156
```sh
152157
pnpm -F bailian-cli exec tsx src/main.ts auth login --console
153-
pnpm -F bailian-cli exec tsx src/main.ts usage stats --dry-run --output json
158+
pnpm -F bailian-cli exec tsx src/main.ts usage stats --dry-run --output json --workspace-id ws-xxx
154159
```
155160

161+
注意:`usage stats --dry-run` 仍会先校验 workspace,必须传入 `--workspace-id`(或 `BAILIAN_WORKSPACE_ID` / config `workspace_id`)。
162+
156163
## 常见漏点
157164

158165
- ✗ 加了新 token 来源但忘了改 resolver 优先级,实际不生效

packages/cli/README.md

Lines changed: 71 additions & 135 deletions
Large diffs are not rendered by default.

packages/cli/README.zh.md

Lines changed: 71 additions & 136 deletions
Large diffs are not rendered by default.

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bailian-cli",
3-
"version": "1.14.1",
3+
"version": "1.14.2",
44
"description": "CLI for Aliyun Model Studio (DashScope) AI Platform.",
55
"keywords": [
66
"agent",

packages/cli/src/commands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ import {
9797
skillUpdate,
9898
skillRemove,
9999
skillList,
100+
skillInit,
100101
managedAgentInit,
101102
managedAgentValidate,
102103
managedAgentPlan,
@@ -219,6 +220,7 @@ export const commands: Record<string, AnyCommand> = {
219220
"skill update": skillUpdate,
220221
"skill remove": skillRemove,
221222
"skill list": skillList,
223+
"skill init": skillInit,
222224
"managed-agent init": managedAgentInit,
223225
"managed-agent validate": managedAgentValidate,
224226
"managed-agent plan": managedAgentPlan,

packages/commands/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bailian-cli-commands",
3-
"version": "1.14.1",
3+
"version": "1.14.2",
44
"description": "Command library for bailian-cli products (knowledge, memory, media, …). See https://www.npmjs.com/package/bailian-cli for usage.",
55
"homepage": "https://bailian.console.aliyun.com/cli",
66
"bugs": {

packages/commands/src/commands/skill/add.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,31 @@ const INSTALL_CONCURRENCY = 3;
2727
export default defineCommand({
2828
description: "Install skills from the Bailian skill registry into local agents",
2929
auth: "none",
30-
usageArgs: "--name <all|name,...>",
30+
usageArgs: "--all | --name <name,...>",
3131
flags: {
32+
all: {
33+
type: "switch",
34+
description: "Install all skills from the registry",
35+
},
3236
name: {
3337
type: "string",
34-
valueHint: "<all|name,...>",
35-
description: "Skills to install: all or comma-separated skill names",
36-
required: true,
38+
valueHint: "<name,...>",
39+
description: "Comma-separated skill names to install",
3740
},
3841
},
39-
exampleArgs: ["--name all", "--name spark-video,bailian-model-recommend"],
42+
validate(flags) {
43+
if (flags.all && flags.name) return "Use either --all or --name, not both";
44+
if (!flags.all && !flags.name)
45+
return "Specify --all to install everything or --name <name,...> for specific skills";
46+
return undefined;
47+
},
48+
exampleArgs: ["--all", "--name spark-video,bailian-model-recommend"],
4049
async run(ctx) {
4150
const format = ctx.settings.outputExplicit ? ctx.settings.output : "json";
42-
const requested = parseSkillNames(ctx.flags.name, false);
4351
const index = await fetchSkillsIndex();
4452
const remoteNames = Object.keys(index.skills);
45-
const names = requested === "all" ? remoteNames : requested;
53+
const parsed = ctx.flags.all ? "all" : parseSkillNames(ctx.flags.name, false);
54+
const names = parsed === "all" ? remoteNames : parsed;
4655

4756
const lock = readSkillLock();
4857
const agents = detectInstalledAgents();
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import {
2+
BailianError,
3+
ExitCode,
4+
defineCommand,
5+
detectInstalledAgents,
6+
fetchSkillsIndex,
7+
getSkillRegistryBaseUrl,
8+
installSkillWithFanout,
9+
readSkillLock,
10+
runWithConcurrency,
11+
writeSkillLock,
12+
} from "bailian-cli-core";
13+
import { emitBare, emitResult, formatTable } from "bailian-cli-runtime";
14+
15+
interface InitOutcome {
16+
name: string;
17+
status: "installed" | "failed";
18+
publishedAt?: string;
19+
agents?: string[];
20+
reason?: string;
21+
}
22+
23+
/** Prefix used to identify first-party Bailian skills in the registry. */
24+
const BAILIAN_PREFIX = "bailian-";
25+
26+
/** Max number of skills downloading/installing at the same time. */
27+
const INIT_CONCURRENCY = 3;
28+
29+
export default defineCommand({
30+
description: "Install all bailian-* skills (one-shot bootstrap for new environments)",
31+
auth: "none",
32+
usageArgs: "",
33+
exampleArgs: [""],
34+
notes: [
35+
"Fetches the registry index and installs every skill whose name starts with bailian-",
36+
"Equivalent to: bl skill add --all (filtered to bailian-* skills)",
37+
],
38+
async run(ctx) {
39+
const format = ctx.settings.outputExplicit ? ctx.settings.output : "json";
40+
const index = await fetchSkillsIndex();
41+
42+
// Discover all bailian-* skills from the live registry index
43+
const names = Object.keys(index.skills).filter((name) => name.startsWith(BAILIAN_PREFIX));
44+
45+
const lock = readSkillLock();
46+
const agents = detectInstalledAgents();
47+
48+
const tasks = names.map((name) => async (): Promise<InitOutcome> => {
49+
const entry = index.skills[name];
50+
try {
51+
const record = await installSkillWithFanout(
52+
name,
53+
entry,
54+
agents,
55+
lock.skills[name]?.links ?? [],
56+
);
57+
lock.skills[name] = record.lockEntry;
58+
return {
59+
name,
60+
status: "installed",
61+
publishedAt: entry.publishedAt,
62+
agents: record.linkedAgents,
63+
};
64+
} catch (err) {
65+
return {
66+
name,
67+
status: "failed",
68+
reason: err instanceof Error ? err.message : String(err),
69+
};
70+
}
71+
});
72+
const results = await runWithConcurrency(tasks, INIT_CONCURRENCY);
73+
writeSkillLock(lock);
74+
75+
if (format === "json") {
76+
emitResult(
77+
{
78+
registry: getSkillRegistryBaseUrl(),
79+
agents: agents.map((agent) => agent.id),
80+
skills: results,
81+
},
82+
format,
83+
);
84+
} else if (results.length === 0) {
85+
emitBare("No bailian-* skills found in the registry.");
86+
} else {
87+
const rows = results.map((result) => [
88+
result.name,
89+
result.status,
90+
result.publishedAt ? result.publishedAt.slice(0, 10) : "-",
91+
result.status === "installed" ? result.agents?.join(", ") || "-" : (result.reason ?? "-"),
92+
]);
93+
for (const line of formatTable(["NAME", "STATUS", "PUBLISHED", "AGENTS / REASON"], rows)) {
94+
emitBare(line);
95+
}
96+
}
97+
98+
const failed = results.filter((result) => result.status === "failed");
99+
if (failed.length > 0) {
100+
throw new BailianError(
101+
`${failed.length}/${results.length} skill(s) failed to install`,
102+
ExitCode.GENERAL,
103+
"Check the reason for failed skills in the output; network failures can be retried with bl skill init",
104+
);
105+
}
106+
},
107+
});

0 commit comments

Comments
 (0)