@2en/clawly-plugins 1.21.0 → 1.21.2

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/index.ts CHANGED
@@ -21,6 +21,7 @@
21
21
  * - /clawly_echo — echo text back without LLM
22
22
  *
23
23
  * Hooks:
24
+ * - before_message_write — restores original /skill command in user messages (undoes gateway rewrite)
24
25
  * - tool_result_persist — copies TTS audio to persistent outbound directory
25
26
  * - before_tool_call — enforces delivery fields on cron.create
26
27
  * - agent_end — sends push notification when client is offline
@@ -36,6 +37,7 @@ import {registerGateway} from './gateway'
36
37
  import {getGatewayConfig} from './gateway-fetch'
37
38
  import {setupModelGateway} from './model-gateway-setup'
38
39
  import {registerOutboundHook, registerOutboundHttpRoute, registerOutboundMethods} from './outbound'
40
+ import {registerSkillCommandRestore} from './skill-command-restore'
39
41
  import {registerTools} from './tools'
40
42
 
41
43
  type PluginRuntime = {
@@ -108,6 +110,7 @@ export default {
108
110
  name: 'Clawly Plugins',
109
111
  description: 'Clawly utility RPC methods (clawly.*).',
110
112
  register(api: PluginApi) {
113
+ registerSkillCommandRestore(api)
111
114
  registerOutboundHook(api)
112
115
  registerOutboundMethods(api)
113
116
  registerOutboundHttpRoute(api)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2en/clawly-plugins",
3
- "version": "1.21.0",
3
+ "version": "1.21.2",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "repository": {
@@ -24,6 +24,7 @@
24
24
  "gateway-fetch.ts",
25
25
  "outbound.ts",
26
26
  "model-gateway-setup.ts",
27
+ "skill-command-restore.ts",
27
28
  "openclaw.plugin.json"
28
29
  ],
29
30
  "publishConfig": {
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Hook: before_message_write — restore original /skill command in user messages.
3
+ *
4
+ * The OpenClaw gateway rewrites `/skill <name> <args>` into a formatted prompt:
5
+ * Use the "<name>" skill for this request.
6
+ *
7
+ * User input:
8
+ * <args>
9
+ *
10
+ * This rewrite is useful for the LLM but pollutes chat history — the mobile app
11
+ * sees the rewritten text instead of what the user actually typed.
12
+ *
13
+ * This hook intercepts user messages before they're written to the session JSONL
14
+ * and restores the original `/skill <name> <args>` format.
15
+ */
16
+
17
+ import type {PluginApi} from './index'
18
+
19
+ const SKILL_REWRITE_RE = /^Use the "(.+?)" skill for this request\.(?:\n\nUser input:\n([\s\S]+))?$/
20
+
21
+ type AgentMessage = {
22
+ role: string
23
+ content: unknown
24
+ }
25
+
26
+ type BeforeMessageWriteEvent = {
27
+ message: AgentMessage
28
+ }
29
+
30
+ type BeforeMessageWriteResult = {
31
+ message?: AgentMessage
32
+ }
33
+
34
+ function extractText(content: unknown): string {
35
+ if (typeof content === 'string') return content
36
+ if (Array.isArray(content)) {
37
+ return content
38
+ .map((part: unknown) => {
39
+ if (!part || typeof part !== 'object') return ''
40
+ const p = part as {type?: string; text?: string}
41
+ return p.type === 'text' && typeof p.text === 'string' ? p.text : ''
42
+ })
43
+ .filter(Boolean)
44
+ .join('')
45
+ }
46
+ return ''
47
+ }
48
+
49
+ function replaceText(content: unknown, newText: string): unknown {
50
+ if (typeof content === 'string') return newText
51
+ if (Array.isArray(content)) {
52
+ // Collapse all text parts into one to avoid duplicating the restored text
53
+ // when the original content was split across multiple text parts.
54
+ let replaced = false
55
+ return content.flatMap((part: unknown) => {
56
+ if (!part || typeof part !== 'object') return [part]
57
+ const p = part as {type?: string; text?: string}
58
+ if (p.type === 'text' && typeof p.text === 'string') {
59
+ if (!replaced) {
60
+ replaced = true
61
+ return [{...p, text: newText}]
62
+ }
63
+ return []
64
+ }
65
+ return [part]
66
+ })
67
+ }
68
+ return content
69
+ }
70
+
71
+ export function registerSkillCommandRestore(api: PluginApi) {
72
+ api.on(
73
+ 'before_message_write',
74
+ (event: BeforeMessageWriteEvent): BeforeMessageWriteResult | void => {
75
+ const {message} = event
76
+ if (message.role !== 'user') return
77
+
78
+ const text = extractText(message.content)
79
+ const match = text.match(SKILL_REWRITE_RE)
80
+ if (!match) return
81
+
82
+ const skillName = match[1]
83
+ const args = match[2]?.trim()
84
+ const restored = args ? `/skill ${skillName} ${args}` : `/skill ${skillName}`
85
+
86
+ return {
87
+ message: {
88
+ ...message,
89
+ content: replaceText(message.content, restored),
90
+ },
91
+ }
92
+ },
93
+ )
94
+ }