feat: add DSH AI supervision core

This commit is contained in:
阿白叔 committed 2026-10-30 09:22:40 +08:00
1 parent 12895e9868
commit bf14b20a38
13 files changed
+382

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
from dx_productivity.dsh.actions import validate_action
from dx_productivity.dsh.client import DshClientError, DshConfig, OpenAICompatibleClient
from dx_productivity.dsh.rules import classify
from dx_productivity.dsh.snapshot import TaskSnapshot
from dx_productivity.dsh.supervisor import DshSupervisor
def test_snapshot_redacts_paths_and_bounds_progress():
snapshot = TaskSnapshot("task-1", "failed", {"completed": 2, "path": "secret"}, "boom" * 500, "timeout")
safe = snapshot.safe_dict()
assert "path" not in safe["progress"]
assert len(safe["issue"]) == 500
def test_failed_event_auto_retries_once():
calls = []
supervisor = DshSupervisor(calls.append)
snapshot = TaskSnapshot("task-1", "failed", issue_code="worker_error")
first = supervisor.observe(snapshot)
second = supervisor.observe(snapshot)
assert first["proposal"]["name"] == "retry_failed"
assert len(calls) == 1
assert second["result"] is None
def test_uncertain_is_manual_review():
assert classify(TaskSnapshot("t", "uncertain")) == "manual_review"
def test_unknown_action_and_unconfigured_client_fail_closed():
try:
validate_action({"name": "shell", "task_id": "t"})
except ValueError as error:
assert str(error) == "unknown_dsh_action"
else:
raise AssertionError("unknown action accepted")
try:
OpenAICompatibleClient(DshConfig()).chat("hi", {})
except DshClientError as error:
assert str(error) == "dsh_model_not_configured"
else:
raise AssertionError("unconfigured client accepted")
+15
View File
@@ -0,0 +1,15 @@
from dx_productivity.dsh.actions import ActionProposal
from dx_productivity.dsh.service_adapter import DshServiceAdapter
class FakeService:
def __init__(self): self.calls = []
def prepare_failed_quick_run(self, task_id): self.calls.append(("retry", task_id))
def pause_task(self, task_id): self.calls.append(("pause", task_id))
def test_adapter_exposes_only_fixed_service_operations():
service = FakeService()
result = DshServiceAdapter(service).execute(ActionProposal("retry_failed", "task-1"))
assert result["status"] == "accepted"
assert service.calls == [("retry", "task-1")]