Files
Elydora-Python-SDK/elydora/plugins/grok_io.py
T
雷电芽衣 407e4628a0 chore(python): audit providers kimi grok qwen letta
Move the four providers onto _runtime and _shell_command; expected
runtime scripts take the runtime config; add unique_preconditions.

Claude-Session: https://claude.ai/code/session_01Agoc9bRVE9KL7mmWtey9Vq
2026-09-02 23:58:10 -04:00

58 lines
1.7 KiB
Python

"""Grok user-hook discovery and managed runtime I/O."""
from __future__ import annotations
import os
from typing import List, Optional
from ._managed_files import physical_directory_exists, read_physical_file
from ._runtime import rendered_source_change, runtime_contract_exists
from ._transaction import FileChange
from .grok_contract import (
AGENT_KEY,
GrokDocument,
GrokRuntimeContract,
RenderedGrokDocument,
create_grok_document,
parse_grok_document,
)
CONFIG_FILE = "elydora-audit.json"
def grok_config_path() -> str:
configured = os.environ.get("GROK_HOME")
grok_home = (
os.path.join(os.path.expanduser("~"), ".grok")
if configured is None or configured == ""
else os.path.abspath(configured)
)
return os.path.join(grok_home, "hooks", CONFIG_FILE)
def read_grok_document() -> GrokDocument:
config_path = grok_config_path()
hooks_directory = os.path.dirname(config_path)
physical_directory_exists(os.path.dirname(hooks_directory), "Grok home directory")
physical_directory_exists(hooks_directory, "Grok hooks directory")
snapshot = read_physical_file(config_path, "Grok user hooks")
if snapshot is None:
return create_grok_document(config_path)
return parse_grok_document(config_path, snapshot.contents)
def rendered_change(rendered: RenderedGrokDocument) -> Optional[FileChange]:
if not rendered.changed:
return None
return rendered_source_change(
rendered.document.config_path,
"Grok user hooks",
rendered.document.raw,
rendered.next_source,
)
def grok_runtime_files_exist(contracts: List[GrokRuntimeContract]) -> bool:
return any(runtime_contract_exists(contract, AGENT_KEY, "Grok") for contract in contracts)