Files
hose-use/src/domains/bill
gitea 4e36a1d9a5 feat(approval): introduce sqlite rule engine, deterministic gateway, and hose-aipro cli (v0.7.0)
- Pure Rule Model & AST Parser:
  - Eliminate redundant title field; model rules purely via scope (scene index) and natural language body.
  - Implement AST parser for inline clauses: [action]{硬性|弹性|建议|特殊}.
  - Validate and enforce preference references with @{级别} syntax, strictly blocking invalid grammar.

- Embedded SQLite Database & Repository:
  - Native bun:sqlite integration with zero external dependencies, stored at ~/.config/hose-use/approval.db.
  - 5 core schemas: rules, preferences, approval_runs, approval_findings, and aipro_logs.
  - Support deduplicated scope indexing (listScopes with 1-based indices) and scope drill-down (getScopeDetail).

- Bill Requisition & Backlog Query Extension:
  - Add formatFlowAsBill adapter in domains/bill/tools.ts.
  - Fall back to flow and backlog inspection when bills are not found in invoice endpoints, unlocking full structured inspection for requisitions (such as S26000001) and loan requests.

- Deterministic Approval Gateway & Lifecycle:
  - Enforce mandatory approval lifecycle: points -> checklist -> review -> decide.
  - Physical gateway blocking: forbid decision if audit checklist is missing or empty, or if pending points remain unverified.
  - Hard tier severance: automatically sever and throw GatewayBlockError on approval attempts violating {硬性} clauses.

- Dedicated hose-aipro Global CLI & Immutable Audit Ledger:
  - Register secondary global binary hose-aipro alongside hose-use in package.json and build-binary.mjs.
  - Automatically record every AI Pro invocation, document context, args snapshot, operator, status, and verdict in aipro_logs.
  - Provide intuitive subcommands: points, checklist, review, decide, logs, rules.
  - Bump project version to v0.7.0 and regenerate OpenAPI bundles.
2026-09-06 19:03:06 +08:00
..
2026-09-05 21:56:38 +08:00

Bill 域说明

本目录负责合思/易快报(ekuaibao)费控单据、报销单、借款单、发票、关联引用、审批动作与数据实体元数据字典的检索、执行与格式化。

文件结构

src/domains/bill/
├── api.ts              # 传输层:调用单据、审批详情、审批动作、组织架构和费用类型目录 API
├── tools.ts            # 业务编排层:DataLink 字段字典映射、单号匹配、格式化与动作编排
├── types.ts            # 模型层:Zod Schema 与 TypeScript 类型定义
├── bill.test.ts        # 单元测试
└── README.bill.md      # 本说明文件

核心能力

  1. 单据检索与分页 (searchAndFormatBills):
    • 跨单据池查询费用明细、报销单、借款单与发票。
    • 支持按单号(code)、阶段(stage)、状态(state)、关键字(keyword)过滤。
  2. 按单号/ID 精确查询 (getBillByCodeOrId):
    • 根据业务单号(如 n0GMIM0dkQmKbS)或单据 ID(如 ID01TRzg7HMLcb)查询单据。
  3. DataLink 字段元数据字典 (getFieldDictionary):
    • 自动拉取企业全部实体模型定义,将混淆代码字段(如 E_ae10..._payMoney)还原为人类友好的中文字段名(如 报销金额)。
  4. 关联引用二级解析 (getBillReferences):
    • 通过审批详情、组织架构和费用类型目录批量解析提交人、归属人、费用承担部门与费用类型;
    • 保留原始 ID,并在 JSON 中提供 name、code、部门 path 与未解析 ID;目录在进程内按企业缓存 10 分钟。
  5. 单据关联链 (getBillRelations):
    • 从审批详情中的 expenseLink、loan、requisition、contract 等关系字段抽取前置单据树,保留原始对象供 JSON 下钻。
  6. 附件标准化 (getBillAttachments):
    • 递归识别表单中的 attachments、fileId、fileName、key 与原件 URL,统一输出附件清单并去重。
  7. 审批动作套件:
    • approveBill 调用 POST /api/flow/v2/backlogs/$<backlogId>,使用 freeflow.agree 节点报文;
    • rejectBill 调用 POST /api/flow/v2/backlogs/approveListWithNode,使用 freeflow.reject 批量报文,评论会转为 <p>...</p>;
    • transferBill 与 addNodeBill 共用 backlog 动作接口,分别使用 SHIFT_NODE、PRE_ADD_NODE/AFT_ADD_NODE;
    • 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。