@2en/clawly-plugins 1.7.2 → 1.8.0

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,8 @@
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 message/push tools explicitly)
5
+ * Forces: delivery.mode = "none" (agent uses clawly_send_message/push tools)
6
+ * Appends: delivery instructions to payload.message
6
7
  * Patches: payload.kind "systemEvent" → "agentTurn"
7
8
  *
8
9
  * The cron tool name is "cron" (not "cron.create"). The LLM passes
@@ -18,15 +19,33 @@ function isRecord(v: unknown): v is UnknownRecord {
18
19
  return typeof v === 'object' && v !== null && !Array.isArray(v)
19
20
  }
20
21
 
22
+ const DELIVERY_SUFFIX = [
23
+ '',
24
+ '---',
25
+ 'DELIVERY INSTRUCTIONS (mandatory):',
26
+ 'When done, you MUST deliver your result to the user:',
27
+ '1. Call the clawly_send_message tool with 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
+ ].join('\n')
31
+
21
32
  function patchJob(job: UnknownRecord): UnknownRecord {
22
33
  const patched: UnknownRecord = {...job}
23
34
 
24
- // Force delivery.mode = "none" — agent reports via message/push tools explicitly
35
+ // Force delivery.mode = "none" — agent reports via tools explicitly
25
36
  patched.delivery = {mode: 'none'}
26
37
 
38
+ // Append delivery instructions to payload.message
39
+ if (isRecord(job.payload) && typeof job.payload.message === 'string') {
40
+ patched.payload = {
41
+ ...job.payload,
42
+ message: job.payload.message + DELIVERY_SUFFIX,
43
+ }
44
+ }
45
+
27
46
  // Patch payload.kind: systemEvent → agentTurn
28
- if (isRecord(job.payload) && job.payload.kind === 'systemEvent') {
29
- patched.payload = {...job.payload, kind: 'agentTurn'}
47
+ if (isRecord(patched.payload) && (patched.payload as UnknownRecord).kind === 'systemEvent') {
48
+ patched.payload = {...(patched.payload as UnknownRecord), kind: 'agentTurn'}
30
49
  }
31
50
 
32
51
  return patched
package/index.ts CHANGED
@@ -15,6 +15,7 @@
15
15
  * Agent tools:
16
16
  * - clawly_is_user_online — check if user's device is connected
17
17
  * - clawly_send_app_push — send a push notification to user's device
18
+ * - clawly_send_message — send a message to user via main session agent
18
19
  *
19
20
  * Commands:
20
21
  * - /clawly_echo — echo text back without LLM
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2en/clawly-plugins",
3
- "version": "1.7.2",
3
+ "version": "1.8.0",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "repository": {
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Agent tool: clawly_send_message — send a message to the main session
3
+ * agent from an isolated context (e.g. cron job).
4
+ *
5
+ * Runs `openclaw agent --agent <agent> --message <message>` which delivers
6
+ * the text as a natural assistant response in the user's chat.
7
+ */
8
+
9
+ import {$} from 'zx'
10
+ import type {PluginApi} from '../index'
11
+
12
+ $.verbose = false
13
+
14
+ const TOOL_NAME = 'clawly_send_message'
15
+
16
+ const parameters: Record<string, unknown> = {
17
+ type: 'object',
18
+ required: ['message'],
19
+ properties: {
20
+ message: {type: 'string', description: 'The message to send to the user'},
21
+ agent: {type: 'string', description: 'Target agent ID (default: "clawly")'},
22
+ },
23
+ }
24
+
25
+ export function registerSendMessageTool(api: PluginApi) {
26
+ api.registerTool({
27
+ name: TOOL_NAME,
28
+ description:
29
+ 'Send a message to the user via the main session agent. Use this from cron jobs or isolated sessions to deliver results to the user.',
30
+ parameters,
31
+ async execute(_toolCallId, params) {
32
+ const message = typeof params.message === 'string' ? params.message.trim() : ''
33
+ if (!message) {
34
+ return {content: [{type: 'text', text: JSON.stringify({error: 'message is required'})}]}
35
+ }
36
+
37
+ const agent = typeof params.agent === 'string' ? params.agent.trim() : 'clawly'
38
+
39
+ try {
40
+ await $`openclaw agent --agent ${agent} --message ${message}`
41
+ api.logger.info(
42
+ `${TOOL_NAME}: delivered message (${message.length} chars) to agent ${agent}`,
43
+ )
44
+ return {content: [{type: 'text', text: JSON.stringify({sent: true})}]}
45
+ } catch (err) {
46
+ const msg = err instanceof Error ? err.message : String(err)
47
+ api.logger.error(`${TOOL_NAME}: failed — ${msg}`)
48
+ return {content: [{type: 'text', text: JSON.stringify({sent: false, error: msg})}]}
49
+ }
50
+ },
51
+ })
52
+
53
+ api.logger.info(`tool: registered ${TOOL_NAME} agent tool`)
54
+ }
package/tools/index.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import type {PluginApi} from '../index'
2
2
  import {registerIsUserOnlineTool} from './clawly-is-user-online'
3
3
  import {registerSendAppPushTool} from './clawly-send-app-push'
4
+ import {registerSendMessageTool} from './clawly-send-message'
4
5
 
5
6
  export function registerTools(api: PluginApi) {
6
7
  registerIsUserOnlineTool(api)
7
8
  registerSendAppPushTool(api)
9
+ registerSendMessageTool(api)
8
10
  }