持久化常驻复用现有 hose-aipro service start(detached + pid 文件、
127.0.0.1:8889),本次只补前端与数据出口,不做端口/K8s 化改造。
是否映射公网由使用者自行决定,工具仍只监听回环地址。
- web/:Vue 3.5 + Vite 6 + TS + vue-router + Tailwind 3 子工程,配置对齐
本机 twc-approval-go-bridge/web(base /static/、outDir 到后端内嵌目录、
dev proxy → 8889、hash 路由)。5 个视图:总览、审批会话、规则与要点、
审计流水、命令终端;统一经 POST /api/cli 调用现有 CLI 能力。
- scripts/build/build-webui.mjs:把 Vite 产物 JS/CSS 内联成单文件 HTML,
生成 src/packaging/generated/webui.txt。生成物随 git 提交,编译二进制
与 CI 不需要安装前端依赖;.webui-dist/ 为忽略的中间产物。
- src/packaging/embedded-webui.ts:with { type: text } 内嵌。用 .txt 后缀
而非 .html,避开 Bun 对 .html 的 HTMLBundle 类型推断导致 tsc 报错。
- src/http/routes.ts:AI Pro daemon 暴露 GET /report(含 /report/* 兜底);
server.ts 启动日志补控制台地址;hose-use daemon 不暴露该路由。
- src/cli/commands/aipro/report.ts:新增 report --json 聚合命令,一次返回
场景/规则/会话/要点/流水/授权状态;单据快照等大字段不下发,避免撑爆
浏览器。命令在统一门禁之后,未激活仍会被拦截。
- 新增 embedded-webui / webui 路由 / report 聚合三组测试;同步
SKILL.md、README.md、packaging README、.gitignore 与 package.json 脚本。
校验:bun test 1108 pass / 0 fail,bun run check、check:readme 全通过;
编译二进制实测 GET /report 返回 200 且资源全内联(140KB、零外链),
POST /api/cli report --json 返回真实聚合数据(2 场景/3 规则/45 条流水)。
本次不打 tag、不发版,留待 0.9.4。
81 lines
2.4 KiB
TypeScript
81 lines
2.4 KiB
TypeScript
import { printJson } from "../../printer.js";
|
|
import { VERSION } from "../../../version.js";
|
|
import { checkAiProLicense } from "../../aipro-license.js";
|
|
import type { AiProCommandResult, AiProExecutionContext } from "./types.js";
|
|
|
|
/**
|
|
* hose-aipro report --json:本地 Web 控制台的聚合数据源。
|
|
* 只读、不联网;单据快照等大字段不返回,避免撑爆浏览器。
|
|
*/
|
|
export function handleAiProReport(ctx: AiProExecutionContext): AiProCommandResult {
|
|
const { repo, corp, corpId, operator } = ctx;
|
|
|
|
const scopes = repo.listScopes("active");
|
|
const rules = repo.listRules();
|
|
const runs = repo.listRuns({ corpId, limit: 500 });
|
|
const logs = repo.listAiProLogs(undefined, 200);
|
|
const license = checkAiProLicense();
|
|
|
|
const runRows = runs.map((run) => ({
|
|
id: run.id,
|
|
shortId: run.shortId,
|
|
documentSn: run.documentSn,
|
|
corpId: run.corpId,
|
|
decision: run.decision,
|
|
createdAt: run.createdAt,
|
|
updatedAt: run.updatedAt,
|
|
findingsCount: repo.getFindingsByRunId(run.id).length,
|
|
}));
|
|
|
|
const findings = runs.flatMap((run) =>
|
|
repo.getFindingsByRunId(run.id).map((finding) => ({
|
|
runId: run.shortId || run.id,
|
|
documentSn: run.documentSn,
|
|
ruleCode: finding.ruleCode,
|
|
status: finding.checkStatus,
|
|
strictness: finding.strictness,
|
|
content: finding.clauseText,
|
|
evidence: finding.evidence,
|
|
reasoning: finding.reasoning,
|
|
}))
|
|
);
|
|
|
|
const payload = {
|
|
version: VERSION,
|
|
generatedAt: new Date().toISOString(),
|
|
corp: corp
|
|
? {
|
|
id: corp.id,
|
|
name: corp.name,
|
|
staffId: corp.credentials?.staffId || corp.staffId || null,
|
|
baseUrl: corp.baseUrl || null,
|
|
source: corp.source || null,
|
|
}
|
|
: null,
|
|
operator,
|
|
license: license.ok
|
|
? {
|
|
activated: true,
|
|
subject: license.payload.sub,
|
|
expiresAt: new Date(license.payload.exp * 1000).toISOString(),
|
|
maxVersion: license.payload.maxVersion,
|
|
}
|
|
: { activated: false, reason: license.reason, message: license.message },
|
|
summary: {
|
|
scopes: scopes.length,
|
|
rules: rules.length,
|
|
runs: runRows.length,
|
|
pending: runRows.filter((run) => run.decision === "PENDING").length,
|
|
findings: findings.length,
|
|
logs: logs.length,
|
|
},
|
|
scopes,
|
|
rules,
|
|
runs: runRows,
|
|
findings,
|
|
logs,
|
|
};
|
|
|
|
return { stdout: printJson(payload) + "\n", stderr: "", exitCode: 0 };
|
|
}
|