feat: 所有非交互命令支持 --format json/yaml/table #328

Closed
opened 2026-05-18 13:30:27 +00:00 by xiaoju · 0 comments
Owner

背景

当前所有 uwf 命令都只输出 JSON(writeJson)。需要支持多种输出格式方便不同场景:

  • json(默认)— agent 和管道友好
  • yaml — 人类阅读友好
  • table — 终端交互友好,列表类命令(workflow list、thread list、schema list 等)

需求

1. 全局 --format 选项

program 级别加 --format <fmt> 选项(默认 json),所有子命令继承。

2. 统一输出函数

替换现有的 writeJson(data),改为 writeOutput(data, format) 或类似机制:

  • jsonJSON.stringify(data) + newline(当前行为)
  • yamlyaml.stringify(data)
  • table → 对数组类数据渲染为表格(hash | name 这种),对象类数据渲染为 key-value

3. 涉及的命令

  • uwf workflow list — table: name | hash
  • uwf workflow show — yaml/json
  • uwf workflow put — json/yaml
  • uwf thread list — table: threadId | workflow | head
  • uwf thread show — yaml/json
  • uwf thread start — json/yaml
  • uwf thread step — json/yaml
  • uwf thread kill — json/yaml
  • uwf cas get/cat/put/has/refs/walk — json/yaml
  • uwf cas schema list — table: hash | title
  • uwf cas schema get — json/yaml

4. table 渲染

不引入重依赖。用简单的对齐输出即可,类似:

HASH           TITLE
5GWKR8TN1V3JA  Workflow
8CNWT4KR6D1HV  StartNode
1VPBG9SM5E7WK  StepNode

对非数组数据(单个对象),table 退化为 yaml。

实现提示

  • yaml 包已在依赖中
  • 新建 packages/cli-uwf/src/format.ts,导出 formatOutput(data: unknown, format: string): string
  • cli.tsprogram.option("--format <fmt>", "Output format: json, yaml, table", "json")
  • 替换所有 writeJson(result)writeOutput(result, opts.format)

验收标准

  • uwf workflow list --format table 输出人类友好表格
  • uwf cas schema list --format yaml 输出 YAML
  • 默认(不传 --format)行为不变,仍然输出 JSON
  • tsc --noEmit 通过
## 背景 当前所有 uwf 命令都只输出 JSON(`writeJson`)。需要支持多种输出格式方便不同场景: - `json`(默认)— agent 和管道友好 - `yaml` — 人类阅读友好 - `table` — 终端交互友好,列表类命令(workflow list、thread list、schema list 等) ## 需求 ### 1. 全局 `--format` 选项 在 `program` 级别加 `--format <fmt>` 选项(默认 `json`),所有子命令继承。 ### 2. 统一输出函数 替换现有的 `writeJson(data)`,改为 `writeOutput(data, format)` 或类似机制: - `json` → `JSON.stringify(data)` + newline(当前行为) - `yaml` → `yaml.stringify(data)` - `table` → 对数组类数据渲染为表格(hash | name 这种),对象类数据渲染为 key-value ### 3. 涉及的命令 - `uwf workflow list` — table: name | hash - `uwf workflow show` — yaml/json - `uwf workflow put` — json/yaml - `uwf thread list` — table: threadId | workflow | head - `uwf thread show` — yaml/json - `uwf thread start` — json/yaml - `uwf thread step` — json/yaml - `uwf thread kill` — json/yaml - `uwf cas get/cat/put/has/refs/walk` — json/yaml - `uwf cas schema list` — table: hash | title - `uwf cas schema get` — json/yaml ### 4. table 渲染 不引入重依赖。用简单的对齐输出即可,类似: ``` HASH TITLE 5GWKR8TN1V3JA Workflow 8CNWT4KR6D1HV StartNode 1VPBG9SM5E7WK StepNode ``` 对非数组数据(单个对象),table 退化为 yaml。 ## 实现提示 - `yaml` 包已在依赖中 - 新建 `packages/cli-uwf/src/format.ts`,导出 `formatOutput(data: unknown, format: string): string` - `cli.ts` 中 `program.option("--format <fmt>", "Output format: json, yaml, table", "json")` - 替换所有 `writeJson(result)` 为 `writeOutput(result, opts.format)` ## 验收标准 - [ ] `uwf workflow list --format table` 输出人类友好表格 - [ ] `uwf cas schema list --format yaml` 输出 YAML - [ ] 默认(不传 --format)行为不变,仍然输出 JSON - [ ] tsc --noEmit 通过
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#328