Merge pull request #46 from yunyingk/fix/approval-corp-isolation-and-release-packaging
fix(approval): isolate runs by corp, handle execution error, bundle hose-aipro alias, and bump to v0.7.1
This commit is contained in:
15 files changed
+156
-62
No files matched your search
@@ -42,12 +42,27 @@ jobs:
|
||||
- name: Package release archives
|
||||
run: |
|
||||
sudo apt-get update && sudo apt-get install -y zip
|
||||
cd dist/bin
|
||||
tar -czf hose-use-linux-x64.tar.gz hose-use-linux-x64
|
||||
tar -czf hose-use-linux-arm64.tar.gz hose-use-linux-arm64
|
||||
tar -czf hose-use-darwin-x64.tar.gz hose-use-darwin-x64
|
||||
tar -czf hose-use-darwin-arm64.tar.gz hose-use-darwin-arm64
|
||||
zip -q hose-use-windows-x64.zip hose-use-windows-x64.exe
|
||||
package_unix() {
|
||||
local binary="$1"
|
||||
local archive="$2"
|
||||
local stage
|
||||
stage=$(mktemp -d)
|
||||
cp "dist/bin/${binary}" "${stage}/${binary}"
|
||||
ln -s "${binary}" "${stage}/hose-aipro"
|
||||
tar -czf "dist/bin/${archive}" -C "${stage}" "${binary}" hose-aipro
|
||||
rm -rf "${stage}"
|
||||
}
|
||||
|
||||
package_unix hose-use-linux-x64 hose-use-linux-x64.tar.gz
|
||||
package_unix hose-use-linux-arm64 hose-use-linux-arm64.tar.gz
|
||||
package_unix hose-use-darwin-x64 hose-use-darwin-x64.tar.gz
|
||||
package_unix hose-use-darwin-arm64 hose-use-darwin-arm64.tar.gz
|
||||
|
||||
stage=$(mktemp -d)
|
||||
cp dist/bin/hose-use-windows-x64.exe "${stage}/hose-use-windows-x64.exe"
|
||||
printf '@echo off\r\n"%%~dp0hose-use-windows-x64.exe" %%*\r\n' > "${stage}/hose-aipro.cmd"
|
||||
(cd "${stage}" && zip -q "${GITHUB_WORKSPACE}/dist/bin/hose-use-windows-x64.zip" hose-use-windows-x64.exe hose-aipro.cmd)
|
||||
rm -rf "${stage}"
|
||||
|
||||
- name: Publish GitHub Release
|
||||
env:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hose-use",
|
||||
"version": "0.7.0",
|
||||
"version": "0.7.1",
|
||||
"description": "合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号登录、企业租户切换、单据明细检索、工作流管理、内置 HTTP 服务与常驻守护进程。",
|
||||
"author": {
|
||||
"name": "yingqing"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# hose-use (v0.7.0)
|
||||
# hose-use (v0.7.1)
|
||||
|
||||
合思/易快报(ekuaibao)企业级 CLI 命令行工具与底层 SDK。
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
||||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "hose-use API & MCP Tools Specification",
|
||||
"version": "0.7.0",
|
||||
"version": "0.7.1",
|
||||
"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.0
|
||||
version: 0.7.1
|
||||
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.0",
|
||||
"version": "0.7.1",
|
||||
"module": "src/server.ts",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
||||
+3
-1
@@ -152,9 +152,10 @@ fi
|
||||
chmod +x "$TMP_FILE"
|
||||
mv "$TMP_FILE" "$TARGET_PATH"
|
||||
|
||||
# Also create 'hose' symlink if possible
|
||||
# Create command aliases pointing at the same 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
|
||||
|
||||
# Ad-hoc sign on macOS
|
||||
@@ -177,4 +178,5 @@ echo " 2. List corps: hose-use corps list"
|
||||
echo " 3. List workflows: hose-use workflow list"
|
||||
echo " 4. Switch mode: hose-use config mode stateless"
|
||||
echo " 5. Self-update: hose-use update"
|
||||
echo " AI PRO alias: hose-aipro"
|
||||
echo ""
|
||||
@@ -1,12 +1,12 @@
|
||||
---
|
||||
name: hose-use
|
||||
description: "v0.6.0: 合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号 API 登录、租户切换、单据检索与审批动作、工作流跨域扫描、内置 HTTP 交互文档与常驻守护进程。"
|
||||
description: "v0.7.1: 合思/易快报 (ekuaibao) 企业级 SaaS CLI 与底层 SDK:多账号 API 登录、租户切换、单据检索与审批动作、工作流跨域扫描、内置 HTTP 交互文档与常驻守护进程。"
|
||||
metadata:
|
||||
version: 0.6.0
|
||||
short-description: 合思/易快报企业级 CLI 工具与底层 SDK (v0.6.0)
|
||||
version: 0.7.1
|
||||
short-description: 合思/易快报企业级 CLI 工具与底层 SDK (v0.7.1)
|
||||
---
|
||||
|
||||
# hose-use (v0.7.0)
|
||||
# hose-use (v0.7.1)
|
||||
|
||||
在具备 MCP 的 AI 智能体环境中,**优先使用 `hose_cli` 单工具网关**,传入 `command: string` 执行;在终端或自动化脚本中,直接调用全局 `hose` 或 `hose-use` 命令行。
|
||||
本 Skill 是智能体的路由分发层:保持主文档简明,遇到复杂业务时深入查阅对应的专属参考文档(`references/*.md`)。
|
||||
|
||||
+25
-15
@@ -19,18 +19,9 @@ export async function runAiProCli(rawArgs: string[]): Promise<{ stdout: string;
|
||||
});
|
||||
|
||||
const corp = runtime.selectedCorp;
|
||||
if (!corp) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose-use auth login 登录。\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
const client = await createEkbClient(corp);
|
||||
const corpId = corp.corpId || corp.id;
|
||||
const repo = new ApprovalRepository();
|
||||
const service = new ApprovalService(repo);
|
||||
let client: Awaited<ReturnType<typeof createEkbClient>> | undefined;
|
||||
|
||||
const positional: string[] = [];
|
||||
for (let i = 0; i < rawArgs.length; i++) {
|
||||
@@ -56,7 +47,22 @@ export async function runAiProCli(rawArgs: string[]): Promise<{ stdout: string;
|
||||
const command = (positional[0] || "help").toLowerCase();
|
||||
const targetSn = positional[1] || stringOption(parsed.options, ["code", "sn", "id", "target"]);
|
||||
const args = positional.slice(1);
|
||||
const operator = corp.staffId || corp.name || "AI-Agent";
|
||||
const corpId = corp?.corpId || corp?.id;
|
||||
const operator = corp?.staffId || corp?.name || "AI-Agent";
|
||||
|
||||
const requireCorpId = () => {
|
||||
if (!corpId) {
|
||||
throw new Error("未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose-use auth login 登录。");
|
||||
}
|
||||
return corpId;
|
||||
};
|
||||
|
||||
const getClient = async () => {
|
||||
const activeCorpId = requireCorpId();
|
||||
if (!corp) throw new Error("未找到当前企业配置");
|
||||
client ??= await createEkbClient(corp);
|
||||
return { client, corpId: activeCorpId };
|
||||
};
|
||||
|
||||
try {
|
||||
switch (command) {
|
||||
@@ -68,7 +74,8 @@ export async function runAiProCli(rawArgs: string[]): Promise<{ stdout: string;
|
||||
}
|
||||
|
||||
const scopeOption = stringOption(parsed.options, ["scope", "s"]);
|
||||
const result = await service.injectAuditPoints(client, corpId, targetSn, {
|
||||
const context = await getClient();
|
||||
const result = await service.injectAuditPoints(context.client, context.corpId, targetSn, {
|
||||
scope: scopeOption ? (isNaN(Number(scopeOption)) ? scopeOption : Number(scopeOption)) : undefined,
|
||||
});
|
||||
|
||||
@@ -123,7 +130,8 @@ export async function runAiProCli(rawArgs: string[]): Promise<{ stdout: string;
|
||||
throw new Error("请提供单号: hose-aipro checklist <单号>");
|
||||
}
|
||||
|
||||
const { run, findings } = service.getAuditChecklist(targetSn);
|
||||
const activeCorpId = requireCorpId();
|
||||
const { run, findings } = service.getAuditChecklist(targetSn, activeCorpId);
|
||||
if (!run || findings.length === 0) {
|
||||
repo.logAiProAction({
|
||||
action: "checklist",
|
||||
@@ -211,7 +219,8 @@ export async function runAiProCli(rawArgs: string[]): Promise<{ stdout: string;
|
||||
);
|
||||
}
|
||||
|
||||
const updatedFindings = service.evaluateAuditPoints(targetSn, updates);
|
||||
const activeCorpId = requireCorpId();
|
||||
const updatedFindings = service.evaluateAuditPoints(targetSn, updates, activeCorpId);
|
||||
const pendingCount = updatedFindings.filter((f) => f.checkStatus === "PENDING").length;
|
||||
|
||||
repo.logAiProAction({
|
||||
@@ -267,7 +276,8 @@ export async function runAiProCli(rawArgs: string[]): Promise<{ stdout: string;
|
||||
const requestedAction = command === "approve" ? "approve" : command === "reject" ? "reject" : (stringOption(parsed.options, ["action"]) as any);
|
||||
const userComment = stringOption(parsed.options, ["comment", "message", "m"]);
|
||||
|
||||
const decisionResult = await service.decideAudit(client, corpId, targetSn, {
|
||||
const context = await getClient();
|
||||
const decisionResult = await service.decideAudit(context.client, context.corpId, targetSn, {
|
||||
requestedAction,
|
||||
apply,
|
||||
comment: userComment,
|
||||
|
||||
@@ -101,7 +101,7 @@ export async function handleApprovalCommand(
|
||||
throw new Error("请提供单号或单据 ID: hose-use approval audit checklist <单号>");
|
||||
}
|
||||
|
||||
const { run, findings } = service.getAuditChecklist(targetSn);
|
||||
const { run, findings } = service.getAuditChecklist(targetSn, corpId);
|
||||
if (!run || findings.length === 0) {
|
||||
const errorMsg =
|
||||
`[审批链路阻断] 单据 [${targetSn}] 尚未注入任何明细级审核要点(要点列表为空)!\n` +
|
||||
@@ -195,7 +195,7 @@ export async function handleApprovalCommand(
|
||||
}
|
||||
|
||||
try {
|
||||
const updatedFindings = service.evaluateAuditPoints(targetSn, updates);
|
||||
const updatedFindings = service.evaluateAuditPoints(targetSn, updates, corpId);
|
||||
const headers = ["#", "严格程度", "审核要点内容", "核验状态", "事实证据与说明"];
|
||||
const rows = updatedFindings.map((f, i) => [
|
||||
i + 1,
|
||||
@@ -308,7 +308,7 @@ export async function handleApprovalCommand(
|
||||
}
|
||||
|
||||
// 检查当前是否已注入要点
|
||||
const { run } = service.getAuditChecklist(targetSn);
|
||||
const { run } = service.getAuditChecklist(targetSn, corpId);
|
||||
if (!run) {
|
||||
// 自动触发第一步:注入并出审核要点
|
||||
return await handleApprovalCommand(
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Database } from "bun:sqlite";
|
||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
||||
import { closeApprovalDatabase, getApprovalDatabase } from "./db.js";
|
||||
import { ApprovalRepository } from "./repository.js";
|
||||
import { ApprovalService } from "./service.js";
|
||||
import { ApprovalRuleValidationError } from "./types.js";
|
||||
|
||||
describe("Approval Domain - SQLite 持久化与规约仓储", () => {
|
||||
@@ -248,5 +249,51 @@ describe("Approval Domain - SQLite 持久化与规约仓储", () => {
|
||||
expect(logs[0]!.action).toBe("decide");
|
||||
expect(logs[0]!.status).toBe("BLOCKED");
|
||||
});
|
||||
});
|
||||
|
||||
test("审批运行按当前企业隔离相同单号", () => {
|
||||
const corpARun = repo.createOrResetApprovalRun({
|
||||
documentSn: "SAME-SN",
|
||||
corpId: "corp-a",
|
||||
decision: "PENDING",
|
||||
});
|
||||
repo.injectFindings(corpARun.id, [
|
||||
{ clauseText: "企业 A 要点", strictness: "硬性", checkStatus: "PENDING" },
|
||||
]);
|
||||
|
||||
const corpBRun = repo.createOrResetApprovalRun({
|
||||
documentSn: "SAME-SN",
|
||||
corpId: "corp-b",
|
||||
decision: "PENDING",
|
||||
});
|
||||
expect(corpBRun.id).not.toBe(corpARun.id);
|
||||
expect(repo.getAuditChecklist("SAME-SN", "corp-a").findings[0]?.clauseText).toBe("企业 A 要点");
|
||||
expect(repo.getAuditChecklist("SAME-SN", "corp-b").findings).toEqual([]);
|
||||
});
|
||||
|
||||
test("下游审批执行失败时将运行标记为 ERROR", async () => {
|
||||
const run = repo.createOrResetApprovalRun({
|
||||
documentSn: "EXEC-FAIL",
|
||||
corpId: "corp-a",
|
||||
decision: "PENDING",
|
||||
});
|
||||
repo.injectFindings(run.id, [
|
||||
{ clauseText: "已核验", strictness: "硬性", checkStatus: "PASS" },
|
||||
]);
|
||||
|
||||
const service = new ApprovalService(repo);
|
||||
const client = {
|
||||
post: async () => {
|
||||
throw new Error("downstream unavailable");
|
||||
},
|
||||
} as any;
|
||||
|
||||
await expect(
|
||||
service.decideAudit(client, "corp-a", "EXEC-FAIL", {
|
||||
apply: true,
|
||||
requestedAction: "approve",
|
||||
}),
|
||||
).rejects.toThrow("downstream unavailable");
|
||||
|
||||
expect(repo.getAuditChecklist("EXEC-FAIL", "corp-a").run?.decision).toBe("ERROR");
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Database } from "bun:sqlite";
|
||||
import { existsSync, mkdirSync } from "node:fs";
|
||||
import { chmodSync, existsSync, mkdirSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
|
||||
@@ -40,6 +40,11 @@ export function getApprovalDatabase(customPath?: string): Database {
|
||||
}
|
||||
|
||||
const db = new Database(targetPath);
|
||||
if (targetPath !== ":memory:") {
|
||||
// 规则、单据快照、审核证据和审计日志都可能包含敏感信息。
|
||||
// SQLite 默认文件权限受 umask 影响,不能依赖默认值保护凭证与业务数据。
|
||||
chmodSync(targetPath, 0o600);
|
||||
}
|
||||
currentDbPath = targetPath;
|
||||
activeDb = db;
|
||||
|
||||
|
||||
@@ -288,7 +288,7 @@ export class ApprovalRepository {
|
||||
// ===================== 审批运行与要点清单 (Runs & Findings) =====================
|
||||
|
||||
public createOrResetApprovalRun(input: CreateApprovalRunInput): ApprovalRunRecord {
|
||||
const existing = this.getLatestRunBySn(input.documentSn);
|
||||
const existing = this.getLatestRunBySn(input.documentSn, input.corpId ?? undefined);
|
||||
const now = Date.now();
|
||||
if (existing) {
|
||||
// 清理旧要点,重置运行记录
|
||||
@@ -339,10 +339,15 @@ export class ApprovalRepository {
|
||||
return this.getRunById(id)!;
|
||||
}
|
||||
|
||||
public getLatestRunBySn(documentSn: string): ApprovalRunRecord | null {
|
||||
const row = this.db
|
||||
.query("SELECT * FROM approval_runs WHERE document_sn = ? ORDER BY created_at DESC LIMIT 1")
|
||||
.get(documentSn.trim()) as any;
|
||||
public getLatestRunBySn(documentSn: string, corpId?: string): ApprovalRunRecord | null {
|
||||
const params: string[] = [documentSn.trim()];
|
||||
let sql = "SELECT * FROM approval_runs WHERE document_sn = ?";
|
||||
if (corpId !== undefined) {
|
||||
sql += " AND corp_id = ?";
|
||||
params.push(corpId);
|
||||
}
|
||||
sql += " ORDER BY created_at DESC LIMIT 1";
|
||||
const row = this.db.query(sql).get(...params) as any;
|
||||
return row ? this.mapRunRow(row) : null;
|
||||
}
|
||||
|
||||
@@ -464,11 +469,11 @@ export class ApprovalRepository {
|
||||
return this.mapFindingRow(updated);
|
||||
}
|
||||
|
||||
public getAuditChecklist(documentSn: string): {
|
||||
public getAuditChecklist(documentSn: string, corpId?: string): {
|
||||
run: ApprovalRunRecord | null;
|
||||
findings: ApprovalFindingRecord[];
|
||||
} {
|
||||
const run = this.getLatestRunBySn(documentSn);
|
||||
const run = this.getLatestRunBySn(documentSn, corpId);
|
||||
if (!run) {
|
||||
return { run: null, findings: [] };
|
||||
}
|
||||
@@ -632,4 +637,3 @@ export interface CreateAiProLogInput {
|
||||
summary?: string | null;
|
||||
}
|
||||
|
||||
|
||||
@@ -146,8 +146,8 @@ export class ApprovalService {
|
||||
/**
|
||||
* 查看单据当前审核清单状态
|
||||
*/
|
||||
public getAuditChecklist(documentSn: string) {
|
||||
return this.repo.getAuditChecklist(documentSn);
|
||||
public getAuditChecklist(documentSn: string, corpId?: string) {
|
||||
return this.repo.getAuditChecklist(documentSn, corpId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,9 +161,10 @@ export class ApprovalService {
|
||||
status: FindingCheckStatus;
|
||||
evidence?: string;
|
||||
reasoning?: string;
|
||||
}>
|
||||
}>,
|
||||
corpId?: string,
|
||||
): ApprovalFindingRecord[] {
|
||||
const { run, findings } = this.repo.getAuditChecklist(documentSn);
|
||||
const { run, findings } = this.repo.getAuditChecklist(documentSn, corpId);
|
||||
if (!run || findings.length === 0) {
|
||||
throw new ApprovalGatewayBlockedError(
|
||||
`[审批链路阻断] 单据 [${documentSn}] 尚未注入任何审核要点清单(要点列表为空)。\n` +
|
||||
@@ -203,7 +204,7 @@ export class ApprovalService {
|
||||
documentSn: string,
|
||||
options: DecideAuditOptions = {}
|
||||
): Promise<DecideAuditResult> {
|
||||
const { run, findings } = this.repo.getAuditChecklist(documentSn);
|
||||
const { run, findings } = this.repo.getAuditChecklist(documentSn, corpId);
|
||||
|
||||
// ── 核心门禁 1:如果审核要点列表为空,审批链路物理不通! ────────────────────
|
||||
if (!run || findings.length === 0) {
|
||||
@@ -293,24 +294,34 @@ export class ApprovalService {
|
||||
let appliedAction = options.requestedAction;
|
||||
let actionResult: unknown = undefined;
|
||||
|
||||
// 5. 如果开启了 --apply,由网关在内部安全受控地调用下游接口
|
||||
// 5. 如果开启了 --apply,由网关在内部安全受控地调用下游接口。
|
||||
// 远端失败时把本地运行标记为 ERROR,避免数据库显示“已决策”但实际未执行。
|
||||
if (options.apply) {
|
||||
if (!appliedAction) {
|
||||
appliedAction = decision === "REJECT" ? "reject" : decision === "APPROVE" || decision === "PASS_WITH_NOTE" ? "approve" : "comment";
|
||||
}
|
||||
|
||||
if (appliedAction === "reject") {
|
||||
actionResult = await rejectBill(client, corpId, documentSn, {
|
||||
comment: decisionSummary,
|
||||
});
|
||||
} else if (appliedAction === "approve") {
|
||||
actionResult = await approveBill(client, corpId, documentSn, {
|
||||
comment: decisionSummary,
|
||||
});
|
||||
} else {
|
||||
actionResult = await commentBill(client, corpId, documentSn, {
|
||||
comment: decisionSummary,
|
||||
try {
|
||||
if (appliedAction === "reject") {
|
||||
actionResult = await rejectBill(client, corpId, documentSn, {
|
||||
comment: decisionSummary,
|
||||
});
|
||||
} else if (appliedAction === "approve") {
|
||||
actionResult = await approveBill(client, corpId, documentSn, {
|
||||
comment: decisionSummary,
|
||||
});
|
||||
} else {
|
||||
actionResult = await commentBill(client, corpId, documentSn, {
|
||||
comment: decisionSummary,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
this.repo.updateApprovalRun(run.id, {
|
||||
decision: "ERROR",
|
||||
decisionSummary: `${decisionSummary}\n[下游执行失败] ${message}`,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
export const VERSION = "0.7.0";
|
||||
export const VERSION = "0.7.1";
|
||||
Reference in new issue
Block a user