Merge pull request #194 from yunyingk/feat/agent-docs-self-reflection
CI / validate (push) Canceled after 0s
CI / validate (push) Canceled after 0s
feat(agent): 增强开放平台文档自省与端点检索引导
This commit is contained in:
6 files changed
+152
-1
No files matched your search
@@ -39,6 +39,7 @@ CLI (src/cli.ts) / AI PRO (src/aipro-cli.ts) / MCP (src/server.ts) / HTTP (src/h
|
||||
- `server.ts` 只做单工具 MCP 协议适配(`hose_cli` 委托 `src/cli/runner.ts`)
|
||||
- `src/cli/registry.ts` 作为顶层命令、别名与常驻属性的唯一声明式注册表
|
||||
- 业务编排统一放在 `domains/*/tools.ts` 或 `domains/*/services.ts`
|
||||
- 开放平台官方接口/规范/参数规格检索统一使用 `hose-use docs search/show`,严禁 Agent 或上层代码绕过 CLI 直接解析 specs 目录下的底层 JSON 数据
|
||||
- 自建应用平台统一位于 `domains/platform/`,applications、datalink、workflow 分别拥有自己的模型、传输与服务出口;applications 不反向依赖另外两者,DataLink 不依赖 workflow,跨子模块不得直接调用 api。
|
||||
- `domains/**/api.ts` 只负责 HTTP 请求和响应校验,严禁被入口层直接导入
|
||||
- `core/` 严格保持基础设施窄白名单(`auth/`, `cache/`, `config/`, `db/`, `errors.ts`, `http/`),构建产物与 Skill 分发统一置于 `src/packaging/`
|
||||
@@ -54,6 +55,7 @@ CLI (src/cli.ts) / AI PRO (src/aipro-cli.ts) / MCP (src/server.ts) / HTTP (src/h
|
||||
常用子域入口:
|
||||
|
||||
- Platform 说明:[src/domains/platform/README.platform.md](./src/domains/platform/README.platform.md)
|
||||
- Docs 说明:[src/domains/docs/README.docs.md](./src/domains/docs/README.docs.md)
|
||||
|
||||
## 开发与修改规则
|
||||
|
||||
|
||||
@@ -89,6 +89,14 @@ metadata:
|
||||
- 原生 `every` 的筛选字段物理键与右值选择器是两种结构:左侧保留 `feeTypeId`,右侧固定费用类型需保留前端 `value()` 描述符的真实 `key` 和 `label`;裸 ID 运行成功不代表设计器正常显示;
|
||||
- 金额来源、费用类型与明细对应关系须按用户确认的业务规则和实际字段元数据确定;创单引用循环聚合结果,空明细不得继续创单或回写成功;
|
||||
- 回读用户手工保存的 JSON 时,同时检查 `batch` / `batchSize`;并行配置会改变执行方式,不得当作显示修复自动覆盖。完整结构、金额类型与空列表兼容方案见 [references/workflow.md §20](./references/workflow.md#20-原生循环筛选选择器与费用明细)。
|
||||
18. **合思开放平台接口自省铁律(Docs & OpenAPI Self-Reflection First & Zero-JSON-Digging)**:
|
||||
- 当需要调研或回答“合思有哪些接口、支持哪些字段、具体参数/返回值规范是什么、如何设计第三方系统对接方案”时,**唯一正规、第一优先级的入口是 `hose-use docs search <关键词>` 与 `hose-use docs show <Path>`**;
|
||||
- **严禁翻找源码或 specs 目录下的 `docs-catalog.json` / `openapi*.json`**,严禁使用 `bun -e '...'` 或系统临时脚本暴力解析底层 JSON 文件;
|
||||
- 检索三步法:
|
||||
1. 查看模块大类:`hose-use docs categories`(了解合思 26+ 个业务分类及端点分布);
|
||||
2. 关键词检索:`hose-use docs search <关键词> [--category=<分类>] [--json]`(毫秒级获取接口清单与废弃标记);
|
||||
3. 单篇精细查阅:`hose-use docs show <Path|URL|名称> [--json]`(获取官方完整参数规格、类型约束与 CURL 示例);
|
||||
- 细节查阅专属参考文档:[references/docs.md](./references/docs.md)。
|
||||
|
||||
---
|
||||
|
||||
@@ -97,6 +105,7 @@ metadata:
|
||||
| 用户意图 / 场景 | 推荐命令 | 深入参考文档 |
|
||||
|---|---|---|
|
||||
| 全局运行上下文 / 身份诊断 / 免读源码自省 | `hose-use context [--json]`, `hose-use status` | [references/auth.md](./references/auth.md) |
|
||||
| 合思开放平台官方接口/文档规范/售前能力调研/端点规格与CURL检索 | `hose-use docs search <关键词>`, `hose-use docs show <Path>`, `hose-use docs categories` | [references/docs.md](./references/docs.md) |
|
||||
| AI PRO 确定性审批仲裁全流程 / 事实证据核验 | `hose-aipro bind`, `hose-aipro review`, `hose-aipro decide` | [独立技能 hose-aipro](../hose-aipro/SKILL.md) |
|
||||
| 本机 AI PRO 审批网关常驻服务启停与管理 | `hose-use aipro <start\|stop\|restart\|status>` | [references/service.md](./references/service.md) |
|
||||
| 本地审批规约场景与规则管理 | `hose-use rule scopes`, `hose-use rule add --dry-run/--yes`, `hose-use rule list` | [references/service.md](./references/service.md) |
|
||||
@@ -288,6 +297,16 @@ hose-use service status # 查看常驻守护进
|
||||
hose-use service poll --corp=ID01ofWoOC1wiX --json # 轮询待办/消息并去重落盘
|
||||
hose-use service logs # 查看常驻守护进程日志
|
||||
hose-use service stop # 停止后台常驻守护进程
|
||||
|
||||
# 8. 合思开放平台官方接口文档与端点规范 (docs)
|
||||
hose-use docs categories # 查看 26+ 个业务分类及 HTTP 端点分布
|
||||
hose-use docs categories --json # 结构化查看业务模块清单
|
||||
hose-use docs search 预算 # 智能加权检索包含“预算”的全部接口与指南
|
||||
hose-use docs search 批量更新 --category=预算 # 在指定业务分类内精准检索
|
||||
hose-use docs search 角色组 --json # 结构化输出匹配端点列表
|
||||
hose-use docs show /api/openapi/v2.1/budgets/\$budgetId/batchUpdate # 查看指定端点完整参数规格、约束与 CURL 示例
|
||||
hose-use docs show /api/openapi/v2.1/budgets/\$budgetId/batchUpdate --json # 结构化输出端点定义模型
|
||||
hose-use docs sync # 强制与 docs.ekuaibao.com 线上文档全量同步
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
# 合思开放平台官方接口文档与端点规范 (docs)
|
||||
|
||||
合思/易快报拥有 26+ 个业务分类、330+ 篇官方文档与 270+ 个 HTTP OpenAPI 端点。
|
||||
`hose-use docs` 命令域提供了**完全离线、毫秒级响应、带加权打分与完整 CURL/参数表格**的结构化自省能力。
|
||||
|
||||
> [!IMPORTANT]
|
||||
> **Agent 与实施首选铁律**:
|
||||
> 凡涉及“合思有哪些接口、特定业务(如预算/发票/报销/自建应用)支持哪些 API、请求参数与返回结构是什么、如何设计第三方系统集成方案”等场景,**唯一正规、第一优先级的入口是 `hose-use docs search` 与 `hose-use docs show`**。
|
||||
> **严禁**翻找源码目录或直接用临时脚本(如 `bun -e`)硬扒 `specs/docs-catalog.json`!
|
||||
|
||||
---
|
||||
|
||||
## 常用子命令与速查
|
||||
|
||||
### 1. 业务分类全览 (`hose-use docs categories`)
|
||||
查看合思开放平台包含的所有业务大类以及每个分类下的端点数量:
|
||||
|
||||
```bash
|
||||
hose-use docs categories
|
||||
hose-use docs categories --json
|
||||
```
|
||||
|
||||
输出示例:
|
||||
```text
|
||||
====== 合思开放平台业务模块分类 (共 26 个) ======
|
||||
|
||||
# 业务分类 文档篇数 HTTP 端点数
|
||||
-- ------------ -------- -----------
|
||||
1 单据 50 篇 42 个
|
||||
2 自建应用 45 篇 38 个
|
||||
3 预算 13 篇 9 个
|
||||
4 费用类型 12 篇 10 个
|
||||
5 员工档案 15 篇 12 个
|
||||
...
|
||||
```
|
||||
|
||||
### 2. 关键词加权智能检索 (`hose-use docs search`)
|
||||
按接口标题、请求路径、URL、参数规格、正文段落综合加权搜索。
|
||||
|
||||
```bash
|
||||
# 基础检索
|
||||
hose-use docs search 预算
|
||||
hose-use docs search roleDefGroups
|
||||
hose-use docs search "发票查重"
|
||||
|
||||
# 限定业务大类检索 (通过 --category)
|
||||
hose-use docs search 批量更新 --category=预算
|
||||
hose-use docs search 审批 --category=单据
|
||||
|
||||
# 限制返回条数与 JSON 结构化输出 (最适合 Agent 解析)
|
||||
hose-use docs search 预算 --limit=10 --json
|
||||
```
|
||||
|
||||
**JSON 模式返回字段说明**:
|
||||
- `total`: 命中总数
|
||||
- `results`: 匹配条目数组,包含:
|
||||
- `id`: 文档 ID
|
||||
- `title`: 中文标题(如“批量更新(新增/修改/删除)预算节点”)
|
||||
- `category`: 业务分类(如“预算”)
|
||||
- `path`: HTTP 路由(如 `/api/openapi/v2.1/budgets/$budgetId/batchUpdate`)
|
||||
- `method`: HTTP 方法(`GET`, `POST`, `PUT`, `DELETE` 等)
|
||||
- `permalink`: 官方在线文档链接
|
||||
- `matchReason`: 匹配依据与高亮摘要
|
||||
|
||||
### 3. 单篇接口详细规格查询 (`hose-use docs show`)
|
||||
精准调阅指定端点的全量参数规格表、Query/Path/Body 定义、完整 CURL 示例以及成功/失败响应报文。
|
||||
|
||||
```bash
|
||||
# 按接口 Path 查看 (推荐)
|
||||
hose-use docs show /api/openapi/v2.1/budgets/\$budgetId/batchUpdate
|
||||
|
||||
# 按文档 URL 查看
|
||||
hose-use docs show /docs/open-api/budget/batch-pdate-budget-node
|
||||
|
||||
# 按中文标题模糊查看
|
||||
hose-use docs show "批量更新(新增/修改/删除)预算节点"
|
||||
|
||||
# JSON 模式输出完整原始模型
|
||||
hose-use docs show /api/openapi/v2.1/budgets/\$budgetId/batchUpdate --json
|
||||
```
|
||||
|
||||
输出包含以下结构:
|
||||
- **基本信息**:标题、分类、方法、路径、在线链接;
|
||||
- **参数规格与定义**:Path Parameters、Query Parameters、Body Parameters(含层级嵌套、字段类型、必填性、默认值、枚举值和业务语义备注);
|
||||
- **CURL / 调用示例**:包含实际请求头、典型 Payload JSON 模板;
|
||||
- **响应示例**:成功响应 JSON 与失败状态码说明。
|
||||
|
||||
### 4. 强制全量同步更新 (`hose-use docs sync`)
|
||||
当合思官方开放平台上线新接口或调整文档时,运行同步命令:
|
||||
|
||||
```bash
|
||||
hose-use docs sync
|
||||
```
|
||||
该命令会自动从 `https://docs.ekuaibao.com/search-index.json` 拉取最新全量索引,并自动更新本地 SQLite 缓存与静态存储。
|
||||
|
||||
---
|
||||
|
||||
## 接口调研与售前方案编写标准 SOP (Agent Playbook)
|
||||
|
||||
当客户提出“我们需要做一个第三方系统(如预算系统、HRM、CRM、ERP)与合思的集成方案”时,Agent 必须遵循以下工作流:
|
||||
|
||||
1. **第一步:摸底业务分类**
|
||||
执行 `hose-use docs categories`,识别目标业务在合思体系中的归属分类(例如预算归属于“预算”,部门人员归属于“企业组织架构/员工档案”,单据归属于“单据”)。
|
||||
2. **第二步:拉取端点清单**
|
||||
执行 `hose-use docs search <核心词> --category=<分类> --json`,获取该业务领域全量推荐端点,并注意过滤掉标注为 `历史版本(不推荐)` 的废弃接口。
|
||||
3. **第三步:获取主力端点规格**
|
||||
对筛选出的 2~3 个主力接口(如主数据批量更新、单据提交、状态回调),执行 `hose-use docs show <Path> --json` 获取精确的字段层级、类型与约束。
|
||||
4. **第四步:产出方案**
|
||||
基于官方规范提炼出系统对接模式(定时下发 vs 实时回调)、字段映射表、版本控制机制与并发防踩坑建议。整个过程完全通过 CLI 命令自闭环,高效且精确。
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
getEnterprisesDirCandidates,
|
||||
} from "../../core/config/loader.js";
|
||||
import { ApprovalRepository } from "../../domains/approval/index.js";
|
||||
import { getDocsCatalog } from "../../domains/docs/tools.js";
|
||||
import { VERSION } from "../../version.js";
|
||||
import { formatExpiresAt, formatSourceLabel, formatCorpEnvLabel, printJson } from "../printer.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
|
||||
@@ -53,6 +54,18 @@ export async function handleContextCommand(
|
||||
// 容错处理(如 SQLite 尚未初始化等场景)
|
||||
}
|
||||
|
||||
let docsStats = { totalDocs: 0, totalEndpoints: 0, ready: false };
|
||||
try {
|
||||
const catalog = await getDocsCatalog();
|
||||
docsStats = {
|
||||
totalDocs: catalog.totalDocs,
|
||||
totalEndpoints: catalog.totalEndpoints,
|
||||
ready: true,
|
||||
};
|
||||
} catch {
|
||||
// 容错处理
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
const validCorps = allCorps.filter((c) => c.persistent || !c.expiresAt || c.expiresAt > now);
|
||||
const expiredCorps = allCorps.filter((c) => !c.persistent && c.expiresAt && c.expiresAt <= now);
|
||||
@@ -114,6 +127,7 @@ export async function handleContextCommand(
|
||||
pendingRunsCount,
|
||||
totalRunsCount,
|
||||
},
|
||||
docsCatalog: docsStats,
|
||||
runtime: {
|
||||
mode: isStateful ? "stateful" : "stateless",
|
||||
configFile,
|
||||
@@ -152,6 +166,7 @@ export async function handleContextCommand(
|
||||
` 凭证有效状态 : ${currentCorp ? formatExpiresAt(corpExpiresAt, currentPersistent, hasOpenApiPersistentCredentials(currentCorp) ? "openapi" : currentCorp.source) : "-"}`,
|
||||
` 主站 BaseURL : ${currentCorp?.baseUrl || "-"}`,
|
||||
` 已配置企业总数: ${allCorps.length} 家 (🏭 正式: ${prodCount} 家, 🧪 测试: ${testCount} 家, 🎪 演示: ${demoCount} 家)`,
|
||||
` 开放平台接口库: ${docsStats.ready ? `已就绪 (${docsStats.totalDocs} 篇文档 / ${docsStats.totalEndpoints} 个端点,可用 hose-use docs search 检索)` : "未就绪"}`,
|
||||
` AI PRO 规约库 : ${scopesStr}`,
|
||||
` AI PRO 待决断 : ${pendingRunsCount} 个待决断会话 (当前企业历史总会话: ${totalRunsCount} 个)`,
|
||||
` 运行模式设置 : ${isStateful ? "有状态模式 (Stateful - 自动记忆当前企业)" : "无状态模式 (Stateless)"}`,
|
||||
@@ -160,6 +175,7 @@ export async function handleContextCommand(
|
||||
"",
|
||||
"提示:",
|
||||
" - hose-use 与 hose-aipro 默认共享同一套企业与身份凭证上下文,无须重复配置。",
|
||||
" - 调研合思开放接口与参数规范: hose-use docs search <关键词> 或 hose-use docs show <Path>",
|
||||
" - 切换全局默认企业: hose-use corps switch <企业ID>",
|
||||
" - 单次临时指定企业: hose-use --corp=<企业ID> <命令> 或 hose-aipro --corp=<企业ID> <子命令>",
|
||||
" - AI PRO 专属上下文: hose-aipro status",
|
||||
|
||||
@@ -49,6 +49,8 @@ describe("embedded-skill - 双 Skill 体系内嵌与分发 (hose-use 与 hose-ai
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/store.md"]).toContain("hose-use keys");
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/assist-platform.md"]).toBeDefined();
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/assist-platform.md"]).toContain("assist-platform");
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/docs.md"]).toBeDefined();
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["references/docs.md"]).toContain("hose-use docs");
|
||||
|
||||
// 套件结构:根入口路由到 multi/ 下的子技能
|
||||
expect(EMBEDDED_HOSE_USE_SKILL_FILES["SKILL.md"]).toContain("multi/ekuaibao-mvel/SKILL.md");
|
||||
@@ -78,12 +80,13 @@ describe("embedded-skill - 双 Skill 体系内嵌与分发 (hose-use 与 hose-ai
|
||||
try {
|
||||
const res = installHoseUseSkillFiles(tmp);
|
||||
expect(res.targetDir).toBe(tmp);
|
||||
expect(res.files.length).toBe(18);
|
||||
expect(res.files.length).toBe(19);
|
||||
expect(existsSync(join(tmp, "SKILL.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "agents", "openai.yaml"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "auth.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "bill.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "contact.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "docs.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "feetype.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "role.md"))).toBe(true);
|
||||
expect(existsSync(join(tmp, "references", "workflow.md"))).toBe(true);
|
||||
|
||||
@@ -17,6 +17,7 @@ import refRole from "../../skills/hose-use/references/role.md" with { type: "tex
|
||||
import refFeeType from "../../skills/hose-use/references/feetype.md" with { type: "text" };
|
||||
import refStore from "../../skills/hose-use/references/store.md" with { type: "text" };
|
||||
import refAssistPlatform from "../../skills/hose-use/references/assist-platform.md" with { type: "text" };
|
||||
import refDocs from "../../skills/hose-use/references/docs.md" with { type: "text" };
|
||||
import multiMvel from "../../skills/hose-use/multi/ekuaibao-mvel/SKILL.md" with { type: "text" };
|
||||
import multiMvelAgent from "../../skills/hose-use/multi/ekuaibao-mvel/agents/openai.yaml" with { type: "text" };
|
||||
import multiNodes from "../../skills/hose-use/multi/ekuaibao-nodes/SKILL.md" with { type: "text" };
|
||||
@@ -44,6 +45,7 @@ export const EMBEDDED_HOSE_USE_SKILL_FILES: Record<string, string> = {
|
||||
"references/service.md": refService,
|
||||
"references/store.md": refStore,
|
||||
"references/assist-platform.md": refAssistPlatform,
|
||||
"references/docs.md": refDocs,
|
||||
"multi/ekuaibao-mvel/SKILL.md": multiMvel,
|
||||
"multi/ekuaibao-mvel/agents/openai.yaml": multiMvelAgent,
|
||||
"multi/ekuaibao-nodes/SKILL.md": multiNodes,
|
||||
|
||||
Reference in new issue
Block a user