优化:未分类连续维护与柏拉图预汇总,同步已发布修复

This commit is contained in:
2026-11-01 12:40:50 +08:00
parent 572873c6b8
commit 38290f5fec
135 changed files with 17613 additions and 663 deletions
+30 -8
View File
@@ -102,6 +102,7 @@ def protocol_visual_result(evidence, scopes, question, turn_id, *, release_id, b
try:
from analysis_visuals import build_visuals
from nao_query_plan import scope_context, scope_documents
from nao_weight_ranking import ranking_task
all_visuals, missing, requested_visuals = [], [], False
for scope in scopes:
if not isinstance(scope, dict) or not isinstance(scope.get('task'), dict):
@@ -109,27 +110,50 @@ def protocol_visual_result(evidence, scopes, question, turn_id, *, release_id, b
continue
task = scope['task']
node_id, scope_id = scope.get('nodeId'), scope.get('scopeId')
metric_scope = scope.get('purpose') == 'metrics' or task.get('kind') == 'metrics'
child_question = task.get('question') if isinstance(task.get('question'), str) else question
selected = scope_documents(evidence, scope, release_id=release_id)
# A finite ranking operator can serve a confirmed single-object
# metrics request. Keep that root intent through visual completion,
# using the same exact scope/proof gate as narrative composition.
# An explicit chart request still follows the normal chart checks.
from nao_weight_ranking import protocol_scalar_metrics_scope
root = base_context.get('_agentTask', {}) if isinstance(base_context, dict) else {}
scalar_metrics = (len(selected) == 1 and protocol_scalar_metrics_scope(
root, base_context, selected[0]))
node_requires_chart = any(node.get('visualPreference') == 'required'
for node in root.get('queryPlan', []) if isinstance(node, dict))
if (scalar_metrics and task.get('visualPreference', 'auto') != 'required'
and root.get('visualPreference') != 'required' and not node_requires_chart):
continue
context = scope_context(scope, release_id=release_id, question=question)
if isinstance(base_context, dict):
for key in ('_protocol', '_protocolScopes'):
if key in base_context:
context[key] = copy.deepcopy(base_context[key])
preference = task.get('visualPreference', 'auto')
fields, stages = task.get('fields'), task.get('stages') or []
optional_auto_scalar = (metric_scope and task.get('visualPreference') == 'auto'
and task.get('comparisonRequired') is not True and task.get('trendRequired') is not True
and isinstance(fields, list) and len(fields) == 1
and isinstance(stages, list) and len(stages) <= 1)
metric_chart_required = (preference == 'required' or task.get('comparisonRequired') is True
or task.get('visualType') is not None and not optional_auto_scalar)
# Batch Top1 results may intentionally omit auto charts. A model's
# style hint alone must not mark that omission as unavailable.
if scope.get('purpose') == 'changes':
requested_visuals |= preference == 'required'
elif metric_scope:
requested_visuals |= preference != 'none' and (
task.get('trendRequired') is True or metric_chart_required or ranking_task(task))
else:
requested_visuals |= preference != 'none' and (
task.get('trendRequired') is True or preference == 'required'
or task.get('visualType') is not None or task.get('kind') == 'analysis'
and bool(task.get('dimensions')) and set(task.get('fields', [])) <= {'totalWeight', 'scrapWeight'})
or task.get('visualType') is not None or ranking_task(task))
child = build_visuals(selected, child_question, turn_id, context=context)
child_visuals = child.get('visuals') if isinstance(child.get('visuals'), list) else []
metric_visual_requirements = []
if task.get('kind') == 'metrics' and task.get('comparisonRequired'):
if metric_scope and metric_chart_required:
stages = task.get('stages') or []
for field in task.get('fields', []):
if field == 'rate':
@@ -177,8 +201,7 @@ def protocol_visual_result(evidence, scopes, question, turn_id, *, release_id, b
all_visuals.append(copy.deepcopy(visual))
if child.get('visualState') == 'failed':
missing.append('节点'+str(node_id)+'范围'+str(scope.get('label') or scope_id)+'图表整理失败。')
if (scope.get('purpose') != 'defects' and task.get('kind') == 'analysis'
and task.get('dimensions') and set(task.get('fields', [])) <= {'totalWeight', 'scrapWeight'}):
if scope.get('purpose') != 'defects' and ranking_task(task):
from nao_weight_ranking import missing_ranking_visuals
missing.extend('节点'+str(node_id)+'范围'+str(scope.get('label') or scope_id)+':'+gap
for gap in missing_ranking_visuals(task, child_visuals, selected))
@@ -201,11 +224,10 @@ def protocol_visual_result(evidence, scopes, question, turn_id, *, release_id, b
and chart.get('type') in chart_types for chart in child_visuals):
missing.append('节点'+str(node_id)+'范围'+str(scope.get('label') or scope_id)
+'缺少'+str(stage or '综合')+' '+metric+'趋势图。')
elif task.get('kind') == 'metrics' and preference != 'none' and (
preference == 'required' or task.get('visualType') is not None):
elif metric_scope and preference != 'none' and metric_chart_required:
required = metric_visual_requirements
chart_types = ({task.get('visualType')} if task.get('visualType') else
{'bar', 'column'} if task.get('comparisonRequired') else set())
{'bar', 'column'})
if not required:
missing.append('节点'+str(node_id)+'范围'+str(scope.get('label') or scope_id)
+'缺少当前指标范围可表达的图表。')