AgentSkillsCN

events

当您需要编写后台脚本,在任务完成或出现失败时向您发出通知,或在外部触发下立即唤醒自己时,可选用此方法。触发关键词包括:“后台任务”、“脚本已完成”、“任务完成时通知”、“完成后叫醒我”、“事件钩子”、“回调函数”、“出错时执行”、“成功时执行”,以及类似的相关选项。

SKILL.md
--- frontmatter
name: events
description: use when writing background scripts that need to notify you on completion or failure, or when you need to wake yourself up immediately from an external trigger. triggers include "background task", "script finished", "notify on complete", "wake me when done", "event hook", "callback", "on error", "on success", and similar.

events

use events to wake yourself up from background scripts or external triggers.

emit an event

always include --chat-id <id> using the chat_id from your current session.

bun bob event --chat-id <id> "task_done" '{"result": "..."}' - signal success bun bob event --chat-id <id> "task_failed" '{"error": "..."}' - signal failure bun bob event --chat-id <id> "custom_event" '{"data": "..."}' - any custom event

in scripts

when writing scripts, hardcode the chat_id so it knows where to send the event.

typescript
const CHAT_ID = 123456; // from current session

try {
  const result = await doSomething();
  await $`bun bob event --chat-id ${CHAT_ID} "task_done" '{"result": "${result}"}'`;
} catch (err) {
  await $`bun bob event --chat-id ${CHAT_ID} "task_failed" '{"error": "${err.message}"}'`;
}

list pending events

bun bob events list - see unprocessed events