fix(approval): isolate runs by corp, handle execution error, bundle hose-aipro alias, and bump to v0.7.1
This commit is contained in:
1 parent
77bd125ef3
commit
9fa4cfe38f
15 files changed
+156
-62
No files matched your search
+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,
|
||||
|
||||
Reference in new issue
Block a user