合入报告导出为自包含 HTML(数字点得开口径、来源、计算方式)与可验证报告数字详情里的口径卡一节;和可验证报告的遮罩改造合并:口径卡只给 id 的规则(有指标的值取自遮罩列、文档里写成「已遮罩」的)照旧,随文件附带的卡才附上它的输入指向的查询快照;数字详情保留显示文字核对和超过 2^53 的数照 JSON 原文显示,口径卡一节里输入的值同样照原文;样本页从 16 份变成 17 份

This commit is contained in:
ThearchyHelios
2026-10-13 10:03:24 +08:00
17 changed files with 2120 additions and 60 deletions
+43 -7
View File
@@ -19,8 +19,10 @@
报告撰写节点把值不给的写成「已遮罩」;还写着原值的老文档(升级前生成的,或者生成之后数据源才设的遮罩)整份只给 id、
不附带它引用的工件——哪些指标的值不给和写作目录同一个判断(metric_word 的 sure:只按确定取自遮罩列的认,由调用方按
证据面板的那一套认好交进来,api/evidence.py 的 certain_masks),SQL 认不准时没确定取自遮罩列的普通金额照常附带。
文档里写成「已遮罩」的指标所在的口径卡一律只给 id。只给 id 的工件,服务端的文件和 id 对不上的另标 mismatch、解析
不出来的另标 unparsable,核对页照实说(对不上的判不通过)。没被报告引用的工件不嵌。
文档里写成「已遮罩」的指标所在的口径卡一律只给 id。随文件附带的口径卡,它记着的输入指向的查询快照也一并附上(遮罩
规则同上):点开数字时看得到每个输入的 SQL 和被引用的行,引用链(④)按「已核对的口径卡的输入」认它们。只给 id 的
工件,服务端的文件和 id 对不上的另标 mismatch、解析不出来的另标 unparsable,核对页照实说(对不上的判不通过)。没被
报告引用、也没被附带的口径卡的输入引用的工件不嵌。
- 封存之后追加的事件(按需裁判、审批质询这类批注)单列:类型、序号、内容摘要,不进清单。
它只证明「内部一致」:数字、文档、运行记录彼此对得上,而且没被改过。真伪要拿页面上的封存哈希和系统里这次
@@ -1011,6 +1013,30 @@ def _cited_artifacts(doc: dict[str, Any]) -> list[tuple[str, str, str | None]]:
return list(dict.fromkeys(out))
def _card_input_queries(card: Any) -> list[tuple[str, str | None]]:
"""口径卡记着的输入引用的查询快照:(工件 id, 输入来自的节点),按先后、按工件去重。
只认 cell() 取的格、Agent 交来的字段这两类带着定位的输入(nodes.*、input.* 的取值不走查询快照)。
卡是调用方确认过随文件附带的那份(遮罩的、文件不在的不进来):出处面板据此展示每个输入的 SQL 和被引用的行。"""
out: list[tuple[str, str | None]] = []
seen: set[str] = set()
if not isinstance(card, dict):
return out
for metric in card.get("metrics") or []:
if not isinstance(metric, dict):
continue
for item in metric.get("inputs") or []:
if not isinstance(item, dict) or item.get("via") not in ("tool_cell", "agent_field"):
continue
artifact = item.get("artifact")
if not isinstance(artifact, str) or not artifact or artifact in seen:
continue
seen.add(artifact)
owner = item.get("node_id")
out.append((artifact, str(owner) if owner else None))
return out
class _Artifacts:
"""嵌进页面的工件清单,按先后:报告文档在前,接着是它引用到的。同一份只列一次。events 是封存范围内的事件
(认口径卡带不带遮罩时找写变量的节点当时的产出)。"""
@@ -1019,13 +1045,14 @@ class _Artifacts:
self.store = store
self.events = events
self.items: list[dict[str, Any]] = []
self._by_id: dict[str, dict[str, Any]] = {}
self._seen: set[str] = set()
def add(self, artifact: str, kind: str, node_id: str | None, *, masked: bool = False) -> None:
"""masked:调用方另认出不能附带的(报告文档的证据目录里带着值不给的指标的原值;报告文档里写成「已遮罩」的指标
所在的口径卡),只给 id。"""
def add(self, artifact: str, kind: str, node_id: str | None, *, masked: bool = False) -> dict[str, Any] | None:
"""列进清单的一份工件,交回它的条目(同一份只列一次,第二次交回第一次的)。masked:调用方另认出不能附带的
(报告文档的证据目录里带着值不给的指标的原值;报告文档里写成「已遮罩」的指标所在的口径卡),只给 id。"""
if artifact in self._seen:
return
return self._by_id[artifact]
self._seen.add(artifact)
item: dict[str, Any] = {"id": artifact, "kind": kind}
if node_id:
@@ -1047,6 +1074,8 @@ class _Artifacts:
# 原样嵌入,不在这里复验哈希:被改过的文件照实交出去,浏览器自己算出对不上
item["b64"] = base64.b64encode(bytes(raw)).decode("ascii")
self.items.append(item)
self._by_id[artifact] = item
return item
# --------------------------------------------------------------------------
@@ -1236,9 +1265,16 @@ def build_bundle(
for report in reports:
artifacts.add(report["doc_artifact"], "report_doc", report["node_id"], masked=report["node_id"] in withheld)
for artifact, kind, owner in next((_cited_artifacts(doc) for r, doc in docs if r is report), []):
artifacts.add(artifact, kind, owner, masked=kind == "metric_set" and artifact in forced)
item = artifacts.add(artifact, kind, owner, masked=kind == "metric_set" and artifact in forced)
if kind == "query":
cited_queries.append(artifact)
continue
# 口径卡随文件附带了(没遮、文件在):它记着的输入——哪个指标的值取自哪次查询的哪一格——
# 那几次查询的快照也一并附上(设了遮罩的照旧只给 id)。点开数字看得到输入的 SQL 和被引用的行;
# 引用链(④)按「已核对的口径卡的输入」认它们,被改过的卡(intact 不过)不带,免得替它圆
if kind == "metric_set" and item is not None and "b64" in item and store.intact(artifact):
for query, query_owner in _card_input_queries(store.content(artifact)):
artifacts.add(query, "query", query_owner)
masked_run = _masked_run(sealed, store, cited_queries, source_masks or {})
shown_events = []
+107 -21
View File
@@ -136,6 +136,7 @@
chainDoc: (label) => `报告「${label}」的文档`,
chainByEvent: (seq, what) => `第 ${seq} 条事件(${what})`,
chainByDoc: (label, alias) => `报告「${label}」的证据目录(${alias})`,
chainByCard: (label, metric) => `口径卡「${label}」的输入(指标 ${metric})`,
chainFrom: '引用自',
chainNoCheckEvent: '找不到这个报告节点的报告自查事件',
chainCheckEventFailed: '报告自查事件的内容没有通过核对',
@@ -200,6 +201,12 @@
shownOdd: '紧挨着这个数的字不在常见写法里,无法确认读者看到的数',
numNotShown: '正文里没有显示这一处:导出时不会出现这种情况,文件可能被改过',
numAria: (kind, text, result) => `${kind === 'value' ? '取值' : '数字'} ${text},${result},查看出处`,
// 数字详情里口径卡一节:指标、计算方式(原式、代入式)、输入、复算。遮罩未附带的卡没有这一节(原因见核对明细 ③)
dMetric: '指标', dUnit: '单位', dExpression: '原式(计算方式)', dSubstituted: '代入式(代入输入后的算式)',
dInputs: '输入', dRecompute: '复算', dSourceName: '数据源', dInputValue: '取值', dFrom: '取自',
recomputeOk: '复算一致', recomputeBad: '复算不一致:代入式的计算结果与记录值不符', recomputeNone: '无法复算',
inputFrom: (query, row, column) => (query ? `查询 ${query}` : '') + (Number.isInteger(row) ? ` · 第 ${row + 1} 行` : '') + (column ? ` · ${column}` : ''),
inputNotAttached: '快照未随文件附带(见核对明细 ③),输入的值按口径卡的记录展示',
statusOk: (seq, what) => `与第 ${seq} 条事件(${what})一致`,
statusMismatch: (claim, seq, what) => `文件里写的是「${claim}」,与封存范围内最后一条结束类事件(第 ${seq} 条,${what})不符`,
statusLegacy: '早期运行在结束事件落库之前封存,结束事件不在封存范围内,运行结果无法核对',
@@ -1157,6 +1164,7 @@
async function verify(data, digest, shownSeal) {
const out = {
events: [], manifest: [], artifacts: [], chain: [], numbers: [], docs: [], meta: [], checked: new Map(), order: [],
arts: new Map(), queryAliases: new Map(),
}
const events = Array.isArray(data.events) ? data.events.filter(isObj) : []
const meta = data.meta
@@ -1313,12 +1321,33 @@
if (isObj(entry) && typeof entry.artifact === 'string') push(byDoc, entry.artifact, { report, alias })
}
}
// 工件 → 报告目录里它的编号(Q1、M1……):数字详情里口径卡的输入据此写出「查询 Q1 · 第 N 行 · 列」
for (const [id, refs] of byDoc) {
if (refs.length && !out.queryAliases.has(id)) out.queryAliases.set(id, refs[0].alias)
}
out.arts = arts
// 已核对的口径卡记着的输入 → 输入指向的查询快照。卡本身核过哈希(③ 通过),它记的引用和文档的证据目录
// 同一个分量:报告只引用指标、不直接引用查询时,查询快照就是从这条路嵌进来、也是从这条路认的。
// 没核对过的卡(哈希对不上)不认:被改过的卡说输入来自哪,不能替它圆
const byCard = new Map() // 工件 id → [{ card, metric }]
for (const item of out.artifacts) {
if (item.a.kind !== 'metric_set' || item.result !== PASS) continue
for (const metric of Array.isArray(item.json.metrics) ? item.json.metrics : []) {
if (!isObj(metric) || !Array.isArray(metric.inputs)) continue
for (const input of metric.inputs) {
if (isObj(input) && typeof input.artifact === 'string' && input.artifact) {
push(byCard, input.artifact, { card: item, metric: metric.id })
}
}
}
}
for (const item of out.artifacts) {
if (item.a.kind === 'report_doc') continue
const evs = byEvent.get(item.a.id) || []
const docs = byDoc.get(item.a.id) || []
const ok = evs.length > 0 || docs.length > 0
out.chain.push({ kind: item.a.kind, art: item, events: evs, docs, result: ok ? PASS : FAIL,
const cards = byCard.get(item.a.id) || []
const ok = evs.length > 0 || docs.length > 0 || cards.length > 0
out.chain.push({ kind: item.a.kind, art: item, events: evs, docs, cards, result: ok ? PASS : FAIL,
reason: ok ? '' : T.chainUnreferenced })
if (ok) chained.add(item.a.id)
}
@@ -1402,6 +1431,8 @@
const at = metrics.findIndex((m) => isObj(m) && m.id === metricId)
const metric = metrics[at]
info.card = art.json
// 指标本身:详情里据此展示指标名、原式、代入式、输入和复算(计算方式)
info.metric = metric || null
if (!metric) return { ...info, result: FAIL, reason: T.numNoMetric }
info.truth = metric.value
info.truthToken = tokenAt(tokensOf(art), ['metrics', at, 'value'])
@@ -1717,9 +1748,36 @@
return [' ', badge(item.result), item.reason ? h('span', { class: 'muted' }, ` ${item.reason}`) : null]
}
/** 一份随文件附带的查询快照:SQL + 被引用的那一行(引用的格高亮)。数字详情里单元格引用和口径卡的输入共用。
* art 是这份快照的核对条目:数照 JSON 原文写(同「快照里的值」),超过 2^53 的订单号读成 double 会丢位 */
function snapshotBlock(snap, row, column, art) {
const parts = []
if (typeof snap.sql === 'string' && snap.sql) parts.push(h('p', { class: 'sub' }, T.dSql), h('pre', { class: 'sql' }, snap.sql))
if (snap.source) parts.push(kv([[T.dSourceName, String(snap.source)]]))
const record = Number.isInteger(row) && Array.isArray(snap.rows) ? snap.rows[row] : undefined
if (Array.isArray(record) || isObj(record)) {
// 被引用的那一行:快照随文件附带(没碰设了遮罩的列)才走到这里,整行照原样列出,引用的那一格高亮
let columns = (Array.isArray(snap.columns) ? snap.columns : []).map(String)
if (isObj(record) && !columns.length) columns = Object.keys(record)
const tokens = art ? tokensOf(art) : null
const cellText = (c, i) => {
const value = isObj(record) ? own(record, c) : record[i]
if (value == null) return '—'
if (typeof value !== 'number') return textOf(value)
return numberText(value, tokenAt(tokens, ['rows', row, isObj(record) ? c : i]))
}
parts.push(h('p', { class: 'sub' }, T.dRow(row)), h('div', { class: 'table-wrap' }, h('table', {},
h('thead', {}, h('tr', {}, columns.map((c) => h('th', { class: c === column ? 'hit' : null }, c)))),
h('tbody', {}, h('tr', {}, columns.map((c, i) => h('td', { class: c === column ? 'hit' : null,
'data-cell': c }, cellText(c, i))))))))
}
return parts
}
function detailOf(number) {
const cite = isObj(number.seg.cite) ? number.seg.cite : null
const card = number.card
const metric = number.metric
// 显示文字核对过的(引用的值对上了,按显示规则渲染得出来):一致时注明,对不上时另列应显示的字。没有出处的数、
// 核对不了的引用不写:那些字没人重新渲染过。一致不等于通过:运行输入的显示文字对得上,引用的值仍核对不了;紧挨着
// 还有数字的,这处的字本身也对得上,读起来却不是这个值
@@ -1730,6 +1788,8 @@
[T.dSource, number.source],
number.node ? [T.dNode, nodeLabel(number.node)] : null,
card ? [T.dCaliber, [card.caliber || '—', card.caliber_version ? ` ${card.caliber_version}` : ''].join('')] : null,
metric ? [T.dMetric, [metric.name || metric.id || '—', metric.id && metric.name ? h('span', { class: 'muted' }, `(${metric.id})`) : null]] : null,
metric && metric.unit ? [T.dUnit, String(metric.unit)] : null,
cite && cite.status === 'resolved' && 'value' in cite ? [T.dCited, exactText(cite.value, number.citedToken)] : null,
'truth' in number ? [number.kind === 'metric' ? T.dCard : T.dCell,
number.truthText ?? exactText(number.truth, number.truthToken)] : null,
@@ -1739,27 +1799,52 @@
[T.dReport, nodeLabel(number.report.node_id)],
]
const parts = [kv(rows)]
const snap = number.snapshot
if (snap && typeof snap.sql === 'string' && snap.sql) parts.push(h('p', { class: 'sub' }, T.dSql), h('pre', { class: 'sql' }, snap.sql))
const record = snap && Number.isInteger(number.row) && Array.isArray(snap.rows) ? snap.rows[number.row] : undefined
if (Array.isArray(record) || isObj(record)) {
// 被引用的那一行:快照随文件附带(没碰设了遮罩的列)才走到这里,整行照原样列出,引用的那一格高亮。数照 JSON
// 原文写(同上面「快照里的值」):超过 2^53 的订单号读成 double 会丢位,和一位不差的「引用的值」对不上
let columns = (Array.isArray(snap.columns) ? snap.columns : []).map(String)
if (isObj(record) && !columns.length) columns = Object.keys(record)
const art = view.out.artifacts.find((a) => a.a.id === number.artifact)
const tokens = art ? tokensOf(art) : null
const cellText = (c, i) => {
const value = isObj(record) ? own(record, c) : record[i]
if (value == null) return '—'
if (typeof value !== 'number') return textOf(value)
return numberText(value, tokenAt(tokens, ['rows', number.row, isObj(record) ? c : i]))
// 口径卡一节:计算方式(原式、代入式)、输入、复算。卡随文件附带才有(遮罩的只给 id,见核对明细 ③)
if (metric) {
parts.push(h('p', { class: 'sub' }, T.dExpression), h('pre', { class: 'sql' }, String(metric.expression || '—')))
parts.push(h('p', { class: 'sub' }, T.dSubstituted), h('pre', { class: 'sql' }, String(metric.substituted || '—')))
// 输入的值照卡上 JSON 的原文写(同「口径卡里的值」):超过 2^53 的数读成 double 会丢位
const cardArt = view.out.artifacts.find((a) => a.a.id === number.artifact)
const cardTokens = cardArt ? tokensOf(cardArt) : null
const at = Array.isArray(card && card.metrics) ? card.metrics.indexOf(metric) : -1
const inputs = (Array.isArray(metric.inputs) ? metric.inputs : [])
.map((input, i) => ({ input, token: tokenAt(cardTokens, ['metrics', at, 'inputs', i, 'value']) }))
.filter(({ input }) => isObj(input))
if (inputs.length) {
parts.push(h('p', { class: 'sub' }, T.dInputs),
h('ul', { class: 'items' }, inputs.map(({ input, token }) => {
const loc = isObj(input.locator) ? input.locator : {}
const row = Number.isInteger(loc.row) ? loc.row : null
const column = loc.column != null ? String(loc.column) : null
const alias = typeof input.artifact === 'string' ? view.out.queryAliases.get(input.artifact) : undefined
const from = [T.inputFrom(alias, row, column), input.node_id ? nodeLabel(input.node_id) : null]
.filter(Boolean).join(' · ')
return h('li', {},
h('span', { class: 'what' }, [
`${T.dInputValue} `, exactText(input.value, token),
h('span', { class: 'muted' }, ` ← ${input.path || '—'}`),
]),
from ? h('span', { class: 'why' }, `${T.dFrom} ${from}`) : null)
})))
// 输入指向的查询快照:随文件附带的给出 SQL 和被引用的那一行;没附带的(遮罩等)说明按卡的记录展示
for (const { input } of inputs) {
if (typeof input.artifact !== 'string' || !input.artifact) continue
const art = view.out.arts.get(input.artifact)
if (!art || art.result !== PASS) {
parts.push(h('p', { class: 'note' }, `${T.inputNotAttached}${art && art.a.masked ? `:${art.reason}` : ''}`))
continue
}
const loc = isObj(input.locator) ? input.locator : {}
parts.push(...snapshotBlock(art.json, Number.isInteger(loc.row) ? loc.row : null,
loc.column != null ? String(loc.column) : null, art))
}
}
parts.push(h('p', { class: 'sub' }, T.dRow(number.row)), h('div', { class: 'table-wrap' }, h('table', {},
h('thead', {}, h('tr', {}, columns.map((c) => h('th', { class: c === number.column ? 'hit' : null }, c)))),
h('tbody', {}, h('tr', {}, columns.map((c, i) => h('td', { class: c === number.column ? 'hit' : null,
'data-cell': c }, cellText(c, i))))))))
parts.push(kv([[T.dRecompute, metric.recompute_ok == null ? T.recomputeNone
: metric.recompute_ok ? T.recomputeOk : T.recomputeBad]]))
}
const snap = number.snapshot
if (snap) parts.push(...snapshotBlock(snap, number.row, number.column,
view.out.artifacts.find((a) => a.a.id === number.artifact)))
return parts
}
@@ -1920,6 +2005,7 @@
return [T.chainDoc(nodeLabel(c.report.node_id)), ' ', h('code', {}, short(c.report.doc_artifact)), from]
}
const refs = [...c.docs.map((d) => T.chainByDoc(nodeLabel(d.report.node_id), d.alias)),
...c.cards.map((k) => T.chainByCard(nodeLabel(k.card.a.node_id), k.metric)),
...c.events.map((ev) => T.chainByEvent(ev.seq, eventWhat(ev)))]
return [KIND_LABEL[c.kind] || c.kind, ' ', h('code', {}, short(c.art.a.id)),
refs.length ? ` ← ${T.chainFrom}${refs.join('、')}` : '']