@dcrays/dcgchat-test 0.4.23 → 0.4.24

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcrays/dcgchat-test",
3
- "version": "0.4.23",
3
+ "version": "0.4.24",
4
4
  "type": "module",
5
5
  "description": "OpenClaw channel plugin for 书灵墨宝 (WebSocket)",
6
6
  "main": "index.ts",
@@ -7,9 +7,6 @@ import { channelInfo, ENV } from './utils/constant.js'
7
7
  * 自动注入 bestEffort: true,使投递失败时静默降级,
8
8
  * 不影响 cron 执行结果的保存。
9
9
  *
10
- * 另:拦截高危 exec,避免对话内 `openclaw gateway start` 向已运行网关发 SIGTERM、
11
- * 以及反复 `openclaw cron add` 阻塞与握手超时——应改用内置 `cron` 工具或 Gateway RPC。
12
- *
13
10
  * 背景:
14
11
  * - 定时任务的 delivery 设为 announce 模式,如果没有指定 channel,
15
12
  * 投递可能因找不到有效渠道而失败
@@ -82,23 +79,6 @@ function isCronTool(toolName: string): boolean {
82
79
  return toolName === 'cron'
83
80
  }
84
81
 
85
- /** 非 running 会话(如定时触发)也需跑本钩子的 exec 子串 */
86
- export function execCommandNeedsCronToolHook(command: string): boolean {
87
- const c = command.trim()
88
- if (!c) return false
89
- if (c.includes('cron create') || c.includes('cron add')) return true
90
- return /\bopenclaw\s+gateway\s+start\b/i.test(c)
91
- }
92
-
93
- const BLOCK_GATEWAY_START =
94
- '禁止在对话内 exec `openclaw gateway start`:当前会话可能正跑在本网关上,重复启动会先 SIGTERM 旧进程导致断连。' +
95
- '若仅需确认存活,请改用只读命令,例如 `openclaw gateway health --json` 或 `openclaw gateway probe`(以本机 CLI 为准)。' +
96
- '若确认网关未运行,请在宿主机/服务管理(systemd 等)中启动,勿由 Agent 代 exec。'
97
-
98
- const BLOCK_CRON_CLI =
99
- '请勿用 exec 跑 `openclaw cron add` / `openclaw cron create`:请改用内置 **`cron` 工具**(框架走 Gateway `cron.*`,由本插件自动补全 delivery / sessionKey)。' +
100
- '高频 exec CLI 易长时间占满子进程并加剧网关 WebSocket 握手压力。'
101
-
102
82
  /**
103
83
  * 从 cron 参数中提取 delivery 配置
104
84
  * cron 工具的参数结构可能是:
@@ -157,7 +137,7 @@ function patchCronDeliveryInParams(
157
137
  if (agentId) d.accountId = agentId
158
138
  if (announceNoChannel) {
159
139
  d.bestEffort = true
160
- d.channel = "dcgchat-test"
140
+ d.channel = 'dcgchat-test'
161
141
  }
162
142
  }
163
143
 
@@ -208,22 +188,14 @@ export function cronToolCall(event: { toolName: any; params: any; toolCallId: an
208
188
 
209
189
  return { params: newParams }
210
190
  } else if (toolName === 'exec') {
211
- const cmd = typeof params.command === 'string' ? params.command : ''
212
- if (/\bopenclaw\s+gateway\s+start\b/i.test(cmd)) {
213
- dcgLogger(`[${LOG_TAG}] blocked exec gateway start (${toolCallId})`)
214
- return { block: true, blockReason: BLOCK_GATEWAY_START }
215
- }
216
- if (/\bopenclaw\s+cron\s+(add|create)\b/i.test(cmd)) {
217
- dcgLogger(`[${LOG_TAG}] blocked exec openclaw cron add/create (${toolCallId})`)
218
- return { block: true, blockReason: BLOCK_CRON_CLI }
219
- }
220
- if (cmd.includes('cron create') || cmd.includes('cron add')) {
191
+ if (params.command.indexOf('cron create') > -1 || params.command.indexOf('cron add') > -1) {
221
192
  const newParams = JSON.parse(JSON.stringify(params)) as Record<string, unknown>
222
193
  newParams.command =
223
- cmd.replace(/--json/g, '').trimEnd() + ` --session-key ${sk} --channel ${"dcgchat-test"} --to dcg-cron:${sk} --json`
194
+ params.command.replace('--json', '') + ` --session-key ${sk} --channel ${'dcgchat-test'} --to dcg-cron:${sk} --json`
224
195
  return { params: newParams }
196
+ } else {
197
+ return undefined
225
198
  }
226
- return undefined
227
199
  }
228
200
 
229
201
  return undefined
package/src/tool.ts CHANGED
@@ -3,7 +3,7 @@ import { getMsgStatus } from './utils/global.js'
3
3
  import { dcgLogger } from './utils/log.js'
4
4
  import { sendFinal, sendText, wsSendRaw } from './transport.js'
5
5
  import { getEffectiveMsgParams, deleteSessionKeyBySubAgentRunId, setSessionKeyBySubAgentRunId } from './utils/params.js'
6
- import { cronToolCall, execCommandNeedsCronToolHook } from './cronToolCall.js'
6
+ import { cronToolCall } from './cronToolCall.js'
7
7
 
8
8
  type PluginHookName =
9
9
  | 'before_model_resolve'
@@ -330,7 +330,7 @@ function shouldRunBeforeToolCallWithoutRunningSession(event: { toolName?: string
330
330
  if (event?.toolName === 'cron') return true
331
331
  const cmd = event?.params?.command
332
332
  if (event?.toolName === 'exec' && typeof cmd === 'string') {
333
- return execCommandNeedsCronToolHook(cmd)
333
+ return cmd.includes('cron create') || cmd.includes('cron add')
334
334
  }
335
335
  return false
336
336
  }
@@ -362,8 +362,7 @@ export function monitoringToolMessage(api: OpenClawPluginApi) {
362
362
  const sk = resolveHookSessionKey(item.event, args ?? {})
363
363
  if (sk) {
364
364
  const toolHooksOk =
365
- isSessionActiveForTool(sk) ||
366
- (item.event === 'before_tool_call' && shouldRunBeforeToolCallWithoutRunningSession(event))
365
+ isSessionActiveForTool(sk) || (item.event === 'before_tool_call' && shouldRunBeforeToolCallWithoutRunningSession(event))
367
366
  if (toolHooksOk) {
368
367
  if (['after_tool_call', 'before_tool_call'].includes(item.event)) {
369
368
  const { result: _result, ...rest } = event
@@ -378,12 +377,7 @@ export function monitoringToolMessage(api: OpenClawPluginApi) {
378
377
  ...rest,
379
378
  status: 'running'
380
379
  })
381
- sendToolCallMessage(
382
- sk,
383
- text,
384
- event.toolCallId || event.runId || Date.now().toString(),
385
- 0
386
- )
380
+ sendToolCallMessage(sk, text, event.toolCallId || event.runId || Date.now().toString(), 0)
387
381
  return hookResult
388
382
  }
389
383
  const text = JSON.stringify({