50 lines
3.7 KiB
Python
50 lines
3.7 KiB
Python
"""Review a task's own requirements when no parent context is available."""
|
|
import time
|
|
|
|
from app.modules.work_assistant.requirement_review import review_requirements
|
|
from app.modules.work_assistant.review_commentary import review_commentary
|
|
from .task_review_contract import GOAL_RULE, SCHEMA_VERSION
|
|
|
|
|
|
def review_standalone(payload, *, invoke):
|
|
started = time.monotonic()
|
|
task = payload.goal
|
|
source = next(s for s in payload.sources if s.id == f'task:{task.id}')
|
|
findings = []
|
|
|
|
def issue(title, detail, suggestion, dimension='时间安排'):
|
|
findings.append(dict(dimension=dimension, severity='problem', origin='rule', title=title,
|
|
detail=detail, suggestion=suggestion, source_id=source.id, quote=source.text[:500]))
|
|
|
|
if task.start and task.end and task.start > task.end:
|
|
issue('开始日期晚于结束日期', f'当前安排为 {task.start} 至 {task.end}。', '核对并调整当前任务的起止日期。')
|
|
if not task.assignee.strip():
|
|
issue('未明确责任人', f'「{task.name}」未填写责任人。', '明确负责这项工作的人员。', '责任分工')
|
|
overdue = bool(task.end and task.end < payload.as_of and task.status != '1')
|
|
if overdue:
|
|
issue('任务已超过计划结束日', f'计划 {task.end} 完成,截至 {payload.as_of} 尚未登记完成。', '核对实际完成情况及剩余工作安排。')
|
|
requirements = review_requirements(task, [task], payload.sources, invoke=invoke, timeout_seconds=22)
|
|
findings.extend(requirements.pop('findings'))
|
|
schedule = dict(standalone=True, status='risk' if findings else 'recorded_complete' if task.status == '1' else 'insufficient',
|
|
summary='这里展示当前任务的登记情况,完成情况以实际成果为准。', as_of=str(payload.as_of),
|
|
goal_deadline=str(task.end) if task.end else None,
|
|
remaining_calendar_days=(task.end-payload.as_of).days if task.end else None,
|
|
goal_progress=task.progress, task_count=1, completed_count=int(task.status=='1'), overdue_count=int(overdue),
|
|
risks=[], needs=[], tasks=[dict(id=task.id, name=task.name, progress=task.progress,
|
|
status={'0':'进行中','1':'已完成','2':'待审核'}.get(task.status,'状态未明确'),
|
|
start=str(task.start) if task.start else None, end=str(task.end) if task.end else None)])
|
|
commentary = review_commentary(subject=task, goal=None, tasks=[task], sources=payload.sources,
|
|
review_kind='task', workflow=[], alignment=None, findings=findings, schedule=schedule,
|
|
requirements=requirements, limitations=payload.limitations, invoke=invoke,
|
|
timeout_seconds=max(0, 65-(time.monotonic()-started)))
|
|
complete = commentary['status']=='complete'
|
|
status = ('needs_revision' if findings or commentary.get('verdict')=='adjust' else
|
|
'failed' if not complete else
|
|
'insufficient' if payload.limitations or requirements['status']=='incomplete' else
|
|
'suggestions' if commentary.get('verdict')=='clarify' or requirements['attention_count'] else 'no_obvious_issue')
|
|
return dict(status=status, summary=commentary.get('assessment',commentary.get('message','')),
|
|
review_kind='task', standalone=True, subject_name=task.name, findings=findings,
|
|
alignment=None, workflow=[], schedule=schedule, commentary=commentary, requirements=requirements,
|
|
model_completed=complete, analysis_error=None, limitations=list(payload.limitations),
|
|
rule_version=GOAL_RULE, schema_version=SCHEMA_VERSION, sources=[s.model_dump(mode='json') for s in payload.sources])
|