From 24abdbf450b35eafe0ca446845f80c4f82bb4dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=A5=E9=BA=92?= Date: Wed, 24 Jun 2026 14:40:08 +0800 Subject: [PATCH] refactor(commands): decouple command paths from binary name; drop path presets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commands no longer hardcode "bl" or their path — the runtime renders the ` ` prefix from each product's registry key, so shared commands show `bl knowledge retrieve` / `rag retrieve` from one codebase. commands package now exports only individual commands (no groups/catalog); bl and rag each spell out their own path map. Also removes the unused export-schema command. --- packages/cli/src/commands.ts | 101 ++++++++++ packages/cli/src/main.ts | 3 +- .../src/commands/advisor/recommend.ts | 21 +- packages/commands/src/commands/app/call.ts | 23 ++- packages/commands/src/commands/app/list.ts | 10 +- packages/commands/src/commands/auth/login.ts | 5 +- packages/commands/src/commands/auth/logout.ts | 10 +- packages/commands/src/commands/auth/status.ts | 14 +- packages/commands/src/commands/catalog.ts | 2 - .../src/commands/config/export-schema.ts | 47 ----- packages/commands/src/commands/config/set.ts | 15 +- packages/commands/src/commands/config/show.ts | 4 +- .../commands/src/commands/console/call.ts | 15 +- packages/commands/src/commands/file/upload.ts | 19 +- packages/commands/src/commands/groups.ts | 183 ------------------ packages/commands/src/commands/image/edit.ts | 21 +- .../commands/src/commands/image/generate.ts | 27 ++- packages/commands/src/commands/index.ts | 1 - .../src/commands/knowledge/retrieve.ts | 17 +- packages/commands/src/commands/mcp/call.ts | 15 +- packages/commands/src/commands/mcp/list.ts | 7 +- packages/commands/src/commands/mcp/tools.ts | 17 +- packages/commands/src/commands/memory/add.ts | 15 +- .../commands/src/commands/memory/delete.ts | 11 +- packages/commands/src/commands/memory/list.ts | 12 +- .../src/commands/memory/profile-create.ts | 13 +- .../src/commands/memory/profile-get.ts | 12 +- .../commands/src/commands/memory/search.ts | 13 +- .../commands/src/commands/memory/update.ts | 15 +- packages/commands/src/commands/omni/chat.ts | 25 ++- .../commands/src/commands/pipeline/run.ts | 21 +- .../src/commands/pipeline/validate.ts | 12 +- packages/commands/src/commands/quota/check.ts | 15 +- .../commands/src/commands/quota/history.ts | 13 +- packages/commands/src/commands/quota/list.ts | 15 +- .../commands/src/commands/quota/request.ts | 17 +- packages/commands/src/commands/search/web.ts | 17 +- .../commands/src/commands/speech/recognize.ts | 23 ++- .../src/commands/speech/synthesize.ts | 27 ++- packages/commands/src/commands/text/chat.ts | 21 +- packages/commands/src/commands/update.ts | 4 +- packages/commands/src/commands/usage/free.ts | 19 +- .../commands/src/commands/usage/freetier.ts | 17 +- packages/commands/src/commands/usage/stats.ts | 25 +-- .../commands/src/commands/video/download.ts | 15 +- packages/commands/src/commands/video/edit.ts | 17 +- .../commands/src/commands/video/generate.ts | 19 +- packages/commands/src/commands/video/ref.ts | 21 +- .../commands/src/commands/video/task-get.ts | 13 +- .../commands/src/commands/vision/describe.ts | 19 +- .../commands/src/commands/workspace/list.ts | 5 +- packages/commands/src/index.ts | 111 +++++------ packages/core/src/types/command.ts | 28 ++- packages/core/src/utils/index.ts | 1 - packages/core/src/utils/schema.ts | 82 -------- packages/rag/src/main.ts | 60 ++++-- packages/runtime/src/index.ts | 8 +- packages/runtime/src/output/prompt.ts | 13 +- packages/runtime/src/registry.ts | 16 +- skills/bailian-cli/reference/advisor.md | 4 +- skills/bailian-cli/reference/app.md | 2 +- skills/bailian-cli/reference/auth.md | 4 +- skills/bailian-cli/reference/config.md | 35 +--- skills/bailian-cli/reference/console.md | 2 +- skills/bailian-cli/reference/file.md | 2 +- skills/bailian-cli/reference/image.md | 2 +- skills/bailian-cli/reference/index.md | 5 +- skills/bailian-cli/reference/knowledge.md | 2 +- skills/bailian-cli/reference/mcp.md | 10 +- skills/bailian-cli/reference/memory.md | 2 +- skills/bailian-cli/reference/omni.md | 2 +- skills/bailian-cli/reference/pipeline.md | 2 +- skills/bailian-cli/reference/quota.md | 2 +- skills/bailian-cli/reference/search.md | 2 +- skills/bailian-cli/reference/speech.md | 6 +- skills/bailian-cli/reference/text.md | 4 +- skills/bailian-cli/reference/update.md | 2 +- skills/bailian-cli/reference/usage.md | 2 +- skills/bailian-cli/reference/video.md | 2 +- skills/bailian-cli/reference/vision.md | 2 +- skills/bailian-cli/reference/workspace.md | 2 +- tools/generate-reference.ts | 27 +-- 82 files changed, 620 insertions(+), 872 deletions(-) create mode 100644 packages/cli/src/commands.ts delete mode 100644 packages/commands/src/commands/catalog.ts delete mode 100644 packages/commands/src/commands/config/export-schema.ts delete mode 100644 packages/commands/src/commands/groups.ts delete mode 100644 packages/commands/src/commands/index.ts delete mode 100644 packages/core/src/utils/schema.ts diff --git a/packages/cli/src/commands.ts b/packages/cli/src/commands.ts new file mode 100644 index 0000000..9fbc675 --- /dev/null +++ b/packages/cli/src/commands.ts @@ -0,0 +1,101 @@ +import type { Command } from "bailian-cli-core"; +import { + authLogin, + authStatus, + authLogout, + textChat, + textOmni, + imageGenerate, + imageEdit, + videoGenerate, + videoEdit, + videoRef, + videoTaskGet, + videoDownload, + visionDescribe, + configShow, + configSet, + update, + appCall, + appList, + memoryAdd, + memorySearch, + memoryList, + memoryUpdate, + memoryDelete, + memoryProfileCreate, + memoryProfileGet, + knowledgeRetrieve, + mcpCall, + mcpList, + mcpTools, + searchWeb, + speechSynthesize, + speechRecognize, + fileUpload, + consoleCall, + usageFree, + usageFreetier, + usageStats, + pipelineRun, + pipelineValidate, + advisorRecommend, + workspaceList, + quotaList, + quotaRequest, + quotaHistory, + quotaCheck, +} from "bailian-cli-commands"; + +// Full bailian-cli product: every command, exposed under the `bl` binary. +// The command paths below are this product's decision — the command library +// ships no presets, so the map is spelled out here. Kept in its own module +// (no side effects) so tools like generate-reference.ts can import it without +// starting the CLI. +export const commands: Record = { + "auth login": authLogin, + "auth status": authStatus, + "auth logout": authLogout, + "text chat": textChat, + omni: textOmni, + "image generate": imageGenerate, + "image edit": imageEdit, + "video generate": videoGenerate, + "video edit": videoEdit, + "video ref": videoRef, + "video task get": videoTaskGet, + "video download": videoDownload, + "vision describe": visionDescribe, + "config show": configShow, + "config set": configSet, + update, + "app call": appCall, + "app list": appList, + "memory add": memoryAdd, + "memory search": memorySearch, + "memory list": memoryList, + "memory update": memoryUpdate, + "memory delete": memoryDelete, + "memory profile create": memoryProfileCreate, + "memory profile get": memoryProfileGet, + "knowledge retrieve": knowledgeRetrieve, + "mcp call": mcpCall, + "mcp list": mcpList, + "mcp tools": mcpTools, + "search web": searchWeb, + "speech synthesize": speechSynthesize, + "speech recognize": speechRecognize, + "file upload": fileUpload, + "console call": consoleCall, + "usage free": usageFree, + "usage freetier": usageFreetier, + "usage stats": usageStats, + "pipeline run": pipelineRun, + "pipeline validate": pipelineValidate, + "advisor recommend": advisorRecommend, + "workspace list": workspaceList, + "quota list": quotaList, + "quota request": quotaRequest, + "quota history": quotaHistory, + "quota check": quotaCheck, +}; diff --git a/packages/cli/src/main.ts b/packages/cli/src/main.ts index 438133f..1e32e7f 100644 --- a/packages/cli/src/main.ts +++ b/packages/cli/src/main.ts @@ -1,8 +1,7 @@ import { createCli } from "bailian-cli-runtime"; -import { commands } from "bailian-cli-commands"; +import { commands } from "./commands.ts"; import pkg from "../package.json" with { type: "json" }; -// Full bailian-cli product: every command, exposed under the `bl` binary. createCli(commands, { binName: "bl", version: pkg.version, diff --git a/packages/commands/src/commands/advisor/recommend.ts b/packages/commands/src/commands/advisor/recommend.ts index 798ee49..81c6ddd 100644 --- a/packages/commands/src/commands/advisor/recommend.ts +++ b/packages/commands/src/commands/advisor/recommend.ts @@ -19,7 +19,7 @@ import boxen from "boxen"; import chalk, { Chalk, type ChalkInstance } from "chalk"; import { emitBare, emitResult } from "bailian-cli-runtime"; import { createSpinner } from "bailian-cli-runtime"; -import { failIfMissing, promptText } from "bailian-cli-runtime"; +import { failIfMissing, promptText, cmdUsage } from "bailian-cli-runtime"; function formatContextWindow(tokens: number): string { if (tokens >= 1_000_000) @@ -215,10 +215,9 @@ function isEmptyResult(result: RecommendResult): boolean { } export default defineCommand({ - name: "advisor recommend", description: "Recommend the best models for your use case (intent analysis → candidate recall → LLM ranking)", - usage: "bl advisor recommend [flags]", + usageArgs: " [flags]", options: [ { flag: "--message ", @@ -233,13 +232,13 @@ export default defineCommand({ description: "Output format: text (default in TTY), json, yaml", }, ], - examples: [ - 'bl advisor recommend --message "I need a visual-understanding chatbot"', - 'bl advisor recommend --message "Build an Agent that auto-generates animations"', - 'bl advisor recommend --message "Legal contract review, high precision required"', - 'bl advisor recommend --message "Low-cost high-concurrency online customer service" --output json', - 'bl advisor recommend --message "Long document summarization" --dry-run', - "bl advisor recommend # Interactive input", + exampleArgs: [ + '--message "I need a visual-understanding chatbot"', + '--message "Build an Agent that auto-generates animations"', + '--message "Legal contract review, high precision required"', + '--message "Low-cost high-concurrency online customer service" --output json', + '--message "Long document summarization" --dry-run', + " # Interactive input", ], async run(config: Config, flags: GlobalFlags) { const positional = ((flags as Record)._positional as string[]) ?? []; @@ -254,7 +253,7 @@ export default defineCommand({ } userInput = hint; } else { - failIfMissing("message", 'bl advisor recommend "your requirement"'); + failIfMissing("message", cmdUsage(config, '"your requirement"')); } } diff --git a/packages/commands/src/commands/app/call.ts b/packages/commands/src/commands/app/call.ts index 53cd8b3..d784a65 100644 --- a/packages/commands/src/commands/app/call.ts +++ b/packages/commands/src/commands/app/call.ts @@ -11,13 +11,12 @@ import { type AppStreamChunk, type AppCompletionResponse, } from "bailian-cli-core"; -import { failIfMissing } from "bailian-cli-runtime"; +import { failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; export default defineCommand({ - name: "app call", description: "Call a Bailian application (agent or workflow)", - usage: "bl app call --app-id --prompt [flags]", + usageArgs: "--app-id --prompt [flags]", options: [ { flag: "--app-id ", description: "Application ID (required)", required: true }, { flag: "--prompt ", description: "Input prompt text", required: true }, @@ -34,20 +33,20 @@ export default defineCommand({ { flag: "--biz-params ", description: "Business parameters JSON (workflow variables)" }, { flag: "--has-thoughts", description: "Show agent thinking process" }, ], - examples: [ - 'bl app call --app-id abc123 --prompt "Hello"', - 'bl app call --app-id abc123 --prompt "Describe this image" --image https://example.com/photo.jpg', - 'bl app call --app-id abc123 --prompt "Analyze the image" --image img1.jpg --image img2.jpg', - 'bl app call --app-id abc123 --prompt "Continue" --session-id sess_xxx --stream', - 'bl app call --app-id abc123 --prompt "Search for materials" --pipeline-ids pipe1,pipe2', - 'bl app call --app-id abc123 --prompt "Start" --biz-params \'{"key":"value"}\'', + exampleArgs: [ + '--app-id abc123 --prompt "Hello"', + '--app-id abc123 --prompt "Describe this image" --image https://example.com/photo.jpg', + '--app-id abc123 --prompt "Analyze the image" --image img1.jpg --image img2.jpg', + '--app-id abc123 --prompt "Continue" --session-id sess_xxx --stream', + '--app-id abc123 --prompt "Search for materials" --pipeline-ids pipe1,pipe2', + '--app-id abc123 --prompt "Start" --biz-params \'{"key":"value"}\'', ], async run(config: Config, flags: GlobalFlags) { const appId = flags.appId as string; - if (!appId) failIfMissing("app-id", "bl app call --app-id --prompt "); + if (!appId) failIfMissing("app-id", cmdUsage(config, "--app-id --prompt ")); const prompt = flags.prompt as string; - if (!prompt) failIfMissing("prompt", "bl app call --app-id --prompt "); + if (!prompt) failIfMissing("prompt", cmdUsage(config, "--app-id --prompt ")); const shouldStream = flags.stream === true || (flags.stream === undefined && process.stdout.isTTY); diff --git a/packages/commands/src/commands/app/list.ts b/packages/commands/src/commands/app/list.ts index b3247b4..ca98664 100644 --- a/packages/commands/src/commands/app/list.ts +++ b/packages/commands/src/commands/app/list.ts @@ -11,10 +11,9 @@ import { emitResult } from "bailian-cli-runtime"; const APP_LIST_API = "zeldaEasy.broadscope-bailian.app-control.list"; export default defineCommand({ - name: "app list", description: "List Bailian applications", skipDefaultApiKeySetup: true, - usage: "bl app list [flags]", + usageArgs: "[flags]", options: [ { flag: "--name ", @@ -41,12 +40,7 @@ export default defineCommand({ type: "number", }, ], - examples: [ - "bl app list", - "bl app list --name customer service", - "bl app list --page 2 --page-size 10", - "bl app list --output json", - ], + exampleArgs: ["", "--name customer service", "--page 2 --page-size 10", "--output json"], async run(config: Config, flags: GlobalFlags) { const name = (flags.name as string) || ""; const pageNo = (flags.page as number) || 1; diff --git a/packages/commands/src/commands/auth/login.ts b/packages/commands/src/commands/auth/login.ts index 8549ac8..3901369 100644 --- a/packages/commands/src/commands/auth/login.ts +++ b/packages/commands/src/commands/auth/login.ts @@ -18,10 +18,9 @@ import { } from "./login-console.ts"; export default defineCommand({ - name: "auth login", description: "Authenticate with API key or console browser login (credentials can coexist)", skipDefaultApiKeySetup: true, - usage: "bl auth login --api-key | bl auth login --console", + usageArgs: "--api-key | --console", options: [ { flag: "--api-key ", description: "DashScope API key to store" }, { @@ -34,7 +33,7 @@ export default defineCommand({ "Sign in via browser; use --console-site to choose domestic (default) or international", }, ], - examples: ["bl auth login --api-key sk-xxxxx", "bl auth login --console"], + exampleArgs: ["--api-key sk-xxxxx", "--console"], async run(config: Config, flags: GlobalFlags) { if (flags.console) { if (config.dryRun) { diff --git a/packages/commands/src/commands/auth/logout.ts b/packages/commands/src/commands/auth/logout.ts index a690c22..f05646a 100644 --- a/packages/commands/src/commands/auth/logout.ts +++ b/packages/commands/src/commands/auth/logout.ts @@ -18,10 +18,9 @@ async function clearConsoleToken(): Promise { } export default defineCommand({ - name: "auth logout", description: "Clear stored credentials", skipDefaultApiKeySetup: true, - usage: "bl auth logout [--console] [--yes] [--dry-run]", + usageArgs: "[--console] [--yes] [--dry-run]", options: [ { flag: "--console", @@ -30,12 +29,7 @@ export default defineCommand({ }, { flag: "--yes", description: "Skip confirmation prompt" }, ], - examples: [ - "bl auth logout", - "bl auth logout --console", - "bl auth logout --dry-run", - "bl auth logout --yes", - ], + exampleArgs: ["", "--console", "--dry-run", "--yes"], async run(config: Config, flags: GlobalFlags) { const file = readConfigFile(); diff --git a/packages/commands/src/commands/auth/status.ts b/packages/commands/src/commands/auth/status.ts index 68649ed..aacf4ea 100644 --- a/packages/commands/src/commands/auth/status.ts +++ b/packages/commands/src/commands/auth/status.ts @@ -108,7 +108,7 @@ function hasAnyAuth(status: AuthStatusPayload): boolean { ); } -function emitTextStatus(status: AuthStatusPayload): void { +function emitTextStatus(status: AuthStatusPayload, config: Config): void { emitBare("Authentication Status:"); emitBare(" Stored credentials (can coexist):"); if (status.api_key.configured) { @@ -134,14 +134,12 @@ function emitTextStatus(status: AuthStatusPayload): void { ` Console gateway: ${status.console_gateway_commands.method} (${status.console_gateway_commands.source}) ${status.console_gateway_commands.masked}`, ); } else { - emitBare(" Console gateway: unavailable (run bl auth login --console)"); + emitBare(` Console gateway: unavailable (run ${config.binName} auth login --console)`); } } export default defineCommand({ - name: "auth status", description: "Show current authentication state", - usage: "bl auth status", options: [ { flag: "--console-region ", description: "Console region" }, { @@ -154,7 +152,7 @@ export default defineCommand({ type: "number", }, ], - examples: ["bl auth status", "bl auth status --output json"], + exampleArgs: ["", "--output json"], async run(config: Config, _flags: GlobalFlags) { const format = detectOutputFormat(config.output); const status = await buildStatus(config); @@ -164,8 +162,8 @@ export default defineCommand({ authenticated: false, message: "Not authenticated.", hint: [ - "DashScope API: bl auth login --api-key or DASHSCOPE_API_KEY", - "Console gateway: bl auth login --console or DASHSCOPE_ACCESS_TOKEN", + `DashScope API: ${config.binName} auth login --api-key or DASHSCOPE_API_KEY`, + `Console gateway: ${config.binName} auth login --console or DASHSCOPE_ACCESS_TOKEN`, `Get API Key: ${API_KEY_PAGE}`, ].join("\n"), ...status, @@ -179,6 +177,6 @@ export default defineCommand({ return; } - emitTextStatus(status); + emitTextStatus(status, config); }, }); diff --git a/packages/commands/src/commands/catalog.ts b/packages/commands/src/commands/catalog.ts deleted file mode 100644 index 518a152..0000000 --- a/packages/commands/src/commands/catalog.ts +++ /dev/null @@ -1,2 +0,0 @@ -/** Full command registry map (all groups merged). Kept for backward compatibility. */ -export { commands } from "./groups.ts"; diff --git a/packages/commands/src/commands/config/export-schema.ts b/packages/commands/src/commands/config/export-schema.ts deleted file mode 100644 index 70824c3..0000000 --- a/packages/commands/src/commands/config/export-schema.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { defineCommand, generateToolSchema } from "bailian-cli-core"; -import type { Config } from "bailian-cli-core"; -import type { GlobalFlags } from "bailian-cli-core"; -import { BailianError } from "bailian-cli-core"; -import { ExitCode } from "bailian-cli-core"; - -/** - * Commands that are infrastructure/auth-related and not suitable as Agent tools. - */ -const SKIP_PREFIXES = ["auth ", "config ", "update"]; - -export default defineCommand({ - name: "config export-schema", - description: - "Export all (or one) CLI command(s) as Anthropic/OpenAI-compatible JSON tool schemas", - skipDefaultApiKeySetup: true, - usage: 'bl config export-schema [--command ""]', - options: [ - { - flag: "--command ", - description: 'Export schema for a specific command only (e.g. "image generate")', - }, - ], - examples: ["bl config export-schema", 'bl config export-schema --command "video generate"'], - async run(config: Config, flags: GlobalFlags) { - const { commands } = await import("../catalog.ts"); - const targetCommand = flags.command as string | undefined; - - if (targetCommand) { - const command = commands[targetCommand]; - if (!command) { - throw new BailianError(`Command "${targetCommand}" not found.`, ExitCode.USAGE); - } - const schema = generateToolSchema(command); - process.stdout.write(JSON.stringify(schema, null, 2) + "\n"); - return; - } - - // Export all suitable commands - const allCommands = Object.values(commands); - const schemas = allCommands - .filter((c) => !SKIP_PREFIXES.some((p) => c.name.startsWith(p))) - .map((c) => generateToolSchema(c)); - - process.stdout.write(JSON.stringify(schemas, null, 2) + "\n"); - }, -}); diff --git a/packages/commands/src/commands/config/set.ts b/packages/commands/src/commands/config/set.ts index b866473..748594a 100644 --- a/packages/commands/src/commands/config/set.ts +++ b/packages/commands/src/commands/config/set.ts @@ -9,7 +9,7 @@ import { type GlobalFlags, ExitCode, } from "bailian-cli-core"; -import { emitResult } from "bailian-cli-runtime"; +import { emitResult, cmdUsage } from "bailian-cli-runtime"; const VALID_KEYS = [ "base_url", @@ -50,10 +50,9 @@ const KEY_ALIASES: Record = { }; export default defineCommand({ - name: "config set", description: "Set a config value", skipDefaultApiKeySetup: true, - usage: "bl config set --key --value ", + usageArgs: "--key --value ", options: [ { flag: "--key ", @@ -62,10 +61,10 @@ export default defineCommand({ }, { flag: "--value ", description: "Value to set" }, ], - examples: [ - "bl config set --key output --value json", - "bl config set --key timeout --value 600", - "bl config set --key base_url --value https://dashscope.aliyuncs.com", + exampleArgs: [ + "--key output --value json", + "--key timeout --value 600", + "--key base_url --value https://dashscope.aliyuncs.com", ], async run(config: Config, flags: GlobalFlags) { const key = flags.key as string | undefined; @@ -75,7 +74,7 @@ export default defineCommand({ throw new BailianError( "--key and --value are required.", ExitCode.USAGE, - "bl config set --key --value ", + cmdUsage(config, "--key --value "), ); } diff --git a/packages/commands/src/commands/config/show.ts b/packages/commands/src/commands/config/show.ts index a9c1fa8..7b76687 100644 --- a/packages/commands/src/commands/config/show.ts +++ b/packages/commands/src/commands/config/show.ts @@ -10,11 +10,9 @@ import { import { emitResult } from "bailian-cli-runtime"; export default defineCommand({ - name: "config show", description: "Display current configuration", skipDefaultApiKeySetup: true, - usage: "bl config show", - examples: ["bl config show", "bl config show --output json"], + exampleArgs: ["", "--output json"], async run(config: Config, _flags: GlobalFlags) { const file = loadConfigFile(); const format = detectOutputFormat(config.output); diff --git a/packages/commands/src/commands/console/call.ts b/packages/commands/src/commands/console/call.ts index 5726761..525377b 100644 --- a/packages/commands/src/commands/console/call.ts +++ b/packages/commands/src/commands/console/call.ts @@ -9,14 +9,13 @@ import { type Config, type GlobalFlags, } from "bailian-cli-core"; -import { failIfMissing } from "bailian-cli-runtime"; +import { failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult } from "bailian-cli-runtime"; export default defineCommand({ - name: "console call", description: "Call a Bailian console API via the CLI gateway", skipDefaultApiKeySetup: true, - usage: "bl console call --api --data [flags]", + usageArgs: "--api --data [flags]", options: [ { flag: "--api ", @@ -39,16 +38,16 @@ export default defineCommand({ type: "number", }, ], - examples: [ - `bl console call --api zeldaEasy.broadscope-bailian.freeTrial.queryFreeTierQuota --data '{"queryFreeTierQuotaRequest":{"models":["qwen3-max"]}}'`, - `bl console call --api some.api.name --data '{"key":"value"}' --console-region cn-beijing`, + exampleArgs: [ + `--api zeldaEasy.broadscope-bailian.freeTrial.queryFreeTierQuota --data '{"queryFreeTierQuotaRequest":{"models":["qwen3-max"]}}'`, + `--api some.api.name --data '{"key":"value"}' --console-region cn-beijing`, ], async run(config: Config, flags: GlobalFlags) { const api = flags.api as string; - if (!api) failIfMissing("api", "bl console call --api --data "); + if (!api) failIfMissing("api", cmdUsage(config, "--api --data ")); const dataRaw = flags.data as string; - if (!dataRaw) failIfMissing("data", "bl console call --api --data "); + if (!dataRaw) failIfMissing("data", cmdUsage(config, "--api --data ")); let data: Record; try { diff --git a/packages/commands/src/commands/file/upload.ts b/packages/commands/src/commands/file/upload.ts index 999211f..f0a1713 100644 --- a/packages/commands/src/commands/file/upload.ts +++ b/packages/commands/src/commands/file/upload.ts @@ -6,13 +6,12 @@ import { type GlobalFlags, uploadFile, } from "bailian-cli-core"; -import { failIfMissing } from "bailian-cli-runtime"; +import { failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; export default defineCommand({ - name: "file upload", description: "Upload a local file to DashScope temporary storage (48h)", - usage: "bl file upload --file --model ", + usageArgs: "--file --model ", options: [ { flag: "--file ", @@ -25,21 +24,21 @@ export default defineCommand({ required: true, }, ], - examples: [ - "bl file upload --file photo.jpg --model qwen3-vl-plus", - "bl file upload --file video.mp4 --model wan2.1-t2v-plus", - "bl file upload --file audio.wav --model qwen3-asr-flash", - "bl file upload --file cat.png --model qwen-image-2.0", + exampleArgs: [ + "--file photo.jpg --model qwen3-vl-plus", + "--file video.mp4 --model wan2.1-t2v-plus", + "--file audio.wav --model qwen3-asr-flash", + "--file cat.png --model qwen-image-2.0", ], async run(config: Config, flags: GlobalFlags) { const filePath = flags.file as string | undefined; if (!filePath) { - failIfMissing("file", "bl file upload --file --model "); + failIfMissing("file", cmdUsage(config, "--file --model ")); } const model = flags.model as string | undefined; if (!model) { - failIfMissing("model", "bl file upload --file --model "); + failIfMissing("model", cmdUsage(config, "--file --model ")); } const format = detectOutputFormat(config.output); diff --git a/packages/commands/src/commands/groups.ts b/packages/commands/src/commands/groups.ts deleted file mode 100644 index f170821..0000000 --- a/packages/commands/src/commands/groups.ts +++ /dev/null @@ -1,183 +0,0 @@ -import type { Command } from "bailian-cli-core"; - -import authLogin from "./auth/login.ts"; -import authStatus from "./auth/status.ts"; -import authLogout from "./auth/logout.ts"; -import textChat from "./text/chat.ts"; -import textOmni from "./omni/chat.ts"; -import imageGenerate from "./image/generate.ts"; -import imageEdit from "./image/edit.ts"; -import videoGenerate from "./video/generate.ts"; -import videoEdit from "./video/edit.ts"; -import videoRef from "./video/ref.ts"; -import videoTaskGet from "./video/task-get.ts"; -import videoDownload from "./video/download.ts"; -import visionDescribe from "./vision/describe.ts"; -import configShow from "./config/show.ts"; -import configSet from "./config/set.ts"; -import configExportSchema from "./config/export-schema.ts"; -import update from "./update.ts"; -import appCall from "./app/call.ts"; -import appList from "./app/list.ts"; -import memoryAdd from "./memory/add.ts"; -import memorySearch from "./memory/search.ts"; -import memoryList from "./memory/list.ts"; -import memoryUpdate from "./memory/update.ts"; -import memoryDelete from "./memory/delete.ts"; -import memoryProfileCreate from "./memory/profile-create.ts"; -import memoryProfileGet from "./memory/profile-get.ts"; -import knowledgeRetrieve from "./knowledge/retrieve.ts"; -import mcpCall from "./mcp/call.ts"; -import mcpList from "./mcp/list.ts"; -import mcpTools from "./mcp/tools.ts"; -import searchWeb from "./search/web.ts"; -import speechSynthesize from "./speech/synthesize.ts"; -import speechRecognize from "./speech/recognize.ts"; -import fileUpload from "./file/upload.ts"; -import consoleCall from "./console/call.ts"; -import usageFree from "./usage/free.ts"; -import usageFreetier from "./usage/freetier.ts"; -import usageStats from "./usage/stats.ts"; -import pipelineRun from "./pipeline/run.ts"; -import pipelineValidate from "./pipeline/validate.ts"; -import advisorRecommend from "./advisor/recommend.ts"; -import workspaceList from "./workspace/list.ts"; -import quotaList from "./quota/list.ts"; -import quotaRequest from "./quota/request.ts"; -import quotaHistory from "./quota/history.ts"; -import quotaCheck from "./quota/check.ts"; - -// Re-export individual command implementations so entrypoints can remap their -// paths freely (e.g. rag-cli mapping "knowledge retrieve" → "retrieve"). -export { - authLogin, - authStatus, - authLogout, - textChat, - textOmni, - imageGenerate, - imageEdit, - videoGenerate, - videoEdit, - videoRef, - videoTaskGet, - videoDownload, - visionDescribe, - configShow, - configSet, - configExportSchema, - update, - appCall, - appList, - memoryAdd, - memorySearch, - memoryList, - memoryUpdate, - memoryDelete, - memoryProfileCreate, - memoryProfileGet, - knowledgeRetrieve, - mcpCall, - mcpList, - mcpTools, - searchWeb, - speechSynthesize, - speechRecognize, - fileUpload, - consoleCall, - usageFree, - usageFreetier, - usageStats, - pipelineRun, - pipelineValidate, - advisorRecommend, - workspaceList, - quotaList, - quotaRequest, - quotaHistory, - quotaCheck, -}; - -/** - * Base/infrastructure commands every product needs: auth, config, usage, quota, - * update, and file upload. file-upload lives here (not in knowledge) because it - * is generic infra that knowledge and other capabilities build on. - */ -export const baseCommands: Record = { - "auth login": authLogin, - "auth status": authStatus, - "auth logout": authLogout, - "config show": configShow, - "config set": configSet, - "config export-schema": configExportSchema, - "usage free": usageFree, - "usage freetier": usageFreetier, - "usage stats": usageStats, - "quota list": quotaList, - "quota request": quotaRequest, - "quota history": quotaHistory, - "quota check": quotaCheck, - "file upload": fileUpload, - update: update, -}; - -/** Knowledge base (RAG) commands. */ -export const knowledgeCommands: Record = { - "knowledge retrieve": knowledgeRetrieve, -}; - -/** Text & multimodal chat commands. */ -export const textCommands: Record = { - "text chat": textChat, - omni: textOmni, -}; - -/** Media generation commands: image / video / vision / speech. */ -export const mediaCommands: Record = { - "image generate": imageGenerate, - "image edit": imageEdit, - "video generate": videoGenerate, - "video edit": videoEdit, - "video ref": videoRef, - "video task get": videoTaskGet, - "video download": videoDownload, - "vision describe": visionDescribe, - "speech synthesize": speechSynthesize, - "speech recognize": speechRecognize, -}; - -/** Memory system commands. */ -export const memoryCommands: Record = { - "memory add": memoryAdd, - "memory search": memorySearch, - "memory list": memoryList, - "memory update": memoryUpdate, - "memory delete": memoryDelete, - "memory profile create": memoryProfileCreate, - "memory profile get": memoryProfileGet, -}; - -/** Remaining capability commands: mcp / search / app / advisor / workspace / console / pipeline. */ -export const miscCommands: Record = { - "mcp list": mcpList, - "mcp tools": mcpTools, - "mcp call": mcpCall, - "search web": searchWeb, - "app call": appCall, - "app list": appList, - "advisor recommend": advisorRecommend, - "workspace list": workspaceList, - "console call": consoleCall, - "pipeline run": pipelineRun, - "pipeline validate": pipelineValidate, -}; - -/** Full command set (all groups merged) — used by the full bailian-cli product. */ -export const commands: Record = { - ...baseCommands, - ...knowledgeCommands, - ...textCommands, - ...mediaCommands, - ...memoryCommands, - ...miscCommands, -}; diff --git a/packages/commands/src/commands/image/edit.ts b/packages/commands/src/commands/image/edit.ts index 8305bda..e6c302c 100644 --- a/packages/commands/src/commands/image/edit.ts +++ b/packages/commands/src/commands/image/edit.ts @@ -20,16 +20,15 @@ import { } from "bailian-cli-core"; import { downloadFile } from "bailian-cli-runtime"; import { runConcurrent, downloadParallel, getConcurrency } from "bailian-cli-runtime"; -import { promptText, failIfMissing } from "bailian-cli-runtime"; +import { promptText, failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; import { resolveImageSize } from "bailian-cli-runtime"; import { join } from "path"; import { BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE, BOOL_FLAG_WATERMARK } from "bailian-cli-runtime"; export default defineCommand({ - name: "image edit", description: "Edit an existing image with text instructions (Qwen-Image)", - usage: "bl image edit --image --prompt [flags]", + usageArgs: "--image --prompt [flags]", options: [ { flag: "--image ", @@ -60,12 +59,12 @@ export default defineCommand({ { flag: "--out-dir ", description: "Download images to directory" }, { flag: "--out-prefix ", description: "Filename prefix (default: edited)" }, ], - examples: [ - 'bl image edit --image ./photo.png --prompt "Replace the background with a beach"', - 'bl image edit --image https://example.com/logo.png --prompt "Change color to blue" --n 3', - 'bl image edit --image ./a.png --image ./b.png --prompt "Merge two images into one collage"', - 'bl image edit --image https://example.com/photo.png --prompt "Remove the person" --model qwen-image-2.0-pro', - 'bl image edit --image ./photo.png --prompt "Replace the background with a beach" --watermark false', + exampleArgs: [ + '--image ./photo.png --prompt "Replace the background with a beach"', + '--image https://example.com/logo.png --prompt "Change color to blue" --n 3', + '--image ./a.png --image ./b.png --prompt "Merge two images into one collage"', + '--image https://example.com/photo.png --prompt "Remove the person" --model qwen-image-2.0-pro', + '--image ./photo.png --prompt "Replace the background with a beach" --watermark false', ], async run(config: Config, flags: GlobalFlags) { // Normalize --image to string array (supports both single and repeated flags) @@ -76,7 +75,7 @@ export default defineCommand({ rawImages = [flags.image]; } if (rawImages.length === 0) { - failIfMissing("image", "bl image edit --image --prompt "); + failIfMissing("image", cmdUsage(config, "--image --prompt ")); } let prompt = flags.prompt as string | undefined; @@ -91,7 +90,7 @@ export default defineCommand({ } prompt = hint; } else { - failIfMissing("prompt", "bl image edit --image --prompt "); + failIfMissing("prompt", cmdUsage(config, "--image --prompt ")); } } diff --git a/packages/commands/src/commands/image/generate.ts b/packages/commands/src/commands/image/generate.ts index 24f9678..000afd3 100644 --- a/packages/commands/src/commands/image/generate.ts +++ b/packages/commands/src/commands/image/generate.ts @@ -23,7 +23,7 @@ import { import { poll } from "bailian-cli-runtime"; import { downloadFile } from "bailian-cli-runtime"; import { runConcurrent, downloadParallel, getConcurrency } from "bailian-cli-runtime"; -import { promptText, failIfMissing } from "bailian-cli-runtime"; +import { promptText, failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; import { resolveImageSize } from "bailian-cli-runtime"; import { BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE, BOOL_FLAG_WATERMARK } from "bailian-cli-runtime"; @@ -38,9 +38,8 @@ function isSyncModel(model: string): boolean { } export default defineCommand({ - name: "image generate", description: "Generate images (Qwen-Image / wan2.x)", - usage: "bl image generate --prompt [flags]", + usageArgs: "--prompt [flags]", options: [ { flag: "--prompt ", description: "Image description", required: true }, { flag: "--model ", description: "Model ID (default: qwen-image-2.0)" }, @@ -78,16 +77,16 @@ export default defineCommand({ type: "number", }, ], - examples: [ - 'bl image generate --prompt "A cat in a spacesuit on Mars"', - 'bl image generate --prompt "Logo design" --n 3 --out-dir ./generated/', - 'bl image generate --prompt "Mountain landscape" --size 2688*1536', - 'bl image generate --prompt "A castle" --seed 42 --prompt-extend false', - 'bl image generate --prompt "Logo" --watermark false', - 'bl image generate --prompt "An alien in the space" --watermark false', - 'bl image generate --prompt "sunset" --model wan2.6-t2i --no-wait --quiet', - 'bl image generate --prompt "Pro quality" --model qwen-image-2.0-pro', - 'bl image generate --prompt "Product shots" --n 2 --concurrent 3 # 6 images in parallel', + exampleArgs: [ + '--prompt "A cat in a spacesuit on Mars"', + '--prompt "Logo design" --n 3 --out-dir ./generated/', + '--prompt "Mountain landscape" --size 2688*1536', + '--prompt "A castle" --seed 42 --prompt-extend false', + '--prompt "Logo" --watermark false', + '--prompt "An alien in the space" --watermark false', + '--prompt "sunset" --model wan2.6-t2i --no-wait --quiet', + '--prompt "Pro quality" --model qwen-image-2.0-pro', + '--prompt "Product shots" --n 2 --concurrent 3 # 6 images in parallel', ], async run(config: Config, flags: GlobalFlags) { let prompt = (flags.prompt ?? (flags._positional as string[] | undefined)?.[0]) as @@ -105,7 +104,7 @@ export default defineCommand({ } prompt = hint; } else { - failIfMissing("prompt", "bl image generate --prompt "); + failIfMissing("prompt", cmdUsage(config, "--prompt ")); } } diff --git a/packages/commands/src/commands/index.ts b/packages/commands/src/commands/index.ts deleted file mode 100644 index ac06d96..0000000 --- a/packages/commands/src/commands/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { commands } from "./catalog.ts"; diff --git a/packages/commands/src/commands/knowledge/retrieve.ts b/packages/commands/src/commands/knowledge/retrieve.ts index b4b3b12..aa227b2 100644 --- a/packages/commands/src/commands/knowledge/retrieve.ts +++ b/packages/commands/src/commands/knowledge/retrieve.ts @@ -17,16 +17,15 @@ import { BailianError, ExitCode, } from "bailian-cli-core"; -import { failIfMissing } from "bailian-cli-runtime"; +import { failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; const BAILIAN_HOST = "bailian.cn-beijing.aliyuncs.com"; export default defineCommand({ - name: "knowledge retrieve", description: "Retrieve from a Bailian knowledge base", skipDefaultApiKeySetup: true, - usage: "bl knowledge retrieve --index-id --query [flags]", + usageArgs: "--index-id --query [flags]", options: [ { flag: "--index-id ", description: "Knowledge base index ID (required)", required: true }, { flag: "--query ", description: "Search query (required)", required: true }, @@ -76,16 +75,16 @@ export default defineCommand({ "Authentication: pass `--api-key `. AK/SK auth is deprecated and will be removed in a future version.", "`--workspace-id` is NOT required when using --api-key.", ], - examples: [ - 'bl knowledge retrieve --index-id idx_xxx --query "How to use Alibaba Cloud Bailian"', - 'bl knowledge retrieve --api-key $DASHSCOPE_API_KEY --index-id idx_xxx --query "RAG retrieval" --rerank --rerank-model qwen3-rerank-hybrid', + exampleArgs: [ + '--index-id idx_xxx --query "How to use Alibaba Cloud Bailian"', + '--api-key $DASHSCOPE_API_KEY --index-id idx_xxx --query "RAG retrieval" --rerank --rerank-model qwen3-rerank-hybrid', ], async run(config: Config, flags: GlobalFlags) { const indexId = flags.indexId as string; - if (!indexId) failIfMissing("index-id", "bl knowledge retrieve --index-id --query "); + if (!indexId) failIfMissing("index-id", cmdUsage(config, "--index-id --query ")); const query = flags.query as string; - if (!query) failIfMissing("query", "bl knowledge retrieve --index-id --query "); + if (!query) failIfMissing("query", cmdUsage(config, "--index-id --query ")); const format = detectOutputFormat(config.output); @@ -196,7 +195,7 @@ async function runWithAkSk( if (!workspaceId) { throw new BailianError( "Knowledge retrieve requires a workspace ID.\n" + - "Set via: --workspace-id flag, or env: BAILIAN_WORKSPACE_ID, or config: bl config set workspace_id ", + `Set via: --workspace-id flag, or env: BAILIAN_WORKSPACE_ID, or config: ${config.binName} config set workspace_id `, ExitCode.USAGE, ); } diff --git a/packages/commands/src/commands/mcp/call.ts b/packages/commands/src/commands/mcp/call.ts index a547ad1..43b36f8 100644 --- a/packages/commands/src/commands/mcp/call.ts +++ b/packages/commands/src/commands/mcp/call.ts @@ -6,7 +6,7 @@ import { type Config, type GlobalFlags, } from "bailian-cli-core"; -import { failIfMissing } from "bailian-cli-runtime"; +import { failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult } from "bailian-cli-runtime"; import { ensureApiKey } from "bailian-cli-runtime"; @@ -30,10 +30,9 @@ function parseArgFlags(raw: string[]): Record { } export default defineCommand({ - name: "mcp call", description: "Call a tool on an MCP server (tools/call)", skipDefaultApiKeySetup: true, - usage: "bl mcp call . [--arg k=v ...] [--json '{...}'] [--url ]", + usageArgs: ". [--arg k=v ...] [--json '{...}'] [--url ]", options: [ { flag: ".", @@ -56,16 +55,16 @@ export default defineCommand({ }, { flag: "--url ", description: "Override the MCP endpoint URL (for non-Bailian servers)" }, ], - examples: [ - 'bl mcp call market-cmapi00073529.SmartStockSelection --query "Screen consumer stocks with ROE > 15%"', - 'bl mcp call market-cmapi00073529.FinQuery --json \'{"q":"Guizhou Maotai","limit":5}\'', - "bl mcp call market-cmapi00073529.SmartFundSelection --arg riskLevel=R3 --arg minScale=10", + exampleArgs: [ + 'market-cmapi00073529.SmartStockSelection --query "Screen consumer stocks with ROE > 15%"', + 'market-cmapi00073529.FinQuery --json \'{"q":"Guizhou Maotai","limit":5}\'', + "market-cmapi00073529.SmartFundSelection --arg riskLevel=R3 --arg minScale=10", ], async run(config: Config, flags: GlobalFlags) { const positional = ((flags as Record)._positional as string[] | undefined) ?? []; const target = positional[0]; - if (!target) failIfMissing(".", "bl mcp call ."); + if (!target) failIfMissing(".", cmdUsage(config, ".")); const dot = target!.indexOf("."); if (dot <= 0 || dot === target!.length - 1) { diff --git a/packages/commands/src/commands/mcp/list.ts b/packages/commands/src/commands/mcp/list.ts index c739e67..e93fa03 100644 --- a/packages/commands/src/commands/mcp/list.ts +++ b/packages/commands/src/commands/mcp/list.ts @@ -25,10 +25,9 @@ interface ServerSummary { } export default defineCommand({ - name: "mcp list", description: "List MCP servers activated under your Bailian account", skipDefaultApiKeySetup: true, - usage: "bl mcp list [flags]", + usageArgs: "[flags]", options: [ { flag: "--name ", description: "Filter by server name (substring match)" }, { @@ -48,7 +47,7 @@ export default defineCommand({ type: "number", }, ], - examples: ["bl mcp list", "bl mcp list --name finance", "bl mcp list --output json"], + exampleArgs: ["", "--name finance", "--output json"], async run(config: Config, flags: GlobalFlags) { const serverName = (flags.name as string) || ""; const type = (flags.type as string) || "OFFICIAL"; @@ -85,7 +84,7 @@ export default defineCommand({ const msg = (dataField.errorMsg as string | undefined) ?? code; const hint = code === "BailianGateway.Login.NotLogined" - ? "Run `bl auth login --console` to refresh your console session." + ? `Run \`${config.binName} auth login --console\` to refresh your console session.` : undefined; throw new BailianError(`Console gateway: ${msg}`, ExitCode.AUTH, hint); } diff --git a/packages/commands/src/commands/mcp/tools.ts b/packages/commands/src/commands/mcp/tools.ts index 4678c6d..d30aa99 100644 --- a/packages/commands/src/commands/mcp/tools.ts +++ b/packages/commands/src/commands/mcp/tools.ts @@ -6,33 +6,32 @@ import { type Config, type GlobalFlags, } from "bailian-cli-core"; -import { failIfMissing } from "bailian-cli-runtime"; +import { failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult } from "bailian-cli-runtime"; import { ensureApiKey } from "bailian-cli-runtime"; export default defineCommand({ - name: "mcp tools", description: "List tools exposed by an MCP server (tools/list)", skipDefaultApiKeySetup: true, - usage: "bl mcp tools [--url ]", + usageArgs: " [--url ]", options: [ { flag: "", - description: "Server code from `bl mcp list` (e.g. market-cmapi00073529)", + description: "Server code from `mcp list` (e.g. market-cmapi00073529)", required: true, }, { flag: "--url ", description: "Override the MCP endpoint URL (for non-Bailian servers)" }, ], - examples: [ - "bl mcp tools market-cmapi00073529", - "bl mcp tools market-cmapi00073529 --output json", - "bl mcp tools my-server --url https://example.com/mcp", + exampleArgs: [ + "market-cmapi00073529", + "market-cmapi00073529 --output json", + "my-server --url https://example.com/mcp", ], async run(config: Config, flags: GlobalFlags) { const positional = ((flags as Record)._positional as string[] | undefined) ?? []; const code = positional[0]; - if (!code) failIfMissing("server-code", "bl mcp tools "); + if (!code) failIfMissing("server-code", cmdUsage(config, "")); const url = (flags.url as string) || bailianMcpUrl(config.baseUrl, code!); const format = detectOutputFormat(config.output); diff --git a/packages/commands/src/commands/memory/add.ts b/packages/commands/src/commands/memory/add.ts index a32d7b2..830e7c5 100644 --- a/packages/commands/src/commands/memory/add.ts +++ b/packages/commands/src/commands/memory/add.ts @@ -8,13 +8,12 @@ import { type MemoryAddRequest, type MemoryAddResponse, } from "bailian-cli-core"; -import { failIfMissing } from "bailian-cli-runtime"; +import { failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; export default defineCommand({ - name: "memory add", description: "Add memory from messages or custom content", - usage: "bl memory add --user-id [--messages ] [--content ] [flags]", + usageArgs: "--user-id [--messages ] [--content ] [flags]", options: [ { flag: "--user-id ", description: "User ID (required)", required: true }, { @@ -25,14 +24,14 @@ export default defineCommand({ { flag: "--profile-schema ", description: "Profile schema ID for user profiling" }, { flag: "--memory-library-id ", description: "Memory library ID (isolate memory space)" }, ], - examples: [ - 'bl memory add --user-id user1 --content "The user likes Python programming"', - 'bl memory add --user-id user1 --messages \'[{"role":"user","content":"I like traveling"}]\'', - 'bl memory add --user-id user1 --content "Lives in Beijing" --profile-schema schema_xxx', + exampleArgs: [ + '--user-id user1 --content "The user likes Python programming"', + '--user-id user1 --messages \'[{"role":"user","content":"I like traveling"}]\'', + '--user-id user1 --content "Lives in Beijing" --profile-schema schema_xxx', ], async run(config: Config, flags: GlobalFlags) { const userId = flags.userId as string; - if (!userId) failIfMissing("user-id", "bl memory add --user-id "); + if (!userId) failIfMissing("user-id", cmdUsage(config, "--user-id ")); const body: MemoryAddRequest = { user_id: userId }; diff --git a/packages/commands/src/commands/memory/delete.ts b/packages/commands/src/commands/memory/delete.ts index 9ca4758..d359c46 100644 --- a/packages/commands/src/commands/memory/delete.ts +++ b/packages/commands/src/commands/memory/delete.ts @@ -6,25 +6,24 @@ import { type Config, type GlobalFlags, } from "bailian-cli-core"; -import { failIfMissing } from "bailian-cli-runtime"; +import { failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; export default defineCommand({ - name: "memory delete", description: "Delete a memory node", - usage: "bl memory delete --node-id --user-id ", + usageArgs: "--node-id --user-id ", options: [ { flag: "--node-id ", description: "Memory node ID (required)", required: true }, { flag: "--user-id ", description: "User ID (required)", required: true }, { flag: "--memory-library-id ", description: "Memory library ID (non-default library)" }, ], - examples: ["bl memory delete --node-id node_xxx --user-id user1"], + exampleArgs: ["--node-id node_xxx --user-id user1"], async run(config: Config, flags: GlobalFlags) { const nodeId = flags.nodeId as string; - if (!nodeId) failIfMissing("node-id", "bl memory delete --node-id --user-id "); + if (!nodeId) failIfMissing("node-id", cmdUsage(config, "--node-id --user-id ")); const userId = flags.userId as string; - if (!userId) failIfMissing("user-id", "bl memory delete --node-id --user-id "); + if (!userId) failIfMissing("user-id", cmdUsage(config, "--node-id --user-id ")); const format = detectOutputFormat(config.output); const params = new URLSearchParams({ user_id: userId }); diff --git a/packages/commands/src/commands/memory/list.ts b/packages/commands/src/commands/memory/list.ts index d21fa64..77ce5b9 100644 --- a/packages/commands/src/commands/memory/list.ts +++ b/packages/commands/src/commands/memory/list.ts @@ -7,26 +7,22 @@ import { type GlobalFlags, type MemoryNodeListResponse, } from "bailian-cli-core"; -import { failIfMissing } from "bailian-cli-runtime"; +import { failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; export default defineCommand({ - name: "memory list", description: "List memory nodes for a user", - usage: "bl memory list --user-id [flags]", + usageArgs: "--user-id [flags]", options: [ { flag: "--user-id ", description: "User ID (required)", required: true }, { flag: "--page-size ", description: "Results per page (default: 10)", type: "number" }, { flag: "--page ", description: "Page number (default: 1)", type: "number" }, { flag: "--memory-library-id ", description: "Memory library ID" }, ], - examples: [ - "bl memory list --user-id user1", - "bl memory list --user-id user1 --page-size 20 --page 2", - ], + exampleArgs: ["--user-id user1", "--user-id user1 --page-size 20 --page 2"], async run(config: Config, flags: GlobalFlags) { const userId = flags.userId as string; - if (!userId) failIfMissing("user-id", "bl memory list --user-id "); + if (!userId) failIfMissing("user-id", cmdUsage(config, "--user-id ")); const format = detectOutputFormat(config.output); const params = new URLSearchParams(); diff --git a/packages/commands/src/commands/memory/profile-create.ts b/packages/commands/src/commands/memory/profile-create.ts index 07470b4..5f61de3 100644 --- a/packages/commands/src/commands/memory/profile-create.ts +++ b/packages/commands/src/commands/memory/profile-create.ts @@ -8,13 +8,12 @@ import { type ProfileSchemaCreateRequest, type ProfileSchemaCreateResponse, } from "bailian-cli-core"; -import { failIfMissing } from "bailian-cli-runtime"; +import { failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; export default defineCommand({ - name: "memory profile create", description: "Create a user profile schema for memory profiling", - usage: "bl memory profile create --name --attributes [flags]", + usageArgs: "--name --attributes [flags]", options: [ { flag: "--name ", description: "Schema name (required)", required: true }, { flag: "--description ", description: "Schema description" }, @@ -24,16 +23,16 @@ export default defineCommand({ required: true, }, ], - examples: [ - 'bl memory profile create --name "user_basic" --attributes \'[{"name":"age","description":"age"},{"name":"hobby","description":"hobby"}]\'', + exampleArgs: [ + '--name "user_basic" --attributes \'[{"name":"age","description":"age"},{"name":"hobby","description":"hobby"}]\'', ], async run(config: Config, flags: GlobalFlags) { const name = flags.name as string; - if (!name) failIfMissing("name", "bl memory profile create --name --attributes "); + if (!name) failIfMissing("name", cmdUsage(config, "--name --attributes ")); const attrStr = flags.attributes as string; if (!attrStr) - failIfMissing("attributes", "bl memory profile create --name --attributes "); + failIfMissing("attributes", cmdUsage(config, "--name --attributes ")); let attributes; try { diff --git a/packages/commands/src/commands/memory/profile-get.ts b/packages/commands/src/commands/memory/profile-get.ts index 60d6999..9ce1092 100644 --- a/packages/commands/src/commands/memory/profile-get.ts +++ b/packages/commands/src/commands/memory/profile-get.ts @@ -7,25 +7,23 @@ import { type GlobalFlags, type UserProfileResponse, } from "bailian-cli-core"; -import { failIfMissing } from "bailian-cli-runtime"; +import { failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; export default defineCommand({ - name: "memory profile get", description: "Get user profile by schema ID and user ID", - usage: "bl memory profile get --schema-id --user-id ", + usageArgs: "--schema-id --user-id ", options: [ { flag: "--schema-id ", description: "Profile schema ID (required)", required: true }, { flag: "--user-id ", description: "User ID (required)", required: true }, ], - examples: ["bl memory profile get --schema-id schema_xxx --user-id user1"], + exampleArgs: ["--schema-id schema_xxx --user-id user1"], async run(config: Config, flags: GlobalFlags) { const schemaId = flags.schemaId as string; - if (!schemaId) - failIfMissing("schema-id", "bl memory profile get --schema-id --user-id "); + if (!schemaId) failIfMissing("schema-id", cmdUsage(config, "--schema-id --user-id ")); const userId = flags.userId as string; - if (!userId) failIfMissing("user-id", "bl memory profile get --schema-id --user-id "); + if (!userId) failIfMissing("user-id", cmdUsage(config, "--schema-id --user-id ")); const format = detectOutputFormat(config.output); const params = new URLSearchParams({ user_id: userId }); diff --git a/packages/commands/src/commands/memory/search.ts b/packages/commands/src/commands/memory/search.ts index 537ad3f..d7d4522 100644 --- a/packages/commands/src/commands/memory/search.ts +++ b/packages/commands/src/commands/memory/search.ts @@ -8,13 +8,12 @@ import { type MemorySearchRequest, type MemorySearchResponse, } from "bailian-cli-core"; -import { failIfMissing } from "bailian-cli-runtime"; +import { failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; export default defineCommand({ - name: "memory search", description: "Search memory nodes by query or messages", - usage: "bl memory search --user-id [--query ] [flags]", + usageArgs: "--user-id [--query ] [flags]", options: [ { flag: "--user-id ", description: "User ID (required)", required: true }, { flag: "--query ", description: "Search query text" }, @@ -26,13 +25,13 @@ export default defineCommand({ }, { flag: "--memory-library-id ", description: "Memory library ID" }, ], - examples: [ - 'bl memory search --user-id user1 --query "programming preferences"', - 'bl memory search --user-id user1 --messages \'[{"role":"user","content":"recommend a book"}]\' --top-k 5', + exampleArgs: [ + '--user-id user1 --query "programming preferences"', + '--user-id user1 --messages \'[{"role":"user","content":"recommend a book"}]\' --top-k 5', ], async run(config: Config, flags: GlobalFlags) { const userId = flags.userId as string; - if (!userId) failIfMissing("user-id", "bl memory search --user-id "); + if (!userId) failIfMissing("user-id", cmdUsage(config, "--user-id ")); const body: MemorySearchRequest = { user_id: userId }; diff --git a/packages/commands/src/commands/memory/update.ts b/packages/commands/src/commands/memory/update.ts index a3c3544..431327b 100644 --- a/packages/commands/src/commands/memory/update.ts +++ b/packages/commands/src/commands/memory/update.ts @@ -7,13 +7,12 @@ import { type GlobalFlags, type MemoryNodeUpdateRequest, } from "bailian-cli-core"; -import { failIfMissing } from "bailian-cli-runtime"; +import { failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; export default defineCommand({ - name: "memory update", description: "Update a memory node content", - usage: "bl memory update --node-id --user-id --content ", + usageArgs: "--node-id --user-id --content ", options: [ { flag: "--node-id ", description: "Memory node ID (required)", required: true }, { flag: "--user-id ", description: "User ID (required)", required: true }, @@ -24,21 +23,19 @@ export default defineCommand({ }, { flag: "--memory-library-id ", description: "Memory library ID (non-default library)" }, ], - examples: [ - 'bl memory update --node-id node_xxx --user-id user1 --content "updated memory content"', - ], + exampleArgs: ['--node-id node_xxx --user-id user1 --content "updated memory content"'], async run(config: Config, flags: GlobalFlags) { const nodeId = flags.nodeId as string; if (!nodeId) - failIfMissing("node-id", "bl memory update --node-id --user-id --content "); + failIfMissing("node-id", cmdUsage(config, "--node-id --user-id --content ")); const userId = flags.userId as string; if (!userId) - failIfMissing("user-id", "bl memory update --node-id --user-id --content "); + failIfMissing("user-id", cmdUsage(config, "--node-id --user-id --content ")); const content = flags.content as string; if (!content) - failIfMissing("content", "bl memory update --node-id --user-id --content "); + failIfMissing("content", cmdUsage(config, "--node-id --user-id --content ")); const body: MemoryNodeUpdateRequest = { user_id: userId, diff --git a/packages/commands/src/commands/omni/chat.ts b/packages/commands/src/commands/omni/chat.ts index 8ac53ed..5ff15b0 100644 --- a/packages/commands/src/commands/omni/chat.ts +++ b/packages/commands/src/commands/omni/chat.ts @@ -17,7 +17,7 @@ import { isInteractive, resolveFileUrl, } from "bailian-cli-core"; -import { promptText, failIfMissing } from "bailian-cli-runtime"; +import { promptText, failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult } from "bailian-cli-runtime"; import { resolveOutputDir, resolveCredential } from "bailian-cli-core"; @@ -85,9 +85,8 @@ function buildWavHeader(dataLength: number): Buffer { } export default defineCommand({ - name: "omni", description: "Multimodal chat with text + audio output (Qwen-Omni)", - usage: "bl omni --message [flags]", + usageArgs: "--message [flags]", options: [ { flag: "--message ", @@ -118,15 +117,15 @@ export default defineCommand({ { flag: "--max-tokens ", description: "Maximum tokens to generate", type: "number" }, { flag: "--temperature ", description: "Sampling temperature (0.0, 2.0]", type: "number" }, ], - examples: [ - 'bl omni --message "Hello, who are you?"', - 'bl omni --message "Describe this image" --image ./photo.jpg', - 'bl omni --message "What is this audio saying?" --audio https://example.com/audio.wav', - 'bl omni --message "Summarize this video" --video https://example.com/video.mp4', - 'bl omni --message "What is this video about?" --video ./local-video.mp4 --text-only', - 'bl omni --message "Answer in Sichuan dialect: How\'s the weather today?" --voice Sunny', - 'bl omni --message "Hello" --text-only --output json', - 'bl omni --message "Read this passage aloud" --audio-out greeting.wav', + exampleArgs: [ + '--message "Hello, who are you?"', + '--message "Describe this image" --image ./photo.jpg', + '--message "What is this audio saying?" --audio https://example.com/audio.wav', + '--message "Summarize this video" --video https://example.com/video.mp4', + '--message "What is this video about?" --video ./local-video.mp4 --text-only', + '--message "Answer in Sichuan dialect: How\'s the weather today?" --voice Sunny', + '--message "Hello" --text-only --output json', + '--message "Read this passage aloud" --audio-out greeting.wav', ], async run(config: Config, flags: GlobalFlags) { // --- Parse messages --- @@ -144,7 +143,7 @@ export default defineCommand({ } userMessages = [hint]; } else { - failIfMissing("message", "bl text omni --message "); + failIfMissing("message", cmdUsage(config, "--message ")); } } diff --git a/packages/commands/src/commands/pipeline/run.ts b/packages/commands/src/commands/pipeline/run.ts index 7b83bba..c3dd3d0 100644 --- a/packages/commands/src/commands/pipeline/run.ts +++ b/packages/commands/src/commands/pipeline/run.ts @@ -1,17 +1,16 @@ import { readFile } from "node:fs/promises"; import { dirname, resolve } from "node:path"; import { defineCommand, type Config, type GlobalFlags } from "bailian-cli-core"; -import { emitResult } from "bailian-cli-runtime"; +import { emitResult, cmdUsage } from "bailian-cli-runtime"; import { initPipelineSteps } from "bailian-cli-runtime"; import { executePipeline, streamPipelineEvents } from "bailian-cli-runtime"; import type { PipelineLifecycleEvent } from "bailian-cli-runtime"; import { loadPipelineFile } from "./load-file.ts"; export default defineCommand({ - name: "pipeline run", description: "Run a pipeline workflow definition", skipDefaultApiKeySetup: true, - usage: "bl pipeline run [flags]", + usageArgs: " [flags]", options: [ { flag: "--input ", description: "Runtime input as inline JSON" }, { flag: "--input-file ", description: "Runtime input from a JSON file" }, @@ -27,17 +26,19 @@ export default defineCommand({ type: "number", }, ], - examples: [ - 'bl pipeline run workflow.yaml --input \'{"brief":"hello"}\'', - "bl pipeline run workflow.json --input-file inputs.json --concurrency 3", - "bl pipeline run workflow.yaml --dry-run", - "bl pipeline run workflow.json --events jsonl", - "bl pipeline run workflow.yaml --output json", + exampleArgs: [ + 'workflow.yaml --input \'{"brief":"hello"}\'', + "workflow.json --input-file inputs.json --concurrency 3", + "workflow.yaml --dry-run", + "workflow.json --events jsonl", + "workflow.yaml --output json", ], async run(config: Config, flags: GlobalFlags) { const file = ((flags._positional as string[] | undefined) ?? [])[0] as string | undefined; if (!file) { - process.stderr.write("Error: pipeline file is required\nUsage: bl pipeline run \n"); + process.stderr.write( + `Error: pipeline file is required\nUsage: ${cmdUsage(config, "")}\n`, + ); process.exit(2); } diff --git a/packages/commands/src/commands/pipeline/validate.ts b/packages/commands/src/commands/pipeline/validate.ts index b4cddbf..27cd2b3 100644 --- a/packages/commands/src/commands/pipeline/validate.ts +++ b/packages/commands/src/commands/pipeline/validate.ts @@ -1,25 +1,21 @@ import { resolve } from "node:path"; import { defineCommand, type Config, type GlobalFlags } from "bailian-cli-core"; -import { emitResult } from "bailian-cli-runtime"; +import { emitResult, cmdUsage } from "bailian-cli-runtime"; import { initPipelineSteps } from "bailian-cli-runtime"; import { collectPipelineIssues, collectPipelineHints } from "bailian-cli-runtime"; import { loadPipelineFile } from "./load-file.ts"; export default defineCommand({ - name: "pipeline validate", description: "Validate a pipeline definition without executing", skipDefaultApiKeySetup: true, - usage: "bl pipeline validate ", + usageArgs: "", options: [], - examples: [ - "bl pipeline validate workflow.yaml", - "bl pipeline validate workflow.json --output json", - ], + exampleArgs: ["workflow.yaml", "workflow.json --output json"], async run(config: Config, flags: GlobalFlags) { const file = ((flags._positional as string[] | undefined) ?? [])[0] as string | undefined; if (!file) { process.stderr.write( - "Error: pipeline file is required\nUsage: bl pipeline validate \n", + `Error: pipeline file is required\nUsage: ${cmdUsage(config, "")}\n`, ); process.exit(2); } diff --git a/packages/commands/src/commands/quota/check.ts b/packages/commands/src/commands/quota/check.ts index b4660f8..817caa6 100644 --- a/packages/commands/src/commands/quota/check.ts +++ b/packages/commands/src/commands/quota/check.ts @@ -235,10 +235,9 @@ function printTable(rows: CheckRow[], noColor: boolean): void { } export default defineCommand({ - name: "quota check", description: "Check current usage against rate limits", skipDefaultApiKeySetup: true, - usage: "bl quota check [--model ] [flags]", + usageArgs: "[--model ] [flags]", options: [ { flag: "--model ", @@ -259,12 +258,12 @@ export default defineCommand({ type: "number", }, ], - examples: [ - "bl quota check", - "bl quota check --model qwen3.6-plus", - "bl quota check --period 5", - "bl quota check --model qwen3.6-plus,qwen-turbo", - "bl quota check --output json", + exampleArgs: [ + "", + "--model qwen3.6-plus", + "--period 5", + "--model qwen3.6-plus,qwen-turbo", + "--output json", ], async run(config: Config, flags: GlobalFlags) { const modelFlag = (flags.model as string) || undefined; diff --git a/packages/commands/src/commands/quota/history.ts b/packages/commands/src/commands/quota/history.ts index 13aee40..0a4e0f9 100644 --- a/packages/commands/src/commands/quota/history.ts +++ b/packages/commands/src/commands/quota/history.ts @@ -91,10 +91,9 @@ function printTable(records: LimitApplicationItem[], noColor: boolean, total: nu } export default defineCommand({ - name: "quota history", description: "View quota change history", skipDefaultApiKeySetup: true, - usage: "bl quota history [flags]", + usageArgs: "[flags]", options: [ { flag: "--page ", @@ -119,13 +118,7 @@ export default defineCommand({ type: "number", }, ], - examples: [ - "bl quota history", - "bl quota history --page 2", - "bl quota history --page-size 20", - "bl quota history --model qwen-turbo", - "bl quota history --output json", - ], + exampleArgs: ["", "--page 2", "--page-size 20", "--model qwen-turbo", "--output json"], async run(config: Config, flags: GlobalFlags) { const page = Number(flags.page) || 1; const pageSize = Number(flags.pageSize) || 10; @@ -152,7 +145,7 @@ export default defineCommand({ } catch (err) { if (err instanceof BailianError && err.message.includes("NotLogined")) { process.stderr.write( - "Error: session expired. Run `bl auth login --console` to re-authenticate.\n", + `Error: session expired. Run \`${config.binName} auth login --console\` to re-authenticate.\n`, ); process.exit(1); } diff --git a/packages/commands/src/commands/quota/list.ts b/packages/commands/src/commands/quota/list.ts index c1adc30..7129fac 100644 --- a/packages/commands/src/commands/quota/list.ts +++ b/packages/commands/src/commands/quota/list.ts @@ -150,10 +150,9 @@ function printTable(models: ModelWithQpm[], noColor: boolean): void { } export default defineCommand({ - name: "quota list", description: "View model RPM/TPM rate limits", skipDefaultApiKeySetup: true, - usage: "bl quota list [--model ] [flags]", + usageArgs: "[--model ] [flags]", options: [ { flag: "--model ", @@ -174,12 +173,12 @@ export default defineCommand({ type: "number", }, ], - examples: [ - "bl quota list", - "bl quota list --model qwen3.6-plus", - "bl quota list --model qwen3.6-plus,qwen-turbo", - "bl quota list --all", - "bl quota list --output json", + exampleArgs: [ + "", + "--model qwen3.6-plus", + "--model qwen3.6-plus,qwen-turbo", + "--all", + "--output json", ], async run(config: Config, flags: GlobalFlags) { const modelFlag = (flags.model as string) || undefined; diff --git a/packages/commands/src/commands/quota/request.ts b/packages/commands/src/commands/quota/request.ts index 193af79..b5b024a 100644 --- a/packages/commands/src/commands/quota/request.ts +++ b/packages/commands/src/commands/quota/request.ts @@ -78,10 +78,9 @@ async function fetchModelQpmInfo( } export default defineCommand({ - name: "quota request", description: "Request a temporary quota increase", skipDefaultApiKeySetup: true, - usage: "bl quota request --model --tpm [flags]", + usageArgs: "--model --tpm [flags]", options: [ { flag: "--model ", @@ -108,10 +107,10 @@ export default defineCommand({ type: "number", }, ], - examples: [ - "bl quota request --model qwen-turbo --tpm 100000", - "bl quota request --model qwen3.6-plus --tpm 8000000 --yes", - "bl quota request --model qwen-turbo --tpm 100000 --output json", + exampleArgs: [ + "--model qwen-turbo --tpm 100000", + "--model qwen3.6-plus --tpm 8000000 --yes", + "--model qwen-turbo --tpm 100000 --output json", ], async run(config: Config, flags: GlobalFlags) { const modelName = flags.model as string; @@ -147,7 +146,9 @@ export default defineCommand({ process.stderr.write( `Error: model "${modelName}" not found or does not support self-service quota increase.\n`, ); - process.stderr.write("Hint: run `bl quota list` to view available models.\n"); + process.stderr.write( + `Hint: run \`${config.binName} quota list\` to view available models.\n`, + ); process.exit(1); } @@ -186,7 +187,7 @@ export default defineCommand({ } catch (err) { if (err instanceof BailianError && err.message.includes("NotLogined")) { process.stderr.write( - "Error: session expired. Run `bl auth login --console` to re-authenticate.\n", + `Error: session expired. Run \`${config.binName} auth login --console\` to re-authenticate.\n`, ); process.exit(1); } diff --git a/packages/commands/src/commands/search/web.ts b/packages/commands/src/commands/search/web.ts index 550f0ae..a7d9594 100644 --- a/packages/commands/src/commands/search/web.ts +++ b/packages/commands/src/commands/search/web.ts @@ -8,23 +8,22 @@ import { McpClient, } from "bailian-cli-core"; import { createSpinner } from "bailian-cli-runtime"; -import { promptText, failIfMissing } from "bailian-cli-runtime"; +import { promptText, failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult } from "bailian-cli-runtime"; export default defineCommand({ - name: "search web", description: "Search the web using DashScope MCP WebSearch service", - usage: "bl search web --query [flags]", + usageArgs: "--query [flags]", options: [ { flag: "--query ", description: "Search query text", required: true }, { flag: "--count ", description: "Number of search results (default: 10)", type: "number" }, { flag: "--list-tools", description: "List available MCP tools and exit" }, ], - examples: [ - 'bl search web --query "Alibaba Cloud Bailian latest features"', - 'bl search web --query "TypeScript 5.9 new features" --count 5', - 'bl search web --query "Today\'s news"', - "bl search web --list-tools", + exampleArgs: [ + '--query "Alibaba Cloud Bailian latest features"', + '--query "TypeScript 5.9 new features" --count 5', + '--query "Today\'s news"', + "--list-tools", ], async run(config: Config, flags: GlobalFlags) { const mcpUrl = mcpWebSearchEndpoint(config.baseUrl); @@ -56,7 +55,7 @@ export default defineCommand({ } query = hint; } else { - failIfMissing("query", "bl search web --query "); + failIfMissing("query", cmdUsage(config, "--query ")); } } diff --git a/packages/commands/src/commands/speech/recognize.ts b/packages/commands/src/commands/speech/recognize.ts index fbfb8c8..c26d702 100644 --- a/packages/commands/src/commands/speech/recognize.ts +++ b/packages/commands/src/commands/speech/recognize.ts @@ -19,13 +19,12 @@ import { speechRecognizeEndpoint, } from "bailian-cli-core"; import { poll } from "bailian-cli-runtime"; -import { failIfMissing } from "bailian-cli-runtime"; +import { failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; export default defineCommand({ - name: "speech recognize", description: "Recognize speech from audio files (FunAudio-ASR)", - usage: "bl speech recognize --url [flags]", + usageArgs: "--url [flags]", options: [ { flag: "--url ", @@ -51,14 +50,14 @@ export default defineCommand({ type: "number", }, ], - examples: [ - "bl speech recognize --url https://example.com/audio.mp3", - "bl speech recognize --url https://example.com/a.mp3 --url https://example.com/b.mp3", - "bl speech recognize --url https://example.com/meeting.wav --diarization --speaker-count 3", - "bl speech recognize --url https://example.com/audio.mp3 --language zh", - "bl speech recognize --url https://example.com/audio.mp3 --vocabulary-id vocab-abc123", - "bl speech recognize --url https://example.com/audio.mp3 --out result.json", - "bl speech recognize --url https://example.com/audio.mp3 --no-wait --quiet", + exampleArgs: [ + "--url https://example.com/audio.mp3", + "--url https://example.com/a.mp3 --url https://example.com/b.mp3", + "--url https://example.com/meeting.wav --diarization --speaker-count 3", + "--url https://example.com/audio.mp3 --language zh", + "--url https://example.com/audio.mp3 --vocabulary-id vocab-abc123", + "--url https://example.com/audio.mp3 --out result.json", + "--url https://example.com/audio.mp3 --no-wait --quiet", ], async run(config: Config, flags: GlobalFlags) { // Normalize --url to string[] (supports both single and repeated flags) @@ -69,7 +68,7 @@ export default defineCommand({ rawUrls = [flags.url]; } if (rawUrls.length === 0) { - failIfMissing("url", "bl speech recognize --url "); + failIfMissing("url", cmdUsage(config, "--url ")); } // Strict validation: --speaker-count requires --diarization diff --git a/packages/commands/src/commands/speech/synthesize.ts b/packages/commands/src/commands/speech/synthesize.ts index 19c8b77..2df8c8f 100644 --- a/packages/commands/src/commands/speech/synthesize.ts +++ b/packages/commands/src/commands/speech/synthesize.ts @@ -23,7 +23,7 @@ import { const COSYVOICE_CLONE_DESIGN_DOC = `${DOCS_HOSTS.cn}/cosyvoice-clone-design-api`; import { downloadFile } from "bailian-cli-runtime"; import { runConcurrent, downloadParallel, getConcurrency } from "bailian-cli-runtime"; -import { promptText, promptSelect, failIfMissing } from "bailian-cli-runtime"; +import { promptText, promptSelect, failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; interface VoiceEntry { @@ -142,9 +142,8 @@ function printVoiceList(model: string): void { } export default defineCommand({ - name: "speech synthesize", description: "Synthesize speech from text (CosyVoice TTS)", - usage: "bl speech synthesize --text [flags]", + usageArgs: "--text [flags]", options: [ { flag: "--text ", description: "Text to synthesize into speech", required: true }, { flag: "--text-file ", description: "Read text from a file instead of --text" }, @@ -181,17 +180,17 @@ export default defineCommand({ }, { flag: "--stream", description: "Stream raw PCM audio to stdout (pipe to player)" }, ], - examples: [ - "bl speech synthesize --list-voices --model cosyvoice-v3-flash", - 'bl speech synthesize --text "Hello, I am Qwen" --voice ', - 'bl speech synthesize --text "Hello world" --voice --language en', - "bl speech synthesize --text-file script.txt --out speech.wav --voice ", - 'bl speech synthesize --text "Today is a good day" --voice --instruction "Use a gentle tone"', - 'bl speech synthesize --text "Hello" --voice --format wav --sample-rate 24000', + exampleArgs: [ + "--list-voices --model cosyvoice-v3-flash", + '--text "Hello, I am Qwen" --voice ', + '--text "Hello world" --voice --language en', + "--text-file script.txt --out speech.wav --voice ", + '--text "Today is a good day" --voice --instruction "Use a gentle tone"', + '--text "Hello" --voice --format wav --sample-rate 24000', "# Stream to audio player (macOS)", - 'bl speech synthesize --text "Hello" --voice --stream | afplay -', + '--text "Hello" --voice --stream | afplay -', "# Pipe to ffplay", - 'bl speech synthesize --text "Hello" --voice --stream | ffplay -nodisp -autoexit -f s16le -ar 24000 -ac 1 -', + '--text "Hello" --voice --stream | ffplay -nodisp -autoexit -f s16le -ar 24000 -ac 1 -', ], async run(config: Config, flags: GlobalFlags) { const model = (flags.model as string) || config.defaultSpeechModel || "cosyvoice-v3-flash"; @@ -223,7 +222,7 @@ export default defineCommand({ } text = hint; } else { - failIfMissing("text", "bl speech synthesize --text "); + failIfMissing("text", cmdUsage(config, "--text ")); } } @@ -264,7 +263,7 @@ export default defineCommand({ const modelVoices = MODEL_VOICES[model]; if (modelVoices && modelVoices.length > 0) { throw new BailianError( - `--voice is required.\nRun the following to see available voices:\n bl speech synthesize --list-voices --model ${model}`, + `--voice is required.\nRun the following to see available voices:\n ${cmdUsage(config, `--list-voices --model ${model}`)}`, ExitCode.USAGE, ); } else { diff --git a/packages/commands/src/commands/text/chat.ts b/packages/commands/src/commands/text/chat.ts index c9db0ba..78a03df 100644 --- a/packages/commands/src/commands/text/chat.ts +++ b/packages/commands/src/commands/text/chat.ts @@ -13,7 +13,7 @@ import { type StreamChunk, isInteractive, } from "bailian-cli-core"; -import { promptText, failIfMissing } from "bailian-cli-runtime"; +import { promptText, failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; import { readFileSync } from "fs"; @@ -68,9 +68,8 @@ function parseMessages(flags: GlobalFlags): ParsedMessages { } export default defineCommand({ - name: "text chat", description: "Send a chat completion (OpenAI compatible, DashScope)", - usage: "bl text chat --message [flags]", + usageArgs: "--message [flags]", options: [ { flag: "--model ", description: "Model ID (default: qwen3.7-max)" }, { @@ -107,13 +106,13 @@ export default defineCommand({ type: "number", }, ], - examples: [ - 'bl text chat --message "What is Qwen?"', - 'bl text chat --model qwen-max --system "You are a coding assistant." --message "Write fizzbuzz in Python"', - 'bl text chat --message "Hello" --message "assistant:Hi!" --message "How are you?"', - "cat conversation.json | bl text chat --messages-file - --stream", - 'bl text chat --message "Hello" --output json', - 'bl text chat --model qwq-plus --message "Solve 1+1" --enable-thinking', + exampleArgs: [ + '--message "What is Qwen?"', + '--model qwen-max --system "You are a coding assistant." --message "Write fizzbuzz in Python"', + '--message "Hello" --message "assistant:Hi!" --message "How are you?"', + "--messages-file - --stream", + '--message "Hello" --output json', + '--model qwq-plus --message "Solve 1+1" --enable-thinking', ], async run(config: Config, flags: GlobalFlags) { const { system, messages: parsedMessages } = parseMessages(flags); @@ -130,7 +129,7 @@ export default defineCommand({ } messages = [{ role: "user", content: hint }]; } else { - failIfMissing("message", "bl text chat --message "); + failIfMissing("message", cmdUsage(config, "--message ")); } } diff --git a/packages/commands/src/commands/update.ts b/packages/commands/src/commands/update.ts index 45e2a10..c8a8a27 100644 --- a/packages/commands/src/commands/update.ts +++ b/packages/commands/src/commands/update.ts @@ -28,11 +28,9 @@ function updateAgentSkill(colors: { green: string; yellow: string; reset: string } export default defineCommand({ - name: "update", description: "Update the CLI to the latest version", skipDefaultApiKeySetup: true, - usage: "bl update", - examples: ["bl update"], + exampleArgs: [""], async run(config) { const npmPackage = config.npmPackage!; const binName = config.binName!; diff --git a/packages/commands/src/commands/usage/free.ts b/packages/commands/src/commands/usage/free.ts index b1b1343..b6361af 100644 --- a/packages/commands/src/commands/usage/free.ts +++ b/packages/commands/src/commands/usage/free.ts @@ -184,10 +184,9 @@ async function fetchAllModels(config: Config, token: string): Promise[,model2,...]] [flags]", + usageArgs: "[--model [,model2,...]] [flags]", options: [ { flag: "--model ", @@ -212,14 +211,14 @@ export default defineCommand({ type: "number", }, ], - examples: [ - "bl usage free", - "bl usage free --model qwen3-max", - "bl usage free --model qwen3-max,qwen-turbo", - "bl usage free --expiring 30", - "bl usage free --sort remaining", - "bl usage free --model qwen-turbo --output json", - "bl usage free --model qwen3-max --console-region cn-beijing", + exampleArgs: [ + "", + "--model qwen3-max", + "--model qwen3-max,qwen-turbo", + "--expiring 30", + "--sort remaining", + "--model qwen-turbo --output json", + "--model qwen3-max --console-region cn-beijing", ], async run(config: Config, flags: GlobalFlags) { const modelFlag = (flags.model as string) || undefined; diff --git a/packages/commands/src/commands/usage/freetier.ts b/packages/commands/src/commands/usage/freetier.ts index f78ea4c..6171513 100644 --- a/packages/commands/src/commands/usage/freetier.ts +++ b/packages/commands/src/commands/usage/freetier.ts @@ -100,11 +100,10 @@ async function fetchAllModelNames(config: Config, token: string): Promise[,model2,...] | --all> [--off] [flags]", + usageArgs: "<--model [,model2,...] | --all> [--off] [flags]", options: [ { flag: "--model ", @@ -133,13 +132,13 @@ export default defineCommand({ type: "number", }, ], - examples: [ - "bl usage freetier --model qwen3-max", - "bl usage freetier --model qwen3-max,qwen-turbo", - "bl usage freetier --all", - "bl usage freetier --on --model qwen3-max", - "bl usage freetier --off --model qwen3-max", - "bl usage freetier --off --all", + exampleArgs: [ + "--model qwen3-max", + "--model qwen3-max,qwen-turbo", + "--all", + "--on --model qwen3-max", + "--off --model qwen3-max", + "--off --all", ], async run(config: Config, flags: GlobalFlags) { const modelFlag = (flags.model as string) || undefined; diff --git a/packages/commands/src/commands/usage/stats.ts b/packages/commands/src/commands/usage/stats.ts index 7ad51ac..f33d4a6 100644 --- a/packages/commands/src/commands/usage/stats.ts +++ b/packages/commands/src/commands/usage/stats.ts @@ -101,9 +101,11 @@ function resolveWorkspaceId(config: Config, flagWorkspaceId?: string): string { if (config.workspaceId) return config.workspaceId; process.stderr.write( - "Error: workspace-id is required. Set via --workspace-id, BAILIAN_WORKSPACE_ID, or `bl config set workspace_id `.\n", + `Error: workspace-id is required. Set via --workspace-id, BAILIAN_WORKSPACE_ID, or \`${config.binName} config set workspace_id \`.\n`, + ); + process.stderr.write( + `Hint: run \`${config.binName} workspace list\` to view available workspaces.\n`, ); - process.stderr.write("Hint: run `bl workspace list` to view available workspaces.\n"); process.exit(1); } @@ -283,10 +285,9 @@ function printModelTable( } export default defineCommand({ - name: "usage stats", description: "Query model usage statistics", skipDefaultApiKeySetup: true, - usage: "bl usage stats [--model ] [--days ] [flags]", + usageArgs: "[--model ] [--days ] [flags]", options: [ { flag: "--model ", @@ -315,14 +316,14 @@ export default defineCommand({ type: "number", }, ], - examples: [ - "bl usage stats", - "bl usage stats --days 30", - "bl usage stats --model qwen-turbo", - "bl usage stats --model qwen-turbo --days 7", - "bl usage stats --model qwen3.6-plus,deepseek-v4-pro", - "bl usage stats --type Text --days 14", - "bl usage stats --output json", + exampleArgs: [ + "", + "--days 30", + "--model qwen-turbo", + "--model qwen-turbo --days 7", + "--model qwen3.6-plus,deepseek-v4-pro", + "--type Text --days 14", + "--output json", ], async run(config: Config, flags: GlobalFlags) { const modelFlag = (flags.model as string) || undefined; diff --git a/packages/commands/src/commands/video/download.ts b/packages/commands/src/commands/video/download.ts index 615f94d..5e99020 100644 --- a/packages/commands/src/commands/video/download.ts +++ b/packages/commands/src/commands/video/download.ts @@ -10,27 +10,26 @@ import { ExitCode, } from "bailian-cli-core"; import { downloadFile, formatBytes } from "bailian-cli-runtime"; -import { failIfMissing } from "bailian-cli-runtime"; +import { failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; export default defineCommand({ - name: "video download", description: "Download a completed video by task ID", - usage: "bl video download --task-id --out ", + usageArgs: "--task-id --out ", options: [ { flag: "--task-id ", description: "Task ID to download from" }, { flag: "--out ", description: "Output file path" }, ], - examples: [ - "bl video download --task-id 3b256896-xxxx --out video.mp4", - "bl video download --task-id 3b256896-xxxx --out video.mp4 --quiet", + exampleArgs: [ + "--task-id 3b256896-xxxx --out video.mp4", + "--task-id 3b256896-xxxx --out video.mp4 --quiet", ], async run(config: Config, flags: GlobalFlags) { const taskId = flags.taskId as string | undefined; - if (!taskId) failIfMissing("task-id", "bl video download --task-id --out "); + if (!taskId) failIfMissing("task-id", cmdUsage(config, "--task-id --out ")); const outPath = flags.out as string | undefined; - if (!outPath) failIfMissing("out", "bl video download --task-id --out video.mp4"); + if (!outPath) failIfMissing("out", cmdUsage(config, "--task-id --out video.mp4")); const format = detectOutputFormat(config.output); diff --git a/packages/commands/src/commands/video/edit.ts b/packages/commands/src/commands/video/edit.ts index c1092d5..cb2156b 100644 --- a/packages/commands/src/commands/video/edit.ts +++ b/packages/commands/src/commands/video/edit.ts @@ -20,15 +20,14 @@ import { } from "bailian-cli-core"; import { poll } from "bailian-cli-runtime"; import { downloadFile, formatBytes } from "bailian-cli-runtime"; -import { promptText, failIfMissing } from "bailian-cli-runtime"; +import { promptText, failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; import { BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT, BOOL_FLAG_WATERMARK } from "bailian-cli-runtime"; export default defineCommand({ - name: "video edit", description: "Edit a video with happyhorse-1.0-video-edit (style transfer, object replacement, etc.)", - usage: "bl video edit --video --prompt [flags]", + usageArgs: "--video --prompt [flags]", options: [ { flag: "--model ", description: "Model ID (default: happyhorse-1.0-video-edit)" }, { @@ -77,11 +76,11 @@ export default defineCommand({ type: "number", }, ], - examples: [ - 'bl video edit --video https://example.com/input.mp4 --prompt "Convert the entire scene to claymation style"', - 'bl video edit --video https://example.com/input.mp4 --prompt "Replace the outfit with the style shown in the image" --ref-image https://example.com/clothes.png', - 'bl video edit --video https://example.com/input.mp4 --prompt "Convert to anime style" --resolution 720P --download output.mp4', - 'bl video edit --video https://example.com/input.mp4 --prompt "Put clothes on the kitten in the video" --watermark false', + exampleArgs: [ + '--video https://example.com/input.mp4 --prompt "Convert the entire scene to claymation style"', + '--video https://example.com/input.mp4 --prompt "Replace the outfit with the style shown in the image" --ref-image https://example.com/clothes.png', + '--video https://example.com/input.mp4 --prompt "Convert to anime style" --resolution 720P --download output.mp4', + '--video https://example.com/input.mp4 --prompt "Put clothes on the kitten in the video" --watermark false', ], async run(config: Config, flags: GlobalFlags) { // --- Validate video URL --- @@ -95,7 +94,7 @@ export default defineCommand({ } videoUrl = hint; } else { - failIfMissing("video", "bl video edit --video --prompt "); + failIfMissing("video", cmdUsage(config, "--video --prompt ")); } } diff --git a/packages/commands/src/commands/video/generate.ts b/packages/commands/src/commands/video/generate.ts index 271c619..320988a 100644 --- a/packages/commands/src/commands/video/generate.ts +++ b/packages/commands/src/commands/video/generate.ts @@ -21,15 +21,14 @@ import { import { poll } from "bailian-cli-runtime"; import { downloadFile, formatBytes } from "bailian-cli-runtime"; import { runConcurrent, getConcurrency } from "bailian-cli-runtime"; -import { promptText, failIfMissing } from "bailian-cli-runtime"; +import { promptText, failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; import { BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT, BOOL_FLAG_WATERMARK } from "bailian-cli-runtime"; export default defineCommand({ - name: "video generate", description: "Generate a video from text or image (happyhorse-1.0-t2v / happyhorse-1.0-i2v / wan2.6-t2v)", - usage: "bl video generate --prompt [--image ] [flags]", + usageArgs: "--prompt [--image ] [flags]", options: [ { flag: "--model ", @@ -69,12 +68,12 @@ export default defineCommand({ type: "number", }, ], - examples: [ - 'bl video generate --prompt "A person reading a book, static shot"', - 'bl video generate --prompt "Ocean waves at sunset." --download sunset.mp4', - 'bl video generate --image https://example.com/cat.png --prompt "Make the cat in the scene move"', - 'bl video generate --prompt "Mountain landscape" --resolution 720P --duration 5', - 'bl video generate --prompt "A cat playing with a ball" --watermark false', + exampleArgs: [ + '--prompt "A person reading a book, static shot"', + '--prompt "Ocean waves at sunset." --download sunset.mp4', + '--image https://example.com/cat.png --prompt "Make the cat in the scene move"', + '--prompt "Mountain landscape" --resolution 720P --duration 5', + '--prompt "A cat playing with a ball" --watermark false', ], async run(config: Config, flags: GlobalFlags) { let prompt = flags.prompt as string | undefined; @@ -88,7 +87,7 @@ export default defineCommand({ } prompt = hint; } else { - failIfMissing("prompt", "bl video generate --prompt "); + failIfMissing("prompt", cmdUsage(config, "--prompt ")); } } diff --git a/packages/commands/src/commands/video/ref.ts b/packages/commands/src/commands/video/ref.ts index 1d0388a..1f2cd34 100644 --- a/packages/commands/src/commands/video/ref.ts +++ b/packages/commands/src/commands/video/ref.ts @@ -20,15 +20,14 @@ import { } from "bailian-cli-core"; import { poll } from "bailian-cli-runtime"; import { downloadFile, formatBytes } from "bailian-cli-runtime"; -import { promptText, failIfMissing } from "bailian-cli-runtime"; +import { promptText, failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; import { BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT, BOOL_FLAG_WATERMARK } from "bailian-cli-runtime"; export default defineCommand({ - name: "video ref", description: "Reference-to-video generation (happyhorse-1.0-r2v / wan2.6-r2v): multi-subject, multi-shot with voice", - usage: "bl video ref --prompt --image ... [--ref-video ...] [flags]", + usageArgs: "--prompt --image ... [--ref-video ...] [flags]", options: [ { flag: "--model ", description: "Model ID (default: happyhorse-1.0-r2v)" }, { @@ -84,12 +83,12 @@ export default defineCommand({ type: "number", }, ], - examples: [ - 'bl video ref --prompt "Image1 running on the grass" --image person.jpg', - 'bl video ref --prompt "Video 1 plays guitar, Image 1 walks over" --ref-video scene.mp4 --image person.jpg', - 'bl video ref --prompt "Image 1 speaks" --image person.jpg --image-voice voice.mp3 --resolution 1080P', - 'bl video ref --prompt "Image 1 and Image 2 have a conversation" --image a.jpg --image b.jpg --image-voice va.mp3 --image-voice vb.mp3', - 'bl video ref --prompt "Image 1 drinks water" --image person.jpg --watermark false', + exampleArgs: [ + '--prompt "Image1 running on the grass" --image person.jpg', + '--prompt "Video 1 plays guitar, Image 1 walks over" --ref-video scene.mp4 --image person.jpg', + '--prompt "Image 1 speaks" --image person.jpg --image-voice voice.mp3 --resolution 1080P', + '--prompt "Image 1 and Image 2 have a conversation" --image a.jpg --image b.jpg --image-voice va.mp3 --image-voice vb.mp3', + '--prompt "Image 1 drinks water" --image person.jpg --watermark false', ], async run(config: Config, flags: GlobalFlags) { // --- Validate prompt --- @@ -105,7 +104,7 @@ export default defineCommand({ } prompt = hint; } else { - failIfMissing("prompt", "bl video ref --prompt --image "); + failIfMissing("prompt", cmdUsage(config, "--prompt --image ")); } } @@ -116,7 +115,7 @@ export default defineCommand({ throw new BailianError( "At least one --image or --ref-video is required.", ExitCode.USAGE, - 'bl video ref --prompt "description" --image person.jpg', + cmdUsage(config, '--prompt "description" --image person.jpg'), ); } diff --git a/packages/commands/src/commands/video/task-get.ts b/packages/commands/src/commands/video/task-get.ts index d497f5c..a214889 100644 --- a/packages/commands/src/commands/video/task-get.ts +++ b/packages/commands/src/commands/video/task-get.ts @@ -7,21 +7,20 @@ import { type GlobalFlags, type DashScopeTaskResponse, } from "bailian-cli-core"; -import { failIfMissing } from "bailian-cli-runtime"; +import { failIfMissing, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; export default defineCommand({ - name: "video task get", description: "Query async task status", - usage: "bl video task get --task-id ", + usageArgs: "--task-id ", options: [{ flag: "--task-id ", description: "Async task ID" }], - examples: [ - "bl video task get --task-id 3b256896-3e70-xxxx-xxxx-xxxxxxxxxxxx", - "bl video task get --task-id 3b256896-3e70-xxxx --output json", + exampleArgs: [ + "--task-id 3b256896-3e70-xxxx-xxxx-xxxxxxxxxxxx", + "--task-id 3b256896-3e70-xxxx --output json", ], async run(config: Config, flags: GlobalFlags) { const taskId = flags.taskId as string | undefined; - if (!taskId) failIfMissing("task-id", "bl video task get --task-id "); + if (!taskId) failIfMissing("task-id", cmdUsage(config, "--task-id ")); const format = detectOutputFormat(config.output); diff --git a/packages/commands/src/commands/vision/describe.ts b/packages/commands/src/commands/vision/describe.ts index 66f7e42..abe04f2 100644 --- a/packages/commands/src/commands/vision/describe.ts +++ b/packages/commands/src/commands/vision/describe.ts @@ -15,7 +15,7 @@ import { ExitCode, isLocalFile, } from "bailian-cli-core"; -import { promptText } from "bailian-cli-runtime"; +import { promptText, cmdUsage } from "bailian-cli-runtime"; import { emitResult, emitBare } from "bailian-cli-runtime"; import { readFileSync, existsSync } from "fs"; import { extname } from "path"; @@ -57,9 +57,8 @@ async function toImageUrl(image: string): Promise { } export default defineCommand({ - name: "vision describe", description: "Describe an image or video using Qwen-VL", - usage: "bl vision describe --image [--video ] [--prompt ]", + usageArgs: "--image [--video ] [--prompt ]", options: [ { flag: "--image ", description: "Local image path or URL" }, { @@ -70,12 +69,12 @@ export default defineCommand({ { flag: "--prompt ", description: "Question about the content (default: auto-detected)" }, { flag: "--model ", description: "Vision model (default: qwen3-vl-plus)" }, ], - examples: [ - "bl vision describe --image photo.jpg", - 'bl vision describe --image https://example.com/photo.jpg --prompt "What breed is this dog?"', - 'bl vision describe --video https://example.com/video.mp4 --prompt "Summarize the video content"', - "bl vision describe --video ./local-video.mp4", - 'bl vision describe --image photo.png --prompt "Extract the text" --model qwen-vl-plus', + exampleArgs: [ + "--image photo.jpg", + '--image https://example.com/photo.jpg --prompt "What breed is this dog?"', + '--video https://example.com/video.mp4 --prompt "Summarize the video content"', + "--video ./local-video.mp4", + '--image photo.png --prompt "Extract the text" --model qwen-vl-plus', ], async run(config: Config, flags: GlobalFlags) { let image = (flags.image ?? (flags._positional as string[] | undefined)?.[0]) as @@ -113,7 +112,7 @@ export default defineCommand({ throw new BailianError( "Missing required argument --image or --video.", ExitCode.USAGE, - "bl vision describe --image \nbl vision describe --video ", + `${cmdUsage(config, "--image ")}\n${cmdUsage(config, "--video ")}`, ); } } diff --git a/packages/commands/src/commands/workspace/list.ts b/packages/commands/src/commands/workspace/list.ts index 5c0095c..eff573e 100644 --- a/packages/commands/src/commands/workspace/list.ts +++ b/packages/commands/src/commands/workspace/list.ts @@ -76,10 +76,9 @@ function printTable(workspaces: WorkspaceInfo[], noColor: boolean): void { } export default defineCommand({ - name: "workspace list", description: "List all workspaces", skipDefaultApiKeySetup: true, - usage: "bl workspace list [flags]", + usageArgs: "[flags]", options: [ { flag: "--list ", @@ -96,7 +95,7 @@ export default defineCommand({ type: "number", }, ], - examples: ["bl workspace list", "bl workspace list --list 5", "bl workspace list --output json"], + exampleArgs: ["", "--list 5", "--output json"], async run(config: Config, flags: GlobalFlags) { const limit = Number(flags.list) || 0; const format = detectOutputFormat(config.output); diff --git a/packages/commands/src/index.ts b/packages/commands/src/index.ts index c4902c5..4fc1ba1 100644 --- a/packages/commands/src/index.ts +++ b/packages/commands/src/index.ts @@ -1,63 +1,50 @@ -// Command library for bailian-cli products. Exposes the full command set, the -// per-capability groups, and individual command implementations so each -// entrypoint (bl / rag / …) can pick and remap exactly what it needs. +// Command library for bailian-cli products. Exposes individual command +// implementations only — no path presets or capability groups. Each product +// entrypoint (bl / rag / …) builds its own `{ "": command }` map, so the +// command paths a product exposes are a product decision, not baked in here. -export { - commands, - baseCommands, - knowledgeCommands, - textCommands, - mediaCommands, - memoryCommands, - miscCommands, -} from "./commands/groups.ts"; - -// Individual command implementations (for custom path remapping). -export { - authLogin, - authStatus, - authLogout, - textChat, - textOmni, - imageGenerate, - imageEdit, - videoGenerate, - videoEdit, - videoRef, - videoTaskGet, - videoDownload, - visionDescribe, - configShow, - configSet, - configExportSchema, - update, - appCall, - appList, - memoryAdd, - memorySearch, - memoryList, - memoryUpdate, - memoryDelete, - memoryProfileCreate, - memoryProfileGet, - knowledgeRetrieve, - mcpCall, - mcpList, - mcpTools, - searchWeb, - speechSynthesize, - speechRecognize, - fileUpload, - consoleCall, - usageFree, - usageFreetier, - usageStats, - pipelineRun, - pipelineValidate, - advisorRecommend, - workspaceList, - quotaList, - quotaRequest, - quotaHistory, - quotaCheck, -} from "./commands/groups.ts"; +export { default as authLogin } from "./commands/auth/login.ts"; +export { default as authStatus } from "./commands/auth/status.ts"; +export { default as authLogout } from "./commands/auth/logout.ts"; +export { default as textChat } from "./commands/text/chat.ts"; +export { default as textOmni } from "./commands/omni/chat.ts"; +export { default as imageGenerate } from "./commands/image/generate.ts"; +export { default as imageEdit } from "./commands/image/edit.ts"; +export { default as videoGenerate } from "./commands/video/generate.ts"; +export { default as videoEdit } from "./commands/video/edit.ts"; +export { default as videoRef } from "./commands/video/ref.ts"; +export { default as videoTaskGet } from "./commands/video/task-get.ts"; +export { default as videoDownload } from "./commands/video/download.ts"; +export { default as visionDescribe } from "./commands/vision/describe.ts"; +export { default as configShow } from "./commands/config/show.ts"; +export { default as configSet } from "./commands/config/set.ts"; +export { default as update } from "./commands/update.ts"; +export { default as appCall } from "./commands/app/call.ts"; +export { default as appList } from "./commands/app/list.ts"; +export { default as memoryAdd } from "./commands/memory/add.ts"; +export { default as memorySearch } from "./commands/memory/search.ts"; +export { default as memoryList } from "./commands/memory/list.ts"; +export { default as memoryUpdate } from "./commands/memory/update.ts"; +export { default as memoryDelete } from "./commands/memory/delete.ts"; +export { default as memoryProfileCreate } from "./commands/memory/profile-create.ts"; +export { default as memoryProfileGet } from "./commands/memory/profile-get.ts"; +export { default as knowledgeRetrieve } from "./commands/knowledge/retrieve.ts"; +export { default as mcpCall } from "./commands/mcp/call.ts"; +export { default as mcpList } from "./commands/mcp/list.ts"; +export { default as mcpTools } from "./commands/mcp/tools.ts"; +export { default as searchWeb } from "./commands/search/web.ts"; +export { default as speechSynthesize } from "./commands/speech/synthesize.ts"; +export { default as speechRecognize } from "./commands/speech/recognize.ts"; +export { default as fileUpload } from "./commands/file/upload.ts"; +export { default as consoleCall } from "./commands/console/call.ts"; +export { default as usageFree } from "./commands/usage/free.ts"; +export { default as usageFreetier } from "./commands/usage/freetier.ts"; +export { default as usageStats } from "./commands/usage/stats.ts"; +export { default as pipelineRun } from "./commands/pipeline/run.ts"; +export { default as pipelineValidate } from "./commands/pipeline/validate.ts"; +export { default as advisorRecommend } from "./commands/advisor/recommend.ts"; +export { default as workspaceList } from "./commands/workspace/list.ts"; +export { default as quotaList } from "./commands/quota/list.ts"; +export { default as quotaRequest } from "./commands/quota/request.ts"; +export { default as quotaHistory } from "./commands/quota/history.ts"; +export { default as quotaCheck } from "./commands/quota/check.ts"; diff --git a/packages/core/src/types/command.ts b/packages/core/src/types/command.ts index 343d58c..f2043da 100644 --- a/packages/core/src/types/command.ts +++ b/packages/core/src/types/command.ts @@ -9,22 +9,33 @@ export interface OptionDef { } export interface Command { - name: string; description: string; - usage?: string; + /** + * Argument portion of the usage line, WITHOUT the ` ` prefix + * (e.g. "--index-id --query [flags]"). The runtime prepends the + * product binary name and the command's actual path when rendering help, so + * the same command renders correctly under any product (bl / rag / …). + */ + usageArgs?: string; options?: OptionDef[]; - examples?: string[]; + /** + * Example argument strings, each WITHOUT the ` ` prefix + * (e.g. '--index-id idx_xxx --query "..."'). The runtime prepends + * ` ` per product when rendering help. + */ + exampleArgs?: string[]; skipDefaultApiKeySetup?: boolean; notes?: string[]; execute: (config: Config, flags: GlobalFlags) => Promise; } export interface CommandSpec { - name: string; description: string; - usage?: string; + /** See {@link Command.usageArgs} — argument portion only, no ` ` prefix. */ + usageArgs?: string; options?: OptionDef[]; - examples?: string[]; + /** See {@link Command.exampleArgs} — argument strings only, no ` ` prefix. */ + exampleArgs?: string[]; skipDefaultApiKeySetup?: boolean; notes?: string[]; run: (config: Config, flags: GlobalFlags) => Promise; @@ -32,11 +43,10 @@ export interface CommandSpec { export function defineCommand(spec: CommandSpec): Command { return { - name: spec.name, description: spec.description, - usage: spec.usage, + usageArgs: spec.usageArgs, options: spec.options, - examples: spec.examples, + exampleArgs: spec.exampleArgs, skipDefaultApiKeySetup: spec.skipDefaultApiKeySetup, notes: spec.notes, execute: (config, flags) => spec.run(config, flags), diff --git a/packages/core/src/utils/index.ts b/packages/core/src/utils/index.ts index 56baedc..25b9f30 100644 --- a/packages/core/src/utils/index.ts +++ b/packages/core/src/utils/index.ts @@ -1,6 +1,5 @@ export { generateFilename } from "./filename.ts"; export { resolveOutputDir } from "./output-dir.ts"; -export { generateToolSchema } from "./schema.ts"; export { maskToken } from "./token.ts"; export { isInteractive } from "./env.ts"; export { isCI } from "./env.ts"; diff --git a/packages/core/src/utils/schema.ts b/packages/core/src/utils/schema.ts deleted file mode 100644 index a368fc5..0000000 --- a/packages/core/src/utils/schema.ts +++ /dev/null @@ -1,82 +0,0 @@ -import type { Command } from "../types/command.ts"; - -/** - * Parse a CLI flag string (e.g. "--prompt ", "--stream") into - * a parameter name and inferred type. - */ -function parseFlag(flag: string): { - name: string; - kebabName: string; - inferredType: string; - isArray: boolean; -} { - // e.g. "--prompt " -> "prompt" - const match = flag.match(/^--([a-zA-Z0-9-]+)/); - const kebabName = match ? match[1]! : ""; - // camelCase to match internal API conventions - const name = kebabName.replace(/-([a-zA-Z0-9])/g, (_, c: string) => c.toUpperCase()); - - let inferredType = "string"; - let isArray = false; - - if (!flag.includes("<") && !flag.includes("[")) { - // No parameter value — typically a boolean flag like --stream - inferredType = "boolean"; - } else if ( - flag.includes("") || - flag.includes("") || - flag.includes("") || - flag.includes("") - ) { - inferredType = "number"; - } - - if (flag.toLowerCase().includes("repeatable")) { - isArray = true; - } - - return { name, kebabName, inferredType, isArray }; -} - -export function generateToolSchema(cmd: Command): Record { - const toolName = `bailian_${cmd.name.replace(/ /g, "_")}`; - - const schema: Record = { - name: toolName, - description: cmd.description, - input_schema: { - type: "object", - properties: {} as Record, - required: [] as string[], - }, - }; - - if (cmd.options) { - for (const opt of cmd.options) { - const { name, inferredType, isArray } = parseFlag(opt.flag); - if (!name) continue; - - // Explicit type from OptionDef takes precedence; fall back to inference - const explicitType = opt.type; - const effectiveType = isArray ? "array" : (explicitType ?? inferredType); - - const propSchema: Record = { description: opt.description }; - - if (effectiveType === "array") { - propSchema.type = "array"; - propSchema.items = { type: "string" }; - } else { - propSchema.type = effectiveType; - } - - const inputSchema = schema.input_schema as Record; - (inputSchema.properties as Record)[name] = propSchema; - - if (opt.required) { - (inputSchema.required as string[]).push(name); - } - } - } - - return schema; -} diff --git a/packages/rag/src/main.ts b/packages/rag/src/main.ts index 4334497..acfdc9c 100644 --- a/packages/rag/src/main.ts +++ b/packages/rag/src/main.ts @@ -1,16 +1,50 @@ import { createCli } from "bailian-cli-runtime"; -import { baseCommands, knowledgeCommands } from "bailian-cli-commands"; +import type { Command } from "bailian-cli-core"; +import { + authLogin, + authStatus, + authLogout, + configShow, + configSet, + update, + fileUpload, + usageFree, + usageFreetier, + usageStats, + quotaList, + quotaRequest, + quotaHistory, + quotaCheck, + knowledgeRetrieve, +} from "bailian-cli-commands"; import pkg from "../package.json" with { type: "json" }; -// rag-cli: knowledge-base product. Ships only the base infrastructure commands -// (auth, config, usage, quota, update, file upload) plus the knowledge commands — -// no model/app capabilities. Command paths are kept as-is (e.g. `rag knowledge retrieve`). -createCli( - { ...baseCommands, ...knowledgeCommands }, - { - binName: "rag", - version: pkg.version, - clientName: "rag-cli", - npmPackage: "bailian-cli-rag", - }, -).run(); +// rag-cli: knowledge-base product. Ships the base infrastructure commands +// (auth, config, usage, quota, update, file upload) plus knowledge retrieval, +// remapped to a flat `rag retrieve` path. Routing is driven entirely by these +// keys, and usage/examples/errors render the path from the key — so the same +// shared command shows `rag retrieve` here and `bl knowledge retrieve` in bl. +const commands: Record = { + "auth login": authLogin, + "auth status": authStatus, + "auth logout": authLogout, + "config show": configShow, + "config set": configSet, + update, + "file upload": fileUpload, + "usage free": usageFree, + "usage freetier": usageFreetier, + "usage stats": usageStats, + "quota list": quotaList, + "quota request": quotaRequest, + "quota history": quotaHistory, + "quota check": quotaCheck, + retrieve: knowledgeRetrieve, +}; + +createCli(commands, { + binName: "rag", + version: pkg.version, + clientName: "rag-cli", + npmPackage: "bailian-cli-rag", +}).run(); diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.ts index aae6867..790df67 100644 --- a/packages/runtime/src/index.ts +++ b/packages/runtime/src/index.ts @@ -22,7 +22,13 @@ export { BAILIAN_CONSOLE_ROOT, BAILIAN_CONSOLE, API_KEY_PAGE } from "./urls.ts"; // Output facilities consumed by commands export { emitResult, emitBare } from "./output/output.ts"; -export { promptText, promptSelect, promptConfirm, failIfMissing } from "./output/prompt.ts"; +export { + promptText, + promptSelect, + promptConfirm, + failIfMissing, + cmdUsage, +} from "./output/prompt.ts"; export { createSpinner, createProgressBar } from "./output/progress.ts"; export { printWelcomeBanner, printQuickStart } from "./output/banner.ts"; export { maybeShowStatusBar } from "./output/status-bar.ts"; diff --git a/packages/runtime/src/output/prompt.ts b/packages/runtime/src/output/prompt.ts index 909e29c..bc1d825 100644 --- a/packages/runtime/src/output/prompt.ts +++ b/packages/runtime/src/output/prompt.ts @@ -10,9 +10,20 @@ * case explicitly. */ -import { BailianError, ExitCode, isInteractive } from "bailian-cli-core"; +import { BailianError, ExitCode, isInteractive, type Config } from "bailian-cli-core"; import { printCurrentCommandHelp, getExecutingCommandPath } from "../utils/command-help.ts"; +/** + * Build a command-usage string for the running command: ` `. + * Both the product binary name and the command path come from the runtime, so + * callers never hardcode "bl" or their own path — the same code renders as + * `bl knowledge retrieve …` under bl and `rag retrieve …` under rag. + */ +export function cmdUsage(config: Config, args = ""): string { + const parts = [config.binName, ...getExecutingCommandPath()].filter(Boolean); + return args ? `${parts.join(" ")} ${args}` : parts.join(" "); +} + // Dynamic import to avoid loading @clack/prompts in non-interactive envs unnecessarily // (though for CLI tools the startup cost is usually acceptable) diff --git a/packages/runtime/src/registry.ts b/packages/runtime/src/registry.ts index 5486bb7..ef23fe8 100644 --- a/packages/runtime/src/registry.ts +++ b/packages/runtime/src/registry.ts @@ -165,7 +165,7 @@ export class CommandRegistry { } if (node.command) { - this.printCommandHelp(node.command, out); + this.printCommandHelp(node.command, commandPath, out); return; } @@ -244,13 +244,17 @@ ${b("Getting Help:")} `); } - private printCommandHelp(cmd: Command, out: NodeJS.WriteStream): void { + private printCommandHelp(cmd: Command, commandPath: string[], out: NodeJS.WriteStream): void { const b = (s: string) => this.bold(s, out); const a = (s: string) => this.accent(s, out); const d = (s: string) => this.dim(s, out); + // ` ` prefix is rendered here, not stored in the command, so the + // same command shows the right invocation under any product (bl / rag / …). + const prefix = [this.cliName, ...commandPath].join(" "); + out.write(`\n${cmd.description}\n`); - if (cmd.usage) out.write(`${b("Usage:")} ${cmd.usage}\n`); + out.write(`${b("Usage:")} ${prefix}${cmd.usageArgs ? ` ${cmd.usageArgs}` : ""}\n`); if (cmd.options && cmd.options.length > 0) { const maxLen = Math.max(...cmd.options.map((o) => o.flag.length)); out.write(`\n${b("Options:")}\n`); @@ -264,10 +268,10 @@ ${b("Getting Help:")} out.write(` ${note}\n`); } } - if (cmd.examples && cmd.examples.length > 0) { + if (cmd.exampleArgs && cmd.exampleArgs.length > 0) { out.write(`\n${b("Examples:")}\n`); - for (const ex of cmd.examples) { - out.write(` ${d(ex)}\n`); + for (const ex of cmd.exampleArgs) { + out.write(` ${d(ex ? `${prefix} ${ex}` : prefix)}\n`); } } out.write( diff --git a/skills/bailian-cli/reference/advisor.md b/skills/bailian-cli/reference/advisor.md index 83db791..306957f 100644 --- a/skills/bailian-cli/reference/advisor.md +++ b/skills/bailian-cli/reference/advisor.md @@ -1,6 +1,6 @@ # `bl advisor` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) @@ -52,5 +52,5 @@ bl advisor recommend --message "Long document summarization" --dry-run ``` ```bash -bl advisor recommend # Interactive input +bl advisor recommend # Interactive input ``` diff --git a/skills/bailian-cli/reference/app.md b/skills/bailian-cli/reference/app.md index 710f366..47ef1af 100644 --- a/skills/bailian-cli/reference/app.md +++ b/skills/bailian-cli/reference/app.md @@ -1,6 +1,6 @@ # `bl app` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) diff --git a/skills/bailian-cli/reference/auth.md b/skills/bailian-cli/reference/auth.md index e4ffe29..e4c9957 100644 --- a/skills/bailian-cli/reference/auth.md +++ b/skills/bailian-cli/reference/auth.md @@ -1,6 +1,6 @@ # `bl auth` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) @@ -21,7 +21,7 @@ Index: [index.md](index.md) | --------------- | ---------------------------------------------------------------------------- | | **Name** | `auth login` | | **Description** | Authenticate with API key or console browser login (credentials can coexist) | -| **Usage** | `bl auth login --api-key \| bl auth login --console` | +| **Usage** | `bl auth login --api-key \| --console` | #### Options diff --git a/skills/bailian-cli/reference/config.md b/skills/bailian-cli/reference/config.md index d99c369..ae92f90 100644 --- a/skills/bailian-cli/reference/config.md +++ b/skills/bailian-cli/reference/config.md @@ -1,44 +1,19 @@ # `bl config` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) ## Commands in this group -| Command | Description | -| ------------------------- | ----------------------------------------------------------------------------------- | -| `bl config export-schema` | Export all (or one) CLI command(s) as Anthropic/OpenAI-compatible JSON tool schemas | -| `bl config set` | Set a config value | -| `bl config show` | Display current configuration | +| Command | Description | +| ---------------- | ----------------------------- | +| `bl config set` | Set a config value | +| `bl config show` | Display current configuration | ## Command details -### `bl config export-schema` - -| Field | Value | -| --------------- | ----------------------------------------------------------------------------------- | -| **Name** | `config export-schema` | -| **Description** | Export all (or one) CLI command(s) as Anthropic/OpenAI-compatible JSON tool schemas | -| **Usage** | `bl config export-schema [--command ""]` | - -#### Options - -| Flag | Type | Required | Description | -| ------------------ | ------ | -------- | ----------------------------------------------------------------- | -| `--command ` | string | no | Export schema for a specific command only (e.g. "image generate") | - -#### Examples - -```bash -bl config export-schema -``` - -```bash -bl config export-schema --command "video generate" -``` - ### `bl config set` | Field | Value | diff --git a/skills/bailian-cli/reference/console.md b/skills/bailian-cli/reference/console.md index 384f3f0..ee61c38 100644 --- a/skills/bailian-cli/reference/console.md +++ b/skills/bailian-cli/reference/console.md @@ -1,6 +1,6 @@ # `bl console` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) diff --git a/skills/bailian-cli/reference/file.md b/skills/bailian-cli/reference/file.md index 85b0651..060e257 100644 --- a/skills/bailian-cli/reference/file.md +++ b/skills/bailian-cli/reference/file.md @@ -1,6 +1,6 @@ # `bl file` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) diff --git a/skills/bailian-cli/reference/image.md b/skills/bailian-cli/reference/image.md index 4273a77..d9e9490 100644 --- a/skills/bailian-cli/reference/image.md +++ b/skills/bailian-cli/reference/image.md @@ -1,6 +1,6 @@ # `bl image` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) diff --git a/skills/bailian-cli/reference/index.md b/skills/bailian-cli/reference/index.md index b5fdbb9..13478ff 100644 --- a/skills/bailian-cli/reference/index.md +++ b/skills/bailian-cli/reference/index.md @@ -1,6 +1,6 @@ # bailian-cli (`bl`) command reference -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Command **details** are in sibling `.md` files in this directory. @@ -16,7 +16,6 @@ Use this index for the full quick index and global flags. | `bl auth login` | Authenticate with API key or console browser login (credentials can coexist) | [auth.md](auth.md) | | `bl auth logout` | Clear stored credentials | [auth.md](auth.md) | | `bl auth status` | Show current authentication state | [auth.md](auth.md) | -| `bl config export-schema` | Export all (or one) CLI command(s) as Anthropic/OpenAI-compatible JSON tool schemas | [config.md](config.md) | | `bl config set` | Set a config value | [config.md](config.md) | | `bl config show` | Display current configuration | [config.md](config.md) | | `bl console call` | Call a Bailian console API via the CLI gateway | [console.md](console.md) | @@ -64,7 +63,7 @@ Use this index for the full quick index and global flags. | `advisor` | `recommend` | [advisor.md](advisor.md) | | `app` | `call`, `list` | [app.md](app.md) | | `auth` | `login`, `logout`, `status` | [auth.md](auth.md) | -| `config` | `export-schema`, `set`, `show` | [config.md](config.md) | +| `config` | `set`, `show` | [config.md](config.md) | | `console` | `call` | [console.md](console.md) | | `file` | `upload` | [file.md](file.md) | | `image` | `edit`, `generate` | [image.md](image.md) | diff --git a/skills/bailian-cli/reference/knowledge.md b/skills/bailian-cli/reference/knowledge.md index a194b30..d2a0d49 100644 --- a/skills/bailian-cli/reference/knowledge.md +++ b/skills/bailian-cli/reference/knowledge.md @@ -1,6 +1,6 @@ # `bl knowledge` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) diff --git a/skills/bailian-cli/reference/mcp.md b/skills/bailian-cli/reference/mcp.md index 449de8e..e879e36 100644 --- a/skills/bailian-cli/reference/mcp.md +++ b/skills/bailian-cli/reference/mcp.md @@ -1,6 +1,6 @@ # `bl mcp` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) @@ -91,10 +91,10 @@ bl mcp list --output json #### Options -| Flag | Type | Required | Description | -| --------------- | ------ | -------- | ---------------------------------------------------------- | -| `` | string | yes | Server code from `bl mcp list` (e.g. market-cmapi00073529) | -| `--url ` | string | no | Override the MCP endpoint URL (for non-Bailian servers) | +| Flag | Type | Required | Description | +| --------------- | ------ | -------- | ------------------------------------------------------- | +| `` | string | yes | Server code from `mcp list` (e.g. market-cmapi00073529) | +| `--url ` | string | no | Override the MCP endpoint URL (for non-Bailian servers) | #### Examples diff --git a/skills/bailian-cli/reference/memory.md b/skills/bailian-cli/reference/memory.md index 27b15cd..6d7e561 100644 --- a/skills/bailian-cli/reference/memory.md +++ b/skills/bailian-cli/reference/memory.md @@ -1,6 +1,6 @@ # `bl memory` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) diff --git a/skills/bailian-cli/reference/omni.md b/skills/bailian-cli/reference/omni.md index dbfecf5..d9aed23 100644 --- a/skills/bailian-cli/reference/omni.md +++ b/skills/bailian-cli/reference/omni.md @@ -1,6 +1,6 @@ # `bl omni` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) diff --git a/skills/bailian-cli/reference/pipeline.md b/skills/bailian-cli/reference/pipeline.md index fed7897..b81b52a 100644 --- a/skills/bailian-cli/reference/pipeline.md +++ b/skills/bailian-cli/reference/pipeline.md @@ -1,6 +1,6 @@ # `bl pipeline` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) diff --git a/skills/bailian-cli/reference/quota.md b/skills/bailian-cli/reference/quota.md index d166182..807e472 100644 --- a/skills/bailian-cli/reference/quota.md +++ b/skills/bailian-cli/reference/quota.md @@ -1,6 +1,6 @@ # `bl quota` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) diff --git a/skills/bailian-cli/reference/search.md b/skills/bailian-cli/reference/search.md index d4ce7e7..caf031d 100644 --- a/skills/bailian-cli/reference/search.md +++ b/skills/bailian-cli/reference/search.md @@ -1,6 +1,6 @@ # `bl search` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) diff --git a/skills/bailian-cli/reference/speech.md b/skills/bailian-cli/reference/speech.md index f7e0e17..cf5bbe1 100644 --- a/skills/bailian-cli/reference/speech.md +++ b/skills/bailian-cli/reference/speech.md @@ -1,6 +1,6 @@ # `bl speech` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) @@ -123,7 +123,7 @@ bl speech synthesize --text "Hello" --voice --format wav --sample-rat ``` ```bash -# Stream to audio player (macOS) +bl speech synthesize # Stream to audio player (macOS) ``` ```bash @@ -131,7 +131,7 @@ bl speech synthesize --text "Hello" --voice --stream | afplay - ``` ```bash -# Pipe to ffplay +bl speech synthesize # Pipe to ffplay ``` ```bash diff --git a/skills/bailian-cli/reference/text.md b/skills/bailian-cli/reference/text.md index d006457..cf04650 100644 --- a/skills/bailian-cli/reference/text.md +++ b/skills/bailian-cli/reference/text.md @@ -1,6 +1,6 @@ # `bl text` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) @@ -52,7 +52,7 @@ bl text chat --message "Hello" --message "assistant:Hi!" --message "How are you? ``` ```bash -cat conversation.json | bl text chat --messages-file - --stream +bl text chat --messages-file - --stream ``` ```bash diff --git a/skills/bailian-cli/reference/update.md b/skills/bailian-cli/reference/update.md index ff9b65d..f47effb 100644 --- a/skills/bailian-cli/reference/update.md +++ b/skills/bailian-cli/reference/update.md @@ -1,6 +1,6 @@ # `bl update` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) diff --git a/skills/bailian-cli/reference/usage.md b/skills/bailian-cli/reference/usage.md index 6783bf4..b7f9369 100644 --- a/skills/bailian-cli/reference/usage.md +++ b/skills/bailian-cli/reference/usage.md @@ -1,6 +1,6 @@ # `bl usage` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) diff --git a/skills/bailian-cli/reference/video.md b/skills/bailian-cli/reference/video.md index e75aefc..54b088e 100644 --- a/skills/bailian-cli/reference/video.md +++ b/skills/bailian-cli/reference/video.md @@ -1,6 +1,6 @@ # `bl video` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) diff --git a/skills/bailian-cli/reference/vision.md b/skills/bailian-cli/reference/vision.md index 8aaf4d8..6373bfb 100644 --- a/skills/bailian-cli/reference/vision.md +++ b/skills/bailian-cli/reference/vision.md @@ -1,6 +1,6 @@ # `bl vision` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) diff --git a/skills/bailian-cli/reference/workspace.md b/skills/bailian-cli/reference/workspace.md index 47f588c..27fc6b8 100644 --- a/skills/bailian-cli/reference/workspace.md +++ b/skills/bailian-cli/reference/workspace.md @@ -1,6 +1,6 @@ # `bl workspace` commands -> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand. +> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand. > Regenerate: `pnpm --filter bailian-cli run generate:reference`. Index: [index.md](index.md) diff --git a/tools/generate-reference.ts b/tools/generate-reference.ts index 18a6140..675a4b2 100644 --- a/tools/generate-reference.ts +++ b/tools/generate-reference.ts @@ -1,5 +1,5 @@ /** - * Generator: reads `packages/commands/src/commands/catalog.ts` and writes: + * Generator: reads the bl product command map (`packages/cli/src/commands.ts`) and writes: * - `skills/bailian-cli/reference/index.md` — quick index, global flags, notes * - `skills/bailian-cli/reference/.md` — per top-level command group details * @@ -12,14 +12,14 @@ import { mkdirSync, readdirSync, rmSync, writeFileSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; import { GLOBAL_OPTIONS, type Command, type OptionDef } from "../packages/core/dist/index.mjs"; -import { commands } from "../packages/commands/src/commands/catalog.ts"; +import { commands } from "../packages/cli/src/commands.ts"; const __dirname = dirname(fileURLToPath(import.meta.url)); const REF_DIR = join(__dirname, "../skills/bailian-cli/reference"); const INDEX_PATH = join(REF_DIR, "index.md"); const GENERATED_BANNER = - "> Auto-generated from `packages/commands/src/commands/catalog.ts`. Do not edit by hand.\n" + + "> Auto-generated from `packages/cli/src/commands.ts`. Do not edit by hand.\n" + "> Regenerate: `pnpm --filter bailian-cli run generate:reference`."; function escCell(s: string): string { @@ -50,9 +50,14 @@ function formatOptionsTable(options: OptionDef[] | undefined): string { ].join("\n"); } -function formatExamples(examples: string[] | undefined): string { - if (!examples?.length) return "_No examples._\n"; - return examples.map((ex) => ["```bash", ex, "```"].join("\n")).join("\n\n") + "\n"; +function formatExamples(path: string, exampleArgs: string[] | undefined): string { + if (!exampleArgs?.length) return "_No examples._\n"; + // Commands store argument-only examples; prepend `bl ` for the reference. + return ( + exampleArgs + .map((ex) => ["```bash", `bl ${path}${ex ? ` ${ex}` : ""}`, "```"].join("\n")) + .join("\n\n") + "\n" + ); } function formatNotes(notes: string[] | undefined): string { @@ -64,11 +69,11 @@ function commandSection(path: string, cmd: Command): string { const lines: string[] = []; lines.push(`### \`bl ${path}\``, ""); lines.push(`| Field | Value |`, `| --- | --- |`); - lines.push(`| **Name** | \`${escCell(cmd.name)}\` |`); + lines.push(`| **Name** | \`${escCell(path)}\` |`); lines.push(`| **Description** | ${escCell(cmd.description)} |`); - if (cmd.usage) { - lines.push(`| **Usage** | \`${escCell(cmd.usage)}\` |`); - } + // Commands store argument-only usage; the `bl ` prefix is added here. + const usage = `bl ${path}${cmd.usageArgs ? ` ${cmd.usageArgs}` : ""}`; + lines.push(`| **Usage** | \`${escCell(usage)}\` |`); lines.push(""); lines.push("#### Options", ""); @@ -80,7 +85,7 @@ function commandSection(path: string, cmd: Command): string { } lines.push("#### Examples", ""); - lines.push(formatExamples(cmd.examples)); + lines.push(formatExamples(path, cmd.exampleArgs)); return lines.join("\n"); }