wip: preserve local engine and agent workflow changes before ganjihong refactor integration
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Protocol v3 composition root. This is the only layer joining adapters."""
|
||||
"""Single-stage Authoring CDSL composition root."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -6,70 +6,58 @@ from dataclasses import dataclass
|
||||
import shutil
|
||||
|
||||
from app.cad_agent.adapters.artifact_store import FileArtifactStore
|
||||
from app.cad_agent.adapters.author_guidance import FileAuthorGuidance
|
||||
from app.cad_agent.adapters.event_publisher import IdempotentInProcessPublisher
|
||||
from app.cad_agent.adapters.runtime import ProfileCadRuntime
|
||||
from app.cad_agent.adapters.review_gateway import RenderedReviewGateway
|
||||
from app.cad_agent.adapters.sqlite_repository import SqliteTaskRepository
|
||||
from app.cad_agent.adapters.structured_llm import StructuredModelGateway
|
||||
from app.cad_agent.adapters.verifier import RegistryVerifierExecutor
|
||||
from app.cad_agent.application.action_handlers import ActionCommandHandler
|
||||
from app.cad_agent.application.outbox import OutboxDispatcher
|
||||
from app.cad_agent.application.requirements import RequirementsCommandHandler
|
||||
from app.cad_agent.application.workflow import ModelIdentity, WorkflowConfig, WorkflowCoordinator
|
||||
from app.cad_agent.domain.verifier_registry import default_registry
|
||||
from app.settings import BACKEND_ROOT, Settings
|
||||
from app.cad_agent.application.workflow import WorkflowConfig, WorkflowCoordinator
|
||||
from app.cad_agent.application.single_stage import SingleStageExecutor
|
||||
from app.settings import Settings
|
||||
from app.services.storage import WorkspaceStore
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class V3Services:
|
||||
class CadServices:
|
||||
repository: SqliteTaskRepository
|
||||
artifacts: FileArtifactStore
|
||||
workflow: WorkflowCoordinator
|
||||
models: StructuredModelGateway
|
||||
outbox: OutboxDispatcher
|
||||
single_stage: SingleStageExecutor
|
||||
|
||||
|
||||
def compose_v3(settings: Settings) -> V3Services:
|
||||
repository = SqliteTaskRepository(settings.task_root.parent / "autonomous-cad-v3.sqlite3")
|
||||
if repository.protocol_reset and settings.task_root.exists():
|
||||
# Protocol 3.1 has no valid interpretation for structured-only task
|
||||
# artifacts, so clear that task root together with its old database.
|
||||
def compose_cad_services(settings: Settings) -> CadServices:
|
||||
database_root = settings.task_root.parent
|
||||
legacy_database = database_root / "autonomous-cad-v3.sqlite3"
|
||||
removed_legacy_database = False
|
||||
if legacy_database.exists():
|
||||
# The removed coordinator persisted incompatible task/action state in
|
||||
# its own database. Delete it as part of the deliberate destructive
|
||||
# migration, including SQLite sidecars if a worker stopped mid-write.
|
||||
for candidate in (legacy_database, *(database_root / f"{legacy_database.name}{suffix}" for suffix in ("-wal", "-shm"))):
|
||||
if candidate.exists():
|
||||
candidate.unlink()
|
||||
removed_legacy_database = True
|
||||
repository = SqliteTaskRepository(database_root / "autonomous-cad-single-stage.sqlite3")
|
||||
protocol_reset = repository.protocol_reset or removed_legacy_database
|
||||
if protocol_reset and settings.task_root.exists():
|
||||
# Old task artifacts have no valid interpretation under the Authoring
|
||||
# protocol, so clear them together with the task database.
|
||||
shutil.rmtree(settings.task_root)
|
||||
if repository.protocol_reset:
|
||||
if protocol_reset:
|
||||
WorkspaceStore(settings).clear_current_task_references()
|
||||
artifacts = FileArtifactStore(settings.task_root)
|
||||
runtime = ProfileCadRuntime(settings)
|
||||
registry = default_registry()
|
||||
verifier = RegistryVerifierExecutor(registry)
|
||||
requirements = RequirementsCommandHandler(repository, artifacts, registry, atomic_ids=runtime.supported_atomic_ids)
|
||||
actions = ActionCommandHandler(repository, artifacts, runtime, verifier)
|
||||
fallbacks = tuple(
|
||||
ModelIdentity(provider.id, model.id)
|
||||
for provider in settings.providers
|
||||
if provider.configured
|
||||
for model in provider.models[:1]
|
||||
)
|
||||
models = StructuredModelGateway(settings)
|
||||
outbox = OutboxDispatcher(repository, IdempotentInProcessPublisher())
|
||||
single_stage = SingleStageExecutor(repository, artifacts, runtime)
|
||||
workflow = WorkflowCoordinator(
|
||||
WorkflowConfig(
|
||||
max_turns=max(8, settings.agent_tool_calls_per_cycle * 8),
|
||||
format_error_limit=settings.agent_format_error_repeat_limit,
|
||||
author_fallbacks=fallbacks,
|
||||
),
|
||||
WorkflowConfig(),
|
||||
repository,
|
||||
artifacts,
|
||||
runtime,
|
||||
models,
|
||||
RenderedReviewGateway(models),
|
||||
requirements,
|
||||
actions,
|
||||
FileAuthorGuidance(
|
||||
BACKEND_ROOT / "agent" / "skills" / "cdsl-author-guidance",
|
||||
enabled=settings.agent_author_guidance_enabled,
|
||||
max_chars=settings.agent_author_guidance_max_chars,
|
||||
),
|
||||
single_stage,
|
||||
)
|
||||
return V3Services(repository, artifacts, workflow, models, outbox)
|
||||
return CadServices(repository, artifacts, workflow, models, outbox, single_stage)
|
||||
|
||||
Reference in New Issue
Block a user