From 235e4b806de6a5a2fc01ac8ec64a2b6f99d6dc73 Mon Sep 17 00:00:00 2001 From: yunyingk Date: Wed, 18 Nov 2026 15:24:01 +0800 Subject: [PATCH] =?UTF-8?q?docs(agent):=20=E8=A1=A5=E9=BD=90=20platform=20?= =?UTF-8?q?records=20--all=20=E7=9A=84=E6=B5=81=E5=BC=8F=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E7=BA=A6=E6=9D=9F=E4=B8=8E=20JSON=20=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - platform records 的 JSON 结构化错误补充 exitCode 与 nextAction,与 runner 的统一错误形状对齐;非 JSON 路径同步携带 nextAction; - 新增 --json 模式下 DATASET_TOO_LARGE 单测,覆盖分页与流式导出建议; - Skill 与 workflow 参考文档中的 --all 示例统一改为 --ndjson -o,并补充 DATASET_TOO_LARGE 的恢复说明,修正 bbcf96c 声称完成但遗漏的 skill guidelines; - datalink README 补充 --all 的流式导出约束与结构化错误字段。 校验:bun test 1156 pass / 0 fail;bun run check 通过; check:readme 的 specs/ 与 src/core/db/ 缺失为仓库既有问题,与本次改动无关。 --- skills/hose-use/SKILL.md | 4 +-- skills/hose-use/references/workflow.md | 6 +++-- src/cli/commands/platform.test.ts | 27 +++++++++++++++++++ src/cli/commands/platform/records.ts | 7 +++-- .../platform/datalink/README.datalink.md | 2 ++ 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/skills/hose-use/SKILL.md b/skills/hose-use/SKILL.md index 1836a55..575f01b 100644 --- a/skills/hose-use/SKILL.md +++ b/skills/hose-use/SKILL.md @@ -140,7 +140,7 @@ metadata: | 企业通讯录检索 / 员工档案 / 防爆保护 | `hose-use contact search`, `hose-use contact list`, `hose-use contact get` | [references/contact.md](./references/contact.md) | | 待办中心 / 已审批 / 我发起的 / 审批记录 / 抄送 | `hose-use task todo`, `hose-use task submitted`, `hose-use task records`, `hose-use task cc` | [references/task.md](./references/task.md) | | 应用管理 (桌面端工作台开通的用车/套件/制度/自建前台应用) | `hose-use app list [--keyword]`, `hose-use app get <应用>` | [references/workflow.md](./references/workflow.md) | -| 自建应用与数据模型 (开放平台业务对象/字段定义/全量记录/健康度体检) | `hose-use platform list`, `hose-use platform entities <应用>`, `hose-use platform records <应用> <对象> --all`, `hose-use platform audit <应用> <对象>` | [references/workflow.md](./references/workflow.md) | +| 自建应用与数据模型 (开放平台业务对象/字段定义/全量记录/健康度体检) | `hose-use platform list`, `hose-use platform entities <应用>`, `hose-use platform records <应用> <对象> --all --ndjson -o `, `hose-use platform audit <应用> <对象>` | [references/workflow.md](./references/workflow.md) | | 自建应用单条/批量记录安全操作 (详情/停启用/安全合并编辑/批量补丁/台账重算) | `hose-use platform record ` | [references/workflow.md](./references/workflow.md) | | 跨自建应用工作流聚合检索与节点扫描 | `hose-use workflow list`, `hose-use workflow find --task=code-js2` | [references/workflow.md](./references/workflow.md) | | 桌面端全站主导航与一级模块树 | `hose-use menu list`, `hose-use menu tree` | [references/workflow.md](./references/workflow.md) | @@ -242,7 +242,7 @@ hose-use platform list # 列出企业可见的 hose-use platform entities 新转转集团 # 查看自建应用下的业务对象与字段 hose-use platform records 新转转集团 合同 --stats # 宏观结构画像(总数/启停比率/重名数/编码规则聚类) hose-use platform records 新转转集团 合同 --ndjson --flat # 万级海量数据 $O(1)$ 内存逐行流式输出 JSON Lines -hose-use platform records 新转转集团 合同 --all -o /tmp/records.json # 自动翻页导出全量业务对象记录 +hose-use platform records 新转转集团 合同 --all --ndjson -o /tmp/records.json # 自动翻页并流式导出全量业务对象记录 hose-use platform audit 新转转集团 合同 --check-fields="我方签约主体" # 一键巡检必填缺失、停用引用与跨表同步差异 hose-use platform record get <记录ID> # 免传应用/对象,直接按记录 ID 获取完整详情 hose-use platform record toggle 新转转集团 合同 <记录ID> --dry-run # 预览状态切换 diff --git a/skills/hose-use/references/workflow.md b/skills/hose-use/references/workflow.md index 51a4baf..f6f4fb6 100644 --- a/skills/hose-use/references/workflow.md +++ b/skills/hose-use/references/workflow.md @@ -44,12 +44,14 @@ hose-use platform entities 新转转集团 hose-use platform schema 新转转集团 合同 hose-use platform schema 新转转集团 合同 --keyword="金额" -# 检索业务对象的底层真实数据记录(支持 --all 自动翻页拉取全量记录) +# 检索业务对象的底层真实数据记录(--all 自动翻页拉取全量记录) hose-use platform records 新转转集团 合同 --limit=5 hose-use platform records 新转转集团 合同 --keyword="技术服务" --fields "合同编号,金额,经办人" --json -hose-use platform records 新转转集团 支付计划表 --all --json -o /tmp/payment_plans.json +hose-use platform records 新转转集团 支付计划表 --all --ndjson -o /tmp/payment_plans.json ``` +> `--all` 必须与 `--ndjson --output-file ` 一起使用;缺少流式导出时会返回 `DATASET_TOO_LARGE`(exitCode 2),并给出分页与流式导出的恢复建议。 + ### 2.1 业务对象记录操作 (`platform record`) 与安全全量合并 (Read-Modify-Write) > **关键防坑说明**:合思 DataLink `PUT /api/v2.2/datalink/platformDataLink/$id` 是**整单覆盖接口**,而非局部 PATCH。若只传修改的 1 个字段,未传字段会被清空、对象引用若未提取 `.id` 会报 417、`visibility` 漏传会导致全员不可见。`hose-use platform record edit` 与 `batch-edit` 默认内置 **Read-Modify-Write 安全合并引擎**,自动拉取原记录与 Schema、归一化嵌套引用 ID、保留全部存量字段与 `visibility` 权限,并支持字段中英文短名自动解析。 diff --git a/src/cli/commands/platform.test.ts b/src/cli/commands/platform.test.ts index 902246a..46f8b02 100644 --- a/src/cli/commands/platform.test.ts +++ b/src/cli/commands/platform.test.ts @@ -528,6 +528,33 @@ describe("CLI - platform 命令与 record 动作", () => { ).rejects.toThrow("--all 不再直接返回全量"); }); + it("platform records --all --json 返回 DATASET_TOO_LARGE 结构化错误", async () => { + spies.push(spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any)); + spies.push(spyOn(servicesApplications, "resolvePlatform").mockResolvedValue(mockPlatform as any)); + spies.push(spyOn(services, "resolveEntity").mockResolvedValue(mockEntity as any)); + const result = await handlePlatformCommand( + { + area: "platform", + action: "records", + args: ["platform-1", "entity-1"], + options: { all: true, json: true }, + raw: ["platform", "records", "platform-1", "entity-1", "--all", "--json"], + }, + { ...dummyRuntime, jsonMode: true } + ); + + expect(result.exitCode).toBe(2); + const parsed = JSON.parse(result.stdout); + expect(parsed.error).toBe(true); + expect(parsed.code).toBe("DATASET_TOO_LARGE"); + expect(parsed.exitCode).toBe(2); + expect(parsed.nextAction).toContain("--ndjson"); + expect(parsed.suggestions).toEqual([ + { type: "paginate", command: "--page=1 --pageSize=500" }, + { type: "stream_export", command: "--ndjson --output-file=" }, + ]); + }); + it("rejects malformed batch predicates before fetching all records or calling the writer", async () => { spies.push(spyOn(helpers, "createClientsForCorp").mockResolvedValue({ ekbClient: {} } as any)); spies.push(spyOn(servicesApplications, "resolvePlatform").mockResolvedValue(mockPlatform as any)); diff --git a/src/cli/commands/platform/records.ts b/src/cli/commands/platform/records.ts index 54c1d94..1c51766 100644 --- a/src/cli/commands/platform/records.ts +++ b/src/cli/commands/platform/records.ts @@ -65,12 +65,15 @@ export async function handleRecords(parsed: CliParsedArgs, runtime: CliRuntime): if (!isStream || !runtime.outputOptions?.outputFile) { const message = "--all 不再直接返回全量 JSON/表格。请使用 --page/--count 分页查询,或使用 --ndjson --output-file 流式导出;大范围检索建议交给脚本处理。"; + const nextAction = "hose-use platform records <应用> <业务对象> --ndjson --output-file "; if (runtime.jsonMode) { return { stdout: JSON.stringify({ error: true, code: "DATASET_TOO_LARGE", - message: message, + message, + exitCode: 2, + nextAction, suggestions: [ { type: "paginate", command: "--page=1 --pageSize=500" }, { type: "stream_export", command: "--ndjson --output-file=" }, @@ -80,7 +83,7 @@ export async function handleRecords(parsed: CliParsedArgs, runtime: CliRuntime): exitCode: 2, }; } - throw usageError(message); + throw usageError(message, nextAction); } } diff --git a/src/domains/platform/datalink/README.datalink.md b/src/domains/platform/datalink/README.datalink.md index 6851c94..29a21a8 100644 --- a/src/domains/platform/datalink/README.datalink.md +++ b/src/domains/platform/datalink/README.datalink.md @@ -50,6 +50,8 @@ hose-use platform imports <应用 ID|名称> <对象 ID|名称> - `records <业务对象>`(单参数免应用查询):当企业自建应用较多时,无需事先查询 platformId。直接输入业务对象名称或编码,CLI 自动遍历企业全量自建应用进行智能反查与寻址;若跨应用重名则抛出精准候选项提示,避免人工心智负担。 - `records --ndjson`(或 `--stream`):针对万级~十万级海量记录,采用 AsyncGenerator 分页流式生成,逐行向 `stdout` 发射 NDJSON。内存恒定为 $O(\text{pageSize})$,严防大报文撑爆内存或终端,无缝对接下游 `jq`、Python 处理流水线。 + +- `records --all`:全量记录不再直接返回 JSON/表格;必须与 `--ndjson --output-file ` 一起使用,否则返回 `DATASET_TOO_LARGE`(exitCode 2)并附分页/流式导出建议。`--json` 模式下该错误以 `{ error, code, message, exitCode, nextAction, suggestions }` 结构化输出,Agent 可直接解析。 - 终端入口提供显式输出回调并等待写入完成以响应背压;`--ndjson -o ` 写入真正的 NDJSON 文件,返回文件路径、字节数和记录数摘要。 - MCP / HTTP 默认不提供终端输出通道;未指定文件时拒绝直接流式输出,避免污染协议 stdout 或返回空的成功响应。输出逐行执行统一脱敏。 - `records --page=<页码> --count=<每页>`:分页查询,默认 `count=20`;用于替代无边界全量拉取。