Files
Elydora-Open-Source/sdks/python/elydora/plugins/qwen.py
T
雷电芽衣 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

89 lines
2.9 KiB
Python

"""Qwen Code 0.20 native global user-hook integration."""
from __future__ import annotations
from typing import Dict
from ._runtime import RuntimePaths
from .base import AgentPlugin, InstallConfig, PluginStatus
from .qwen_config import render_qwen_document
from .qwen_contract import (
AGENT_KEY,
AUDIT_HOOK_NAME,
GUARD_HOOK_NAME,
JsonObject,
build_qwen_group,
qwen_runtime_contracts,
)
from .qwen_installation import (
commit_qwen_installation,
commit_qwen_uninstall,
preflight_qwen_installation,
prepare_qwen_installation,
prepare_qwen_uninstall,
)
from .qwen_io import qwen_runtime_files_exist
from .qwen_sources import read_qwen_sources
def _installed_groups(paths: RuntimePaths) -> Dict[str, JsonObject]:
return {
"PreToolUse": build_qwen_group(paths.guard_path, GUARD_HOOK_NAME),
"PostToolUse": build_qwen_group(paths.audit_path, AUDIT_HOOK_NAME),
"PostToolUseFailure": build_qwen_group(
paths.audit_path, AUDIT_HOOK_NAME
),
}
class QwenPlugin(AgentPlugin):
"""Install Elydora into Qwen Code's native user settings."""
manages_guard_runtime = True
def preflight_install(self, config: InstallConfig) -> None:
sources = read_qwen_sources()
preflight_qwen_installation(config, sources)
def install(self, config: InstallConfig) -> None:
sources = read_qwen_sources()
paths = preflight_qwen_installation(config, sources)
rendered = render_qwen_document(
sources.user,
None,
_installed_groups(paths),
)
changes = prepare_qwen_installation(config, paths, rendered)
commit_qwen_installation(changes, sources)
print(f"Qwen Code hooks installed at {sources.user.file_path}")
print("Qwen Code verification: run /hooks and restart active sessions.")
def uninstall(self, agent_id: str = "") -> None:
sources = read_qwen_sources()
rendered = render_qwen_document(
sources.user, agent_id or None, {}
)
commit_qwen_uninstall(prepare_qwen_uninstall(rendered), sources)
def status(self) -> PluginStatus:
sources = read_qwen_sources()
contracts = qwen_runtime_contracts(sources.user.hooks)
configured = not sources.disable_control.disabled and bool(contracts)
installed = configured and qwen_runtime_files_exist(contracts)
if installed:
details = f"Config: {sources.user.file_path}"
elif contracts and sources.disable_control.disabled:
details = f"Configured hooks are disabled: {sources.user.file_path}"
elif contracts:
details = (
f"Configured at {sources.user.file_path}; "
"managed contract incomplete"
)
else:
details = "Not installed"
return PluginStatus(
installed=installed,
agent=AGENT_KEY,
details=details,
)