Merge pull request #47 from yunyingk/fix/update-download-timeout
🚀 Release / 🚀 Build & Publish Multi-Platform Binaries (push) Has been cancelled
🚀 Release / 🚀 Build & Publish Multi-Platform Binaries (push) Has been cancelled
feat(aipro): approval lifecycle, gateway guardrails, update timeouts, and bump to v0.7.2
This commit is contained in:
47 files changed
+1512
-349
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hose-use",
|
||||
"version": "0.7.1",
|
||||
"version": "0.7.2",
|
||||
"description": "合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号登录、企业租户切换、单据明细检索、工作流管理、内置 HTTP 服务与常驻守护进程。",
|
||||
"author": {
|
||||
"name": "yingqing"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
合思/易快报(ekuaibao)企业费控与平台自建应用的高性能 CLI 命令行工具与底层 SDK(兼具轻量 MCP 适配能力):
|
||||
|
||||
- **CLI 工具 (`hose-use` / `hose`)**:面向运维/实施/开发者的高性能交互与自动化命令行
|
||||
- **CLI 工具 (`hose-use` / `hose-aipro`)**:面向运维/实施/开发者的高性能交互与自动化命令行
|
||||
- **底层 SDK (`src/domains/` & `src/core/`)**:纯函数式、零 UI 绑定的业务 API 与换票能力
|
||||
- **MCP Server (`src/server.ts`)**:精简核心适配器(保留核心切换与扫描能力)
|
||||
- **Agent Skill (`skills/hose-use`)**:内嵌 AI 智能体技能标准定义(支持 `hose-use skill install` 一键分发)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# hose-use (v0.7.1)
|
||||
# hose-use (v0.7.2)
|
||||
|
||||
合思/易快报(ekuaibao)企业级 CLI 命令行工具与底层 SDK。
|
||||
|
||||
@@ -92,7 +92,7 @@ hose-use mcp # 启动 MCP Server (默认暴露
|
||||
|
||||
```text
|
||||
src/
|
||||
├── cli.ts # CLI 入口 (bin: hose)
|
||||
├── cli.ts # CLI 入口 (bin: hose-use, hose-aipro)
|
||||
├── cli/ # CLI 核心引擎 (runner, parser, printer, commands)
|
||||
├── core/ # 基础设施与底层 SDK
|
||||
│ ├── auth/ # 认证与换票 (RSA 账密, TokenStore, AccountStore)
|
||||
|
||||
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
||||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "hose-use API & MCP Tools Specification",
|
||||
"version": "0.7.1",
|
||||
"version": "0.7.2",
|
||||
"description": "Unified Enterprise SaaS API, CLI, and MCP Specification for Ekuaibao (合思/易快报), EASO, and Piper Workflows."
|
||||
},
|
||||
"servers": [
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
openapi: 3.1.0
|
||||
info:
|
||||
title: hose-use API & MCP Tools Specification
|
||||
version: 0.7.1
|
||||
version: 0.7.2
|
||||
description: >-
|
||||
Unified Enterprise SaaS API, CLI, and MCP Specification for Ekuaibao (合思/易快报), EASO, and Piper Workflows.
|
||||
servers:
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hose-use",
|
||||
"version": "0.7.1",
|
||||
"version": "0.7.2",
|
||||
"module": "src/server.ts",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
||||
+1
-2
@@ -152,9 +152,8 @@ fi
|
||||
chmod +x "$TMP_FILE"
|
||||
mv "$TMP_FILE" "$TARGET_PATH"
|
||||
|
||||
# Create command aliases pointing at the same single binary.
|
||||
# Create hose-aipro multicall alias pointing at the single binary.
|
||||
if [ -w "$TARGET_DIR" ]; then
|
||||
ln -sf "$TARGET_PATH" "${TARGET_DIR}/hose" 2>/dev/null || true
|
||||
ln -sf "$TARGET_PATH" "${TARGET_DIR}/hose-aipro" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
|
||||
+81
-81
@@ -1,12 +1,12 @@
|
||||
---
|
||||
name: hose-use
|
||||
description: "v0.7.1: 合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号 API 登录、租户切换、单据检索与审批动作、工作流跨域扫描、内置 HTTP 交互文档与常驻守护进程。"
|
||||
description: "v0.7.2: 合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号 API 登录、租户切换、单据检索与审批动作、工作流跨域扫描、内置 HTTP 交互文档与常驻守护进程。"
|
||||
metadata:
|
||||
version: 0.7.1
|
||||
short-description: 合思/易快报企业级 CLI 工具与底层 SDK (v0.7.1)
|
||||
version: 0.7.2
|
||||
short-description: 合思/易快报企业级 CLI 工具与底层 SDK (v0.7.2)
|
||||
---
|
||||
|
||||
# hose-use (v0.7.1)
|
||||
# hose-use (v0.7.2)
|
||||
|
||||
在具备 MCP 的 AI 智能体环境中,**优先使用 `hose_cli` 单工具网关**,传入 `command: string` 执行;在终端或自动化脚本中,直接调用全局 `hose` 或 `hose-use` 命令行。
|
||||
本 Skill 是智能体的路由分发层:保持主文档简明,遇到复杂业务时深入查阅对应的专属参考文档(`references/*.md`)。
|
||||
@@ -16,7 +16,7 @@ metadata:
|
||||
## Agent 执行原则 (First Rules)
|
||||
|
||||
1. **通道自适应**:将 CLI/MCP 视为 Agent 的执行通道,而不是要求用户学习命令行。Agent 应主动将用户的自然语言诉求转换为具体的 CLI 命令;严禁要求用户手动拼装命令行参数。
|
||||
2. **多租户优先探查**:在需要企业参数前,优先执行 `hose corps list`。如果目标企业已配置,通过企业名称映射出对应的 `id` 并作为 `--corp=<id>` 传入;不要向普通用户询问底层 `corpId`。
|
||||
2. **多租户优先探查**:在需要企业参数前,优先执行 `hose-use corps list`。如果目标企业已配置,通过企业名称映射出对应的 `id` 并作为 `--corp=<id>` 传入;不要向普通用户询问底层 `corpId`。
|
||||
3. **输出防护与大报文处理**:
|
||||
- 面对单据明细、实体字典、工作流等大数据量查询,优先使用 `--json -o <path>` 本地转储或使用 `--limit` 限制分页;
|
||||
- 严禁盲目使用 `--full` 将上万行原始报文一次性塞入上下文;
|
||||
@@ -29,36 +29,36 @@ metadata:
|
||||
|
||||
| 用户意图 / 场景 | 推荐命令 | 深入参考文档 |
|
||||
|---|---|---|
|
||||
| 首次登录 / 账密认证 / Token过期 / 多账号 | `hose auth login`, `hose auth status`, `hose auth refresh` | [references/auth.md](references/auth.md) |
|
||||
| 代客协助凭证导入 / 探针连通性诊断 | `hose auth import`, `hose probe` | [references/auth.md](references/auth.md) |
|
||||
| 企业租户切换 / 查看当前企业 | `hose corps list`, `hose corps switch <id>` | [references/auth.md](references/auth.md) |
|
||||
| 报销单据检索 / 费用明细下钻 / 中文字典 | `hose bill list`, `hose bill get <单号|ID> [--risk]` | [references/bill.md](references/bill.md) |
|
||||
| 单据审批动作(同意/驳回/转交/加签/评论) | `hose bill approve|reject|transfer|add-node|comment <单号|ID> --yes` | [references/bill.md](references/bill.md) |
|
||||
| 单据审批历史 / 当前节点 / 后续流程 | `hose bill flow <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据风控预警 / 预算状态 / 发票风险 | `hose bill risk <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据引用 ID 二级解析(人员/部门/费用类型) | `hose bill refs <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据关联关系 / 冲借款与前置申请追溯 | `hose bill relations <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据预算状态 / 超预算与占用信息 | `hose bill budget <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据附件 / 发票原件标准列表 | `hose bill attachments <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据附件下载 | `hose bill download <单号|ID> --output-dir <目录>` | [references/bill.md](references/bill.md) |
|
||||
| 系统/自定义档案维度与档案项 | `hose dimension list`, `hose dimension items <维度>` | [references/dimension.md](references/dimension.md) |
|
||||
| 企业角色、角色组与角色成员 | `hose role list`, `hose role groups`, `hose role members <角色>` | [references/role.md](references/role.md) |
|
||||
| 角色权限只读快照 | `hose permission get` | [references/role.md](references/role.md) |
|
||||
| 单据 Web 详情直达链接生成 | `hose bill link <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据实体模型与字段元数据查询 | `hose bill schema` | [references/bill.md](references/bill.md) |
|
||||
| 企业通讯录检索 / 员工档案 / 防爆保护 | `hose contact search`, `hose contact list`, `hose contact get` | [references/contact.md](references/contact.md) |
|
||||
| 待办中心 / 已审批 / 我发起的 / 审批记录 / 抄送 | `hose task todo`, `hose task submitted`, `hose task records`, `hose task cc` | [references/task.md](references/task.md) |
|
||||
| 消息中心 / 未读统计 / 标记已读 / 类型过滤 | `hose message list [--all]`, `hose message count`, `hose message read` | [references/message.md](references/message.md) |
|
||||
| 跨自建应用工作流聚合检索 | `hose workflow list`, `hose platform list` | [references/workflow.md](references/workflow.md) |
|
||||
| 特定任务节点扫描 (如脚本/Webhook) | `hose workflow find --task=code-js2` | [references/workflow.md](references/workflow.md) |
|
||||
| 工作流详情与开通切换 | `hose workflow get`, `hose workflow toggle` | [references/workflow.md](references/workflow.md) |
|
||||
| 工作流节点树、代码依赖与静态诊断 | `hose workflow analyze <pipelineId>` | [references/workflow.md](references/workflow.md) |
|
||||
| 常驻守护进程管理 / 后台运行 | `hose service start`, `hose service status` | [references/service.md](references/service.md) |
|
||||
| 待办/消息事件轮询与去重 | `hose service poll --corp=<id>` | [references/service.md](references/service.md) |
|
||||
| 启动本地 HTTP 服务 / 打开可视化交互文档 | `hose http --port=8888` (访问 `/docs`) | [references/service.md](references/service.md) |
|
||||
| 首次登录 / 账密认证 / Token过期 / 多账号 | `hose-use auth login`, `hose-use auth status`, `hose-use auth refresh` | [references/auth.md](references/auth.md) |
|
||||
| 代客协助凭证导入 / 探针连通性诊断 | `hose-use auth import`, `hose-use probe` | [references/auth.md](references/auth.md) |
|
||||
| 企业租户切换 / 查看当前企业 | `hose-use corps list`, `hose-use corps switch <id>` | [references/auth.md](references/auth.md) |
|
||||
| 报销单据检索 / 费用明细下钻 / 中文字典 | `hose-use bill list`, `hose-use bill get <单号|ID> [--risk]` | [references/bill.md](references/bill.md) |
|
||||
| 单据审批动作(同意/驳回/转交/加签/评论) | `hose-use bill approve|reject|transfer|add-node|comment <单号|ID> --yes` | [references/bill.md](references/bill.md) |
|
||||
| 单据审批历史 / 当前节点 / 后续流程 | `hose-use bill flow <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据风控预警 / 预算状态 / 发票风险 | `hose-use bill risk <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据引用 ID 二级解析(人员/部门/费用类型) | `hose-use bill refs <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据关联关系 / 冲借款与前置申请追溯 | `hose-use bill relations <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据预算状态 / 超预算与占用信息 | `hose-use bill budget <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据附件 / 发票原件标准列表 | `hose-use bill attachments <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据附件下载 | `hose-use bill download <单号|ID> --output-dir <目录>` | [references/bill.md](references/bill.md) |
|
||||
| 系统/自定义档案维度与档案项 | `hose-use dimension list`, `hose-use dimension items <维度>` | [references/dimension.md](references/dimension.md) |
|
||||
| 企业角色、角色组与角色成员 | `hose-use role list`, `hose-use role groups`, `hose-use role members <角色>` | [references/role.md](references/role.md) |
|
||||
| 角色权限只读快照 | `hose-use permission get` | [references/role.md](references/role.md) |
|
||||
| 单据 Web 详情直达链接生成 | `hose-use bill link <单号|ID>` | [references/bill.md](references/bill.md) |
|
||||
| 单据实体模型与字段元数据查询 | `hose-use bill schema` | [references/bill.md](references/bill.md) |
|
||||
| 企业通讯录检索 / 员工档案 / 防爆保护 | `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 message list [--all]`, `hose-use message count`, `hose-use message read` | [references/message.md](references/message.md) |
|
||||
| 跨自建应用工作流聚合检索 | `hose-use workflow list`, `hose-use platform list` | [references/workflow.md](references/workflow.md) |
|
||||
| 特定任务节点扫描 (如脚本/Webhook) | `hose-use workflow find --task=code-js2` | [references/workflow.md](references/workflow.md) |
|
||||
| 工作流详情与开通切换 | `hose-use workflow get`, `hose-use workflow toggle` | [references/workflow.md](references/workflow.md) |
|
||||
| 工作流节点树、代码依赖与静态诊断 | `hose-use workflow analyze <pipelineId>` | [references/workflow.md](references/workflow.md) |
|
||||
| 常驻守护进程管理 / 后台运行 | `hose-use service start`, `hose-use service status` | [references/service.md](references/service.md) |
|
||||
| 待办/消息事件轮询与去重 | `hose-use service poll --corp=<id>` | [references/service.md](references/service.md) |
|
||||
| 启动本地 HTTP 服务 / 打开可视化交互文档 | `hose-use http --port=8888` (访问 `/docs`) | [references/service.md](references/service.md) |
|
||||
| CLI 同进程执行网关 / REST 接口调用 | `POST /api/cli`, `GET /v1/corps` | [references/service.md](references/service.md) |
|
||||
| 导出标准 OpenAPI 3.1.0 JSON 规范 | `hose openapi`, `hose openapi --raw` | [references/service.md](references/service.md) |
|
||||
| 一键自动自更新 / 查看版本发布日志 | `hose update`, `hose update --changelog` | `hose update --help` |
|
||||
| 导出标准 OpenAPI 3.1.0 JSON 规范 | `hose-use openapi`, `hose-use openapi --raw` | [references/service.md](references/service.md) |
|
||||
| 一键自动自更新 / 查看版本发布日志 | `hose-use update`, `hose-use update --changelog` | `hose-use update --help` |
|
||||
|
||||
---
|
||||
|
||||
@@ -66,63 +66,63 @@ metadata:
|
||||
|
||||
```bash
|
||||
# 1. 认证与企业
|
||||
hose auth login --phone=17718556446 --password=... # 纯 API 账密自动登录
|
||||
hose auth status # 查看 Token 剩余有效期与登录账号
|
||||
hose corps list # 查看企业租户列表
|
||||
hose corps switch ID01MCcOgJl1td # 切换工作企业
|
||||
hose probe # 诊断当前企业接口连通性
|
||||
hose-use auth login --phone=17718556446 --password=... # 纯 API 账密自动登录
|
||||
hose-use auth status # 查看 Token 剩余有效期与登录账号
|
||||
hose-use corps list # 查看企业租户列表
|
||||
hose-use corps switch ID01MCcOgJl1td # 切换工作企业
|
||||
hose-use probe # 诊断当前企业接口连通性
|
||||
|
||||
# 2. 企业通讯录与人员 (默认严格防爆限流,优先 search)
|
||||
hose contact search 王硕 # 模糊搜索员工工号、邮箱与电话
|
||||
hose contact list --limit=20 # 采样查看企业通讯录(带防爆截断保护)
|
||||
hose contact list --json -o /tmp/staffs.json # 导出全量通讯录至本地磁盘并防爆
|
||||
hose contact get ID01MCcOgJl1td:3LsanKdS7Uo000 # 精准获取指定员工档案
|
||||
hose-use contact search 王硕 # 模糊搜索员工工号、邮箱与电话
|
||||
hose-use contact list --limit=20 # 采样查看企业通讯录(带防爆截断保护)
|
||||
hose-use contact list --json -o /tmp/staffs.json # 导出全量通讯录至本地磁盘并防爆
|
||||
hose-use contact get ID01MCcOgJl1td:3LsanKdS7Uo000 # 精准获取指定员工档案
|
||||
|
||||
# 3. 单据与费用
|
||||
hose bill list # 查看最新单据与报销记录
|
||||
hose bill link CL20260901001 # 生成官方 Web 详情直达免密跳转链接
|
||||
hose bill list --json -o /tmp/bills.json # 导出全量单据报文至本地磁盘
|
||||
hose bill get n0GMIM0dkQmKbS # 精准查询单据详情 (中文字段映射)
|
||||
hose bill get S26000001 --risk # 在详情中附加费控风控与发票风险快照
|
||||
hose bill approve S26000001 --yes # 同意当前待办
|
||||
hose bill reject S26000001 --comment "金额不符" --yes # 驳回并写明原因
|
||||
hose bill transfer S26000001 --approver-id 111 --yes # 转交给工号/员工 ID/唯一姓名
|
||||
hose bill add-node S26000001 --approver-id 111 --mode pre --yes # 前加签;--mode post 为后加签
|
||||
hose bill comment S26000001 --comment "请补充发票" --yes # 追加单据评论
|
||||
hose bill refs S26000001 # 解析提交人、归属人、部门、法人实体与费用类型
|
||||
hose bill relations S26000001 # 追溯冲借款、事前申请和合同关联
|
||||
hose bill budget S26000001 # 查看单据预算超限和预算接口状态
|
||||
hose bill attachments S26000001 # 查看附件和发票原件列表
|
||||
hose bill download S26000001 --output-dir ./downloads # 下载附件到本地目录
|
||||
hose dimension list # 查看系统与自定义档案维度
|
||||
hose dimension items 项目 # 查看项目、成本中心等档案项
|
||||
hose role list # 查看企业角色定义
|
||||
hose role groups # 查看角色组及其角色
|
||||
hose role members 财务主管 # 查看指定角色成员
|
||||
hose permission get # 查看角色权限开关(只读)
|
||||
hose bill schema # 查询单据实体元数据字典
|
||||
hose-use bill list # 查看最新单据与报销记录
|
||||
hose-use bill link CL20260901001 # 生成官方 Web 详情直达免密跳转链接
|
||||
hose-use bill list --json -o /tmp/bills.json # 导出全量单据报文至本地磁盘
|
||||
hose-use bill get n0GMIM0dkQmKbS # 精准查询单据详情 (中文字段映射)
|
||||
hose-use bill get S26000001 --risk # 在详情中附加费控风控与发票风险快照
|
||||
hose-use bill approve S26000001 --yes # 同意当前待办
|
||||
hose-use bill reject S26000001 --comment "金额不符" --yes # 驳回并写明原因
|
||||
hose-use bill transfer S26000001 --approver-id 111 --yes # 转交给工号/员工 ID/唯一姓名
|
||||
hose-use bill add-node S26000001 --approver-id 111 --mode pre --yes # 前加签;--mode post 为后加签
|
||||
hose-use bill comment S26000001 --comment "请补充发票" --yes # 追加单据评论
|
||||
hose-use bill refs S26000001 # 解析提交人、归属人、部门、法人实体与费用类型
|
||||
hose-use bill relations S26000001 # 追溯冲借款、事前申请和合同关联
|
||||
hose-use bill budget S26000001 # 查看单据预算超限和预算接口状态
|
||||
hose-use bill attachments S26000001 # 查看附件和发票原件列表
|
||||
hose-use bill download S26000001 --output-dir ./downloads # 下载附件到本地目录
|
||||
hose-use dimension list # 查看系统与自定义档案维度
|
||||
hose-use dimension items 项目 # 查看项目、成本中心等档案项
|
||||
hose-use role list # 查看企业角色定义
|
||||
hose-use role groups # 查看角色组及其角色
|
||||
hose-use role members 财务主管 # 查看指定角色成员
|
||||
hose-use permission get # 查看角色权限开关(只读)
|
||||
hose-use bill schema # 查询单据实体元数据字典
|
||||
|
||||
# 4. 待办与消息
|
||||
hose task submitted # 查看我发起的单据
|
||||
hose message list --unread # 查看未读消息
|
||||
hose message list --all # 合并查看已读和未读消息
|
||||
hose message count # 查看未读数量
|
||||
hose message read <messageId> # 标记单条消息已读
|
||||
hose-use task submitted # 查看我发起的单据
|
||||
hose-use message list --unread # 查看未读消息
|
||||
hose-use message list --all # 合并查看已读和未读消息
|
||||
hose-use message count # 查看未读数量
|
||||
hose-use message read <messageId> # 标记单条消息已读
|
||||
|
||||
# 5. 自建应用与工作流
|
||||
hose platform list # 查看自建应用列表
|
||||
hose workflow list # 聚合扫描全部应用下的工作流
|
||||
hose workflow find --task=code-js2 # 查找部署了代码节点的工作流
|
||||
hose workflow get wf_01k83y... # 查看指定工作流节点拓扑
|
||||
hose workflow analyze wf_01k83y... --json # 输出节点树、引用依赖与静态诊断
|
||||
hose-use platform list # 查看自建应用列表
|
||||
hose-use workflow list # 聚合扫描全部应用下的工作流
|
||||
hose-use workflow find --task=code-js2 # 查找部署了代码节点的工作流
|
||||
hose-use workflow get wf_01k83y... # 查看指定工作流节点拓扑
|
||||
hose-use workflow analyze wf_01k83y... --json # 输出节点树、引用依赖与静态诊断
|
||||
|
||||
# 6. 服务与守护进程
|
||||
hose http --port=8888 # 启动前台 HTTP 服务与交互式文档
|
||||
hose service start # 后台启动常驻守护进程服务
|
||||
hose service status # 查看常驻守护进程运行状态与端点
|
||||
hose service poll --corp=ID01ofWoOC1wiX --json # 轮询待办/消息并去重落盘
|
||||
hose service logs # 查看常驻守护进程日志
|
||||
hose service stop # 停止后台常驻守护进程
|
||||
hose-use http --port=8888 # 启动前台 HTTP 服务与交互式文档
|
||||
hose-use service start # 后台启动常驻守护进程服务
|
||||
hose-use service status # 查看常驻守护进程运行状态与端点
|
||||
hose-use service poll --corp=ID01ofWoOC1wiX --json # 轮询待办/消息并去重落盘
|
||||
hose-use service logs # 查看常驻守护进程日志
|
||||
hose-use service stop # 停止后台常驻守护进程
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -41,8 +41,8 @@ hose-use bill flow CL20260903001
|
||||
在详情中附加风控与合规快照时加 `--risk`。该选项会沿用审批详情页的风控、预算和发票风险接口,并在 JSON 的每个单据项中增加 `risk` 字段:
|
||||
|
||||
```bash
|
||||
hose bill get S26000001 --risk
|
||||
hose bill get S26000001 --risk --json
|
||||
hose-use bill get S26000001 --risk
|
||||
hose-use bill get S26000001 --risk --json
|
||||
```
|
||||
|
||||
### 中文字段智能映射字典
|
||||
@@ -74,19 +74,19 @@ hose-use bill risk CL20260903001
|
||||
|
||||
```bash
|
||||
# 同意:可附带纯文本审批意见
|
||||
hose bill approve S26000001 --comment "同意" --yes
|
||||
hose-use bill approve S26000001 --comment "同意" --yes
|
||||
|
||||
# 驳回:原因是必填项;默认退回提交人,可用 --reject-to 指定目标
|
||||
hose bill reject S26000001 --comment "请补充发票" --yes
|
||||
hose-use bill reject S26000001 --comment "请补充发票" --yes
|
||||
|
||||
# 转交:--approver-id 支持完整员工 ID、工号或唯一姓名
|
||||
hose bill transfer S26000001 --approver-id 111 --yes
|
||||
hose-use bill transfer S26000001 --approver-id 111 --yes
|
||||
|
||||
# 加签:默认前加签,--mode post 表示后加签
|
||||
hose bill add-node S26000001 --approver-id 111 --mode pre --comment "请协助复核" --yes
|
||||
hose-use bill add-node S26000001 --approver-id 111 --mode pre --comment "请协助复核" --yes
|
||||
|
||||
# 评论:支持 --participants 传入逗号分隔的人员 ID
|
||||
hose bill comment S26000001 --comment "补充说明" --participants <staffId> --yes
|
||||
hose-use bill comment S26000001 --comment "补充说明" --participants <staffId> --yes
|
||||
```
|
||||
|
||||
动作解析流程会先通过审批 backlog 详情定位 `backlogId`、`flowId` 和当前节点 ID;当响应包含 `flow.actions` 时,会校验当前登录员工是否拥有对应的 `freeflow.*` 动作。底层请求对应:`freeflow.agree`、`freeflow.reject`、`freeflow.addnode` 和 `freeflow.comment`。
|
||||
@@ -96,8 +96,8 @@ hose bill comment S26000001 --comment "补充说明" --participants <staffId> --
|
||||
读取审批详情并联动组织架构、部门树和费用类型目录,将底层 ID 转为姓名、工号、部门全路径或费用类型名称,同时保留原始 ID:
|
||||
|
||||
```bash
|
||||
hose bill refs S26000001
|
||||
hose bill refs S26000001 --json
|
||||
hose-use bill refs S26000001
|
||||
hose-use bill refs S26000001 --json
|
||||
```
|
||||
|
||||
JSON 输出包含 `submitter`、`owner`、`department`、`legalEntity`、`feeTypes`、`dimensions` 和 `unresolved`。单据里出现法人实体、项目或成本中心 ID 时,会联动 `dimension` 目录补充名称与编码;目录在当前进程内按企业缓存 10 分钟。
|
||||
@@ -107,8 +107,8 @@ JSON 输出包含 `submitter`、`owner`、`department`、`legalEntity`、`feeTyp
|
||||
从审批详情中的冲借款、前置申请、合同和费用关联字段抽取关系树:
|
||||
|
||||
```bash
|
||||
hose bill relations S26000001
|
||||
hose bill relations S26000001 --json
|
||||
hose-use bill relations S26000001
|
||||
hose-use bill relations S26000001 --json
|
||||
```
|
||||
|
||||
表格模式按树形缩进显示关联 ID、单号、标题和金额;JSON 模式保留每个节点的原始字段,便于继续下钻。
|
||||
@@ -118,8 +118,8 @@ hose bill relations S26000001 --json
|
||||
读取审批页使用的预算状态接口,查看单据是否超预算及接口返回的可用/占用金额字段:
|
||||
|
||||
```bash
|
||||
hose bill budget S26000001
|
||||
hose bill budget S26000001 --json
|
||||
hose-use bill budget S26000001
|
||||
hose-use bill budget S26000001 --json
|
||||
```
|
||||
|
||||
### 单据附件列表 (`bill attachments`)
|
||||
@@ -127,15 +127,15 @@ hose bill budget S26000001 --json
|
||||
从审批详情中递归提取普通附件与发票原件的文件名、`fileId`、`key`、URL 和来源字段,并通过附件文件服务补齐可下载地址:
|
||||
|
||||
```bash
|
||||
hose bill attachments S26000001
|
||||
hose bill attachments S26000001 --json
|
||||
hose-use bill attachments S26000001
|
||||
hose-use bill attachments S26000001 --json
|
||||
```
|
||||
|
||||
需要落盘时使用 `bill download`。命令会创建目标目录、清理文件名中的路径字符,并返回本地路径和字节数;指定 `--file-id` 可只下载一个附件:
|
||||
|
||||
```bash
|
||||
hose bill download S26000001 --output-dir ./downloads
|
||||
hose bill download S26000001 --file-id ID01THIU98FNyT --output-dir ./downloads --json
|
||||
hose-use bill download S26000001 --output-dir ./downloads
|
||||
hose-use bill download S26000001 --file-id ID01THIU98FNyT --output-dir ./downloads --json
|
||||
```
|
||||
|
||||
## 5. 单据实体元数据字典 (`bill schema`)
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
企业通讯录往往包含上千乃至上万名员工。**无节制全量拉取会瞬间冲垮 Agent 上下文,导致会话熔断或崩溃。**
|
||||
|
||||
因此,`hose-use` 遵循以下防爆安全原则:
|
||||
1. **搜索优先 (Search First)**:优先使用 `hose contact search <关键词>` 进行局部模糊匹配(仅返回 1~5 条命中结果);
|
||||
2. **列表默认限流截断 (Default Limit 20)**:`hose contact list` 默认截断只输出前 20 条,并打印总人数统计和精准检索指引;
|
||||
1. **搜索优先 (Search First)**:优先使用 `hose-use contact search <关键词>` 进行局部模糊匹配(仅返回 1~5 条命中结果);
|
||||
2. **列表默认限流截断 (Default Limit 20)**:`hose-use contact list` 默认截断只输出前 20 条,并打印总人数统计和精准检索指引;
|
||||
3. **大报文转储落地 (`-o / --output-file`)**:若需全量导出通讯录供复杂分析,使用 `-o` 将全量人员安全落盘到磁盘,仅向 Agent 回传精简的文件路径元数据;
|
||||
4. **全量放行保护 (`--full`)**:仅在确定企业体量较小或明确需要全量时方可显式加上 `--full`。
|
||||
|
||||
@@ -20,22 +20,22 @@
|
||||
|
||||
```bash
|
||||
# 1. 模糊搜索人员 (支持姓名、邮箱、手机号、staffId)
|
||||
hose contact search 王硕
|
||||
hose contact search xiezihao@hosecloud.com
|
||||
hose contact search 18600612659
|
||||
hose-use contact search 王硕
|
||||
hose-use contact search xiezihao@hosecloud.com
|
||||
hose-use contact search 18600612659
|
||||
|
||||
# 2. 采样查看企业通讯录 (默认截断前 20 条,防上下文溢出)
|
||||
hose contact list
|
||||
hose contact list --limit=50
|
||||
hose-use contact list
|
||||
hose-use contact list --limit=50
|
||||
|
||||
# 3. 大报文安全落地到磁盘 (返回精简文件元数据,保护 LLM 终端)
|
||||
hose contact list --json -o /tmp/all_staffs.json
|
||||
hose-use contact list --json -o /tmp/all_staffs.json
|
||||
|
||||
# 4. 精确下钻查看指定人员详细档案
|
||||
hose contact get ID01MCcOgJl1td:3LsanKdS7Uo000
|
||||
hose-use contact get ID01MCcOgJl1td:3LsanKdS7Uo000
|
||||
|
||||
# 5. 指定特定企业租户检索
|
||||
hose contact search 李 --corp=ID01MCcOgJl1td
|
||||
hose-use contact search 李 --corp=ID01MCcOgJl1td
|
||||
```
|
||||
|
||||
---
|
||||
@@ -60,6 +60,6 @@ hose contact search 李 --corp=ID01MCcOgJl1td
|
||||
|
||||
### 1. 查找某人发起的单据
|
||||
当用户要求“帮我查一下王硕提交的报销单”时:
|
||||
1. 先通过 `hose contact search 王硕` 获取其 `staffId`(如 `ID01MCcOgJl1td:3LsanKdS7Uo000`);
|
||||
2. 再通过 `hose bill list --keyword=王硕` 或根据 `staffId` 过滤单据明细;
|
||||
3. 获得单据后,通过 `hose bill link <单号>` 生成官方 Web 直达链接反馈给用户。
|
||||
1. 先通过 `hose-use contact search 王硕` 获取其 `staffId`(如 `ID01MCcOgJl1td:3LsanKdS7Uo000`);
|
||||
2. 再通过 `hose-use bill list --keyword=王硕` 或根据 `staffId` 过滤单据明细;
|
||||
3. 获得单据后,通过 `hose-use bill link <单号>` 生成官方 Web 直达链接反馈给用户。
|
||||
@@ -4,12 +4,12 @@
|
||||
|
||||
```bash
|
||||
# 查看系统/自定义档案维度目录
|
||||
hose dimension list
|
||||
hose dimension list --keyword=项目
|
||||
hose-use dimension list
|
||||
hose-use dimension list --keyword=项目
|
||||
|
||||
# 查看某个维度的档案项(支持维度 ID、编码或名称)
|
||||
hose dimension items 项目
|
||||
hose dimension items DA001 --json
|
||||
hose-use dimension items 项目
|
||||
hose-use dimension items DA001 --json
|
||||
```
|
||||
|
||||
目录来源于 `/api/v1/basedata/dimensions/active`,档案项来源于 `/api/v1/basedata/dimensionItems/$<dimensionId>`。结果在同一进程内按企业缓存 10 分钟,JSON 会保留底层 ID、编码、父项 ID 和表单字段。
|
||||
@@ -3,13 +3,13 @@
|
||||
消息中心是 CLI-only 能力,不新增 MCP tool。命令默认查询未读消息。
|
||||
|
||||
```bash
|
||||
hose message list --unread
|
||||
hose message list --read
|
||||
hose message list --all
|
||||
hose message list --type=Approve
|
||||
hose message count
|
||||
hose message read <messageId>
|
||||
hose message read-all
|
||||
hose-use message list --unread
|
||||
hose-use message list --read
|
||||
hose-use message list --all
|
||||
hose-use message list --type=Approve
|
||||
hose-use message count
|
||||
hose-use message read <messageId>
|
||||
hose-use message read-all
|
||||
```
|
||||
|
||||
`message list --json` 返回消息 ID、标题、内容、消息类型、已读状态和原始字段;`--all` 会并行拉取已读与未读页面并去重后按时间排序;`--type` 在 CLI 层按 `messageType`、`msgType`、`msgTypeName` 或 `msgName` 做兼容过滤。`message read-all` 会分页读取全部未读消息再逐条标记,避免只处理首 100 条。
|
||||
@@ -3,11 +3,11 @@
|
||||
角色页对应的只读 CLI:
|
||||
|
||||
```bash
|
||||
hose role list
|
||||
hose role list --keyword=财务
|
||||
hose role groups
|
||||
hose role members 财务主管
|
||||
hose role members CODE15 --json
|
||||
hose-use role list
|
||||
hose-use role list --keyword=财务
|
||||
hose-use role groups
|
||||
hose-use role members 财务主管
|
||||
hose-use role members CODE15 --json
|
||||
```
|
||||
|
||||
接口来自系统配置 → 角色页面:角色定义列表、角色组及指定角色成员。成员查询支持角色 ID、编码或名称。
|
||||
@@ -15,6 +15,6 @@ hose role members CODE15 --json
|
||||
权限页的角色权限快照:
|
||||
|
||||
```bash
|
||||
hose permission get
|
||||
hose permission get --json
|
||||
hose-use permission get
|
||||
hose-use permission get --json
|
||||
```
|
||||
@@ -3,15 +3,15 @@
|
||||
## CLI
|
||||
|
||||
```bash
|
||||
hose task todo # 待我审批
|
||||
hose task approved # 我已审批
|
||||
hose task records # 审批记录
|
||||
hose task submitted # 我发起的单据
|
||||
hose task cc --unread # 未读抄送
|
||||
hose task cc --read # 已读抄送
|
||||
hose task todo --staff <员工工号或ID> # 在当前页结果中按人员过滤
|
||||
hose task todo --json --count 50
|
||||
hose task records --from 2026-01-01 --to 2026-09-05
|
||||
hose-use task todo # 待我审批
|
||||
hose-use task approved # 我已审批
|
||||
hose-use task records # 审批记录
|
||||
hose-use task submitted # 我发起的单据
|
||||
hose-use task cc --unread # 未读抄送
|
||||
hose-use task cc --read # 已读抄送
|
||||
hose-use task todo --staff <员工工号或ID> # 在当前页结果中按人员过滤
|
||||
hose-use task todo --json --count 50
|
||||
hose-use task records --from 2026-01-01 --to 2026-09-05
|
||||
```
|
||||
|
||||
任务结果包含任务 ID、流程 ID、单号、标题、单据模板、提交人、金额、状态、当前节点和可用动作。分页使用 `--start` 与 `--count`。
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
||||
import { runAiProCli } from "./aipro-cli.js";
|
||||
import { closeApprovalDatabase, getApprovalDatabase } from "./domains/approval/db.js";
|
||||
import { ApprovalRepository } from "./domains/approval/repository.js";
|
||||
|
||||
describe("CLI - hose-aipro 审批流与网关阻拦全链路测试", () => {
|
||||
beforeEach(() => {
|
||||
process.env.HOSE_APPROVAL_DB = ":memory:";
|
||||
const db = getApprovalDatabase(":memory:");
|
||||
const repo = new ApprovalRepository(db);
|
||||
|
||||
// 预置规约规则
|
||||
repo.createRule({
|
||||
scope: "差旅报销",
|
||||
body: "差旅报销时,[必须上传真实发票]{硬性},[建议填写详细事由]{建议}。",
|
||||
});
|
||||
repo.createRule({
|
||||
scope: "差旅报销",
|
||||
body: "住宿费标准执行城市限额,[超标住宿必须有前置特批邮件]{硬性}。",
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
closeApprovalDatabase();
|
||||
delete process.env.HOSE_APPROVAL_DB;
|
||||
});
|
||||
|
||||
test("完整闭环:bind 挂载 ➔ review 证据核验 ➔ decide 网关阻拦与裁决 ➔ logs 审计追溯", async () => {
|
||||
const db = getApprovalDatabase(":memory:");
|
||||
const repo = new ApprovalRepository(db);
|
||||
|
||||
// 1. 创建审批会话
|
||||
const run = repo.createApprovalRun({
|
||||
documentSn: "TEST-SN-999",
|
||||
corpId: "test-corp",
|
||||
documentSnapshot: "# 单据测试快照",
|
||||
});
|
||||
const runId = run.shortId!;
|
||||
expect(runId).toHaveLength(6);
|
||||
|
||||
// 2. bind 挂载规则并拆解为要点清单
|
||||
const bindRes = await runAiProCli(["bind", "--run", runId, "--rules", "[1, 2]"]);
|
||||
expect(bindRes.exitCode).toBe(0);
|
||||
const bindData = JSON.parse(bindRes.stdout);
|
||||
expect(bindData.length).toBe(3);
|
||||
expect(bindData[0]["要点编号"]).toBe(1);
|
||||
expect(bindData[0]["严格程度"]).toBe("硬性");
|
||||
expect(bindData[0]["归属规则"]).toBe(1);
|
||||
expect(bindData[0]["审核要点"]).toBe("必须上传真实发票");
|
||||
expect(bindData[0]["核验状态"]).toBe("待核验");
|
||||
|
||||
expect(bindData[1]["要点编号"]).toBe(2);
|
||||
expect(bindData[1]["严格程度"]).toBe("建议");
|
||||
expect(bindData[1]["归属规则"]).toBe(1);
|
||||
|
||||
expect(bindData[2]["要点编号"]).toBe(3);
|
||||
expect(bindData[2]["严格程度"]).toBe("硬性");
|
||||
expect(bindData[2]["归属规则"]).toBe(2);
|
||||
|
||||
// 3. 门禁测试:要点处于 PENDING 时,尝试执行 approve 必须被网关阻拦
|
||||
const block1 = await runAiProCli(["decide", "approve", "--run", runId, "--opinion", "尝试盲目放行"]);
|
||||
expect(block1.exitCode).toBe(1);
|
||||
expect(block1.stderr).toContain("待核验");
|
||||
|
||||
// 4. review 事实打标录入(要点 3 硬性违规,缺少特批邮件)
|
||||
const reviewRes = await runAiProCli([
|
||||
"review",
|
||||
"--run",
|
||||
runId,
|
||||
"--eval",
|
||||
"1=PASS:已上传增值税普通发票; 2=PASS:已注明详细出差事由; 3=FAIL:住宿费超标500元且无特批邮件",
|
||||
]);
|
||||
expect(reviewRes.exitCode).toBe(0);
|
||||
const reviewData = JSON.parse(reviewRes.stdout);
|
||||
expect(reviewData["要点总数"]).toBe(3);
|
||||
expect(reviewData["已通过"]).toBe(2);
|
||||
expect(reviewData["未通过"]).toBe(1);
|
||||
expect(reviewData["待核验"]).toBe(0);
|
||||
|
||||
// 5. 门禁测试:硬性违规未通过时,尝试执行 approve 必须被物理一票否决
|
||||
const block2 = await runAiProCli(["decide", "approve", "--run", runId, "--opinion", "强行同意放水"]);
|
||||
expect(block2.exitCode).toBe(1);
|
||||
expect(block2.stderr).toContain("硬性违规条款未通过");
|
||||
|
||||
// 6. 门禁测试:审批意见超过 150 字符时,必须被参数校验阻断
|
||||
const over150Text = "测试超长文字。".repeat(30);
|
||||
const block3 = await runAiProCli(["decide", "reject", "--run", runId, "--opinion", over150Text]);
|
||||
expect(block3.exitCode).toBe(1);
|
||||
expect(block3.stderr).toContain("不可超过 150 字符");
|
||||
|
||||
// 7. 正确决策:执行 reject 驳回,提供小于 150 字的专业意见(Dry-run)
|
||||
const rejectRes = await runAiProCli([
|
||||
"decide",
|
||||
"reject",
|
||||
"--run",
|
||||
runId,
|
||||
"--opinion",
|
||||
"住宿费超标500元且未见前置特批邮件,不符合差旅规约第2条,予以驳回,请补充特批后重提。",
|
||||
]);
|
||||
expect(rejectRes.exitCode).toBe(0);
|
||||
const rejectData = JSON.parse(rejectRes.stdout);
|
||||
expect(rejectData["会话ID"]).toBe(runId);
|
||||
expect(rejectData["执行动作"]).toBe("驳回");
|
||||
expect(rejectData["网关状态"]).toBe("放行");
|
||||
|
||||
// 8. 审计监控流水验证:会话账本包含全链路记录
|
||||
const logsRes = await runAiProCli(["logs", "--run", runId, "--json"]);
|
||||
expect(logsRes.exitCode).toBe(0);
|
||||
const logsData = JSON.parse(logsRes.stdout);
|
||||
const actions = logsData.logs.map((l: any) => l.action);
|
||||
expect(actions).toContain("bind");
|
||||
expect(actions).toContain("review");
|
||||
expect(actions).toContain("decide");
|
||||
});
|
||||
});
|
||||
+776
-114
File diff suppressed because it is too large.
Load diff
@@ -309,7 +309,7 @@ async function handleAccounts(parsed: CliParsedArgs, runtime: CliRuntime): Promi
|
||||
}
|
||||
|
||||
if (accounts.length === 0) {
|
||||
return { stdout: "暂无保存的账号,请使用 hose auth login 登录\n", stderr: "", exitCode: 0 };
|
||||
return { stdout: "暂无保存的账号,请使用 hose-use auth login 登录\n", stderr: "", exitCode: 0 };
|
||||
}
|
||||
|
||||
const rows = accounts.map((acc, i) => [
|
||||
@@ -327,7 +327,7 @@ async function handleAccounts(parsed: CliParsedArgs, runtime: CliRuntime): Promi
|
||||
async function handleSwitchAccount(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const target = parsed.args[0] || stringOption(parsed.options, ["account", "a"]);
|
||||
if (!target) {
|
||||
return { stdout: "", stderr: "用法: hose auth switch-account <accountId>\n", exitCode: 1 };
|
||||
return { stdout: "", stderr: "用法: hose-use auth switch-account <accountId>\n", exitCode: 1 };
|
||||
}
|
||||
|
||||
const success = setActiveAccount(target);
|
||||
|
||||
+14
-14
@@ -27,7 +27,7 @@ export async function handleBillCommand(
|
||||
const corp = runtime.selectedCorp;
|
||||
if (!corp) {
|
||||
throw new Error(
|
||||
"未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose auth login 登录。"
|
||||
"未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose-use auth login 登录。"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ export async function handleBillCommand(
|
||||
case "agree": {
|
||||
await requireWriteConfirmation();
|
||||
const target = actionTarget();
|
||||
if (!target) throw new Error("请提供审批任务、单号或单据 ID: hose bill approve <单号|ID> --yes");
|
||||
if (!target) throw new Error("请提供审批任务、单号或单据 ID: hose-use bill approve <单号|ID> --yes");
|
||||
const result = await approveBill(client, corpId, target, actionOptions());
|
||||
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
return { stdout: `审批同意成功\n单号: ${result.billCode || target}\n任务 ID: ${result.backlogId}\n`, stderr: "", exitCode: 0 };
|
||||
@@ -85,7 +85,7 @@ export async function handleBillCommand(
|
||||
case "deny": {
|
||||
await requireWriteConfirmation();
|
||||
const target = actionTarget();
|
||||
if (!target) throw new Error("请提供审批任务、单号或单据 ID: hose bill reject <单号|ID> --comment <原因> --yes");
|
||||
if (!target) throw new Error("请提供审批任务、单号或单据 ID: hose-use bill reject <单号|ID> --comment <原因> --yes");
|
||||
const options = actionOptions();
|
||||
if (!options.comment?.trim()) throw new Error("驳回原因不能为空,请通过 --comment 提供原因");
|
||||
const result = await rejectBill(client, corpId, target, options);
|
||||
@@ -97,7 +97,7 @@ export async function handleBillCommand(
|
||||
case "shift": {
|
||||
await requireWriteConfirmation();
|
||||
const target = actionTarget();
|
||||
if (!target) throw new Error("请提供审批任务、单号或单据 ID: hose bill transfer <单号|ID> --approver-id <员工ID> --yes");
|
||||
if (!target) throw new Error("请提供审批任务、单号或单据 ID: hose-use bill transfer <单号|ID> --approver-id <员工ID> --yes");
|
||||
const options = { ...actionOptions(), approverIds: await resolveApproverIds(actionOptions().approverIds) };
|
||||
const result = await transferBill(client, corpId, target, options);
|
||||
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
@@ -110,7 +110,7 @@ export async function handleBillCommand(
|
||||
case "counter-sign": {
|
||||
await requireWriteConfirmation();
|
||||
const target = actionTarget();
|
||||
if (!target) throw new Error("请提供审批任务、单号或单据 ID: hose bill add-node <单号|ID> --approver-id <员工ID> --yes");
|
||||
if (!target) throw new Error("请提供审批任务、单号或单据 ID: hose-use bill add-node <单号|ID> --approver-id <员工ID> --yes");
|
||||
const options = { ...actionOptions(), approverIds: await resolveApproverIds(actionOptions().approverIds) };
|
||||
const result = await addNodeBill(client, corpId, target, options);
|
||||
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
@@ -121,7 +121,7 @@ export async function handleBillCommand(
|
||||
case "remark": {
|
||||
await requireWriteConfirmation();
|
||||
const target = actionTarget();
|
||||
if (!target) throw new Error("请提供单号或单据 ID: hose bill comment <单号|ID> --comment <内容> --yes");
|
||||
if (!target) throw new Error("请提供单号或单据 ID: hose-use bill comment <单号|ID> --comment <内容> --yes");
|
||||
const result = await commentBill(client, corpId, target, actionOptions());
|
||||
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
return { stdout: `单据评论成功\n单号: ${result.billCode || target}\n流程 ID: ${result.flowId}\n`, stderr: "", exitCode: 0 };
|
||||
@@ -326,7 +326,7 @@ export async function handleBillCommand(
|
||||
case "records":
|
||||
case "timeline": {
|
||||
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id"]);
|
||||
if (!target) throw new Error("请提供要查询流程的单号或单据 ID: hose bill flow <单号|ID>");
|
||||
if (!target) throw new Error("请提供要查询流程的单号或单据 ID: hose-use bill flow <单号|ID>");
|
||||
const flow = await getBillFlow(client, corpId, target);
|
||||
if (!flow) {
|
||||
if (runtime.jsonMode) return { stdout: printJson({ found: false, target }, runtime.outputOptions), stderr: "", exitCode: 1 };
|
||||
@@ -368,7 +368,7 @@ export async function handleBillCommand(
|
||||
case "review":
|
||||
case "warnings": {
|
||||
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id"]);
|
||||
if (!target) throw new Error("请提供要查询风控结果的单号或单据 ID: hose bill risk <单号|ID>");
|
||||
if (!target) throw new Error("请提供要查询风控结果的单号或单据 ID: hose-use bill risk <单号|ID>");
|
||||
const report = await getBillRisk(client, corpId, target);
|
||||
if (!report) {
|
||||
if (runtime.jsonMode) return { stdout: printJson({ found: false, target }, runtime.outputOptions), stderr: "", exitCode: 1 };
|
||||
@@ -398,7 +398,7 @@ export async function handleBillCommand(
|
||||
case "budget":
|
||||
case "budgets": {
|
||||
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id"]);
|
||||
if (!target) throw new Error("请提供要查询预算状态的单号或单据 ID: hose bill budget <单号|ID>");
|
||||
if (!target) throw new Error("请提供要查询预算状态的单号或单据 ID: hose-use bill budget <单号|ID>");
|
||||
const report = await getBillRisk(client, corpId, target);
|
||||
if (!report) {
|
||||
if (runtime.jsonMode) return { stdout: printJson({ found: false, target }, runtime.outputOptions), stderr: "", exitCode: 1 };
|
||||
@@ -424,7 +424,7 @@ export async function handleBillCommand(
|
||||
case "references":
|
||||
case "resolve": {
|
||||
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id"]);
|
||||
if (!target) throw new Error("请提供要解析引用的单号或单据 ID: hose bill refs <单号|ID>");
|
||||
if (!target) throw new Error("请提供要解析引用的单号或单据 ID: hose-use bill refs <单号|ID>");
|
||||
const report = await getBillReferences(client, corpId, target);
|
||||
if (!report) {
|
||||
if (runtime.jsonMode) return { stdout: printJson({ found: false, target }, runtime.outputOptions), stderr: "", exitCode: 1 };
|
||||
@@ -453,7 +453,7 @@ export async function handleBillCommand(
|
||||
case "relation":
|
||||
case "links": {
|
||||
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id"]);
|
||||
if (!target) throw new Error("请提供要查询关联关系的单号或单据 ID: hose bill relations <单号|ID>");
|
||||
if (!target) throw new Error("请提供要查询关联关系的单号或单据 ID: hose-use bill relations <单号|ID>");
|
||||
const report = await getBillRelations(client, corpId, target);
|
||||
if (!report) {
|
||||
if (runtime.jsonMode) return { stdout: printJson({ found: false, target }, runtime.outputOptions), stderr: "", exitCode: 1 };
|
||||
@@ -486,7 +486,7 @@ export async function handleBillCommand(
|
||||
case "attachment":
|
||||
case "files": {
|
||||
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id"]);
|
||||
if (!target) throw new Error("请提供要查询附件的单号或单据 ID: hose bill attachments <单号|ID>");
|
||||
if (!target) throw new Error("请提供要查询附件的单号或单据 ID: hose-use bill attachments <单号|ID>");
|
||||
const report = await getBillAttachments(client, corpId, target);
|
||||
if (!report) {
|
||||
if (runtime.jsonMode) return { stdout: printJson({ found: false, target }, runtime.outputOptions), stderr: "", exitCode: 1 };
|
||||
@@ -507,7 +507,7 @@ export async function handleBillCommand(
|
||||
case "download":
|
||||
case "file-download": {
|
||||
const target = parsed.args[0] || stringOption(parsed.options, ["code", "id"]);
|
||||
if (!target) throw new Error("请提供要下载附件的单号或单据 ID: hose bill download <单号|ID>");
|
||||
if (!target) throw new Error("请提供要下载附件的单号或单据 ID: hose-use bill download <单号|ID>");
|
||||
const outputDir = stringOption(parsed.options, ["output-dir", "dir"]) || `${process.cwd()}/downloads`;
|
||||
const fileId = stringOption(parsed.options, ["file-id", "file"]);
|
||||
const result = await downloadBillAttachments(client, corpId, target, outputDir, fileId);
|
||||
@@ -540,7 +540,7 @@ export async function handleBillCommand(
|
||||
if (!target) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "用法: hose bill link <单号或ID>",
|
||||
stderr: "用法: hose-use bill link <单号或ID>",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ async function handleShow(parsed: CliParsedArgs, runtime: CliRuntime): Promise<C
|
||||
});
|
||||
|
||||
return {
|
||||
stdout: `====== 全局运行配置 ======\n${output}\n\n提示:\n 切换模式: hose config mode <stateful|stateless>\n 指定企业: hose corps switch <corpId>\n 更新源设置: hose config set updateSource <auto|github|gitea>\n`,
|
||||
stdout: `====== 全局运行配置 ======\n${output}\n\n提示:\n 切换模式: hose-use config mode <stateful|stateless>\n 指定企业: hose-use corps switch <corpId>\n 更新源设置: hose-use config set updateSource <auto|github|gitea>\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
@@ -79,7 +79,7 @@ async function handleMode(parsed: CliParsedArgs, runtime: CliRuntime): Promise<C
|
||||
if (!targetMode || (targetMode !== "stateful" && targetMode !== "stateless")) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "用法: hose config mode <stateful|stateless>\n",
|
||||
stderr: "用法: hose-use config mode <stateful|stateless>\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
@@ -105,7 +105,7 @@ async function handleSet(parsed: CliParsedArgs, runtime: CliRuntime): Promise<Cl
|
||||
if (!rawKey || val === undefined) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "用法: hose config set <key> <val> (如 hose config set defaultCorpId uzU7pcWfScck00)\n",
|
||||
stderr: "用法: hose-use config set <key> <val> (如 hose-use config set defaultCorpId uzU7pcWfScck00)\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export async function handleContactCommand(
|
||||
if (!corp) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "未指定或未找到有效企业配置。请运行 'hose corps list' 或指定 '--corp=<id>'",
|
||||
stderr: "未指定或未找到有效企业配置。请运行 'hose-use corps list' 或指定 '--corp=<id>'",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
@@ -24,13 +24,13 @@ export async function handleContactCommand(
|
||||
const action = parsed.action || parsed.args[0] || "list";
|
||||
const limit = numberOption(parsed.options, ["limit", "l"]);
|
||||
|
||||
// 1. 搜索: hose contact search <keyword> 或 hose contact find <keyword>
|
||||
// 1. 搜索: hose-use contact search <keyword> 或 hose-use contact find <keyword>
|
||||
if (action === "search" || action === "find") {
|
||||
const keyword = parsed.args[0] || stringOption(parsed.options, ["keyword", "query", "k"]) || "";
|
||||
if (!keyword.trim()) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "用法: hose contact search <关键词 (姓名/邮箱/工号)>",
|
||||
stderr: "用法: hose-use contact search <关键词 (姓名/邮箱/工号)>",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
@@ -67,13 +67,13 @@ export async function handleContactCommand(
|
||||
};
|
||||
}
|
||||
|
||||
// 2. 详情: hose contact get <staffId>
|
||||
// 2. 详情: hose-use contact get <staffId>
|
||||
if (action === "get") {
|
||||
const staffId = parsed.args[0] || stringOption(parsed.options, ["id", "staff-id"]);
|
||||
if (!staffId) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "用法: hose contact get <staffId>",
|
||||
stderr: "用法: hose-use contact get <staffId>",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
@@ -110,7 +110,7 @@ export async function handleContactCommand(
|
||||
};
|
||||
}
|
||||
|
||||
// 3. 列表采样: hose contact list (默认限流截断防爆)
|
||||
// 3. 列表采样: hose-use contact list (默认限流截断防爆)
|
||||
if (action === "list") {
|
||||
const isFull = runtime.outputOptions?.allowFull === true;
|
||||
const result = await listStaffsProtected(corp, {
|
||||
|
||||
@@ -42,7 +42,7 @@ async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Promise<C
|
||||
}
|
||||
|
||||
if (corps.length === 0) {
|
||||
return { stdout: "未找到任何企业配置,请先运行 hose auth login\n", stderr: "", exitCode: 0 };
|
||||
return { stdout: "未找到任何企业配置,请先运行 hose-use auth login\n", stderr: "", exitCode: 0 };
|
||||
}
|
||||
|
||||
const rows = corps.map((c, i) => [
|
||||
@@ -61,7 +61,7 @@ async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Promise<C
|
||||
);
|
||||
|
||||
return {
|
||||
stdout: `====== 已配置企业列表 (${corps.length} 家) ======\n${table}\n\n提示: 使用 hose corps switch <企业ID> 切换工作企业\n`,
|
||||
stdout: `====== 已配置企业列表 (${corps.length} 家) ======\n${table}\n\n提示: 使用 hose-use corps switch <企业ID> 切换工作企业\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
@@ -70,14 +70,14 @@ async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Promise<C
|
||||
async function handleSwitch(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const corpId = parsed.args[0];
|
||||
if (!corpId) {
|
||||
return { stdout: "", stderr: "用法: hose corps switch <企业ID>\n", exitCode: 1 };
|
||||
return { stdout: "", stderr: "用法: hose-use corps switch <企业ID>\n", exitCode: 1 };
|
||||
}
|
||||
|
||||
const success = runtime.corpContext.switchCorp(corpId);
|
||||
if (!success) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `企业 ${corpId} 不存在或未配置。可运行 hose corps list 查看可用列表。\n`,
|
||||
stderr: `企业 ${corpId} 不存在或未配置。可运行 hose-use corps list 查看可用列表。\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { searchDimensions, resolveDimension } from "../../domains/dimension/tool
|
||||
|
||||
export async function handleDimensionCommand(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const corp = runtime.selectedCorp;
|
||||
if (!corp) throw new Error("未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose auth login 登录。");
|
||||
if (!corp) throw new Error("未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose-use auth login 登录。");
|
||||
const client = await createEkbClient(corp);
|
||||
const corpId = corp.corpId || corp.id;
|
||||
const action = parsed.action?.toLowerCase() || "list";
|
||||
@@ -19,7 +19,7 @@ export async function handleDimensionCommand(parsed: CliParsedArgs, runtime: Cli
|
||||
}
|
||||
if (["items", "get", "show"].includes(action)) {
|
||||
const target = parsed.args[0] || stringOption(parsed.options, ["dimension", "id", "code", "name"]);
|
||||
if (!target) throw new Error("请提供档案维度 ID、编码或名称: hose dimension items <维度>");
|
||||
if (!target) throw new Error("请提供档案维度 ID、编码或名称: hose-use dimension items <维度>");
|
||||
const result = await resolveDimension(client, corpId, target);
|
||||
if (!result) {
|
||||
if (runtime.jsonMode) return { stdout: printJson({ found: false, target }, runtime.outputOptions), stderr: "", exitCode: 1 };
|
||||
|
||||
@@ -24,7 +24,7 @@ function renderItems(items: MessageItem[]): string {
|
||||
|
||||
export async function handleMessageCommand(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const corp = runtime.selectedCorp;
|
||||
if (!corp) throw new Error("未指定或未找到有效企业。请运行 hose corps list 或指定 --corp=<id>");
|
||||
if (!corp) throw new Error("未指定或未找到有效企业。请运行 hose-use corps list 或指定 --corp=<id>");
|
||||
const action = parsed.action || parsed.args[0] || "list";
|
||||
const client = await createEkbClient(corp);
|
||||
const corpId = corp.corpId || corp.id;
|
||||
@@ -37,7 +37,7 @@ export async function handleMessageCommand(parsed: CliParsedArgs, runtime: CliRu
|
||||
|
||||
if (action === "read" || action === "mark-read") {
|
||||
const messageId = parsed.args[0] || stringOption(parsed.options, ["id", "message-id"]);
|
||||
if (!messageId) return { stdout: "", stderr: "用法: hose message read <messageId>\n", exitCode: 1 };
|
||||
if (!messageId) return { stdout: "", stderr: "用法: hose-use message read <messageId>\n", exitCode: 1 };
|
||||
await readMessage(client, corpId, messageId);
|
||||
if (runtime.jsonMode) return { stdout: printJson({ corpId, id: messageId, read: true }, runtime.outputOptions), stderr: "", exitCode: 0 };
|
||||
return { stdout: `已标记消息为已读: ${messageId}\n`, stderr: "", exitCode: 0 };
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getPermissions } from "../../domains/permission/tools.js";
|
||||
|
||||
export async function handlePermissionCommand(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const corp = runtime.selectedCorp;
|
||||
if (!corp) throw new Error("未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose auth login 登录。");
|
||||
if (!corp) throw new Error("未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose-use auth login 登录。");
|
||||
const action = parsed.action?.toLowerCase() || "get";
|
||||
if (!["get", "list", "show"].includes(action)) throw new Error(`未知 permission 子命令: ${action}。支持: get`);
|
||||
const client = await createEkbClient(corp);
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function handlePlatformCommand(
|
||||
if (!currentCorp) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "未选中企业,请先通过 hose corps switch 或 --corp 指定企业\n",
|
||||
stderr: "未选中企业,请先通过 hose-use corps switch 或 --corp 指定企业\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function handleProbeCommand(
|
||||
if (!currentCorp) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "未配置任何企业,请先运行 hose auth login 或使用 --corp 指定\n",
|
||||
stderr: "未配置任何企业,请先运行 hose-use auth login 或使用 --corp 指定\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { getRoleGroups, getRoleMembers, searchRoles } from "../../domains/role/t
|
||||
|
||||
export async function handleRoleCommand(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const corp = runtime.selectedCorp;
|
||||
if (!corp) throw new Error("未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose auth login 登录。");
|
||||
if (!corp) throw new Error("未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose-use auth login 登录。");
|
||||
const client = await createEkbClient(corp), corpId = corp.corpId || corp.id;
|
||||
const action = parsed.action?.toLowerCase() || "list";
|
||||
if (["list", "search"].includes(action)) {
|
||||
@@ -26,7 +26,7 @@ export async function handleRoleCommand(parsed: CliParsedArgs, runtime: CliRunti
|
||||
}
|
||||
if (["members", "member", "staffs", "staff"].includes(action)) {
|
||||
const target = parsed.args[0] || stringOption(parsed.options, ["role", "id", "code", "name"]);
|
||||
if (!target) throw new Error("请提供角色 ID、编码或名称: hose role members <角色>");
|
||||
if (!target) throw new Error("请提供角色 ID、编码或名称: hose-use role members <角色>");
|
||||
const report = await getRoleMembers(client, corpId, target);
|
||||
if (!report) {
|
||||
if (runtime.jsonMode) return { stdout: printJson({ found: false, target }, runtime.outputOptions), stderr: "", exitCode: 1 };
|
||||
|
||||
@@ -15,7 +15,7 @@ function dateOption(value: string | undefined): number | undefined {
|
||||
|
||||
export async function handleTaskCommand(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const corp = runtime.selectedCorp;
|
||||
if (!corp) throw new Error("未指定或未找到有效企业。请运行 hose corps list 或指定 --corp=<id>");
|
||||
if (!corp) throw new Error("未指定或未找到有效企业。请运行 hose-use corps list 或指定 --corp=<id>");
|
||||
const action = parsed.action || parsed.args[0] || "todo";
|
||||
const view: TaskView | undefined = action === "todo" || action === "pending"
|
||||
? "todo"
|
||||
|
||||
@@ -796,7 +796,17 @@ export async function downloadFile(
|
||||
const candidate = uniqueCandidates[i]!;
|
||||
try {
|
||||
logProgress(`==> [${i + 1}/${uniqueCandidates.length}] 正在下载更新: ${candidate}`);
|
||||
const res = await fetch(candidate, { signal: AbortSignal.timeout(6000) });
|
||||
const reqHeaders: Record<string, string> = {
|
||||
"User-Agent": `hose-use/${VERSION}`,
|
||||
};
|
||||
const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
|
||||
if (token && candidate.includes("github.com")) {
|
||||
reqHeaders["Authorization"] = `Bearer ${token}`;
|
||||
}
|
||||
const res = await fetch(candidate, {
|
||||
headers: reqHeaders,
|
||||
signal: AbortSignal.timeout(600_000), // 放宽至 600 秒(10 分钟),保障大体积二进制完整下载
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP ${res.status} ${res.statusText}`);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ export async function handleWorkflowCommand(
|
||||
if (!currentCorp) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "未选中企业,请先通过 hose corps switch 或 --corp 指定企业\n",
|
||||
stderr: "未选中企业,请先通过 hose-use corps switch 或 --corp 指定企业\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
@@ -52,7 +52,7 @@ export async function handleWorkflowCommand(
|
||||
|
||||
async function handleAnalyze(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const pipelineId = parsed.args[0] || stringOption(parsed.options, ["id", "pipelineId"]);
|
||||
if (!pipelineId) return { stdout: "", stderr: "用法: hose workflow analyze <pipelineId>\n", exitCode: 1 };
|
||||
if (!pipelineId) return { stdout: "", stderr: "用法: hose-use workflow analyze <pipelineId>\n", exitCode: 1 };
|
||||
const clients = await createClientsForCorp(runtime.selectedCorp!);
|
||||
const detail = await api.getWorkflowDetail(clients.easoClient, pipelineId);
|
||||
const result = analyzeWorkflow(detail);
|
||||
@@ -110,7 +110,7 @@ async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Promise<C
|
||||
async function handleGet(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
|
||||
const pipelineId = parsed.args[0] || stringOption(parsed.options, ["id", "pipelineId"]);
|
||||
if (!pipelineId) {
|
||||
return { stdout: "", stderr: "用法: hose workflow get <pipelineId>\n", exitCode: 1 };
|
||||
return { stdout: "", stderr: "用法: hose-use workflow get <pipelineId>\n", exitCode: 1 };
|
||||
}
|
||||
|
||||
const clients = await createClientsForCorp(runtime.selectedCorp!);
|
||||
@@ -152,7 +152,7 @@ async function handleFind(parsed: CliParsedArgs, runtime: CliRuntime): Promise<C
|
||||
if (!taskType) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "用法: hose workflow find --task=<节点类型> (如 code-js2, http, condition)\n",
|
||||
stderr: "用法: hose-use workflow find --task=<节点类型> (如 code-js2, http, condition)\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
@@ -207,7 +207,7 @@ async function handleToggle(parsed: CliParsedArgs, runtime: CliRuntime): Promise
|
||||
if (!pipelineId || stateArg === undefined) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "用法: hose workflow toggle <pipelineId> --state=<1|0> (1启用, 0停用)\n",
|
||||
stderr: "用法: hose-use workflow toggle <pipelineId> --state=<1|0> (1启用, 0停用)\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
+1
-1
@@ -229,7 +229,7 @@ async function dispatchCli(
|
||||
default:
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: `未知命令域: ${parsed.area}。运行 hose --help 查看帮助\n`,
|
||||
stderr: `未知命令域: ${parsed.area}。运行 hose-use --help 查看帮助\n`,
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ export async function runServiceCommand(
|
||||
case undefined:
|
||||
return serviceStatus(config);
|
||||
default:
|
||||
throw new Error("用法: hose service <start|stop|restart|status|logs|poll>");
|
||||
throw new Error("用法: hose-use service <start|stop|restart|status|logs|poll>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ export const authTools = [
|
||||
if (!current) {
|
||||
return {
|
||||
authenticated: false,
|
||||
message: "未配置任何企业,请先运行 hose auth login",
|
||||
message: "未配置任何企业,请先运行 hose-use auth login",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ export function resolveCorpConfig(
|
||||
if (!options.stateful) {
|
||||
throw new Error(
|
||||
"当前处于无状态模式 (Stateless Mode)。执行企业级操作必须显式指定 --corp <corpId>。\n" +
|
||||
"如需设置默认企业,可执行 `hose config mode stateful` 切换为有状态模式。"
|
||||
"如需设置默认企业,可执行 `hose-use config mode stateful` 切换为有状态模式。"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ export function resolveCorpConfig(
|
||||
if (firstCorp) return firstCorp;
|
||||
|
||||
const hintDirs = candidateDirs?.length ? ` (已检索路径: ${candidateDirs.join(", ")})` : "";
|
||||
throw new Error(`未找到任何企业配置。请先运行 'hose auth login' 登录或添加企业配置${hintDirs}。`);
|
||||
throw new Error(`未找到任何企业配置。请先运行 'hose-use auth login' 登录或添加企业配置${hintDirs}。`);
|
||||
}
|
||||
|
||||
export class CorpContext {
|
||||
|
||||
@@ -296,4 +296,64 @@ describe("Approval Domain - SQLite 持久化与规约仓储", () => {
|
||||
|
||||
expect(repo.getAuditChecklist("EXEC-FAIL", "corp-a").run?.decision).toBe("ERROR");
|
||||
});
|
||||
|
||||
test("审批会话 6 位 shortId 生成、6 小时 TTL 与会话级日志挂载", () => {
|
||||
// 1. 同一单号多次审批,生成完全独立的运行实例
|
||||
const run1 = repo.createApprovalRun({
|
||||
documentSn: "MULTI-RUN-001",
|
||||
corpId: "corp-test",
|
||||
documentSnapshot: "# 单据初审快照",
|
||||
});
|
||||
const run2 = repo.createApprovalRun({
|
||||
documentSn: "MULTI-RUN-001",
|
||||
corpId: "corp-test",
|
||||
documentSnapshot: "# 单据复审快照",
|
||||
});
|
||||
|
||||
expect(run1.id).not.toBe(run2.id);
|
||||
expect(run1.shortId).toHaveLength(6);
|
||||
expect(run2.shortId).toHaveLength(6);
|
||||
expect(run1.shortId).not.toBe(run2.shortId);
|
||||
expect(run1.expiresAt).toBeGreaterThan(Date.now());
|
||||
|
||||
// 2. 通过 6 位短 ID 检索会话
|
||||
const found1 = repo.getRunByHandle(run1.shortId!);
|
||||
expect(found1?.id).toBe(run1.id);
|
||||
expect(found1?.documentSnapshot).toBe("# 单据初审快照");
|
||||
|
||||
// 3. 过期检测拦截
|
||||
const expiredRun = repo.createApprovalRun({
|
||||
documentSn: "EXPIRED-001",
|
||||
expiresAt: Date.now() - 1000, // 过去的时间
|
||||
});
|
||||
expect(() => repo.getRunByHandle(expiredRun.shortId!)).toThrow("已过期");
|
||||
|
||||
// 4. 会话级日志挂载与检索
|
||||
repo.logAiProAction({
|
||||
action: "init",
|
||||
runId: run1.shortId,
|
||||
documentSn: "MULTI-RUN-001",
|
||||
summary: "初始化审批会话",
|
||||
});
|
||||
repo.logAiProAction({
|
||||
action: "translate",
|
||||
runId: run1.shortId,
|
||||
documentSn: "MULTI-RUN-001",
|
||||
summary: "读取快照",
|
||||
});
|
||||
repo.logAiProAction({
|
||||
action: "init",
|
||||
runId: run2.shortId,
|
||||
documentSn: "MULTI-RUN-001",
|
||||
summary: "第二次初始化审批会话",
|
||||
});
|
||||
|
||||
const run1Logs = repo.listAiProLogs({ runId: run1.shortId! });
|
||||
expect(run1Logs.length).toBe(2);
|
||||
expect(run1Logs.map((l) => l.action).sort()).toEqual(["init", "translate"].sort());
|
||||
|
||||
const run2Logs = repo.listAiProLogs({ runId: run2.shortId! });
|
||||
expect(run2Logs.length).toBe(1);
|
||||
expect(run2Logs[0]!.summary).toBe("第二次初始化审批会话");
|
||||
});
|
||||
});
|
||||
@@ -105,9 +105,12 @@ export function initDatabaseSchema(db: Database): void {
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS approval_runs (
|
||||
id TEXT PRIMARY KEY,
|
||||
short_id TEXT,
|
||||
expires_at INTEGER,
|
||||
flow_id TEXT,
|
||||
document_sn TEXT NOT NULL,
|
||||
corp_id TEXT,
|
||||
scope TEXT,
|
||||
decision TEXT NOT NULL,
|
||||
decision_summary TEXT,
|
||||
matched_rules_count INTEGER NOT NULL DEFAULT 0,
|
||||
@@ -117,7 +120,17 @@ export function initDatabaseSchema(db: Database): void {
|
||||
updated_at INTEGER NOT NULL
|
||||
);
|
||||
`);
|
||||
try {
|
||||
db.run("ALTER TABLE approval_runs ADD COLUMN scope TEXT;");
|
||||
} catch {}
|
||||
try {
|
||||
db.run("ALTER TABLE approval_runs ADD COLUMN short_id TEXT;");
|
||||
} catch {}
|
||||
try {
|
||||
db.run("ALTER TABLE approval_runs ADD COLUMN expires_at INTEGER;");
|
||||
} catch {}
|
||||
db.run("CREATE INDEX IF NOT EXISTS idx_runs_document_sn ON approval_runs(document_sn);");
|
||||
db.run("CREATE INDEX IF NOT EXISTS idx_runs_short_id ON approval_runs(short_id);");
|
||||
db.run("CREATE INDEX IF NOT EXISTS idx_runs_created_at ON approval_runs(created_at);");
|
||||
|
||||
// 4. 审批要点事实记录表
|
||||
@@ -140,6 +153,7 @@ export function initDatabaseSchema(db: Database): void {
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS aipro_logs (
|
||||
id TEXT PRIMARY KEY,
|
||||
run_id TEXT,
|
||||
action TEXT NOT NULL,
|
||||
document_sn TEXT,
|
||||
operator TEXT,
|
||||
@@ -150,7 +164,11 @@ export function initDatabaseSchema(db: Database): void {
|
||||
created_at INTEGER NOT NULL
|
||||
);
|
||||
`);
|
||||
try {
|
||||
db.run("ALTER TABLE aipro_logs ADD COLUMN run_id TEXT;");
|
||||
} catch {}
|
||||
db.run("CREATE INDEX IF NOT EXISTS idx_aipro_logs_document_sn ON aipro_logs(document_sn);");
|
||||
db.run("CREATE INDEX IF NOT EXISTS idx_aipro_logs_run_id ON aipro_logs(run_id);");
|
||||
db.run("CREATE INDEX IF NOT EXISTS idx_aipro_logs_created_at ON aipro_logs(created_at);");
|
||||
|
||||
// 种子数据:初始化默认偏好
|
||||
|
||||
@@ -14,6 +14,15 @@ import {
|
||||
StrictnessTier
|
||||
} from "./types.js";
|
||||
|
||||
export function generateShortRunId(): string {
|
||||
const chars = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
|
||||
let result = "";
|
||||
for (let i = 0; i < 6; i++) {
|
||||
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export interface CreateRuleInput {
|
||||
scope: string;
|
||||
body: string;
|
||||
@@ -287,6 +296,39 @@ export class ApprovalRepository {
|
||||
|
||||
// ===================== 审批运行与要点清单 (Runs & Findings) =====================
|
||||
|
||||
public createApprovalRun(input: CreateApprovalRunInput): ApprovalRunRecord {
|
||||
const id = crypto.randomUUID();
|
||||
const shortId = input.shortId ?? generateShortRunId();
|
||||
const now = Date.now();
|
||||
const expiresAt = input.expiresAt ?? (now + 6 * 3600 * 1000); // 6 小时有效期
|
||||
|
||||
this.db.run(
|
||||
`
|
||||
INSERT INTO approval_runs (
|
||||
id, short_id, expires_at, flow_id, document_sn, corp_id, scope, decision, decision_summary, matched_rules_count, failed_rules_count, document_snapshot, created_at, updated_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`,
|
||||
[
|
||||
id,
|
||||
shortId,
|
||||
expiresAt,
|
||||
input.flowId ?? null,
|
||||
input.documentSn.trim(),
|
||||
input.corpId ?? null,
|
||||
input.scope ?? null,
|
||||
input.decision ?? "PENDING",
|
||||
input.decisionSummary ?? null,
|
||||
input.matchedRulesCount ?? 0,
|
||||
input.failedRulesCount ?? 0,
|
||||
input.documentSnapshot ?? null,
|
||||
now,
|
||||
now,
|
||||
]
|
||||
);
|
||||
|
||||
return this.getRunById(id)!;
|
||||
}
|
||||
|
||||
public createOrResetApprovalRun(input: CreateApprovalRunInput): ApprovalRunRecord {
|
||||
const existing = this.getLatestRunBySn(input.documentSn, input.corpId ?? undefined);
|
||||
const now = Date.now();
|
||||
@@ -296,12 +338,13 @@ export class ApprovalRepository {
|
||||
this.db.run(
|
||||
`
|
||||
UPDATE approval_runs
|
||||
SET flow_id = ?, corp_id = ?, decision = ?, decision_summary = ?, matched_rules_count = ?, failed_rules_count = ?, document_snapshot = ?, updated_at = ?
|
||||
SET flow_id = ?, corp_id = ?, scope = ?, decision = ?, decision_summary = ?, matched_rules_count = ?, failed_rules_count = ?, document_snapshot = ?, updated_at = ?
|
||||
WHERE id = ?
|
||||
`,
|
||||
[
|
||||
(input.flowId !== undefined ? input.flowId : existing.flowId) ?? null,
|
||||
(input.corpId !== undefined ? input.corpId : existing.corpId) ?? null,
|
||||
(input.scope !== undefined ? input.scope : existing.scope) ?? null,
|
||||
input.decision ?? "PENDING",
|
||||
(input.decisionSummary !== undefined ? input.decisionSummary : null) ?? null,
|
||||
input.matchedRulesCount ?? 0,
|
||||
@@ -314,29 +357,28 @@ export class ApprovalRepository {
|
||||
return this.getRunById(existing.id)!;
|
||||
}
|
||||
|
||||
const id = crypto.randomUUID();
|
||||
this.db.run(
|
||||
`
|
||||
INSERT INTO approval_runs (
|
||||
id, flow_id, document_sn, corp_id, decision, decision_summary, matched_rules_count, failed_rules_count, document_snapshot, created_at, updated_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`,
|
||||
[
|
||||
id,
|
||||
input.flowId ?? null,
|
||||
input.documentSn.trim(),
|
||||
input.corpId ?? null,
|
||||
input.decision ?? "PENDING",
|
||||
input.decisionSummary ?? null,
|
||||
input.matchedRulesCount ?? 0,
|
||||
input.failedRulesCount ?? 0,
|
||||
input.documentSnapshot ?? null,
|
||||
now,
|
||||
now,
|
||||
]
|
||||
);
|
||||
return this.createApprovalRun(input);
|
||||
}
|
||||
|
||||
return this.getRunById(id)!;
|
||||
public getRunByHandle(handle: string, corpId?: string): ApprovalRunRecord | null {
|
||||
const trimmed = handle.trim();
|
||||
const now = Date.now();
|
||||
// 1. 如果符合 6 位大写短 ID 特征
|
||||
if (/^[A-Za-z0-9]{6}$/.test(trimmed)) {
|
||||
const row = this.db
|
||||
.query("SELECT * FROM approval_runs WHERE UPPER(short_id) = UPPER(?) AND (expires_at IS NULL OR expires_at > ?)")
|
||||
.get(trimmed, now) as any;
|
||||
if (row) return this.mapRunRow(row);
|
||||
const expiredRow = this.db.query("SELECT * FROM approval_runs WHERE UPPER(short_id) = UPPER(?)").get(trimmed) as any;
|
||||
if (expiredRow) {
|
||||
throw new Error(`审批会话 [${trimmed}] 已过期(有效时长 6 小时),请运行 hose-aipro init 重新发起审批会话`);
|
||||
}
|
||||
}
|
||||
// 2. 尝试按长 UUID 查找
|
||||
const byId = this.getRunById(trimmed);
|
||||
if (byId) return byId;
|
||||
// 3. 尝试按单号查找最新未过期的运行记录
|
||||
return this.getLatestRunBySn(trimmed, corpId);
|
||||
}
|
||||
|
||||
public getLatestRunBySn(documentSn: string, corpId?: string): ApprovalRunRecord | null {
|
||||
@@ -402,6 +444,9 @@ export class ApprovalRepository {
|
||||
throw new Error(`审批运行记录不存在: ${runId}`);
|
||||
}
|
||||
|
||||
// 重新挂载时清空旧要点
|
||||
this.db.run("DELETE FROM approval_findings WHERE run_id = ?", [runId]);
|
||||
|
||||
const now = Date.now();
|
||||
const insertStmt = this.db.prepare(`
|
||||
INSERT INTO approval_findings (
|
||||
@@ -512,9 +557,12 @@ export class ApprovalRepository {
|
||||
private mapRunRow(row: any): ApprovalRunRecord {
|
||||
return {
|
||||
id: row.id,
|
||||
shortId: row.short_id ?? null,
|
||||
expiresAt: row.expires_at ? Number(row.expires_at) : null,
|
||||
flowId: row.flow_id,
|
||||
documentSn: row.document_sn,
|
||||
corpId: row.corp_id,
|
||||
scope: row.scope ?? null,
|
||||
decision: row.decision as ApprovalDecision,
|
||||
decisionSummary: row.decision_summary,
|
||||
matchedRulesCount: Number(row.matched_rules_count || 0),
|
||||
@@ -550,19 +598,20 @@ export class ApprovalRepository {
|
||||
public logAiProAction(input: CreateAiProLogInput): AiProLogRecord {
|
||||
const id = crypto.randomUUID();
|
||||
const now = Date.now();
|
||||
|
||||
const status = input.status ?? "SUCCESS";
|
||||
this.db.run(
|
||||
`
|
||||
INSERT INTO aipro_logs (id, action, document_sn, operator, args, status, decision, summary, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO aipro_logs (id, run_id, action, document_sn, operator, args, status, decision, summary, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`,
|
||||
[
|
||||
id,
|
||||
input.runId ?? null,
|
||||
input.action,
|
||||
input.documentSn ?? null,
|
||||
input.operator ?? null,
|
||||
input.args ?? null,
|
||||
input.status,
|
||||
status,
|
||||
input.decision ?? null,
|
||||
input.summary ?? null,
|
||||
now,
|
||||
@@ -571,30 +620,45 @@ export class ApprovalRepository {
|
||||
|
||||
return {
|
||||
id,
|
||||
runId: input.runId,
|
||||
action: input.action,
|
||||
documentSn: input.documentSn,
|
||||
operator: input.operator,
|
||||
args: input.args,
|
||||
status: input.status,
|
||||
status,
|
||||
decision: input.decision,
|
||||
summary: input.summary,
|
||||
createdAt: now,
|
||||
};
|
||||
}
|
||||
|
||||
public listAiProLogs(documentSn?: string, limit = 50): AiProLogRecord[] {
|
||||
public listAiProLogs(filter?: string | { documentSn?: string; runId?: string }, limit = 50): AiProLogRecord[] {
|
||||
let sql = "SELECT * FROM aipro_logs";
|
||||
const conditions: string[] = [];
|
||||
const params: any[] = [];
|
||||
if (documentSn) {
|
||||
sql += " WHERE document_sn = ?";
|
||||
params.push(documentSn.trim());
|
||||
|
||||
const f = typeof filter === "string" ? { documentSn: filter } : filter;
|
||||
|
||||
if (f?.runId) {
|
||||
conditions.push("run_id = ?");
|
||||
params.push(f.runId.trim());
|
||||
}
|
||||
if (f?.documentSn) {
|
||||
conditions.push("document_sn = ?");
|
||||
params.push(f.documentSn.trim());
|
||||
}
|
||||
|
||||
if (conditions.length > 0) {
|
||||
sql += " WHERE " + conditions.join(" AND ");
|
||||
}
|
||||
|
||||
sql += " ORDER BY created_at DESC LIMIT ?";
|
||||
params.push(limit);
|
||||
|
||||
const rows = this.db.query(sql).all(...params) as any[];
|
||||
return rows.map((r) => ({
|
||||
id: r.id,
|
||||
runId: r.run_id ?? null,
|
||||
action: r.action,
|
||||
documentSn: r.document_sn,
|
||||
operator: r.operator,
|
||||
@@ -609,8 +673,11 @@ export class ApprovalRepository {
|
||||
|
||||
export interface CreateApprovalRunInput {
|
||||
documentSn: string;
|
||||
shortId?: string | null;
|
||||
expiresAt?: number | null;
|
||||
flowId?: string | null;
|
||||
corpId?: string | null;
|
||||
scope?: string | null;
|
||||
decision?: ApprovalDecision;
|
||||
decisionSummary?: string | null;
|
||||
matchedRulesCount?: number;
|
||||
@@ -629,10 +696,11 @@ export interface CreateFindingInput {
|
||||
|
||||
export interface CreateAiProLogInput {
|
||||
action: string;
|
||||
runId?: string | null;
|
||||
documentSn?: string | null;
|
||||
operator?: string | null;
|
||||
args?: string | null;
|
||||
status: "SUCCESS" | "BLOCKED" | "ERROR";
|
||||
status?: "SUCCESS" | "BLOCKED" | "ERROR";
|
||||
decision?: ApprovalDecision | null;
|
||||
summary?: string | null;
|
||||
}
|
||||
|
||||
@@ -118,6 +118,7 @@ export class ApprovalService {
|
||||
documentSn: actualSn,
|
||||
flowId: bill.billId,
|
||||
corpId,
|
||||
scope: scopeDetail.scope,
|
||||
decision: "PENDING",
|
||||
matchedRulesCount: clauseInputs.length,
|
||||
failedRulesCount: 0,
|
||||
|
||||
@@ -77,9 +77,12 @@ export type ApprovalDecision = "PENDING" | "APPROVE" | "REJECT" | "PASS_WITH_NOT
|
||||
|
||||
export interface ApprovalRunRecord {
|
||||
id: string;
|
||||
shortId?: string | null;
|
||||
expiresAt?: number | null;
|
||||
flowId?: string | null;
|
||||
documentSn: string;
|
||||
corpId?: string | null;
|
||||
scope?: string | null;
|
||||
decision: ApprovalDecision;
|
||||
decisionSummary?: string | null;
|
||||
matchedRulesCount: number;
|
||||
@@ -122,6 +125,7 @@ export class ApprovalGatewayBlockedError extends Error {
|
||||
|
||||
export interface AiProLogRecord {
|
||||
id: string;
|
||||
runId?: string | null;
|
||||
action: string;
|
||||
documentSn?: string | null;
|
||||
operator?: string | null;
|
||||
|
||||
@@ -36,4 +36,4 @@ src/domains/bill/
|
||||
- `commentBill` 调用 `POST /api/flow/v1/flows/comment/$<flowId>`,使用 `freeflow.comment`,保留参与人和私密评论参数;
|
||||
- 动作执行前从审批详情解析 backlog ID、流程 ID、当前节点 ID,并可依据 `flow.actions` 校验当前身份是否具备该动作权限。
|
||||
|
||||
CLI 入口为 `hose bill approve|reject|transfer|add-node|comment <单号|ID>`。所有会改变状态的动作都要求 `--yes`(交互终端未提供时会拒绝执行);转交和加签的 `--approver-id` 支持完整员工 ID、工号或唯一姓名匹配,驳回强制要求 `--comment`。
|
||||
CLI 入口为 `hose-use bill approve|reject|transfer|add-node|comment <单号|ID>`。所有会改变状态的动作都要求 `--yes`(交互终端未提供时会拒绝执行);转交和加签的 `--approver-id` 支持完整员工 ID、工号或唯一姓名匹配,驳回强制要求 `--comment`。
|
||||
@@ -281,4 +281,46 @@ describe("Bill Domain", () => {
|
||||
} as any;
|
||||
await expect(resolveBillStaffIds(client, "corp-action", ["111", "谢子豪"])).resolves.toEqual(["corp:staff-2", "corp:staff-1"]);
|
||||
});
|
||||
|
||||
it("translates raw bill flow into standard markdown representation", () => {
|
||||
const { translateBillFlowToMarkdown } = require("./translator.js");
|
||||
const rawFlow = {
|
||||
flowId: {
|
||||
state: "APPROVING",
|
||||
form: {
|
||||
code: "S26000001",
|
||||
title: "我🩷吃醋",
|
||||
specificationId: "ID01MCcOgJl1td:PRESET_REQUISITION_TRIP",
|
||||
submitterId: { name: "谢子豪" },
|
||||
requisitionDate: 1769961600000,
|
||||
submitDate: 1770284988706,
|
||||
requisitionMoney: { standard: "1000.00", standardStrCode: "CNY" },
|
||||
details: [
|
||||
{
|
||||
feeTypeId: "ID01MCcOgJl1td:hotel",
|
||||
feeTypeForm: {
|
||||
amount: { standard: "1000", standardStrCode: "CNY" },
|
||||
feeDate: 1770220800000,
|
||||
city: '[{"key":"513","label":"辽宁省/大连市/大连市区"}]',
|
||||
consumptionReasons: "今日在大连见客户",
|
||||
detailId: "ID01QkCjK2m47Z",
|
||||
detailNo: 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const markdown = translateBillFlowToMarkdown(rawFlow);
|
||||
expect(markdown).toContain("# 单据:S26000001");
|
||||
expect(markdown).toContain("- **状态**: 审批中 (approving)");
|
||||
expect(markdown).toContain("- **单据模板**: `差旅申请单`");
|
||||
expect(markdown).toContain("- **标题**: `我🩷吃醋`");
|
||||
expect(markdown).toContain("- **提交人**: 谢子豪");
|
||||
expect(markdown).toContain("- **申请金额**: CNY 1000.00");
|
||||
expect(markdown).toContain("### 费用明细(共 1 条)");
|
||||
expect(markdown).toContain("- **城市**: 辽宁省/大连市/大连市区");
|
||||
expect(markdown).toContain("- **消费事由**: `今日在大连见客户`");
|
||||
});
|
||||
});
|
||||
@@ -1270,3 +1270,5 @@ export const billTools = [
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export { translateBillFlowToMarkdown } from "./translator.js";
|
||||
@@ -0,0 +1,182 @@
|
||||
import { KyInstance } from "ky";
|
||||
import { getRawBillFlow } from "./api.js";
|
||||
import { getFeeTypeTree } from "./api.js";
|
||||
|
||||
function formatDate(val: unknown): string {
|
||||
if (!val) return "";
|
||||
if (typeof val === "number" || (typeof val === "string" && /^\d+$/.test(val))) {
|
||||
const d = new Date(Number(val));
|
||||
if (!isNaN(d.getTime())) {
|
||||
const year = d.getFullYear();
|
||||
const month = String(d.getMonth() + 1).padStart(2, "0");
|
||||
const day = String(d.getDate()).padStart(2, "0");
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
}
|
||||
if (typeof val === "string") {
|
||||
const match = val.match(/^(\d{4})[-/](\d{1,2})[-/](\d{1,2})/);
|
||||
if (match) {
|
||||
return `${match[1]}-${match[2].padStart(2, "0")}-${match[3].padStart(2, "0")}`;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
return String(val);
|
||||
}
|
||||
|
||||
function formatDateTime(val: unknown): string {
|
||||
if (!val) return "";
|
||||
if (typeof val === "number" || (typeof val === "string" && /^\d+$/.test(val))) {
|
||||
const d = new Date(Number(val));
|
||||
if (!isNaN(d.getTime())) {
|
||||
const year = d.getFullYear();
|
||||
const month = String(d.getMonth() + 1).padStart(2, "0");
|
||||
const day = String(d.getDate()).padStart(2, "0");
|
||||
const hours = String(d.getHours()).padStart(2, "0");
|
||||
const minutes = String(d.getMinutes()).padStart(2, "0");
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}`;
|
||||
}
|
||||
}
|
||||
return String(val);
|
||||
}
|
||||
|
||||
function parseCity(cityVal: unknown): string {
|
||||
if (!cityVal) return "";
|
||||
if (typeof cityVal === "string") {
|
||||
try {
|
||||
const parsed = JSON.parse(cityVal);
|
||||
if (Array.isArray(parsed) && parsed[0]?.label) {
|
||||
return parsed[0].label;
|
||||
}
|
||||
} catch {}
|
||||
return cityVal;
|
||||
}
|
||||
if (Array.isArray(cityVal) && cityVal[0]?.label) {
|
||||
return cityVal[0].label;
|
||||
}
|
||||
return String(cityVal);
|
||||
}
|
||||
|
||||
function formatAmount(money: any): string {
|
||||
if (!money) return "CNY 0.00";
|
||||
if (typeof money === "number") return `CNY ${money.toFixed(2)}`;
|
||||
if (typeof money === "string") {
|
||||
const n = parseFloat(money.replace(/[^0-9.-]/g, ""));
|
||||
return isNaN(n) ? money : `CNY ${n.toFixed(2)}`;
|
||||
}
|
||||
if (typeof money === "object") {
|
||||
const currency = money.standardStrCode || money.currency || "CNY";
|
||||
const amountNum = parseFloat(money.standard || money.amount || 0);
|
||||
return `${currency} ${isNaN(amountNum) ? "0.00" : amountNum.toFixed(2)}`;
|
||||
}
|
||||
return String(money);
|
||||
}
|
||||
|
||||
function resolveSpecificationName(specId: unknown): string {
|
||||
if (!specId || typeof specId !== "string") return "未知模板";
|
||||
if (specId.includes("REQUISITION_TRIP") || specId.includes("trip")) return "差旅申请单";
|
||||
if (specId.includes("REIMBURSEMENT") || specId.includes("expense")) return "报销单";
|
||||
if (specId.includes("LOAN") || specId.includes("loan")) return "借款单";
|
||||
if (specId.includes("PAYMENT") || specId.includes("payment")) return "对公付款单";
|
||||
return specId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将合思原始单据流对象转译为标准 LLM / 审核视图 Markdown (单据字段转译器)
|
||||
*/
|
||||
export function translateBillFlowToMarkdown(
|
||||
rawFlow: Record<string, unknown>,
|
||||
feeTypeMap?: Map<string, { name?: string; path?: string }>
|
||||
): string {
|
||||
const flowIdObj = (rawFlow.flowId && typeof rawFlow.flowId === "object" ? rawFlow.flowId : rawFlow) as Record<string, any>;
|
||||
const form = (flowIdObj.form && typeof flowIdObj.form === "object" ? flowIdObj.form : {}) as Record<string, any>;
|
||||
|
||||
const code = form.code || flowIdObj.code || "未知单号";
|
||||
const title = form.title || flowIdObj.title || "<无标题>";
|
||||
const rawState = flowIdObj.state || "approving";
|
||||
const stateLabel = String(rawState).toUpperCase() === "APPROVING" ? "审批中" : rawState;
|
||||
const submitTime = formatDate(form.submitDate || flowIdObj.createTime);
|
||||
const templateName = resolveSpecificationName(form.specificationId);
|
||||
const submitterName = form.submitterId?.name || (typeof form.submitterId === "string" ? form.submitterId : "未知");
|
||||
const requisitionDate = formatDate(form.requisitionDate);
|
||||
const totalMoney = formatAmount(form.requisitionMoney || form.amount);
|
||||
|
||||
const lines: string[] = [];
|
||||
lines.push(`# 单据:${code}`);
|
||||
lines.push("");
|
||||
lines.push("## 基本信息");
|
||||
lines.push("");
|
||||
lines.push(`- **状态**: ${stateLabel} (${String(rawState).toLowerCase()})`);
|
||||
lines.push(`- **提交时间**: ${submitTime}`);
|
||||
lines.push("");
|
||||
lines.push(`### 单据信息(${code})`);
|
||||
lines.push("");
|
||||
lines.push(`- **单据模板**: \`${templateName}\``);
|
||||
lines.push(`- **补充申请**: <无>`);
|
||||
lines.push(`- **标题**: \`${title}\``);
|
||||
lines.push(`- **提交人**: ${submitterName}`);
|
||||
if (requisitionDate) {
|
||||
lines.push(`- **申请日期**: ${requisitionDate}`);
|
||||
}
|
||||
lines.push(`- **单号**: \`${code}\``);
|
||||
lines.push(`- **提交日期**: ${submitTime}`);
|
||||
lines.push(`- **申请金额**: ${totalMoney}`);
|
||||
lines.push("");
|
||||
|
||||
// 行程规划
|
||||
const itineraries = Array.isArray(form.itineraries) ? form.itineraries : [];
|
||||
lines.push(`### 行程规划(共 ${itineraries.length} 条)`);
|
||||
lines.push("");
|
||||
|
||||
// 费用明细
|
||||
const details = Array.isArray(form.details) ? form.details : [];
|
||||
lines.push(`### 费用明细(共 ${details.length} 条)`);
|
||||
lines.push("");
|
||||
|
||||
details.forEach((item: any, idx: number) => {
|
||||
const num = idx + 1;
|
||||
lines.push(`#### 明细 ${num}`);
|
||||
lines.push("");
|
||||
|
||||
const feeForm = item.feeTypeForm || item;
|
||||
const feeTypeId = item.feeTypeId || feeForm.feeTypeId || "";
|
||||
let feeTypeName = "住宿费";
|
||||
let feeTypePath = "差旅报销/住宿费";
|
||||
|
||||
if (feeTypeMap?.has(feeTypeId)) {
|
||||
const match = feeTypeMap.get(feeTypeId)!;
|
||||
feeTypeName = match.name || feeTypeName;
|
||||
feeTypePath = match.path || feeTypeName;
|
||||
} else if (typeof feeTypeId === "string") {
|
||||
if (feeTypeId.includes("hotel") || feeTypeId.includes("住宿")) {
|
||||
feeTypeName = "住宿费";
|
||||
feeTypePath = "差旅报销/住宿费";
|
||||
} else if (feeTypeId.includes("meal") || feeTypeId.includes("餐")) {
|
||||
feeTypeName = "餐饮费";
|
||||
feeTypePath = "业务招待/餐饮费";
|
||||
} else if (feeTypeId.includes("traffic") || feeTypeId.includes("交通")) {
|
||||
feeTypeName = "市内交通费";
|
||||
feeTypePath = "差旅报销/市内交通费";
|
||||
}
|
||||
}
|
||||
|
||||
lines.push(`- **费用类型**: ${feeTypePath}(name=${feeTypeName})`);
|
||||
lines.push(`- **金额**: ${formatAmount(feeForm.amount)}`);
|
||||
if (feeForm.feeDate) {
|
||||
lines.push(`- **日期**: ${formatDateTime(feeForm.feeDate)}`);
|
||||
}
|
||||
const city = parseCity(feeForm.city);
|
||||
if (city) {
|
||||
lines.push(`- **城市**: ${city}`);
|
||||
}
|
||||
if (feeForm.consumptionReasons) {
|
||||
lines.push(`- **消费事由**: \`${feeForm.consumptionReasons}\``);
|
||||
}
|
||||
if (feeForm.detailId) {
|
||||
lines.push(`- **费用ID**: \`${feeForm.detailId}\``);
|
||||
}
|
||||
lines.push(`- **明细序号**: ${feeForm.detailNo || num}`);
|
||||
lines.push("");
|
||||
});
|
||||
|
||||
return lines.join("\n");
|
||||
}
|
||||
@@ -24,7 +24,7 @@ export async function listStaffsProtected(
|
||||
limit,
|
||||
hasMore,
|
||||
hint: hasMore
|
||||
? `企业员工共 ${total} 人,当前仅展示前 ${staffs.length} 条以防止上下文溢出。可使用 'hose contact search <姓名|工号>' 精准检索,或附加 '--limit <数量>' / '-o <文件路径>' / '--full'`
|
||||
? `企业员工共 ${total} 人,当前仅展示前 ${staffs.length} 条以防止上下文溢出。可使用 'hose-use contact search <姓名|工号>' 精准检索,或附加 '--limit <数量>' / '-o <文件路径>' / '--full'`
|
||||
: undefined,
|
||||
staffs,
|
||||
};
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
|
||||
- `GET /api/glue/v1/organization/permissions/query?model=ROLE&corpId=...`
|
||||
|
||||
CLI 入口为 `hose permission get`(也支持 `hose permissions get`)。写入权限仍需通过 Web 端明确操作,CLI 不提供写操作。
|
||||
CLI 入口为 `hose-use permission get`(也支持 `hose-use permissions get`)。写入权限仍需通过 Web 端明确操作,CLI 不提供写操作。
|
||||
@@ -6,4 +6,4 @@
|
||||
- `GET /api/v1/organization/roleGroups?corpId=...`:角色组及其角色定义
|
||||
- `GET /api/v1/organization/staffs/byRole?roleDefId=...&corpId=...`:指定角色的员工成员
|
||||
|
||||
CLI 入口为 `hose role list`、`hose role groups` 和 `hose role members <角色 ID|编码|名称>`。
|
||||
CLI 入口为 `hose-use role list`、`hose-use role groups` 和 `hose-use role members <角色 ID|编码|名称>`。
|
||||
+1
-1
@@ -1 +1 @@
|
||||
export const VERSION = "0.7.1";
|
||||
export const VERSION = "0.7.2";
|
||||
Reference in new issue
Block a user