Skip to content

添加agent studio的cli能力#116

Open
chenanran555 wants to merge 7 commits into
mainfrom
feat/cma
Open

添加agent studio的cli能力#116
chenanran555 wants to merge 7 commits into
mainfrom
feat/cma

Conversation

@chenanran555

Copy link
Copy Markdown
Collaborator

No description provided.

# Conflicts:
#	packages/commands/src/commands/auth/login.ts
#	packages/commands/src/commands/config/set.ts
#	packages/commands/src/index.ts
#	packages/core/src/client/index.ts
#	packages/core/src/config/schema.ts
#	skills/bailian-cli/reference/auth.md
#	skills/bailian-cli/reference/config.md
#	skills/bailian-cli/reference/index.md

@XXPermanentXX XXPermanentXX left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这次接入方向基本正确:使用 @openagentpack/sdk,并把能力注册为真实 CLI command,而不是简单转发 argv;同时也补了 User-Agent、渠道 header 和部分错误适配。

但当前实现还没有完整接入 Bailian CLI 的宿主契约,在命令空间、鉴权/Profile、dry-run、结构化输出、错误分类、timeout、运行时兼容性和配置生命周期方面仍有阻塞问题。部分问题会产生真实误操作、账号错用或破坏自动化调用,因此本轮先 Request changes。

合入前至少需要完成:

  • 命令统一迁移到产品确认的独立命名空间,例如 bl cma ...
  • 建立明确的 Host Adapter,由 Bailian CLI 负责鉴权、Profile、遥测、输出、错误和 timeout;不要通过 SDK bootstrap 隐式接管这些能力。
  • 所有本地及远程 mutation 正确支持 --dry-run
  • 保证 --output json 的 stdout 始终只有一个合法 JSON 结果。
  • 解决 SDK Node >=22 与 Bailian CLI Node >=18.17 的发布契约冲突。
  • 补齐配置写入、Profile、logout、URL 规范化和错误映射。
  • 增加 commands E2E,覆盖 help、缺参、dry-run、JSON、Profile、鉴权、网络错误和最低 Node 版本。

另外请确认产品边界:当前实现同时暴露 bailianclaudeqoderarkall。如果首期只支持百炼,应由产品层 policy 禁止其他 provider;如果确定支持多 provider,需要正式设计 provider credential、telemetry、错误归属和安全边界,不能继续统一使用 auth: "none"

当前只有错误映射和 credential bridge 的辅助单测,没有新增 CMA/Agent commands topic E2E。修复后请至少覆盖每个 leaf command 的 help/缺参、dry-run 不联网不写盘、单一 JSON stdout、显式 JSONL、命名 Profile、NETWORK/TIMEOUT、配置/logout 生命周期,以及最低支持 Node 版本 smoke。

Comment thread packages/cli/src/commands.ts Outdated
"plugin link": pluginLink,
"plugin list": pluginList,
"plugin remove": pluginRemove,
"agent init": agentInit,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 命令命名空间与现有 Command Pack 冲突

这里把 OpenAgentPack 注册到了 bl agent ...,但 agent 已经属于现有内网 Command Pack 的允许前缀。两套能力共用一级命名空间会混淆帮助信息和能力归属;当两边出现同路径命令时,Command Pack 还会因为 command conflict 整包加载失败。

请改为产品确认的独立前缀,例如原先约定的 bl cma ...,并同步更新 reference、help、示例、错误提示和 E2E。

"check": "vp check"
},
"dependencies": {
"@openagentpack/sdk": "0.3.0-beta-8d9edcd-20260722",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] SDK 的 Node 版本破坏现有发布契约

当前引入的 @openagentpack/sdk 声明 engines.node >=22,但 bailian-clibailian-cli-commands 和 README 仍承诺 Node >=18.17。Agent commands 又通过 commands index 静态导出,SDK 没有被安全隔离到 bl cma 执行时才加载,因此 Node 18/20 下可能影响整个 bl 的启动。

请先统一运行时契约:要么让 SDK 支持并验证现有 Node 范围,要么同步提升所有发布包、README、CI 和发布检查的 Node 下限。需要增加最低支持 Node 版本下的安装及 bl --help smoke。

