@dhf-openclaw/grix 0.4.9 → 0.4.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dhf-openclaw/grix",
3
- "version": "0.4.9",
4
- "description": "Connect OpenClaw to grix.dhf.pub for OpenClaw website management with mobile PWA support",
3
+ "version": "0.4.10",
4
+ "description": "Unified Grix OpenClaw plugin with channel transport, typed admin tools, and operator CLI",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "exports": {
@@ -28,9 +28,7 @@
28
28
  "README.md",
29
29
  "openclaw.plugin.json",
30
30
  "dist/index.js",
31
- "skills/message-send/SKILL.md",
32
- "skills/message-unsend/SKILL.md",
33
- "skills/message-unsend/flowchart.mermaid"
31
+ "skills"
34
32
  ],
35
33
  "publishConfig": {
36
34
  "access": "public",
@@ -44,7 +42,7 @@
44
42
  "publish:npm": "npm run publish:npm:preview",
45
43
  "publish:npm:preview": "bash ./scripts/publish_npm.sh",
46
44
  "publish:npm:release": "bash ./scripts/publish_npm.sh --publish",
47
- "test": "node --test src/*.test.ts"
45
+ "test": "node --test src/*.test.ts src/admin/*.test.ts"
48
46
  },
49
47
  "devDependencies": {
50
48
  "esbuild": "0.27.4",
@@ -0,0 +1,170 @@
1
+ ---
2
+ name: egg-install
3
+ description: 在虾塘触发的安装私聊中处理 egg 安装。适用于主 OpenClaw agent 收到包含 install_id、egg、install、main_agent 的安装上下文时,负责与用户多轮确认、执行 persona.zip 到 OpenClaw agent 或 skill.zip 到 Claude agent 的正规安装流程,并在当前私聊里持续回报进度、失败原因和最终结果。
4
+ ---
5
+
6
+ # Egg Install
7
+
8
+ 仅在"虾塘发起的安装私聊"里使用这个技能。
9
+
10
+ 这类会话通常会先收到一条系统代发的安装请求,正文里会带一个 JSON 上下文块,至少包含:
11
+
12
+ - `install_id` — 安装单唯一 ID,所有状态指令必须使用原值
13
+ - `egg` — egg 包标识,格式为 `<name>@<version>` 或带完整下载 URL 的对象
14
+ - `install` — 安装模式,枚举值:`create_new`(新建目标 agent)或 `existing_agent`(安装到已有 agent)
15
+ - `main_agent` — 发起安装的主 OpenClaw agent ID,安装完成后如需通知或回调,使用该 ID
16
+
17
+ 你的职责不是返回隐藏协议结果,而是直接在当前私聊里把安装流程做完。
18
+
19
+ ## 工作方式
20
+
21
+ 1. 先读完整个 JSON 上下文,确认 egg、版本、安装模式和目标类型。
22
+ 2. 在真正动手前,先在当前私聊里和用户确认关键目标。
23
+ 3. `create_new` 时,先确认新 agent 的命名和用途,再继续创建。
24
+ 4. `existing_agent` 时,只能操作上下文里指定的目标 agent,不要私自换目标。
25
+ 5. 安装过程中,每完成一个关键动作就用自然语言回报一次进度。
26
+ 6. 在"包下载完成"和"安装内容落位完成待校验"两个节点,各额外发送一条 `status=running` 的**独立安装状态指令消息**。
27
+ 7. 最终成功或失败时,必须发送一条 `status=success` 或 `status=failed` 的**独立安装状态指令消息**。
28
+ 8. 出错时,直接说明失败点、影响和下一步建议,不要模糊带过。
29
+ 9. 最终明确告诉用户:装到了哪个 agent、结果成功还是失败、后续是否还要继续操作。
30
+
31
+ ## 绝对规则
32
+
33
+ - 只在当前私聊里沟通,不要切换到隐藏协议,不要输出机器专用 JSON。
34
+ - 必须按 OpenClaw / Claude 的正规步骤安装,不要直接改后端数据库。
35
+ - 需要创建远端 API agent 时,使用 `grix_agent_admin`。
36
+ - 所有远端 API 通讯都必须走统一工具入口:`grix_query` / `grix_group` / `grix_agent_admin`,禁止在对话里自行发 HTTP 请求。
37
+ - 禁止使用 `curl`、`fetch`、`axios` 或临时脚本直连 `/v1/agent-api`。
38
+ - 单个业务动作只调用一次对应工具,失败后先说明原因,不要静默重试。
39
+ - `persona.zip` 只能面向 OpenClaw 目标。
40
+ - `skill.zip` 只能面向 Claude 目标。
41
+ - 不要自动新建 Claude 目标 agent。
42
+ - 没完成校验前,绝不能宣称安装成功。
43
+ - 如果新建目标后又失败了,能安全回滚就先回滚;不能回滚就如实告诉用户当前残留状态。
44
+ - 最终成功或失败时,必须发送一条独立的 `egg-install-status` 指令消息。
45
+ - 状态指令消息必须单独发送,不要和自然语言解释混在同一条里。
46
+ - 用户拒绝确认或主动取消时,必须发送 `status=failed`、`error_code=user_cancelled` 的状态指令后再结束。
47
+
48
+ ## 安装状态指令
49
+
50
+ server 不会猜自然语言。要让安装单进入"进行中 / 成功 / 失败",你必须发送这类单行消息:
51
+
52
+ ```text
53
+ [[egg-install-status|install_id=<INSTALL_ID>|status=<running|success|failed>|step=<STEP>|summary=<URI_ENCODED_SUMMARY>]]
54
+ ```
55
+
56
+ 常用可选字段:
57
+
58
+ - `target_agent_id=<AGENT_ID>`:成功时尽量带上,尤其是 `create_new`。
59
+ - `detail_text=<URI_ENCODED_DETAIL>`:补充更长说明。
60
+ - `error_code=<ERROR_CODE>`:失败时建议带上。
61
+ - `error_msg=<URI_ENCODED_ERROR_MSG>`:失败时建议带上。
62
+
63
+ 规则:
64
+
65
+ 1. `install_id` 必须使用上下文里的原值。
66
+ 2. `status` 只能是 `running`、`success`、`failed`。
67
+ 3. `summary`、`detail_text`、`error_msg` 如果有空格、中文或特殊字符,按 URI component 编码。
68
+ 4. 这条指令只负责状态收口;如果要跟用户解释原因,另发一条正常文字消息。
69
+ 5. `create_new` 成功时,必须尽量带 `target_agent_id`,否则 server 可能无法通过最终校验。
70
+
71
+ ## 统一 API 请求机制
72
+
73
+ 当安装流程需要访问 Grix 远端能力时,统一按下面路由,不要绕过:
74
+
75
+ 1. 查联系人 / 会话 / 消息:调用 `grix_query`
76
+ 2. 群治理动作(建群、加人、移人、禁言、解散):调用 `grix_group`
77
+ 3. 创建远端 API agent:调用 `grix_agent_admin`
78
+
79
+ 规则:
80
+
81
+ 1. 不直接拼接 `Authorization` 或手工构造 `/v1/agent-api/*` 请求。
82
+ 2. 不写临时通讯脚本,不走隐藏协议。
83
+ 3. 优先复用 `accountId`;若上下文有歧义,先确认后再调用工具。
84
+
85
+ ## 推荐流程
86
+
87
+ ### `persona.zip` -> OpenClaw
88
+
89
+ 1. 读取上下文,确认是 `create_new` 还是 `existing_agent`。
90
+ 2. 和用户确认目标 agent 或新 agent 命名;**用户拒绝则发 `failed/user_cancelled` 指令后结束**。
91
+ 3. 如果需要新建远端 API agent,用 `grix_agent_admin` 创建。
92
+ 4. 用 OpenClaw 正规步骤准备本地目标目录和配置。
93
+ 5. 下载 egg 包,并校验 hash / manifest(如果上下文提供)。
94
+ 6. 发送 `status=running`、`step=downloaded` 状态指令。
95
+ 7. 安装 persona 内容。
96
+ 8. 发送 `status=running`、`step=installed` 状态指令。
97
+ 9. 按需刷新或重启本地运行时。
98
+ 10. 校验目标 agent 仍然可用。
99
+ - 校验失败 → 尝试回滚(含步骤3新建的远端 agent),无法回滚则如实告知残留状态 → 发 `failed` 指令后结束。
100
+ 11. 发送 `status=success` 状态指令(带 `target_agent_id`),再向用户汇报完成。
101
+
102
+ ### `skill.zip` -> Claude
103
+
104
+ 1. 确认上下文指定的 Claude 目标 agent 存在;**不存在则发 `failed/target_not_found` 指令后结束**。
105
+ 2. 和用户确认目标 agent;**用户拒绝则发 `failed/user_cancelled` 指令后结束**。
106
+ 3. 下载 skill 包,并校验 hash / manifest(如果上下文提供)。
107
+ 4. 发送 `status=running`、`step=downloaded` 状态指令。
108
+ 5. 用 Claude 正规步骤安装 skill 包。
109
+ 6. 发送 `status=running`、`step=installed` 状态指令。
110
+ 7. 按需刷新配置或重载运行时。
111
+ 8. 校验目标 agent 仍然可用。
112
+ - 校验失败 → 如实告知用户 → 发 `failed` 指令后结束。
113
+ 9. 发送 `status=success` 状态指令(带 `target_agent_id`),再向用户汇报完成。
114
+
115
+ ## 每次安装至少校验这些点
116
+
117
+ - 目标 agent 选对了
118
+ - 包已成功下载
119
+ - hash / manifest 校验通过(如果提供)
120
+ - 安装内容已经落到目标位置
121
+ - 目标 agent 安装后仍然可用
122
+
123
+ ## 指令示例
124
+
125
+ 进行中(下载完成):
126
+
127
+ ```text
128
+ [[egg-install-status|install_id=eggins_20370001|status=running|step=downloaded|summary=%E5%B7%B2%E4%B8%8B%E8%BD%BD%E5%B9%B6%E9%AA%8C%E8%AF%81%E5%AE%89%E8%A3%85%E5%8C%85]]
129
+ ```
130
+
131
+ 进行中(安装落位完成):
132
+
133
+ ```text
134
+ [[egg-install-status|install_id=eggins_20370001|status=running|step=installed|summary=%E5%AE%89%E8%A3%85%E5%86%85%E5%AE%B9%E5%B7%B2%E8%90%BD%E4%BD%8D%EF%BC%8C%E6%A0%A1%E9%AA%8C%E4%B8%AD]]
135
+ ```
136
+
137
+ 成功:
138
+
139
+ ```text
140
+ [[egg-install-status|install_id=eggins_20370001|status=success|step=completed|target_agent_id=2035123456789012345|summary=%E5%B7%B2%E5%AE%8C%E6%88%90%E5%AE%89%E8%A3%85]]
141
+ ```
142
+
143
+ 失败(用户取消):
144
+
145
+ ```text
146
+ [[egg-install-status|install_id=eggins_20370001|status=failed|step=user_cancelled|error_code=user_cancelled|summary=%E7%94%A8%E6%88%B7%E5%8F%96%E6%B6%88%E5%AE%89%E8%A3%85]]
147
+ ```
148
+
149
+ 失败(目标不存在):
150
+
151
+ ```text
152
+ [[egg-install-status|install_id=eggins_20370001|status=failed|step=target_not_found|error_code=target_not_found|error_msg=%E6%8C%87%E5%AE%9A%E7%9A%84%20Claude%20agent%20%E4%B8%8D%E5%AD%98%E5%9C%A8|summary=%E5%AE%89%E8%A3%85%E5%A4%B1%E8%B4%A5]]
153
+ ```
154
+
155
+ 失败(下载失败):
156
+
157
+ ```text
158
+ [[egg-install-status|install_id=eggins_20370001|status=failed|step=download_failed|error_code=download_failed|error_msg=%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85%E5%8C%85%E5%A4%B1%E8%B4%A5|summary=%E5%AE%89%E8%A3%85%E5%A4%B1%E8%B4%A5]]
159
+ ```
160
+
161
+ ## 回复风格
162
+
163
+ - 用正常对话回复用户
164
+ - 进度回报要短、明确、可执行
165
+ - 失败说明要具体
166
+ - 最终总结必须包含目标 agent 和安装结果
167
+
168
+ ## References
169
+
170
+ 1. Load [references/api-contract.md](references/api-contract.md).
@@ -0,0 +1,38 @@
1
+ # API Contract
2
+
3
+ ## Purpose
4
+
5
+ Unify remote API communication in `egg-install` with the same typed tool pathway used by other grix-admin skills.
6
+
7
+ ## Base Rules
8
+
9
+ 1. Base path is `/v1/agent-api`.
10
+ 2. Auth is `Authorization: Bearer <agent_api_key>`.
11
+ 3. Caller must be `provider_type=3` and `status=active`.
12
+ 4. `egg-install` must not send direct HTTP requests to Grix by itself.
13
+
14
+ ## Unified Tool Path
15
+
16
+ Use only these entry points for remote communication:
17
+
18
+ | Install intent | Tool | Notes |
19
+ |---|---|---|
20
+ | Contact/session/message lookup | `grix_query` | Read-only queries |
21
+ | Group lifecycle and membership ops | `grix_group` | Governance operations |
22
+ | Create remote API agent | `grix_agent_admin` | Returns `id`, `agent_name`, `api_endpoint`, `api_key`, `api_key_hint` |
23
+
24
+ Local binding remains a local operation via bundled script:
25
+
26
+ - `scripts/grix_agent_bind.py configure-local-openclaw ... --apply`
27
+
28
+ ## Prohibited Paths
29
+
30
+ 1. Do not use `curl`, `fetch`, `axios`, or custom temporary scripts to call `/v1/agent-api/*`.
31
+ 2. Do not bypass typed tools with hidden protocol payloads.
32
+ 3. Do not auto-retry non-idempotent create actions without explicit confirmation.
33
+
34
+ ## Retry Policy
35
+
36
+ 1. Scope/auth/parameter errors: no automatic retry.
37
+ 2. Transient network failure: at most one retry, and only after explicit confirmation.
38
+ 3. Installation status directives (`egg-install-status`) must still be emitted on terminal success/failure.
@@ -0,0 +1,85 @@
1
+ ---
2
+ name: grix-agent-admin
3
+ description: 通过 Grix Agent API 协议创建 `provider_type=3` 的 API agent,并直接完成本地 OpenClaw agent 与 Grix 渠道绑定配置(默认直接应用并返回结果)。
4
+ ---
5
+
6
+ # Grix Agent Admin
7
+
8
+ Create a remote `provider_type=3` API agent, then complete local OpenClaw agent + grix channel binding in one flow.
9
+
10
+ ## Security + Auth Path
11
+
12
+ 1. This skill does **not** ask the user for website account/password.
13
+ 2. Remote create action uses local `channels.grix` credentials and `Authorization: Bearer <agent_api_key>`.
14
+ 3. Local OpenClaw config is handled by `scripts/grix_agent_bind.py`.
15
+
16
+ ## Required Input
17
+
18
+ 1. `agentName` (required): regex `^[a-z][a-z0-9-]{2,31}$`
19
+ 2. `describeMessageTool` (required): must contain non-empty `actions`
20
+ 3. `accountId` (optional)
21
+ 4. `avatarUrl` (optional)
22
+
23
+ ## Full Workflow
24
+
25
+ ### A. Create Remote API Agent
26
+
27
+ 1. Validate `agentName` and `describeMessageTool`.
28
+ 2. Call `grix_agent_admin` once.
29
+ 3. Read result fields: `id`, `agent_name`, `api_endpoint`, `api_key`, `api_key_hint`.
30
+
31
+ ### B. Apply Local OpenClaw Binding Directly
32
+
33
+ Run with `--apply` directly:
34
+
35
+ ```bash
36
+ scripts/grix_agent_bind.py configure-local-openclaw \
37
+ --agent-name <agent_name> \
38
+ --agent-id <agent_id> \
39
+ --api-endpoint '<api_endpoint>' \
40
+ --api-key '<api_key>' \
41
+ --apply
42
+ ```
43
+
44
+ This applies:
45
+
46
+ 1. upsert `agents.list` for `<agent_name>`
47
+ 2. upsert `channels.grix.accounts.<agent_name>`
48
+ 3. upsert `bindings` route to `channel=grix`, `accountId=<agent_name>`
49
+ 4. ensure required tools (`message`, `grix_group`, `grix_agent_admin`)
50
+ 5. create workspace defaults under `~/.openclaw/workspace-<agent_name>/`
51
+ 6. run `openclaw gateway restart`
52
+
53
+ ### C. Optional Verification
54
+
55
+ If you need explicit post-check state, run:
56
+
57
+ ```bash
58
+ scripts/grix_agent_bind.py inspect-local-openclaw --agent-name <agent_name>
59
+ ```
60
+
61
+ ## Guardrails
62
+
63
+ 1. Never ask user for website account/password.
64
+ 2. Treat remote create as non-idempotent; do not auto-retry without confirmation.
65
+ 3. Keep full `api_key` one-time only; do not repeatedly echo it.
66
+ 4. Do not claim success before apply command returns success.
67
+
68
+ ## Error Handling Rules
69
+
70
+ 1. invalid name: ask user for a valid English lowercase name.
71
+ 2. `403/20011`: ask owner to grant `agent.api.create` scope.
72
+ 3. `401/10001`: verify local `agent_api_key` / grix account config.
73
+ 4. `409/20002`: ask for another agent name.
74
+ 5. local apply failed: return concrete failed command/result and stop.
75
+
76
+ ## Response Style
77
+
78
+ 1. Report two stages separately: remote create status + local binding status.
79
+ 2. Include created `agent_id`, `agent_name`, `api_endpoint`, `api_key_hint`.
80
+ 3. Clearly state local config has been applied (or failed with concrete reason).
81
+
82
+ ## References
83
+
84
+ 1. Load [references/api-contract.md](references/api-contract.md).
85
+ 2. Use [scripts/grix_agent_bind.py](scripts/grix_agent_bind.py) for local binding apply.
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "Grix Agent Admin"
3
+ short_description: "Create Grix API agents and finish local OpenClaw binding."
4
+ default_prompt: "Use this skill when users ask to create a new Grix API agent and finish OpenClaw binding. Never ask for website account/password. Validate `agentName` and require `describeMessageTool` (`actions` must be non-empty), then call `grix_agent_admin` once. After successful create, directly run `scripts/grix_agent_bind.py configure-local-openclaw ... --apply` and return final local binding result (success or exact failure reason)."
@@ -0,0 +1,87 @@
1
+ # API Contract
2
+
3
+ ## Purpose
4
+
5
+ Map remote provisioning action to Aibot Agent API HTTP route, then hand over to local OpenClaw binding.
6
+
7
+ ## Base Rules
8
+
9
+ 1. Base path: `/v1/agent-api`
10
+ 2. Auth: `Authorization: Bearer <agent_api_key>`
11
+ 3. Caller must be `provider_type=3` and `status=active`.
12
+ 4. Route must pass scope middleware before service business checks.
13
+ 5. Do not ask users to provide website account/password for this flow.
14
+
15
+ ## Action Mapping (v1)
16
+
17
+ | Tool | Method | Route | Required Scope |
18
+ |---|---|---|---|
19
+ | `grix_agent_admin` | `POST` | `/agents/create` | `agent.api.create` |
20
+
21
+ ## Payload Template
22
+
23
+ ```json
24
+ {
25
+ "agentName": "ops-assistant",
26
+ "avatarUrl": "https://example.com/avatar.png",
27
+ "describeMessageTool": {
28
+ "actions": ["unsend", "delete"]
29
+ }
30
+ }
31
+ ```
32
+
33
+ `agentName` validation rule for this skill:
34
+
35
+ - regex: `^[a-z][a-z0-9-]{2,31}$`
36
+ - only lowercase English letters, digits, and hyphen
37
+
38
+ `describeMessageTool` is required and must align with OpenClaw SDK discovery shape (`actions` required, optional `capabilities` and `schema`).
39
+
40
+ ## Success Payload Highlights
41
+
42
+ ```json
43
+ {
44
+ "code": 0,
45
+ "data": {
46
+ "id": "2029786829095440384",
47
+ "agent_name": "ops-assistant",
48
+ "provider_type": 3,
49
+ "api_endpoint": "ws://host/v1/agent-api/ws?agent_id=2029786829095440384",
50
+ "api_key": "ak_2029786829095440384_xxx",
51
+ "api_key_hint": "xxxxxx12"
52
+ }
53
+ }
54
+ ```
55
+
56
+ ## Error Matrix
57
+
58
+ | HTTP/BizCode | Meaning | Skill Response |
59
+ |---|---|---|
60
+ | `403/20011` | `agent.api.create` scope missing | Ask owner to grant scope |
61
+ | `401/10001` | invalid or missing auth | Check `api_key` and account config |
62
+ | `403/10002` | caller agent inactive / invalid provider | Ask owner to activate caller agent |
63
+ | `409/20002` | duplicate agent name | Ask user for another `agent_name` |
64
+ | `400/20004` | owner quota exceeded | Ask owner to clean up unused agents |
65
+ | `400/10003` | invalid payload | Ask for corrected parameters |
66
+
67
+ ## Retry Policy
68
+
69
+ 1. Never auto-retry `agent_api_create` unless user explicitly confirms.
70
+ 2. Do not retry scope/auth/parameter failures.
71
+ 3. Network transient errors can be retried once after explicit confirmation.
72
+
73
+ ## Post-Create Handover
74
+
75
+ After `code=0`, continue with local OpenClaw binding via bundled script:
76
+
77
+ 1. apply local changes directly:
78
+ - `scripts/grix_agent_bind.py configure-local-openclaw --agent-name <agent_name> --agent-id <agent_id> --api-endpoint '<api_endpoint>' --api-key '<api_key>' --apply`
79
+ 2. optionally run inspect after apply when you need state verification:
80
+ - `scripts/grix_agent_bind.py inspect-local-openclaw --agent-name <agent_name>`
81
+
82
+ Local apply writes:
83
+
84
+ 1. `agents.list` entry
85
+ 2. `channels.grix.accounts.<agent_name>` entry
86
+ 3. `bindings` route for `channel=grix`
87
+ 4. required tools config and gateway restart