
    +j                     d    d Z ddlZdefdZ e            ZdefdZdefdZdefdZd Z	d	d
gZ
dS )u]  
lightclawbot — LightClaw platform plugin for Hermes Agent.

Registers the LightClaw adapter via the Hermes plugin discovery system.
No source-code modifications to lighthouse-hermes are required — the adapter
is discovered automatically when this package is placed under
``~/.hermes/plugins/lightclawbot/`` or installed via pip (entry_points).
    Nreturnc                  H    	 ddl m}   | d          S # t          $ r Y dS w xY w)z>Return package version from importlib.metadata, with fallback.r   versionlightclawbotz0.0.0)importlib.metadatar   	Exceptionr   s    8/home/agentuser/.hermes/plugins/lightclawbot/__init__.py_get_versionr      sK    ......w~&&&   wws    
!!c                      	 dS )a  Return the LightClaw-specific LLM capability hint.

    Only contents that are *unique* to LightClaw belong here.  The generic
    ``MEDIA:/absolute/path/to/file`` protocol, supported extensions and
    text post-processing are owned by the framework
    (``BasePlatformAdapter.extract_media`` + ``PLATFORM_HINTS`` in
    ``agent/prompt_builder.py``) and are intentionally NOT re-stated here.
    u  You are on LightClaw, a WebSocket-based messaging platform. Markdown formatting is supported (code blocks, bold, italic, tables).

FILE DELIVERY (MANDATORY — READ CAREFULLY):
After ANY tool creates or writes a file, your reply MUST contain a MEDIA: tag for that file — one tag per file, each on its own line.
The ONLY correct format is exactly:
MEDIA:<absolute path>

Correct examples:
  MEDIA:/home/ubuntu/报告.md
  MEDIA:/home/ubuntu/数据分析结果.xlsx

WRONG — never do any of these:
  [报告.md](/home/ubuntu/报告.md)        ← markdown link is WRONG
  [下载文件]()                            ← empty markdown link is WRONG
  MEDIA:[报告.md](...)                    ← MEDIA must be followed by a raw path only
  localfile:///home/ubuntu/报告.md        ← URL schemes are WRONG
  file:///home/ubuntu/报告.md             ← URL schemes are WRONG

Rules:
1. Use the literal prefix 'MEDIA:' followed immediately by the raw absolute path. No brackets, no parentheses, no markdown, no quotes.
2. The path must be the FULL absolute path returned by the tool, even if it contains Chinese characters or spaces. Copy it verbatim.
3. Emit the MEDIA: line even if you already described the file in prose.
4. One MEDIA: line per file when multiple files were written.
The framework converts each MEDIA: line into a download link for the user; without it the user gets NO download link.

For cron jobs / reminders / scheduled tasks, always set deliver='lightclawbot:<chat_id>' so results reach the user instead of being saved locally. r       r
   _load_platform_hintr      s    	 r   c                     t          | di           pi }t          |                    d          p&t          j        dd                                                    S )z=Check whether the platform config has enough info to connect.extraapi_keysLIGHTCLAW_API_KEY getattrboolgetosgetenvstripconfigr   s     r
   _validate_configr   C   sP    FGR((.BE		*%%S3F)K)K)Q)Q)S)STTTr   c                     t          | di           pi }t          |                    d          p&t          j        dd                                                    S )u  Check whether the platform is sufficiently configured (for status display).

    Hermes gateway 在启动时会用一个空的 ``PlatformConfig(enabled=True)`` 作为
    *probe_cfg* 来调用这个函数（见 ``gateway/config.py`` 的 plugin-platform
    enablement pass）。如果只检查 ``extra.api_keys``，env-only 配置（也就是
    把 ``LIGHTCLAW_API_KEY`` 写在 ``.env`` 而不写在 ``config.yaml``）会被
    误判为「未配置」，导致 gateway 跳过该平台、永不连接。

    所以必须兜底读 ENV。API key 等敏感凭证只应放在 ``.env``，``config.yaml``
    里仅放 ``platforms.lightclawbot.enabled: true`` 作为激活开关，这是
    hermes 官方插件（IRC / Teams / Line / ntfy 等）的通用做法。
    r   r   r   r   r   r   s     r
   _is_connectedr    I   sR     FGR((.BE		*%%S3F)K)K)Q)Q)S)STTTr   c                     ddl mm} |                     ddfd|t          t
          dgddd	d
dt                                 dS )a  Called by the Hermes plugin discovery system.

    Registers the LightClaw platform adapter so that:
      - Platform("lightclawbot") resolves to a dynamic enum member
      - The gateway creates and connects a LightClawAdapter at startup
      - send_message routes to the adapter via _send_via_adapter()
      - Cron delivery to "lightclawbot:<chat_id>" works automatically
      - User authorization respects LIGHTCLAW_ALLOWED_USERS env var
       )LightClawAdaptercheck_lightclaw_requirementsr   LightClawBotc                      |           S )Nr   )cfgr#   s    r
   <lambda>zregister.<locals>.<lambda>i   s    $4$4S$9$9 r   r   z*See https://pypi.org/project/lightclawbot/LIGHTCLAW_ALLOWED_USERSLIGHTCLAW_ALLOW_ALL_USERSi   u   ⚡)namelabeladapter_factorycheck_fnvalidate_configis_connectedrequired_envinstall_hintallowed_users_envallow_all_envmax_message_lengthemojiplatform_hintN)srcr#   r$   register_platformr   r    r   )ctxr$   r#   s     @r
   registerr;   Z   s~     DCCCCCCC9999-(")*A31)++      r   r;   __version__)__doc__r   strr   r<   r   r   r   r    r;   __all__r   r   r
   <module>r@      s     
			c     lnn&S & & & &RU U U U UUT U U U U"  : }
%r   