Split the 657-line operation service into eor, submit, and verify modules, add the AGENT_REVOKED and KEY_RETIRED codes the Backend already emits, and condense every multi-line comment. Mirror Node, Python, and Go at 2.1.0 with the deep-health 503, non-idempotent retry, rotation grace, and path-encoding fixes. Document which routes and response fields the self-hosted server does not provide. Claude-Session: https://claude.ai/code/session_01Agoc9bRVE9KL7mmWtey9Vq
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
"""Physical Cline hook and managed runtime validation."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from typing import Tuple
|
|
|
|
from ._managed_files import physical_directory_exists, read_physical_file
|
|
from ._runtime import expected_runtime_scripts, runtime_contract_exists
|
|
from ._strict_json import JsonObject
|
|
from .cline_contract import AGENT_KEY, HookFile, RuntimeContract, parse_metadata
|
|
|
|
|
|
def validate_hook_tree(hooks_directory: str) -> None:
|
|
physical_directory_exists(os.path.dirname(hooks_directory), "Cline configuration directory")
|
|
physical_directory_exists(hooks_directory, "Cline hooks directory")
|
|
|
|
|
|
def read_hook_file(file_path: str) -> HookFile:
|
|
validate_hook_tree(os.path.dirname(file_path))
|
|
snapshot = read_physical_file(file_path, "Cline hook")
|
|
if snapshot is None:
|
|
return HookFile(False, file_path)
|
|
return HookFile(
|
|
exists=True,
|
|
file_path=file_path,
|
|
source=snapshot.contents,
|
|
metadata=parse_metadata(file_path, snapshot.contents),
|
|
)
|
|
|
|
|
|
def require_available_hook_file(file: HookFile) -> None:
|
|
if file.exists and file.metadata is None:
|
|
raise ValueError(
|
|
f"Cline hook at {file.file_path} already exists and is owned "
|
|
"by another integration"
|
|
)
|
|
|
|
|
|
def _expected_scripts(agent_id: str, _config: JsonObject) -> Tuple[str, str]:
|
|
return expected_runtime_scripts(AGENT_KEY, agent_id)
|
|
|
|
|
|
def runtime_files_exist(contract: RuntimeContract) -> bool:
|
|
return runtime_contract_exists(contract, AGENT_KEY, "Cline", _expected_scripts)
|