@2en/clawly-plugins 1.21.1 → 1.21.3

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/cron-hook.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * before_tool_call hook for cron (action=add) — ensures delivery fields are
3
3
  * always set correctly, even when the LLM omits them.
4
4
  *
5
- * Forces: delivery.mode = "none" (agent uses clawly_send_message/push tools)
5
+ * Forces: delivery.mode = "none" (agent uses clawly_send_message tool)
6
6
  * Appends: delivery instructions to payload.message
7
7
  * Patches: payload.kind "systemEvent" → "agentTurn"
8
8
  *
@@ -25,8 +25,6 @@ const DELIVERY_SUFFIX = [
25
25
  'DELIVERY INSTRUCTIONS (mandatory):',
26
26
  'When done, you MUST deliver your result to the user:',
27
27
  '1. Call the clawly_send_message tool with role="assistant" and a brief, natural summary of your result.',
28
- '2. Call clawly_is_user_online to check if the user is online.',
29
- '3. If offline, also call clawly_send_app_push with a short notification.',
30
28
  ].join('\n')
31
29
 
32
30
  function patchJob(job: UnknownRecord): UnknownRecord {
package/index.ts CHANGED
@@ -36,6 +36,7 @@ import {registerEmail} from './email'
36
36
  import {registerGateway} from './gateway'
37
37
  import {getGatewayConfig} from './gateway-fetch'
38
38
  import {setupModelGateway} from './model-gateway-setup'
39
+ import {setupSession} from './session-setup'
39
40
  import {registerOutboundHook, registerOutboundHttpRoute, registerOutboundMethods} from './outbound'
40
41
  import {registerSkillCommandRestore} from './skill-command-restore'
41
42
  import {registerTools} from './tools'
@@ -120,6 +121,7 @@ export default {
120
121
  registerGateway(api)
121
122
  registerAutoPair(api)
122
123
  setupModelGateway(api)
124
+ setupSession(api)
123
125
 
124
126
  // Email & calendar (optional — requires skillGatewayBaseUrl + skillGatewayToken in config)
125
127
  const gw = getGatewayConfig(api)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2en/clawly-plugins",
3
- "version": "1.21.1",
3
+ "version": "1.21.3",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "repository": {
@@ -24,6 +24,8 @@
24
24
  "gateway-fetch.ts",
25
25
  "outbound.ts",
26
26
  "model-gateway-setup.ts",
27
+ "session-setup.ts",
28
+ "skill-command-restore.ts",
27
29
  "openclaw.plugin.json"
28
30
  ],
29
31
  "publishConfig": {
@@ -0,0 +1,42 @@
1
+ /**
2
+ * On plugin init, patches openclaw.json to set `session.dmScope` to
3
+ * "per-channel-peer". This isolates Telegram (and other channel) DMs from the
4
+ * Clawly mobile session so messages don't leak across channels.
5
+ *
6
+ * Runs synchronously during plugin registration, same pattern as
7
+ * model-gateway-setup.ts.
8
+ */
9
+
10
+ import path from 'node:path'
11
+
12
+ import type {PluginApi} from './index'
13
+ import {readOpenclawConfig, resolveStateDir, writeOpenclawConfig} from './model-gateway-setup'
14
+
15
+ const DESIRED_DM_SCOPE = 'per-channel-peer'
16
+
17
+ export function setupSession(api: PluginApi): void {
18
+ const stateDir = resolveStateDir(api)
19
+ if (!stateDir) {
20
+ api.logger.warn('Cannot resolve state dir — session setup skipped.')
21
+ return
22
+ }
23
+
24
+ const configPath = path.join(stateDir, 'openclaw.json')
25
+ const config = readOpenclawConfig(configPath)
26
+
27
+ const session = ((config.session as Record<string, unknown>) ?? {}) as Record<string, unknown>
28
+
29
+ if (session.dmScope === DESIRED_DM_SCOPE) {
30
+ return
31
+ }
32
+
33
+ session.dmScope = DESIRED_DM_SCOPE
34
+ config.session = session
35
+
36
+ try {
37
+ writeOpenclawConfig(configPath, config)
38
+ api.logger.info(`Session: set dmScope to "${DESIRED_DM_SCOPE}".`)
39
+ } catch (err) {
40
+ api.logger.error(`Failed to update session config: ${(err as Error).message}`)
41
+ }
42
+ }
@@ -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
+ }