feat: connect DSH supervision to task center UI

This commit is contained in:
阿白叔 committed 2026-10-30 09:22:40 +08:00
1 parent bf14b20a38
commit 0933766dcf
1 file changed
+24
@@ -24,11 +24,16 @@ from .queries import LatestQuery
from .task_log import TaskLogPresenter
from .execution_feedback import format_feedback
from .operation_state import ContextReadPhase, OperationPhase, OperationState
from ...dsh.service_adapter import DshServiceAdapter
from ...dsh.snapshot import TaskSnapshot
from ...dsh.supervisor import DshSupervisor
from .dsh_panel import DshPanel
class TrialTaskCenterWindow(QMainWindow):
def __init__(self, service, directory_picker=None, quick_run_confirmer=None, close_plan_confirmer=None):
super().__init__()
self.service = service
self._dsh = DshSupervisor(DshServiceAdapter(service).execute)
self._close_plan_confirmer = close_plan_confirmer or self._confirm_close_plans
self._close_pending = False
self._close_saving = False
@@ -87,6 +92,8 @@ class TrialTaskCenterWindow(QMainWindow):
self.move_mapping_down_button.clicked.connect(lambda: self._move_mapping(1))
self.plan_panel = ProjectPlanPanel(self)
self.run_panel = RunPanel()
self.dsh_button = QPushButton('DSH AI 监管')
self.dsh_button.clicked.connect(self._open_dsh)
self._log_presenter = TaskLogPresenter(service, self.run_panel, self)
self.run_panel.quick_run_button.clicked.connect(self._prepare_quick_run)
self.run_panel.stop_queue_button.clicked.connect(self._pause_queue)
@@ -158,6 +165,7 @@ class TrialTaskCenterWindow(QMainWindow):
details_layout = QVBoxLayout(details)
details_layout.setContentsMargins(0, 0, 0, 0)
details_layout.addWidget(self.run_panel.copy_value_check)
details_layout.addWidget(self.dsh_button)
details_layout.addWidget(self.archive_on_close_check)
details_layout.addWidget(self.detail_splitter, 1)
self.workspace_splitter = QSplitter(Qt.Orientation.Horizontal)
@@ -815,6 +823,14 @@ class TrialTaskCenterWindow(QMainWindow):
self.run_panel.operator_band.style().unpolish(self.run_panel.operator_band)
self.run_panel.operator_band.style().polish(self.run_panel.operator_band)
def _open_dsh(self):
task_id = self._task_id or ''
status = getattr(getattr(self, '_context', None), 'task', None)
status_value = getattr(getattr(status, 'status', None), 'value', 'observe')
panel = DshPanel(self.service, task_id=task_id,
snapshot=TaskSnapshot(task_id, str(status_value)), parent=self)
panel.exec()
def _cancel_ui_operation(self):
self.operation_state = self.operation_state.cancel()
self._set_operator_message(self.operation_state.message)
@@ -894,6 +910,14 @@ class TrialTaskCenterWindow(QMainWindow):
name = next((t.name for t in self._tasks if t.task_id == owner_task_id), owner_task_id)
message = f'任务「{name}」:{message}'
self._set_operator_message(message, 'error')
task_id = owner_task_id or self._task_id
if task_id and not (isinstance(error, TaskCenterError) and error.code == 'operation_cancelled'):
issue_code = getattr(error, 'code', error.__class__.__name__).lower()
try:
self._dsh.observe(TaskSnapshot(task_id, 'failed', issue_code=issue_code, issue=message))
except Exception:
# DSH must never hide or replace the original operation error.
pass
if owner_task_id is None or owner_task_id == self._task_id:
self._append_log(message)
self._update_gates()