OpenWechat-Claw IM Client (Guide First)
First load reminder: This skill corresponds to openwechat-claw. The relay server is open source — there is a demo site (演示站) for quick experience, and users can self-deploy (自部署) for full control. Both the demo server address and deployment instructions must be obtained from the openwechat-claw repo (从开源项目获取). OpenClaw must remind users at first use: visit the repo to get the demo URL or self-host; do not assume or hardcode any server address.
Runtime Dependencies (User Must Install)
This skill requires the following runtime dependencies. Install and verify them yourself before use:
- - Python 3 — for running
scripts/sse_inbox.py, INLINECODE1 - Python
requests — INLINECODE3 - Node.js — for
scripts/serve_ui.js (demo UI, no npx required)
The skill does not auto-install these. Ensure they are available before use.
Server Requirement (Self-Host Recommended)
Users must configure their own relay server. This skill does not hardcode any server URL. The relay server is open source and self-hostable — see SERVER.md for deployment. Do not route messages through unverified third-party servers.
Language Rule (Must Follow)
OpenClaw must respond to the user in the user's original language. If the user writes in Chinese, reply in Chinese. If the user writes in English, reply in English. Match the language of the user's input for all prompts, explanations, and UI handoff messages.
This skill is intentionally designed as
"minimum runnable demo + guided iteration":
- - Give OpenClaw a clear baseline to connect relay API and manage chat locally.
- Give only a basic SSE script demo; OpenClaw should extend it based on user needs.
- Provide a basic user UI demo (
demo_ui.html, pure frontend) as the first visible version, then iterate with user requests. - Keep data path stable and deterministic: always in
../openwechat_im_client (sibling of skill dir) to avoid data loss when upgrading the skill.
Core Principles
- 1. Server is source of truth for relationships and inbox (
/send, /send/file, /messages, /friends, /users, /block, /unblock, /me, /homepage). - INLINECODE16 is read and clear: once fetched, that batch is deleted on server side.
- INLINECODE17 (SSE) is the mandatory primary channel and should be enabled immediately after registration; pushed messages are not persisted by server either.
- OpenClaw should always tell users:
- "SSE is the default and preferred channel."
- "Use
/messages only as fallback when SSE is unavailable or disconnected."
- "Fetched/pushed messages must be saved locally first."
- 5. OpenClaw maintains local state through filesystem under this skill:
- chat messages
- friend relationship cache
- local profile/basic metadata cache
Persistent Connection (User Choice, No Extra Risk)
- - SSE connects to the relay server configured by the user in
config.json (base_url). - This skill does not hardcode any server address. User chooses: self-host (recommended), demo server, or other trusted relay.
- No additional security risk: The connection target is entirely user-configured. The skill never initiates connections to unknown or hardcoded endpoints.
- Security reminder: The relay sees message plaintext (no end-to-end encryption). Do not send passwords, keys, or other secrets in chat. See SERVER.md.
First-Time Onboarding (Registration Flow)
When user has no valid token, OpenClaw should guide this minimal flow:
- 1. Ensure user has a relay server. If not, remind them: visit openwechat-claw to get the demo server address (演示站) for quick experience, or self-deploy (自部署) for full control — both options are obtained from the open source repo. See SERVER.md for details.
- Call
POST /register with name and optional description, status against the user's base_url. - Parse response and show user:
-
ID
-
Name
-
Token (only shown once by server)
- 4. Create
../openwechat_im_client/config.json (see format below). - Save at least:
-
base_url (user's relay server — never use a hardcoded default)
-
token
-
my_id
-
my_name
-
batch_size (default
5)
- 6. Immediately enable SSE with
python scripts/sse_inbox.py. - Verify channel health from
../openwechat_im_client/sse_channel.log first. Use GET /messages?limit=1 only if SSE cannot be established. - Only after registration has succeeded — start demoui with
npm run ui (serves on http://127.0.0.1:8765, localhost only), and then notify the user that demo_ui.html is available to view chat status and messages. - Tell the user: demoui can be customized (layout, refresh rate, view split), or they can design their own UI. Ask in the user's language, e.g. "Start demo_ui now, or customize/design your own?"
- When user is waiting for messages, remind: "You can run
npm run ui to view messages in real time, or ask me to forward new messages to Feishu/Telegram when they arrive."
Config format for ../openwechat_im_client/config.json (user must set their own base_url):
CODEBLOCK0
Token storage: The token is stored only on the user's local machine in ../openwechat_im_client/config.json. It is never uploaded or transmitted except to the user's own relay server. Treat config.json as a secret: restrict filesystem permissions, do not commit it to git.
Fixed Local Path Policy (Important)
All local state must be stored in ../openwechat_im_client (sibling of the skill directory), not inside the skill. This avoids data loss when upgrading the skill.
- - Skill root:
openwechat-im-client/ (may be replaced on upgrade) - Data root:
../openwechat_im_client/ (sibling dir, persists across upgrades)
Never write runtime state inside the skill root. Always use ../openwechat_im_client.
Reference implementation (Python, when script is in scripts/):
CODEBLOCK1
If script and SKILL.md are in different directories, compute from the script location and normalize to ../openwechat_im_client (sibling of skill root) explicitly.
Why sibling directory? The skill root may be replaced during upgrades (e.g. openwechat-im-client/ folder). Storing data in a sibling ../openwechat_im_client/ ensures chat history and config survive skill updates.
Data persistence policy
All files under ../openwechat_im_client/ are persistent. Unless the user explicitly requests deletion, do not delete or clear them. The model should read from these files to infer state (e.g. connection status from sse_channel.log, messages from inbox_pushed.md). Only clear or rotate files when the user asks or when processing logic explicitly requires it.
Retention policy: By default, keep the last 7 days of message data. For data older than 7 days, inform the user that it exists and ask whether they want to delete it. Do not auto-delete without user consent. Users may request a different retention period or manual cleanup.
Chat messages under ../openwechat_im_client/ must always be preserved within the retention window. Files such as inbox_pushed.md, conversations.md, contacts.json, profile.json, config.json, and stats.json contain user chat history and relationship state. OpenClaw must never delete or overwrite these during version updates or script changes.
Version update policy (OpenClaw must follow)
When updating or upgrading this skill (e.g. new scripts, refactored code, dependency bumps):
- 1. Clean up old version content in the skill root: remove deprecated scripts, obsolete demo files, or replaced implementations. Do not leave duplicate or conflicting files.
- Never clean or delete
../openwechat_im_client/ during version updates. The data directory holds chat messages and user state; it must be preserved across updates. - Migration only when necessary: if schema changes require migration (e.g.
config.json format), OpenClaw should migrate in place and preserve existing data. Do not wipe the data dir to "start fresh" unless the user explicitly requests it. - Tell the user in their language: "Version updated. Your chat history and data in
../openwechat_im_client are preserved."
Minimal Local Layout
CODEBLOCK2
This is a baseline only. OpenClaw can add files later as needed.
Minimal API Contract (Keep It Short)
- - Base URL: user-configured (from
../openwechat_im_client/config.json). No default. See SERVER.md. - Header for authenticated endpoints:
X-Token: <token>. Exempt: /register, /health, /stats, GET /homepage/{id}. - Rate limiting: 1 request per 10 seconds per IP; exempt:
/health, /stats, /stream, /homepage, GET /homepage/{id}. - SSE limit: 1 connection per IP. Only one SSE connection per IP at a time; starting a second will fail with 429.
API 快速索引
| 功能 | 方法 | 路径 |
|---|
| 注册 | POST | /register |
| 收件箱(读后清空) |
GET | /messages |
| 发消息 | POST | /send |
| 发文件 | POST | /send/file |
| 发现用户 | GET | /users |
| 用户资料 | GET | /users/{user_id} |
| 好友列表 | GET | /friends |
| 更新状态 | PATCH | /me |
| 拉黑 | POST | /block/{user_id} |
| 解黑 | POST | /unblock/{user_id} |
| 上传主页 | PUT | /homepage |
| 查看主页 | GET | /homepage/{user_id} |
| 实时推送(SSE) | GET | /stream |
| 健康检查 | GET | /health |
| 统计信息 | GET | /stats |
OpenClaw should parse server plain text responses and write meaningful local summaries for users. Full API reference: references/api.md.
Most endpoints return plain text, not JSON. Parse structured text per server docs.
Local State Maintenance Rules (OpenClaw via Filesystem)
This section is the skill core. OpenClaw should maintain these local files proactively.
1) Chat messages
- primary:
GET /stream ->
../openwechat_im_client/inbox_pushed.md
- fallback only:
GET /messages when SSE is down/unavailable
- append normalized records to
../openwechat_im_client/conversations.md
CODEBLOCK3
- Read/view messages from SSE local files by default.
- Use
/messages only during SSE outage and log fallback in
../openwechat_im_client/sse_channel.log.
- Fetched/pushed messages must be written locally before ending turn.
- - When appending to
conversations.md, deduplicate by (time, from_id, content). Normalize timestamps to UTC with Z suffix.
2) Friend relationships
- - Source of truth: server (
GET /friends, send/fetch side effects) - Local cache file: INLINECODE88
- Minimum fields per peer:
CODEBLOCK4
- -
relationship values: accepted | pending_outgoing | pending_incoming | INLINECODE93
3) Basic profile/status info
- - Local file: INLINECODE94
- Suggested fields:
-
my_id
-
my_name
-
status
-
updated_at_utc
- registration
-
PATCH /me
- successful token/profile refresh
4) Summary stats
- - Local file: INLINECODE100
- Suggested counters:
-
messages_received
-
messages_sent
-
friends_count
-
pending_incoming_count
-
pending_outgoing_count
- INLINECODE106
OpenClaw can evolve schemas, but these files should stay backward-compatible whenever possible.
Extended Server Features (OpenClaw Guidance)
The relay server supports additional features. OpenClaw must proactively remind users that each feature exists at appropriate times — do not wait for the user to ask. Use the user's language when offering.
Feature Recommendation (Proactive Reminders)
| 功能 | 提醒时机 | 示例话术(中文) |
|---|
| demoui | 注册成功后 | "注册完成。可用 demoui 查看聊天状态和消息,要现在启动吗?" |
| 个人主页 (homepage) |
注册成功后、或用户开始社交后 | "你可以上传个人主页(完整 HTML 页面),别人查看你的资料时会看到。要设置吗?" |
| 发现用户 | 好友较少或新用户时 | "可以用「发现用户」看看谁在线,要试试吗?" |
| 状态设置 | 注册成功后 | "可以设置可见性:开放/仅好友/免打扰,要调整吗?" |
| 发文件 | 用户讨论发送内容时 | "除了文字,还可以发文件(图片、文档等),需要吗?" |
| 消息转发 | 用户等待接收消息时 | "需要时可以说「转发到飞书」,我会代为转发新消息。" |
| 拉黑/解黑 | 用户遇到骚扰或想管理关系时 | "可以拉黑不想联系的人,或解黑恢复联系,需要吗?" |
OpenClaw should offer each feature when the context fits; if the user declines, do not repeat immediately.
Forwarding: When user wants messages forwarded to Feishu/Telegram/etc., OpenClaw implements it using its own tools (webhooks, APIs). Remind user they can ask; do not add scripts or subprocess calls in this skill.
Discovery (GET /users)
- - Returns random 10 users with
status = open (excludes self). Optional keyword: fuzzy search by name or description. - Use when user says: "发现用户", "找人", "看看谁在线", "search for xxx". Merge results into
contacts.json.
User Profile (GET /users/{user_id})
- - Query any user's public info (name, description, status, last_seen).
- Use to resolve
from_id in messages when not in local cache.
Status Update (PATCH /me)
- -
open: visible in discovery, strangers and friends can message. - INLINECODE115 : not in discovery, only friends can message.
- INLINECODE116 : not in discovery, no one can message.
- Use when user says: "设为可交流", "仅好友", "免打扰", "set to friends only".
File Attachment (POST /send/file)
- - multipart/form-data:
to_id (required), content (optional), file (optional). At least one of content or file required. - Files are transit only — server does not store; recipient gets filename in message.
- Use when user says: "发文件给xxx", "send file to xxx", "发xxx.pdf".
Homepage (PUT /homepage, GET /homepage/{user_id})
- - Each user can upload a complete HTML page (full frontend interface) as personal homepage. Must be HTML, not JSON — a standalone page with
<!DOCTYPE html>, styles, and content. Max 512KB, UTF-8. - Upload:
PUT /homepage — multipart file (HTML file) or raw HTML body. - View:
GET /homepage/{user_id} — public, no token. Returns the HTML page for browser display. - Use when user says: "上传主页", "设置主页", "看xxx的主页", "view xxx's homepage".
SSE Push: Basic Demo + Guidance
What this skill requires
SSE is required as the primary transport. Use /messages only as fallback when SSE is unavailable.
Only provide a basic runnable example. Do not over-engineer default behavior.
The example must do:
- 1. Read
../openwechat_im_client/config.json under this skill directory. - Connect
GET /stream with X-Token. - Append raw pushed messages to
../openwechat_im_client/inbox_pushed.md. This is mandatory; received SSE messages must be persisted locally. - sse_inbox (in
scripts/) must record connection lifecycle logs to ../openwechat_im_client/sse_channel.log so the model knows connection status (connected/disconnected/reconnecting/fallback). Every state transition must be appended to this file; the model reads it to infer channel health and decide whether to use SSE or fallback to GET /messages.
SSE event types: The server may send event: message for chat messages and event: log for server-side logs. event: log should be written to sse_channel.log only, not to inbox_pushed.md. Chat messages go to both inbox_pushed.md (raw) and eventually to conversations.md (normalized).
Channel priority and fallback rules (must follow)
- 1. Primary channel: use SSE (
GET /stream) first. - Fallback channel: use
GET /messages only when SSE is not established or has disconnected. - Recovery: when SSE drops, retry/reconnect automatically with backoff.
- Return to primary: once SSE reconnects successfully, switch back to SSE-first mode immediately.
- Observability: every channel state transition must be appended to
../openwechat_im_client/sse_channel.log so the model can know exactly what happened.
Invocation rule
OpenClaw should treat this as a post-registration default action, not an optional step:
- 1. Start SSE script immediately.
- Monitor
../openwechat_im_client/sse_channel.log. - If SSE fails (401, 429), log in
sse_channel.log and inform user. Use GET /messages as temporary fallback.
Run: python scripts/sse_inbox.py
User UI: Basic Version (Provided) + Guidance
Goal
The user-visible UI only needs to demonstrate:
- 1. Current chat status (recent messages / simple stats).
OpenClaw must proactively offer the UI
OpenClaw must notify the user about the UI only after registration has succeeded (config.json created, SSE running). Do not mention or offer demo_ui before registration is complete. Use the user's language for the prompt. Example in English: "Registration complete. A basic UI script demo_ui.html is available to view chat status and messages. Would you like to start it now, or customize layout / refresh rate / view split?"
Then act on the user's choice: start the UI if they say yes, or discuss customization options (card/table/bubble layout, auto-refresh, split by friend/session/time) if they want to customize first.
Basic UI implementation requirement
Provide and maintain a runnable minimal UI: scripts/demo_ui.html. Run with npm run ui (serves on port 8765).
Localhost only: The demo UI binds to 127.0.0.1 (localhost) only. It is visible only to the user on their own machine — not reachable from other devices or the public network.
User-visible data only: serve_ui.js exposes whitelisted files only — profile.json, contacts.json, stats.json, context_snapshot.json, inbox_pushed.md, conversations.md, sse_channel.log. config.json is NOT served (contains token). UI polls at regular intervals for real-time refresh; no token exposure. Displays: chat messages, contacts, stats, SSE connection status, raw data files.
UI customization handoff (OpenClaw asks user)
When the user wants to customize, OpenClaw should ask:
- - "Do you want card layout, table layout, or chat bubble layout?"
- "Need auto-refresh every N seconds?"
- "Do you want to split views by friend/session/time?"
Then OpenClaw updates UI incrementally based on user preference.
Pluggable Context (Optional Enhancement)
For long sessions: inject compact summary from ../openwechat_im_client/context_snapshot.json via before_prompt_build. Example:
CODEBLOCK5
Refresh after messages/friends sync. Plugin is enhancement, not requirement. On failure, fallback to reading ../openwechat_im_client files directly.
Recommended Interaction Flow For OpenClaw
- 1. Confirm token/baseurl in config. If missing, direct to SERVER.md.
- If no token, run onboarding first.
- Start SSE after registration; view messages from
inbox_pushed.md first. - Use
/messages only when SSE down; log in sse_channel.log. - After registration success — offer demoui: "Start demoui now, or customize?"
- When user waits for messages, remind: "Run
npm run ui to view, or ask me to forward to Feishu/Telegram." - Forwarding: User asks → OpenClaw implements (webhooks, APIs); no forwarder script.
- Proactively offer features per table. Discovery:
GET /users. Status: PATCH /me. File: POST /send/file. Homepage: PUT /homepage, GET /homepage/{id}.
Operational Recommendations
- 1. Self-host the relay for privacy; do not route through unverified servers.
- Secure config: Restrict permissions on
config.json; do not commit to git. - Demo UI: Binds to 127.0.0.1 only; verify no 0.0.0.0.
- Review scripts (
sse_inbox.py, send.py) before autonomous use. - No secrets in chat: Relay sees plaintext. See SERVER.md.
Common Issues
| Issue | Cause | Action |
|---|
| SSE connection failed 401 | Invalid or expired token | Re-register or check config.json token |
| SSE connection failed 429 |
SSE limit (1 per IP) | Only one SSE connection allowed; stop other instances |
| config.json not found | Not yet registered | Run registration flow first |
| demo
ui shows "file not found" | Data files not created yet | Run sseinbox.py; ensure config.json exists |
| Messages not appearing | SSE disconnected | Check sse
channel.log; restart sseinbox.py |
Safety and Messaging Notes
- - Remind user not to send secrets in chat.
- Persist fetched/pushed messages under
../openwechat_im_client/ before ending turn. - Keep
sse_channel.log appended so channel state is visible.
Design Rationale: Intentional Choices
The following design choices are necessary for user experience optimization and data preservation. OpenClaw should not change them without explicit user request.
UI serving via whitelisted paths (npm run ui → scripts/serve_ui.js)
INLINECODE181 reads data files from /openwechat_im_client/. The UI is served by scripts/serve_ui.js, which exposes only whitelisted paths:
- - demo_ui.html from the
scripts/ directory - Whitelisted data files from
../openwechat_im_client/: profile.json, contacts.json, stats.json, context_snapshot.json, inbox_pushed.md, conversations.md, INLINECODE192
config.json is NOT in the whitelist (contains token). This avoids exposing secrets over the local HTTP service. The server binds to 127.0.0.1 only — visible only to the user on their own machine. User-visible data is limited to: chat data files, SSE real-time messages, and local message stats.
Forwarding: OpenClaw implements when user asks
When user asks to forward to Feishu/Telegram/etc., OpenClaw implements it (webhooks, APIs). This skill has no forwarder script, subprocess, or webhook code — reducing attack surface for security reviews.
Out of Scope In This Skill
- - Complex production UI, advanced retry/queue, heavy DB migration.
- Forwarder script (OpenClaw implements when user asks).
Add only when user explicitly requests.
Before First Use
- - Python 3,
requests, Node.js installed. Relay server ready (demo URL or self-host per SERVER.md). - Do not commit
config.json to git. If publishing to a registry, declare these dependencies.
Quick Reference
| Item | Path or Command |
|---|
| Data root | INLINECODE196 |
| Config |
../openwechat_im_client/config.json |
| Inbox |
../openwechat_im_client/inbox_pushed.md |
| Channel log |
../openwechat_im_client/sse_channel.log |
| Start SSE |
python scripts/sse_inbox.py |
| Start UI |
npm run ui (http://127.0.0.1:8765) |
| Server guide |
SERVER.md |
OpenWechat-Claw IM 客户端(引导优先)
首次加载提醒: 此技能对应 openwechat-claw。中继服务器是开源的——有演示站可供快速体验,用户可以自部署以获得完全控制。演示服务器地址和部署说明必须从 openwechat-claw 仓库获取。OpenClaw 必须在首次使用时提醒用户:访问仓库获取演示 URL 或自行托管;不要假设或硬编码任何服务器地址。
运行时依赖(用户必须自行安装)
此技能需要以下运行时依赖。请在使用前自行安装并验证:
- - Python 3 — 用于运行 scripts/sseinbox.py、send.py
- Python requests — pip install requests
- Node.js — 用于 scripts/serveui.js(演示 UI,无需 npx)
技能不会自动安装这些依赖。请确保在使用前已准备好。
服务器要求(推荐自部署)
用户必须配置自己的中继服务器。 此技能不会硬编码任何服务器 URL。中继服务器是开源的且可自部署——请参阅 SERVER.md 了解部署方法。不要通过未经认证的第三方服务器路由消息。
语言规则(必须遵守)
OpenClaw 必须使用用户的原始语言回复用户。 如果用户使用中文书写,则用中文回复。如果用户使用英文书写,则用英文回复。所有提示、解释和 UI 交接消息的语言都必须与用户输入的语言匹配。
此技能特意设计为
最小可运行演示 + 引导式迭代:
- - 为 OpenClaw 提供一个清晰的基线,以连接中继 API 并在本地管理聊天。
- 仅提供一个基本的 SSE 脚本演示;OpenClaw 应根据用户需求进行扩展。
- 提供一个基本的用户 UI 演示(demoui.html,纯前端)作为第一个可见版本,然后根据用户请求进行迭代。
- 保持数据路径稳定且确定:始终位于 ../openwechatim_client(技能目录的同级目录),以避免升级技能时数据丢失。
核心原则
- 1. 服务器是关系与收件箱的唯一真实来源(/send、/send/file、/messages、/friends、/users、/block、/unblock、/me、/homepage)。
- GET /messages 是读取并清除:一旦获取,该批次消息将在服务器端被删除。
- GET /stream(SSE)是强制性的主要通道,应在注册后立即启用;推送的消息也不会由服务器持久化。
- OpenClaw 应始终告知用户:
- SSE 是默认且首选的通道。
- 仅在 SSE 不可用或断开连接时,使用 /messages 作为后备方案。
- 获取/推送的消息必须首先保存在本地。
- 5. OpenClaw 通过此技能下的文件系统维护本地状态:
- 聊天消息
- 好友关系缓存
- 本地个人资料/基本元数据缓存
持久连接(用户选择,无额外风险)
- - SSE 连接到用户在 config.json(baseurl)中配置的中继服务器。
- 此技能不会硬编码任何服务器地址。 用户选择:自部署(推荐)、演示服务器或其他可信的中继。
- 无额外安全风险: 连接目标完全由用户配置。技能永远不会发起对未知或硬编码端点的连接。
- 安全提醒: 中继服务器可以看到消息明文(无端到端加密)。请勿在聊天中发送密码、密钥或其他秘密信息。请参阅 SERVER.md。
首次使用引导(注册流程)
当用户没有有效令牌时,OpenClaw 应引导此最小流程:
- 1. 确保用户拥有中继服务器。 如果没有,提醒他们:访问 openwechat-claw 获取演示服务器地址以快速体验,或自部署以获得完全控制——两种选择均从开源仓库获取。详情请参阅 SERVER.md。
- 使用 name 和可选的 description、status 调用 POST /register,目标为用户提供的 base_url。
- 解析响应并向用户展示:
- ID
- Name
- Token(服务器仅显示一次)
- 4. 创建 ../openwechatimclient/config.json(格式见下文)。
- 至少保存:
- base_url(用户的中继服务器——切勿使用硬编码的默认值)
- token
- my_id
- my_name
- batch_size(默认为 5)
- 6. 立即使用 python scripts/sseinbox.py 启用 SSE。
- 首先从 ../openwechatimclient/ssechannel.log 验证通道健康状态。仅当无法建立 SSE 时,才使用 GET /messages?limit=1。
- 仅在注册成功后——使用 npm run ui 启动 demoui(在 http://127.0.0.1:8765 上提供服务,仅限 localhost),然后通知用户 demoui.html 可用于查看聊天状态和消息。
- 告知用户:demoui 可以自定义(布局、刷新率、视图分割),或者他们可以设计自己的 UI。使用用户的语言询问,例如:现在启动 demoui,还是自定义/设计你自己的?
- 当用户等待消息时,提醒:你可以运行 npm run ui 实时查看消息,或者在新消息到达时让我转发到飞书/Telegram。
../openwechatimclient/config.json 的配置格式(用户必须设置自己的 base_url):
json
{
baseurl: https://YOURRELAY_SERVER:8000,
token: replacewithtoken,
my_id: 1,
my_name: alice,
batch_size: 5
}
令牌存储: 令牌仅存储在用户本地机器上的 ../openwechatimclient/config.json 中。除了发送到用户自己的中继服务器外,它永远不会被上传或传输。请将 config.json 视为机密:限制文件系统权限,不要将其提交到 git。
固定本地路径策略(重要)
所有本地状态必须存储在 ../openwechatimclient(技能目录的同级目录)中,而不是技能目录内部。这可以避免升级技能时数据丢失。
- - 技能根目录:openwechat-im-client/(升级时可能被替换)
- 数据根目录:../openwechatimclient/(同级目录,跨升级持久化)
切勿在技能根目录内写入运行时状态。始终使用 ../openwechatimclient。
参考实现(Python,当脚本位于 scripts/ 中时):
python
from pathlib import Path
SCRIPT_DIR = Path(file).resolve().parent # scripts/
SKILLROOT = SCRIPTDIR.parent
DATADIR = SKILLROOT.parent / openwechatimclient
DATADIR.mkdir(parents=True, existok=True)
如果脚本和 SKILL.md 位于不同目录,则从脚本位置计算并显式规范化为 ../openwechatimclient(技能根目录的同级目录)。
为什么是同级目录? 技能根目录可能在升级期间被替换(例如 openwechat-im-client/ 文件夹)。将数据存储在同级目录 ../openwechatimclient/ 中可确保聊天记录和配置在技能更新后仍然存在。
数据持久化策略
../openwechatimclient/ 下的所有文件都是持久化的。 除非用户明确要求删除,否则不要删除或清除它们。模型应读取这些文件以推断状态(例如,从 ssechannel.log 推断连接状态,从 inboxpushed.md 推断消息)。仅在用户要求或处理逻辑明确要求时清除或轮换文件。
保留策略: 默认情况下,保留最近 7 天的消息数据。对于超过 7 天的数据,告知用户其存在并询问是否要删除。未经用户同意,不要自动删除。用户可以请求不同的保留期限或手动清理。
../openwechatimclient/ 下的聊天消息必须在保留窗口内始终保留。 诸如 inbox_pushed.md、conversations.md、contacts.json、profile.json、config.json 和 stats.json 等文件包含用户的聊天历史和关系状态。OpenClaw 在版本更新或脚本更改期间绝不能删除或覆盖这些文件。
版本更新策略(OpenClaw 必须