Skip to content

Commit 2ed5131

Browse files
committed
feat: Use command.skipDefaultApiKeySetup instead of NO_AUTH_SETUP to determine whether an API key is required
1 parent 83ea0df commit 2ed5131

27 files changed

Lines changed: 44 additions & 42 deletions

File tree

docs/agents/auth-change.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ flag 优先 ─→ config 文件 ─→ env var
7878

7979
### D. main 启动逻辑
8080

81-
- [ ] `packages/cli/src/main.ts:NO_AUTH_SETUP` 列表:
82-
- 如果新增的命令"自己管鉴权或不需要鉴权",加进去绕开 ensureApiKey 拦截
83-
- 当前清单以 `main.ts:NO_AUTH_SETUP` 为准
81+
- [ ] 若新增命令**自行处理鉴权****不应在入口触发默认 API key 引导**,在对应 `defineCommand` 上设 `skipDefaultApiKeySetup: true`(见 `packages/core/src/types/command.ts`;`packages/cli/src/main.ts``registry.resolve` 后读取 `command.skipDefaultApiKeySetup`)
8482

8583
### E. 错误文案
8684

docs/agents/branch-merge-review.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ git diff --name-only <base>...<head>
5050
- [ ] **`package.json` 没破坏发布元数据**:`bin` / `exports` / `files` / `inlinedDependencies` 字段任何删除或改名都要单独评估
5151
- [ ] **公共依赖没被悄悄升级**:catalog / 根 lockfile 改动要列出来
5252
- [ ] **`package.json` version 没倒退**:目标分支已经更高时(如 main 1.0.3 vs head 1.0.0-beta.1),手动对齐版本号,不要被 head 覆盖
53-
- [ ] **全局表没冲突**:`registry.ts``NO_AUTH_SETUP`(`packages/cli/src/main.ts`)、`ExitCode` 三个全局表新增项不和现有项冲突
53+
- [ ] **全局表没冲突**:`registry.ts``defineCommand``skipDefaultApiKeySetup`(见 `packages/core/src/types/command.ts`)、`ExitCode` 三处新增项不和现有项冲突
5454

5555
## 清单 B:用户透出(用户可见的新东西必看)
5656

@@ -80,7 +80,7 @@ git diff --name-only <base>...<head>
8080
解冲突要点(merge 时不要漏):
8181
- <冲突文件> + <字段/段落> + <怎么取舍>
8282
↑ 放"合并那一刻才会出现"的细节,例如 package.json 的 files/scripts/devDependencies 各取并集、
83-
NO_AUTH_SETUP 这种全局表两边都加项时不要丢一侧、pnpm-lock.yaml 直接 rm 后 pnpm install 重生等。
83+
`skipDefaultApiKeySetup` 这类命令元数据两边都加项时不要丢一侧、pnpm-lock.yaml 直接 rm 后 pnpm install 重生等。
8484
建议修(可后置):
8585
- ...
8686
仅信息(无需动作,告知即可):
@@ -94,11 +94,11 @@ git diff --name-only <base>...<head>
9494

9595
## 常见漏点(基于历史踩坑)
9696

97-
| 漏点 | 后果 |
98-
| ------------------------------------------------------------------------------ | ----------------------------------------------------------------------------- |
99-
| `pnpm-workspace.yaml``packages/*` 收窄成显式列表 | 合并后目标分支的新子包不再被 workspace 识别,`pnpm install` 看似正常但子包失联 |
100-
| 源分支 version 比目标分支低,直接 merge 覆盖 | npm 上版本号回退,latest tag 错乱 |
101-
| `registry.ts` 注册新命令但忘了 [README](README.md) / [README.zh](README.zh.md) | 用户完全感知不到新功能 |
102-
| 共享 util 重构(抽公共函数)只改了一处调用方 | 其它调用方静默走旧分支,行为分裂 |
103-
| `NO_AUTH_SETUP` 加了不该免登录的命令 | 安全风险,用户没登录也能调付费 API |
104-
| `NO_AUTH_SETUP` / `registry.ts` 这类全局表两边都加项,解冲突时被合掉一侧 | 某个命令突然要求登录 / 某个新命令注册丢失,编译能过、回归不易察觉 |
97+
| 漏点 | 后果 |
98+
| ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
99+
| `pnpm-workspace.yaml``packages/*` 收窄成显式列表 | 合并后目标分支的新子包不再被 workspace 识别,`pnpm install` 看似正常但子包失联 |
100+
| 源分支 version 比目标分支低,直接 merge 覆盖 | npm 上版本号回退,latest tag 错乱 |
101+
| `registry.ts` 注册新命令但忘了 [README](README.md) / [README.zh](README.zh.md) | 用户完全感知不到新功能 |
102+
| 共享 util 重构(抽公共函数)只改了一处调用方 | 其它调用方静默走旧分支,行为分裂 |
103+
| 不该跳过默认 API key 引导的命令误设 `skipDefaultApiKeySetup: true` | 安全风险,用户没配置 key 也能调付费 API |
104+
| `catalog.ts` / `skipDefaultApiKeySetup` 这类元数据两边都加项,解冲突时被合掉一侧 | 某个命令突然要求登录 / 某个新命令注册丢失,编译能过、回归不易察觉 |