* providers (claude/qoder/ark) don't need DashScope credentials at all.
*/
export function bridgeBailianCredentials(): void {
const file = readConfigFile();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Bailian 鉴权绕过 Profile 和 authStage

Agent 命令声明 auth: "none",但执行时又通过 SDK bootstrap、readConfigFile()process.env 自行读取凭据。这会绕过 runtime 的 Profile/authStage:显式 --config <name> 或当前激活 Profile 可能与 SDK 实际使用的账号不一致,telemetry 却仍记录 authMethod: none;SDK bootstrap 还会修改进程级环境变量。

请建立正式的 Host Credential Adapter。Bailian provider 应消费 CLI 已解析的 Profile、API Key、workspace 和 endpoint;SDK 不应隐式读取 ~/.agents/config.json、覆盖 shell env 或修改 process.env。也不要机械地把所有命令改成 auth: "apiKey":本地命令应保持离线,真正访问 provider 的命令再进入明确的 credential policy。


const result = await withAgentErrors(() =>
withStdoutProtected(() =>
executePlannedProject(planned, {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] --dry-run 没有阻止真实写操作

这里没有处理全局 settings.dryRun,进入后仍会调用 executePlannedProject,产生真实远程变更。

请在任何远程或本地写操作前处理 dry-run,并同步审计 destroyinitstate import/rmsession create/delete/run/send,以及 plan refresh 产生的本地 state 写入。dry-run 必须在联网、refresh 写 state、创建 session、上传或写文件之前短路,并用 E2E/mock 明确断言 SDK mutation 没有被调用。

}

const creates = actionable.filter((action) => action.action === "create").length;
const updates = actionable.filter((action) => action.action === "update").length;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] --output json 的 stdout 被普通文本污染

apply 在 JSON 模式下仍会先通过 emitBare 输出 action 列表,之后再输出 JSON,导致 stdout 不是合法的单一 JSON。destroy、无变更分支和部分错误诊断也有同类问题。

请统一输出协议:progress、资源列表和提示进入 stderr;--quiet 抑制非必要进度;--output json 的 stdout 只能有一个结构化结果;错误继续由 runtime error handler 统一写入 stderr。

| "access_key_secret"
| "security_token"
| "base_url"
| "agentstudio_base_url"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Logout 没有清理 AgentStudio 地址

新增了 agentstudio_base_url 的持久化能力,但 auth logout 的 all scope 没有清理它。用户重新登录另一个账号或 workspace 后,旧 AgentStudio endpoint 仍可能被继续使用。

请把该字段纳入 LOGOUT_KEYS.all,同步更新 dry-run 文案、实际退出提示和 auth E2E。若未来存在独立 CMA credential scope,也需要明确 scoped logout 的保留/清理规则。

* `/api/v1/agentstudio` path) and must NOT go through model-URL suffix
* stripping like `base_url`.
*/
function isHttpUrl(value: string): boolean {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] AgentStudio URL 没有统一规范化

当前只验证 URL 是否为 http(s),auth login 又会直接持久化用户输入。SDK 使用 ${baseUrl}${path} 拼接请求,因此常见的尾斜杠会产生双斜杠,query/fragment 还会直接破坏后续 API path。

请增加统一的 normalizeAgentStudioBaseUrl,供 config parse、config set 和 auth login 共用。至少应移除尾斜杠、拒绝 query/fragment/userinfo,并明确是否要求 /api/v1/agentstudio、是否允许自定义网关;补 flag/config/Profile 三种来源的测试。

* error mapping, so the caller's response semantics (status handling, SSE,
* conflict detection) stay intact.
*/
export function createInstrumentedFetch(deps: HttpDeps): FetchImplementation {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] SDK transport 没有继承全局 timeout

createInstrumentedFetch 明确没有消费 settings.timeout,因此 bl cma ... --timeout 对 SDK HTTP、SSE 和部分 polling 调用不生效。

请把 timeout/AbortSignal 作为 Host Transport 的正式能力,而不是只补 User-Agent 和 tracking header。需要明确父 signal 与 CLI timeout 的组合方式,并验证普通 fetch、SSE、polling timeout 最终都映射为 Bailian CLI 的 TIMEOUT 错误。

assertProviderConfigured(runtime, flags.provider);
return planProjectContext(runtime, {
provider: flags.provider,
refresh: !flags.noRefresh,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] --refresh-only 当前是死选项

--refresh-only 没有进入任何执行参数,当前行为与普通 plan 完全相同,只是在最后多输出一行提示;它还可以与 --no-refresh 同时使用。

请删除该选项,或实现真实的 refresh-only 语义并拒绝冲突组合。测试应验证该模式只执行允许的 refresh/state 行为,不生成或执行 mutation。

*/
export const CREDENTIALS_NOTE = [
"Credentials come from the env vars referenced in agents.yaml (e.g. ${DASHSCOPE_API_KEY}, ${BAILIAN_BASE_URL}).",
"For the bailian provider, bl fills these from your login as a fallback: `bl auth login --api-key <key> --agentstudio-base-url <url>`.",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 用户提示泄漏上游 agents 和旧的 bl agent 路径

shared commands 中硬编码了 bl agent,SDK 的 UserError 还可能提示用户执行 agents apply。迁移到 bl cma 后,这些 help/hint 会直接误导用户,也违反 commands 不决定产品入口路径的分层约定。

请全量审计用户可见字符串。命令名应由 ctx.identity.binName 和产品 command path 注入;SDK 的本地错误最好返回结构化 code/context,由 Host Adapter 生成宿主侧提示,而不是在 SDK 中硬编码 agents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants