wip: preserve local engine and agent workflow changes before ganjihong refactor integration

This commit is contained in:
2026-09-09 17:08:24 +08:00
parent a5c3ec1f36
commit 387b99e255
112 changed files with 3543 additions and 12177 deletions
+6 -78
View File
@@ -5,60 +5,13 @@ from __future__ import annotations
from dataclasses import dataclass
from typing import Any, Protocol
from .domain.state import TaskPhase, TaskState
from .domain.state import TaskState
class AdapterUnavailable(RuntimeError):
"""A bounded external-service outage; handlers must preserve checkpoints."""
@dataclass(frozen=True, slots=True)
class AuthorGuidanceSelection:
"""Non-authoritative author context selected from the local guidance corpus."""
version: str = ""
section_ids: tuple[str, ...] = ()
content: str = ""
enabled: bool = False
fallback_reason: str = ""
def usage_metadata(self) -> dict[str, object]:
return {
"guidance_version": self.version,
"guidance_section_ids": list(self.section_ids),
"guidance_chars": len(self.content),
"guidance_enabled": self.enabled,
"guidance_fallback_reason": self.fallback_reason,
}
class AuthorGuidance(Protocol):
"""Select bounded local author guidance without interpreting user intent."""
def select(
self,
*,
phase: TaskPhase,
atomic_id: str,
repair_required: bool,
supported_atomic_ids: tuple[str, ...],
) -> AuthorGuidanceSelection: ...
class NullAuthorGuidance:
"""Compatibility default that retains the pre-guidance author prompt."""
def select(
self,
*,
phase: TaskPhase,
atomic_id: str,
repair_required: bool,
supported_atomic_ids: tuple[str, ...],
) -> AuthorGuidanceSelection:
return AuthorGuidanceSelection(fallback_reason="guidance_not_configured")
@dataclass(frozen=True, slots=True)
class InvocationRecord:
invocation_id: str
@@ -68,7 +21,7 @@ class InvocationRecord:
@dataclass(frozen=True, slots=True)
class CandidateStage:
class StagingRevision:
stage_id: str
output_dir: str
@@ -106,38 +59,21 @@ class TaskRepository(Protocol):
class ArtifactStore(Protocol):
def initialize_task(self, task_id: str, request: str, *, source_blocks: list[dict[str, Any]] | None = None, image_inputs: list[dict[str, str]] | None = None) -> None: ...
def sync_action_ledger(self, task_id: str, events: list[dict[str, Any]]) -> str: ...
def write_source_index(self, task_id: str, request: str) -> dict[str, str]: ...
def read_source_index(self, task_id: str) -> dict[str, str]: ...
def sync_event_ledger(self, task_id: str, events: list[dict[str, Any]]) -> str: ...
def read_source_requirements(self, task_id: str) -> str: ...
def source_image_paths(self, task_id: str) -> list[str]: ...
def read_requirements_spec(self, task_id: str, artifact_path: str = "") -> dict[str, Any] | None: ...
def read_requirements_contract(self, task_id: str, artifact_path: str = "") -> dict[str, Any] | None: ...
def write_requirements_contract(self, task_id: str, payload: dict[str, Any], *, invocation_id: str = "") -> str: ...
def read_json(self, task_id: str, relative_path: str) -> dict[str, Any] | None: ...
def write_json_once(self, task_id: str, relative_path: str, payload: dict[str, Any]) -> str: ...
def write_text_once(self, task_id: str, relative_path: str, text: str) -> str: ...
def read_active_cdsl(self, task_id: str, revision_id: str) -> dict[str, Any] | None: ...
def read_topology(self, task_id: str, revision_id: str) -> dict[str, Any] | None: ...
def start_candidate_stage(self, task_id: str, idempotency_key: str, payload: dict[str, Any]) -> CandidateStage: ...
def stage_output_dir(self, task_id: str, stage_id: str) -> str: ...
def start_staging_revision(self, task_id: str, idempotency_key: str, payload: dict[str, Any]) -> StagingRevision: ...
def write_stage_json(self, task_id: str, stage_id: str, relative_path: str, payload: dict[str, Any]) -> str: ...
def read_stage_json(self, task_id: str, stage_id: str, relative_path: str) -> dict[str, Any] | None: ...
def publish_candidate(self, task_id: str, stage_id: str, revision_id: str) -> dict[str, str]: ...
def find_published_candidate(self, task_id: str, stage_id: str) -> tuple[str, dict[str, Any]] | None: ...
def recover_staged_candidates(self, task_id: str, referenced_stage_ids: set[str]) -> None: ...
def publish_staging_revision(self, task_id: str, stage_id: str, revision_id: str) -> dict[str, str]: ...
class CadRuntime(Protocol):
def supported_atomic_ids(self) -> tuple[str, ...]: ...
def operation_contract(self, atomic_id: str) -> dict[str, Any]: ...
def selector_tokens(self, topology: dict[str, Any] | None) -> dict[str, dict[str, Any]]: ...
def reference_tokens(self, cdsl: dict[str, Any] | None) -> dict[str, str]: ...
def materialize_fragment(self, base_cdsl: dict[str, Any] | None, fragment: dict[str, Any], contract: dict[str, Any], selector_tokens: dict[str, dict[str, Any]], reference_tokens: dict[str, str], *, require_through: bool = False, depends_on_feature_ids: tuple[str, ...] | list[str] = ()) -> tuple[dict[str, Any], dict[str, Any]]: ...
def build_checkpoint(self, cdsl: dict[str, Any], output_dir: str, task_id: str, revision_id: str) -> dict[str, Any]: ...
def create_preview(self, output_dir: str) -> dict[str, Any]: ...
def render_review_bundle(self, output_dir: str) -> dict[str, Any]: ...
def rebuild(self, cdsl: dict[str, Any], output_dir: str, task_id: str, revision_id: str) -> dict[str, Any]: ...
def compile_authoring(self, document: dict[str, Any]) -> tuple[dict[str, Any], dict[str, Any]]: ...
def rebuild_best_effort(self, cdsl: dict[str, Any], output_dir: str, task_id: str, revision_id: str) -> tuple[dict[str, Any], list[dict[str, Any]]]: ...
@@ -146,13 +82,5 @@ class ModelGateway(Protocol):
async def conformance(self, *, provider_id: str, model_id: str, tools: list[dict[str, Any]]) -> dict[str, Any]: ...
class ReviewGateway(Protocol):
async def review(self, *, kind: str, payload: dict[str, Any], tool: dict[str, Any], provider_id: str, model_id: str) -> dict[str, Any]: ...
class VerifierExecutor(Protocol):
def evaluate(self, claims: list[dict[str, Any]], facts: dict[str, Any]) -> list[dict[str, Any]]: ...
class EventPublisher(Protocol):
async def publish(self, event: dict[str, Any]) -> None: ...