Files
雷电芽衣 bc6983a62e chore(oss): audit the server package and resync the SDK mirrors
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
2026-09-03 20:48:20 -04:00

62 lines
1.9 KiB
Python

"""Claude Code settings discovery and managed runtime I/O."""
from __future__ import annotations
import os
from typing import List, Optional
from ._managed_files import MAX_SOURCE_BYTES, physical_directory_exists, read_physical_file
from ._runtime import rendered_source_change, runtime_contract_exists
from ._transaction import FileChange, write_changes
from .claudecode_contract import (
AGENT_KEY,
CONFIG_FILE,
ClaudeDocument,
ClaudeRuntimeContract,
RenderedClaudeDocument,
create_claude_document,
parse_claude_document,
)
def claude_config_directory() -> str:
if "CLAUDE_CONFIG_DIR" not in os.environ:
return os.path.join(os.path.expanduser("~"), ".claude")
return os.path.abspath(os.environ["CLAUDE_CONFIG_DIR"])
def claude_settings_path() -> str:
return os.path.join(claude_config_directory(), CONFIG_FILE)
def read_claude_document() -> ClaudeDocument:
file_path = claude_settings_path()
physical_directory_exists(os.path.dirname(file_path), "Claude Code configuration directory")
snapshot = read_physical_file(file_path, "Claude Code user settings", MAX_SOURCE_BYTES)
if snapshot is None:
return create_claude_document(file_path)
return parse_claude_document(file_path, snapshot.contents)
def rendered_change(rendered: RenderedClaudeDocument) -> Optional[FileChange]:
if not rendered.changed:
return None
return rendered_source_change(
rendered.document.file_path,
"Claude Code user settings",
rendered.document.raw,
rendered.next_source,
)
def write_claude_document(rendered: RenderedClaudeDocument) -> None:
change = rendered_change(rendered)
if change is not None:
write_changes([change], "Uninstall Claude Code hooks")
def claude_runtime_files_exist(contracts: List[ClaudeRuntimeContract]) -> bool:
return any(
runtime_contract_exists(contract, AGENT_KEY, "Claude Code") for contract in contracts
)