端到端验收修复与指标出具:

- 身份与工具:登录页建第一个管理员(认人接口的 401 说明能不能建);搭建者有只读的人和组名录,选人给候选并核对名字;授权三行带标题;端点请求头名校验(空名、非法名存不进、发不出时说清原因);写入能力在工具页试运行一律演练、不发送,HTTP 状态照实说成败;写记忆不算只读、查询能力只能选同一端点上的只读能力;审批与遮罩的说法和实际规则一致;开登录时不要署名、导入和发布记登录的人;使用者不显示推演等只给搭建者的操作,403 按是否开登录说话;登录页只认一次人
- 流程与实例:图里用到的岗位(派给谁、超时升级给谁、发送确认派给谁)全部派生、没绑人的发布时报错;写外部系统的参数按能力声明的类型收拢后再算哈希和发送,收不成就不发;发起人的实例页只看这一步的状态,处理人才给待办卡;会签进度带登录核实和时间,升级后照实写规则;实例状态写流程的结论(已退回、未确认、等待核实写入结果),核实生效后不再挂失败原因;流程应用首页不派生最近封存运行的结果块,看板没数据时是安静的空态;样例⑩的金额带类型和下限、待办标题带金额,表单上下限前后端一起生效
- 看板与证据:定时任务模板加 ISO 周、上一 ISO 周、本月、上月;出处链穿过原样解析查询结果的整形节点,追不到原始数据的照实说停在哪里,样例⑨改用 cell();应用首页和版本历史都能做成应用;指标块单位不重复;版本列表带退役说明;定时任务页头跟着刷新;删视图要确认、新视图能起名;编辑器属性用中文名、术语带解释
- 指标出具(用户 2026-10-15 拍板):契约只写「指标来自」、上游没有报告撰写节点、成果里没有模型写的话时按指标出具——必需指标齐、指标输入追到原始数据、成果字段里的数回指得上才完整出具;受管级要求每个指标静态地追到原始数据(governed.metric_untraced);出具横幅和应用印章写明按指标
- 受管工作流降为已发布只给管理员(Q8 顺延,服务端同样拦);工作流接口带当前发布版的级别,画布上改过之后也认得出受管工作流
This commit is contained in:
ThearchyHelios
2026-10-15 07:15:37 +08:00
parent 5d42ffb62b
commit 941723b17c
116 changed files with 4917 additions and 631 deletions
+48 -3
View File
@@ -8,6 +8,7 @@ from typing import Any, Callable
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.engine.issuance import metrics_only
from app.engine.labels import contract_label, field_label, judge_label, option_label, q
from app.engine.schema import (
CLAIMS_JUDGE,
@@ -15,6 +16,7 @@ from app.engine.schema import (
GraphSpec,
NodeType,
ValidationResult,
_ancestors,
_caliber_inputs,
claims_problem,
contract_needs_metrics,
@@ -235,10 +237,16 @@ def _lint_contract(
# 引用模式(report_from)核对的是报告撰写节点产出的文档,数字回指靠文档里的引用标记,
# 用不上 narrative。report_from 指错了(不是报告撰写节点、不在出口上游)由 validate_graph
# 报 error(contract.report_from_invalid),发布时两者一起过,照样挡住
if contract.get("report_from") in (None, "") and not str(contract.get("narrative") or "").strip():
# 只写了「指标来自」、上游没有报告撰写节点的是指标出具(纯指标看板,board_only):出具的就是指标本身,核对成果字段
# 里的数和指标的出处,不缺核对。上游有报告的照旧要指明核哪一份——不然报告的正文没人核
by_metrics = board_only(contract, spec, node_id)
if contract.get("report_from") in (None, "") and not str(contract.get("narrative") or "").strip() \
and not by_metrics:
flag("出具契约既没有设置「报告来自」(核对哪个「报告撰写」节点的文档),也没有填写「叙述」,"
"不会执行数字核对", code="contract.report_from_missing", node_id=node_id, hard=True,
field="contract.report_from")
"不会执行数字核对" + ("" if sources else ";纯指标看板请设置「指标来自」,按指标出具"),
code="contract.report_from_missing", node_id=node_id, hard=True, field="contract.report_from")
if strict and by_metrics:
_lint_metric_lineage(spec, sources, flag, node_id=node_id)
# 引用模式下整张图没有口径卡(只引查询单元格的问数据图):没有指标可列,strict + cells 已经保证
# 每个数点得开出处、对不上就不予出具(用户 2026-09-29 拍板)。有口径卡的照旧要列必需指标——
@@ -540,6 +548,43 @@ def _card_feeders(graph: _Graph, card: GraphNode) -> list[GraphNode]:
return list(out.values())
def board_only(contract: Any, spec: GraphSpec, exit_id: str) -> bool:
"""按指标出具(纯指标看板):契约只写了「指标来自」(issuance.metrics_only),成果上游没有报告撰写节点,成果字段里也
没有模型写的话。有报告的,报告正文要按引用核对;有模型写的话的,那就是叙述——两种都不能因为契约少写了一样就改成
只核指标。门禁和成果节点(nodes/io)用这一处。"""
if not metrics_only(contract):
return False
nodes = spec.node_map()
exit_node = nodes.get(exit_id)
if exit_node is None or any(nodes[a].type == NodeType.REPORT for a in _ancestors(spec, exit_id) if a in nodes):
return False
return not exit_text_fields(spec, exit_node)
def _lint_metric_lineage(spec: GraphSpec, sources: list[str], flag: Callable[..., None], *, node_id: str) -> None:
"""受管级别按指标出具:每个指标的输入都要追到原始数据(查询快照的格、运行输入),静态地按 engine/lineage 认。
没有叙述可核,指标的出处就是出具的全部依据;追不到的那一个,「完整出具」这一档就没有根据。"""
from app.engine.lineage import static_stops
nodes = {n.id: {"type": str(n.type), "title": n.title, "config": n.config} for n in spec.nodes}
for card_id in sources:
card = nodes.get(card_id)
if card is None or card["type"] != str(NodeType.METRICS):
continue
for metric in card["config"].get("metrics") or []:
if not isinstance(metric, dict) or not metric.get("expression"):
continue
stops = static_stops(nodes, str(metric["expression"]))
if not stops:
continue
where = "、".join(dict.fromkeys(
f"{s.path}(停在「{nodes[s.node_id]['title']}」)" if s.node_id in nodes else s.path for s in stops[:3]))
flag(f"受管级别按指标出具时,每个指标都要追到原始数据:口径卡「{card['title']}」的指标"
f"「{metric.get('name') or metric.get('id')}」的输入 {where} 没追到。"
"请在口径卡里用 cell() 按格取数,或让数据整形只原样解析调用工具节点的结果",
code="governed.metric_untraced", node_id=card_id, hard=True, field="metrics")
def _lint_evidence(spec: GraphSpec, flag: Callable[..., None], *, strict: bool) -> None:
graph = _Graph(spec)
outputs = [n for n in spec.nodes if n.type == NodeType.OUTPUT]
+11
View File
@@ -409,6 +409,17 @@ def trace_numbers(
return report
def metrics_only(contract: Any) -> bool:
"""指标出具:契约写了「指标来自」,没写「报告来自」也没写「叙述」——出具的就是指标本身(纯指标看板,用户 2026-10-15
拍板)。三档的语义不变,核对的对象从叙述换成指标:必需指标缺了不予出具;成果字段里给人看的数要回指到指标集;
每个指标的输入要追到原始数据(engine/lineage),追不到的照实写进缺口、不盖完整出具。"""
if not isinstance(contract, dict):
return False
sources = contract.get("metrics_from") or []
return bool(sources) and contract.get("report_from") in (None, "") \
and not str(contract.get("narrative") or "").strip()
def decide_tier(
*,
missing_required: list[str],
+189
View File
@@ -0,0 +1,189 @@
"""口径卡的输入追没追到原始数据:一处认定,三处用。
「原始数据」是查询快照里的格(调用工具节点、合并查询交回的结果;Agent 按出处交来的字段落在的那一格)和运行输入(发起
运行的人填的)。证据面板上的「有出处」说的是另一件事:这个数是口径卡按登记的表达式确定性算出来的、拿代入式复算一致。
两件事分开说,这里只管前一件:
- 运行时(nodes/metrics._input_of):「只是把调用工具节点的结果原样按 JSON 解析」的数据整形节点(parsed_tool)不改动任何
一格,vars.<x>.rows[i][j](row_cell)确定地对到那份查询快照的第 i 行第 j 列,和 cell() 一样按快照核对,记下穿过的整形
节点(through);
- 证据面板(api/evidence 的指标步骤):卡上记的输入里追不到原始数据的(untraced),照实说出处追到哪个节点为止;
- 应用检查(apps/lint):受管级应用里绑定的指标,按 static_stops 静态地认(只有图、没有运行),追不到的给提示。
"""
from __future__ import annotations
import ast
import re
from collections.abc import Callable, Iterable, Mapping
from dataclasses import dataclass
from typing import Any
from app.engine.expressions import ExpressionError, cell_parts, leaf_refs, parse_expression
#: 整形节点的模板整串就是一个节点的全部产出:{{ nodes.fetch }}(不带过滤器、前后不带别的字)
_WHOLE_NODE = re.compile(r"^\s*\{\{\s*nodes\.([A-Za-z0-9_\-]+)\s*\}\}\s*$")
_REF_HEAD = re.compile(r"^(vars|nodes|input)\.([A-Za-z_一-鿿][\w\-一-鿿]*)(.*)$", re.S)
#: 落在查询快照一格上的取值方式(cell() 取的格、Agent 按出处交来的字段),和 engine/recompute、dual_check 同一组
SNAPSHOT_VIAS = ("tool_cell", "agent_field")
#: 核对得了快照的状态:一致,或者对不上(对不上另有说法,但出处是追到了的)
_CHECKED = ("verified", "mismatch")
#: 直接交回查询结果(带快照)的节点:cell() 的第一个参数指到它们就是快照
_TABLE_NODES = ("tool", "merge")
def parsed_tool(node_type: Any, config: Mapping[str, Any] | None, type_of: Callable[[str], Any]) -> str | None:
"""这个节点只是把调用工具节点的结果原样按 JSON 解析:数据整形、按 JSON 解析(mode=json)、模板整串就是
{{ nodes.<id> }}、那个节点是调用工具节点。是的话交回那个调用工具节点的 id,不是返回 None。
只认这一种:表达式、模板拼出来的结构即使带着 rows 和快照 id,行也可能被筛过、换过顺序,第 i 行对不到快照的第 i 行。"""
cfg = config or {}
if str(node_type) != "transform" or cfg.get("mode") != "json":
return None
m = _WHOLE_NODE.match(str(cfg.get("template") or ""))
if not m or str(type_of(m.group(1)) or "") != "tool":
return None
return m.group(1)
@dataclass(frozen=True)
class RowCell:
"""按位置取的一格:<root>.<name>.rows[row][column]。root 是 vars 或 nodes,row 是从 0 数的行号,column 是列号或列名。"""
root: str
name: str
row: int
column: int | str
@property
def table(self) -> str:
"""那份结果本身的取值链:vars.q"""
return f"{self.root}.{self.name}"
def row_cell(path: str) -> RowCell | None:
"""路径正好是 vars.q.rows[0][0]、nodes.parse.rows[1]['gmv'] 这种按位置取一格的样子时拆开;行号是非负整数字面量,
列是非负整数或文本字面量。别的样子(负数下标、下标是变量、多走了一层)返回 None。"""
try:
tree = ast.parse(path, mode="eval").body
except SyntaxError:
return None
if not isinstance(tree, ast.Subscript) or not isinstance(tree.value, ast.Subscript):
return None
column, row, rows = tree.slice, tree.value.slice, tree.value.value
if not (isinstance(rows, ast.Attribute) and rows.attr == "rows" and isinstance(rows.value, ast.Attribute)
and isinstance(rows.value.value, ast.Name) and rows.value.value.id in ("vars", "nodes")):
return None
if not (isinstance(row, ast.Constant) and type(row.value) is int and row.value >= 0):
return None
if not (isinstance(column, ast.Constant) and ((type(column.value) is int and column.value >= 0)
or (isinstance(column.value, str) and column.value))):
return None
return RowCell(rows.value.value.id, rows.value.attr, row.value, column.value)
def traced(item: Mapping[str, Any]) -> bool:
"""卡上记的一个输入追没追到原始数据:落在查询快照的一格上、核对得了快照(cell() 取的格、穿过 JSON 解析按位置取的格、
Agent 按出处交来的字段),或者是运行输入。"""
via = item.get("via")
if via in SNAPSHOT_VIAS:
return bool(item.get("artifact")) and item.get("status") in _CHECKED
return via == "input"
def untraced(inputs: Iterable[Any]) -> list[dict[str, Any]]:
"""卡上记的输入里追不到原始数据的。没有值的不算(缺输入另有说法:值都没有,谈不上追到哪里)。"""
return [item for item in inputs
if isinstance(item, dict) and item.get("value") is not None and not traced(item)]
# --------------------------------------------------------------------------
# 静态地认(只有图)
# --------------------------------------------------------------------------
@dataclass(frozen=True)
class Stop:
"""一个追不到原始数据的输入:路径和停在哪个节点(认不出是哪个节点时为 None)。"""
path: str
node_id: str | None
def static_stops(nodes: Mapping[str, Mapping[str, Any]], expression: str) -> list[Stop]:
"""静态地认一个指标表达式里追不到原始数据的输入。nodes 是节点 id → {type, config}(apps/tree.node_map 的形状)。
和运行时同一套认法,只是不看值:cell() 的第一个参数是查询结果(调用工具、合并查询的产出,或原样解析它的整形节点)、
按位置取的格穿过原样解析的整形节点、运行输入、开了按出处核对字段的 Agent 交来的字段,算追到了;别的(表达式整形、
沙箱代码、模型调用、转抄别的口径卡……)停在写它的那个节点。表达式写错了的不在这里报(画布的校验报)。"""
try:
tree = parse_expression(expression)[0]
except ExpressionError:
return []
out: list[Stop] = []
for path in leaf_refs(tree):
stop = _static_stop(nodes, path)
if stop is not None:
out.append(stop)
return out
def _static_stop(nodes: Mapping[str, Mapping[str, Any]], path: str) -> Stop | None:
type_of = lambda node_id: (nodes.get(node_id) or {}).get("type") # noqa: E731
if (parts := cell_parts(path)) is not None:
writers = _writers(nodes, parts[0])
bad = [w for w in writers if not _table(nodes, w, type_of)]
return Stop(path, bad[0]) if bad or not writers else None
if (at := row_cell(path)) is not None:
writers = _writers(nodes, at.table)
node = nodes.get(writers[0]) if len(writers) == 1 else None
if node is not None and parsed_tool(node.get("type"), node.get("config"), type_of):
return None
head = _REF_HEAD.match(path)
if head and head.group(1) == "input":
return None
writers = _writers(nodes, path)
if not writers:
return Stop(path, None)
field = head.group(3).lstrip(".") if head else ""
for writer in writers:
node = nodes[writer]
if node.get("type") == "input":
continue
if node.get("type") == "agent" and _cited(node, head.group(1) if head else "", field):
continue
return Stop(path, writer)
return None
def _writers(nodes: Mapping[str, Mapping[str, Any]], source: str) -> list[str]:
"""取值链的根是谁写的:nodes.X 是 X;vars.X 是 assign_to 为 X 的节点(入口节点声明了字段 X 的也算)。"""
head = _REF_HEAD.match(source)
if not head:
return []
root, name = head.group(1), head.group(2)
if root == "nodes":
return [name] if name in nodes else []
if root == "input":
return [n for n, node in nodes.items() if node.get("type") == "input"]
out = []
for node_id, node in nodes.items():
cfg = node.get("config") or {}
if str(cfg.get("assign_to") or "").strip() == name:
out.append(node_id)
elif node.get("type") == "input" and any(isinstance(f, dict) and str(f.get("name") or "").strip() == name
for f in cfg.get("fields") or []):
out.append(node_id)
return out
def _table(nodes: Mapping[str, Mapping[str, Any]], node_id: str, type_of: Callable[[str], Any]) -> bool:
node = nodes.get(node_id) or {}
return node.get("type") in _TABLE_NODES or parsed_tool(node.get("type"), node.get("config"), type_of) is not None
def _cited(node: Mapping[str, Any], root: str, field: str) -> bool:
"""开了按出处核对字段的 Agent 交来的字段(vars.X.字段,或 nodes.<agent>.data.字段):逐格核对过快照,是原始数据。"""
cfg = node.get("config") or {}
if not (cfg.get("output_schema") and cfg.get("cite_fields") is True):
return False
return root == "vars" or field.startswith("data.") or field.startswith("data[")
+4 -3
View File
@@ -613,12 +613,13 @@ async def _query_input(item: dict[str, Any], sources: _Sources, aliases: dict[st
return {}, f"输入 {item['path']} 取的是一整段查询结果,盲算只能复核单个格子"
if item["path"] not in tops:
return {}, f"输入 {item['path']} 决定取哪一格,不能单独复算"
value = cell_value(item.get("value"))
if not _number(value):
return {}, f"输入 {item['path']} 不是数值"
# 先认遮罩、再认是不是数:遮罩列上的号码、名称多半是文本,说「不是数值」会让审核人以为改成数就能复算
hidden = await sources.hidden(artifact)
if column.lower() in hidden:
return {}, f"输入 {item['path']} 取自设置了遮罩的列,不能用于复算"
value = cell_value(item.get("value"))
if not _number(value):
return {}, f"输入 {item['path']} 不是数值"
found = await sources.source(source)
derived = derived_columns(snap, set(hidden), found.kind if found is not None else None) if hidden else None
if derived and column.lower() in derived:
+42 -1
View File
@@ -63,7 +63,8 @@ async def run_output(state: GraphState, ctx: NodeContext) -> dict[str, Any]:
governed = await governed_formal(ctx.run.run_id)
cells = cells_allowed(contract, governed=governed)
result["_issuance"] = _apply_contract(contract, state, ctx, reports=reports, cells=cells, governed=governed)
result["_issuance"] = _apply_contract(contract, state, ctx, reports=reports, cells=cells, governed=governed,
fields=result)
evidence = _evidence_of(reports, contract)
if evidence:
result["_evidence"] = evidence
@@ -144,9 +145,11 @@ def _evidence_of(reports: list[dict[str, Any]], contract: Any) -> dict[str, Any]
def _apply_contract(
contract: dict[str, Any], state: GraphState, ctx: NodeContext,
*, reports: list[dict[str, Any]] | None = None, cells: bool = True, governed: bool = False,
fields: dict[str, Any] | None = None,
) -> dict[str, Any]:
from datetime import datetime, timezone
from app.engine.governance import board_only
from app.engine.issuance import decide_tier, incomplete_gaps, sql_check_findings, trace_numbers
nodes = state.get("nodes") or {}
@@ -200,11 +203,19 @@ def _apply_contract(
trace = None
cited: dict[str, Any] = {}
by_metrics = not citations and board_only(contract, ctx.run.spec, ctx.node.id)
if citations:
cited = _check_citations(str(report_from), contract, state, ctx, reports or [], cells=cells,
governed=governed)
gaps.extend(cited["gaps"])
unmatched = cited["unmatched"]
elif by_metrics:
# 指标出具:没有叙述,给人看的是成果字段——字段里的数回指指标集,和叙述同一套规则;每个指标的输入要追到原始
# 数据,追不到的是「这个数有算式、没出处」,照实记成缺口
shown = _shown_text(fields or {})
trace = trace_numbers(shown, metrics, allow=contract.get("allow_numbers")) if shown.strip() else None
unmatched = trace.unmatched if trace else []
gaps.extend(_untraced_gaps(metrics, ctx))
else:
# 2) 叙述数字回指
declared_narrative = str(contract.get("narrative", ""))
@@ -286,6 +297,7 @@ def _apply_contract(
][:50]
issuance = {
"tier": tier,
**({"mode": "metrics"} if by_metrics else {}),
"calibers": calibers, # 口径版本照常印
"metrics_checked": len(metrics),
"missing_required": missing_required,
@@ -301,6 +313,7 @@ def _apply_contract(
ctx.emit(
EventType.ISSUANCE,
tier=tier,
**({"mode": "metrics"} if by_metrics else {}),
missing_required=missing_required,
missing_expected=missing_expected,
unmatched=len(unmatched),
@@ -316,6 +329,34 @@ def _apply_contract(
return issuance
def _shown_text(fields: dict[str, Any]) -> str:
"""指标出具时给人看的文字:成果字段里的文字和数(成果自己的 _issuance、_evidence 不算)。表格、对象这类结构化的值不在
这里核:它们是查询结果,出处是自己的快照,不是口径卡的指标。"""
parts = []
for name, value in fields.items():
if str(name).startswith("_") or isinstance(value, bool):
continue
if isinstance(value, (str, int, float)):
parts.append(str(value))
return "\n".join(parts)
def _untraced_gaps(metrics: list[dict[str, Any]], ctx: NodeContext) -> list[str]:
"""指标出具的缺口:输入没追到原始数据的指标,每个一句,说清停在哪个节点(engine/lineage 的认法)。"""
from app.engine.lineage import untraced
titles = {n.id: n.title for n in ctx.run.spec.nodes}
out = []
for m in metrics:
stops = untraced(m.get("inputs") or [])
if not stops:
continue
where = "、".join(dict.fromkeys(f"{s.get('path')}(停在「{titles.get(s.get('node_id') or '', s.get('node_id') or '未知来源')}」)"
for s in stops[:3]))
out.append(f"指标「{m.get('name') or m.get('id')}」的输入没追到原始数据:{where}")
return out
def _upstream_issuance_gaps(state: GraphState, ctx: NodeContext) -> list[str]:
"""上游节点产出里的 issuance_gaps(字符串列表),每条前面加上是哪个节点说的。
+40 -7
View File
@@ -33,6 +33,7 @@ from app.engine.expressions import (
substitute,
)
from app.engine.labels import field_label
from app.engine.lineage import parsed_tool, row_cell
from app.engine.sql_problems import CHECK_FIELDS, QueryProblem, merge_problems, node_of, query_problems, reason_text
from app.engine.state import GraphState, template_context
@@ -528,12 +529,16 @@ def _input_of(path: str, value: Any, state: GraphState, ctx: NodeContext,
vars.X 要反查是谁写的:assign_to 为 X 的节点里,按执行顺序最后跑的那一个——
和状态里 vars 的覆盖顺序一致。入口节点把输入字段也写进 vars。
两种来历能追到查询快照里的那一格:
三种来历能追到查询快照里的那一格(engine/lineage.py 说「追到了原始数据」的就是这几种,加上运行输入):
- cell(nodes.fetch, 0, 'gmv'):via tool_cell,带 locator、artifact、eid,按快照核对
- vars.q.rows[0][0],q 由「只是把调用工具节点的结果原样按 JSON 解析」的整形节点写:同 cell(),via tool_cell,
另记 through(穿过的整形节点)
- agent 开了 cite_fields 的字段:via agent_field,接上它的 data_evidence(eid、核对状态)
"""
if (parts := cell_parts(path)) is not None:
return _cell_input(path, value, parts, state, ctx, tctx or template_context(state))
if (parsed := _parsed_cell(path, value, state, ctx, tctx or template_context(state))) is not None:
return parsed
spec = ctx.run.spec
nodes = spec.node_map()
node_id: str | None = None
@@ -642,16 +647,42 @@ def _agent_element(evidence: dict[str, Any], key: str) -> dict[str, Any] | None:
return out
def _parsed_cell(path: str, value: Any, state: GraphState, ctx: NodeContext,
tctx: dict[str, Any]) -> dict[str, Any] | None:
"""穿过「只是把调用工具节点的结果原样按 JSON 解析」的整形节点按位置取的一格(vars.q.rows[0][0]、
nodes.parse.rows[0]['gmv']):整形节点不改动任何一格,第 i 行第 j 列就是那份查询快照的第 i 行第 j 列,和 cell() 一样
按快照核对(_cell_input),through 记下穿过的整形节点。
不是这种取法(不是 .rows[行][列] 的样子、写它的不是这种整形节点)返回 None,按一般的来历记:表达式、模板拼出来的
结构即使带着 rows 和快照 id,行也可能被筛过、换过顺序,对不到快照的同一行(见 engine/lineage.parsed_tool)。"""
at = row_cell(path)
if at is None:
return None
nodes = ctx.run.spec.node_map()
transform = at.name if at.root == "nodes" else _writer_of(at.name, state, ctx)
node = nodes.get(transform) if transform else None
tool = parsed_tool(node.type, node.config, lambda i: nodes[i].type if i in nodes else None) if node else None
if node is None or tool is None:
return None
return _cell_input(path, value, (at.table, repr(at.row), repr(at.column)), state, ctx, tctx,
through=(node.id, tool))
def _cell_input(path: str, value: Any, parts: tuple[str, str, str], state: GraphState, ctx: NodeContext,
tctx: dict[str, Any]) -> dict[str, Any]:
tctx: dict[str, Any], *, through: tuple[str, str] | None = None) -> dict[str, Any]:
"""cell() 取的那一格:它来自哪次查询(台账里的 query 条目)、第几行哪一列、快照里是不是这个值。
查询结果经 transform 解析过也认得出来:数据源工具交回的 JSON 里带着快照的工件 id。
取不到快照、或者快照里那一格和算的时候用的值不一样,status 如实写,不替它圆。
through 是 (整形节点, 调用工具节点):穿过原样按 JSON 解析的整形节点按位置取的格(_parsed_cell)。台账按工件认不出时
按那个调用工具节点找它最后一次查询,卡上记下穿过的整形节点。
"""
source, row_src, column_src = parts
entry: dict[str, Any] = {"path": path, "value": value if value is None or isinstance(value, (int, float, str, bool))
else _brief(value), "node_id": None, "via": "tool_cell"}
if through is not None:
entry["through"] = through[0]
table = _value_of(source, tctx)
row, column = _value_of(row_src, tctx), _value_of(column_src, tctx)
data = table
@@ -664,19 +695,21 @@ def _cell_input(path: str, value: Any, parts: tuple[str, str, str], state: Graph
queries = [e for e in state.get("evidence") or [] if isinstance(e, dict) and e.get("kind") == "query"]
ledger = next((e for e in reversed(queries) if artifact and e.get("artifact") == artifact), None)
head = _REF_HEAD.match(source)
if ledger is None and head and head.group(1) == "nodes":
producer = through[1] if through is not None else head.group(2) if head and head.group(1) == "nodes" else None
if ledger is None and producer:
# 台账是按工件认的;工具交回的不是带工件 id 的 JSON 时,按取值链上的节点找它最后一次查询
ledger = next((e for e in reversed(queries) if e.get("node_id") == head.group(2)), None)
ledger = next((e for e in reversed(queries) if e.get("node_id") == producer), None)
if ledger is None:
entry.update(node_id=head.group(2) if head and head.group(1) == "nodes" else None,
status="unresolved", reason="找不到这份数据对应的查询快照:cell() 需要读取查询工具返回的结果")
entry.update(node_id=producer, status="unresolved",
reason="找不到这份数据对应的查询快照:cell() 需要读取查询工具返回的结果" if through is None
else "找不到这份数据对应的查询快照:调用工具节点交回的不是数据源查询的结果")
return entry
entry["node_id"] = ledger.get("node_id")
artifact = ledger.get("artifact")
try:
raw, name = locate_cell(data if isinstance(data, dict) else table, row, column)
except CellError as e:
entry.update(status="unresolved", reason=f"cell() {e}", artifact=artifact)
entry.update(status="unresolved", reason=f"cell() {e}" if through is None else f"{path}:{e}", artifact=artifact)
return entry
locator = {"row": row, "column": name}
entry.update(locator=locator, artifact=artifact, eid=cell_eid(artifact, row, name))
+5 -2
View File
@@ -290,7 +290,10 @@ async def _run_write(state: GraphState, ctx: NodeContext, name: str, args: dict[
await once(ctx, EventType.HUMAN_RESOLVED, tool=name, approved=decision.approved, note=decision.note,
actor=ctx.actor(), payload_hash=confirmed)
if not decision.approved:
raise NodeError(ctx.node.id, f"「{name}」的发送已被驳回" + (f":{decision.note}" if decision.note else ""))
# 驳回是人的决定,不是故障:运行到这里结束(状态记失败,没有可走的出口),说法写成「未确认(被驳回)」,
# 实例页按待办的结论另说(apps/resolve.instance_states)
raise NodeError(ctx.node.id, f"「{ctx.node.title}」未确认(被驳回),没有发送"
+ (f":{decision.note}" if decision.note else ""))
if confirmed != prep.payload_hash:
# 动作确认不接受改参数:要改在上游的表单里改。确认之后上游的数据变了,看过的就不是要发的,拒发
raise NodeError(ctx.node.id, f"「{name}」确认时看到的内容和现在要发送的不一致(内容指纹对不上),"
@@ -300,7 +303,7 @@ async def _run_write(state: GraphState, ctx: NodeContext, name: str, args: dict[
# 外部系统会把审批人当成申请人;无人值守的写入没有人确认,不写 act
on_behalf = {"sub": prep.run.get("started_by"), "act": confirmer}
try:
result = await actions.send(prep, capability, args, run_id=ctx.run.run_id, node_id=ctx.node.id,
result = await actions.send(prep, capability, run_id=ctx.run.run_id, node_id=ctx.node.id,
exec_no=exec_no, emit=ctx.emit, on_behalf=on_behalf)
except actions.ActionFailed as e:
raise NodeError(ctx.node.id, str(e)) from e