docs/agents/command-add-remove.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ registry.ts main.ts tools/generate-reference.ts export-schema.ts
5353
- 增删 `import xxx from "./.../xxx.ts"`
5454
-`export const commands` 里增删 `"<group> <action>": xxx`(key 与 `defineCommand({ name })` 一致)
5555
- [ ] **不要**`registry.ts` 里重复登记命令(已从 catalog 读取)
56-
- [ ] 如果命令需要鉴权之外的特殊路径,看 `packages/cli/src/main.ts` `NO_AUTH_SETUP`
56+
- [ ] 如果命令需要跳过入口的默认 DashScope API key 引导(`ensureApiKey`),在对应 `defineCommand` 上设 `skipDefaultApiKeySetup: true`(字段定义见 `packages/core/src/types/command.ts`;`main.ts` 根据已解析的 `command` 读取)
5757
- [ ] **`config/export-schema.ts`**: 若新命令不适合作为 agent tool,评估是否加入 `SKIP_PREFIXES`;该文件在 `run()``import("../catalog.ts")`,勿顶层 import catalog 以免循环依赖
5858

5959
### B. 文档层

packages/cli/src/commands/app/list.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const APP_LIST_API = "zeldaEasy.broadscope-bailian.app-control.list";
1313
export default defineCommand({
1414
name: "app list",
1515
description: "List Bailian applications",
16+
skipDefaultApiKeySetup: true,
1617
usage: "bl app list [flags]",
1718
options: [
1819
{

packages/cli/src/commands/auth/login.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ async function validateKeyAndPersist(config: Config, key: string): Promise<void>
8181
export default defineCommand({
8282
name: "auth login",
8383
description: "Authenticate with API key or console browser login (credentials can coexist)",
84+
skipDefaultApiKeySetup: true,
8485
usage: "bl auth login --api-key <key> | bl auth login --console",
8586
options: [
8687
{ flag: "--api-key <key>", description: "DashScope API key to store" },

packages/cli/src/commands/auth/logout.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ async function clearConsoleToken(): Promise<boolean> {
2020
export default defineCommand({
2121
name: "auth logout",
2222
description: "Clear stored credentials",
23+
skipDefaultApiKeySetup: true,
2324
usage: "bl auth logout [--console] [--yes] [--dry-run]",
2425
options: [
2526
{

packages/cli/src/commands/config/export-schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default defineCommand({
1313
name: "config export-schema",
1414
description:
1515
"Export all (or one) CLI command(s) as Anthropic/OpenAI-compatible JSON tool schemas",
16+
skipDefaultApiKeySetup: true,
1617
usage: 'bl config export-schema [--command "<name>"]',
1718
options: [
1819
{

packages/cli/src/commands/config/set.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const KEY_ALIASES: Record<string, string> = {
5353
export default defineCommand({
5454
name: "config set",
5555
description: "Set a config value",
56+
skipDefaultApiKeySetup: true,
5657
usage: "bl config set --key <key> --value <value>",
5758
options: [
5859
{

packages/cli/src/commands/config/show.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { emitResult } from "../../output/output.ts";
1212
export default defineCommand({
1313
name: "config show",
1414
description: "Display current configuration",
15+
skipDefaultApiKeySetup: true,
1516
usage: "bl config show",
1617
examples: ["bl config show", "bl config show --output json"],
1718
async run(config: Config, _flags: GlobalFlags) {

packages/cli/src/commands/console/call.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { emitResult } from "../../output/output.ts";
1414
export default defineCommand({
1515
name: "console call",
1616
description: "Call a Bailian console API via the CLI gateway",
17+
skipDefaultApiKeySetup: true,
1718
usage: "bl console call --api <api> --data <json> [flags]",
1819
options: [
1920
{

0 commit comments

Comments
 (0)