Files
hose-use/web/src/views/RulesView.vue
T
gitea 36e21e5dc2 feat: AI PRO 本地 Web 控制台与聚合报表
持久化常驻复用现有 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。
2026-11-05 19:25:52 +08:00

117 lines
5.1 KiB
Vue

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { RefreshCw, Search } from 'lucide-vue-next'
import { getReport, runCommand, type AiProReport } from '../api/client'
const report = ref<AiProReport | null>(null)
const error = ref('')
const pointQuery = ref('1')
const pointResult = ref('')
const checklistSn = ref('')
const checklistResult = ref('')
function row(value: unknown): Record<string, unknown> {
return (value ?? {}) as Record<string, unknown>
}
async function load() {
error.value = ''
try {
report.value = await getReport()
} catch (err) {
error.value = err instanceof Error ? err.message : String(err)
}
}
async function query(target: 'points' | 'checklist') {
try {
const result = await runCommand<unknown>(
target === 'points' ? `points ${pointQuery.value} --json` : `checklist ${checklistSn.value} --json`
)
const text = typeof result === 'string' ? result : JSON.stringify(result, null, 2)
if (target === 'points') pointResult.value = text
else checklistResult.value = text
error.value = ''
} catch (err) {
error.value = err instanceof Error ? err.message : String(err)
}
}
onMounted(load)
</script>
<template>
<div class="p-7 space-y-5 max-w-6xl">
<header class="flex items-start justify-between gap-4">
<div>
<h1 class="text-xl font-semibold">规则与审核要点</h1>
<p class="text-sm text-text-muted mt-1">规约场景库、仲裁规则与单据核验清单</p>
</div>
<button class="btn-ghost" @click="load"><RefreshCw :size="15" />刷新</button>
</header>
<div v-if="error" class="card border-danger/30 bg-danger-soft text-danger text-sm whitespace-pre-wrap">{{ error }}</div>
<div class="grid md:grid-cols-2 gap-4">
<section class="card">
<h2 class="text-sm font-semibold mb-3">规约场景 ({{ report?.summary.scopes ?? 0 }})</h2>
<div class="space-y-1.5 max-h-72 overflow-auto">
<div v-for="(scope, i) in report?.scopes ?? []" :key="i" class="flex items-center justify-between text-sm border-b border-border/60 pb-1.5">
<span>{{ row(scope).scope }}</span>
<span class="text-xs text-text-muted">#{{ row(scope).index }} · {{ row(scope).ruleCount }} 条规则</span>
</div>
</div>
</section>
<section class="card">
<h2 class="text-sm font-semibold mb-3">仲裁规则 ({{ report?.summary.rules ?? 0 }})</h2>
<div class="space-y-2 max-h-72 overflow-auto">
<div v-for="(rule, i) in report?.rules ?? []" :key="i" class="text-xs border-b border-border/60 pb-2">
<div class="flex justify-between text-text-muted"><span>#{{ row(rule).code }} · {{ row(rule).scope }}</span><span>{{ row(rule).status }}</span></div>
<div class="mt-1 text-text whitespace-pre-wrap">{{ row(rule).body }}</div>
</div>
</div>
</section>
</div>
<div class="grid md:grid-cols-2 gap-4">
<section class="card space-y-2">
<h2 class="text-sm font-semibold">查询场景要点</h2>
<div class="flex gap-2">
<input v-model="pointQuery" class="input" placeholder="索引号或场景名" />
<button class="btn-ghost" @click="query('points')"><Search :size="15" /></button>
</div>
<pre v-if="pointResult" class="text-xs bg-bg rounded-lg p-3 overflow-auto max-h-56 whitespace-pre-wrap">{{ pointResult }}</pre>
</section>
<section class="card space-y-2">
<h2 class="text-sm font-semibold">单据核验清单</h2>
<div class="flex gap-2">
<input v-model="checklistSn" class="input" placeholder="单号" />
<button class="btn-ghost" :disabled="!checklistSn" @click="query('checklist')"><Search :size="15" /></button>
</div>
<pre v-if="checklistResult" class="text-xs bg-bg rounded-lg p-3 overflow-auto max-h-56 whitespace-pre-wrap">{{ checklistResult }}</pre>
</section>
</div>
<section v-if="report?.findings.length" class="card">
<h2 class="text-sm font-semibold mb-3">已挂载审核要点 ({{ report.findings.length }})</h2>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead><tr class="text-left text-xs text-text-muted border-b border-border">
<th class="py-2 pr-3">单号</th><th class="py-2 pr-3">状态</th><th class="py-2 pr-3">严格程度</th><th class="py-2">条款</th>
</tr></thead>
<tbody>
<tr v-for="(f, i) in report?.findings ?? []" :key="i" class="border-b border-border/60 last:border-0">
<td class="py-2 pr-3 font-mono text-xs">{{ row(f).documentSn }}</td>
<td class="py-2 pr-3"><span class="tag" :class="row(f).status === 'PASS' ? 'bg-success-soft text-success' : row(f).status === 'FAIL' ? 'bg-danger-soft text-danger' : 'bg-warning-soft text-warning'">{{ row(f).status }}</span></td>
<td class="py-2 pr-3 text-xs">{{ row(f).strictness }}</td>
<td class="py-2 text-xs text-text-muted">{{ row(f).content }}</td>
</tr>
</tbody>
</table>
</div>
</section>
</div>
</template>