npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@wzzjjboy/opencode-wecom-notify-plugin

v0.1.3

Published

OpenCode plugin for WeCom notifications with smart snippets

Downloads

461

Readme

OpenCode 企业微信主动通知插件

这个项目用于在 Linux 服务器运行 OpenCode 时,把关键状态推送到企业微信群机器人,减少盯屏等待。

当前实现策略(保守模式):

  • 需要授权:permission.asked
  • 执行错误:session.error / 失败的 tool.execute.after
  • 需要决策或人工干预:session.status / tui.prompt.append 命中关键词
  • 阶段完成:session.idle(同一会话只发送一次)

通知增强:

  • 在“阶段完成”和“执行错误”通知中,附带 OpenCode 最后一次 assistant 输出的末尾摘要(字段:末尾,默认 300 字,可配置)。

1. 本地开发

要求:Node.js 20+

npm test

2. 配置环境变量

复制并填写 .env.example,或直接在运行环境设置:

  • OPENCODE_NOTIFY_ENABLED:是否开启(默认 true
  • OPENCODE_NOTIFY_WECOM_WEBHOOK:企业微信群机器人 webhook
  • OPENCODE_NOTIFY_DEDUPE_WINDOW_SEC:同类告警去重窗口秒数(默认 60)
  • OPENCODE_NOTIFY_TIMEOUT_MS:单次发送超时毫秒(默认 3000)
  • OPENCODE_NOTIFY_HOSTNAME:通知中显示的主机名(可选;未设置时自动使用系统 hostname)
  • OPENCODE_NOTIFY_SNIPPET_MAX_CHARS:末尾摘要最大字符数(默认 300,仅作用于“阶段完成/执行错误”)

3. 在 OpenCode 中启用

OpenCode 会自动加载 ~/.config/opencode/plugins/ 下的 JS 文件。

你也可以通过 npm 包快速安装(推荐):

~/.config/opencode/opencode.json 中配置:

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": ["@wzzjjboy/opencode-wecom-notify-plugin"]
}

OpenCode 启动时会自动安装并加载。

注意:

  • npm 远程插件与本地 plugins/*.js 文件插件的加载协议不同。
  • 本包现在同时提供两种入口:
  • npm 包入口:包根默认导出 { id, server() },供 OpenCode 远程安装使用。
  • 本地文件入口:src/opencode-notify-plugin.js,供你继续软链到 ~/.config/opencode/plugins/ 使用。

建议将下列文件放到该目录(保持相对路径):

  • src/opencode-notify-plugin.js
  • src/notify/map-event.js
  • src/notify/dedupe.js
  • src/notify/format-wecom.js
  • src/notify/sender-wecom.js
  • src/notify/types.js

示例(从项目根目录执行):

mkdir -p ~/.config/opencode/plugins/notify
cp src/opencode-notify-plugin.js ~/.config/opencode/plugins/opencode-notify-plugin.js
cp src/notify/*.js ~/.config/opencode/plugins/notify/

如果你有全局环境文件,可把 webhook 等变量放在启动 OpenCode 的 shell 环境里。

4. 验证步骤

  1. 重启 OpenCode
  2. 触发授权请求,确认群里收到“需要授权”
  3. 人为触发工具失败,确认收到“执行错误”
  4. 完成会话进入 session.idle,确认收到“阶段完成”

通知示例(含主机名):

[OpenCode][阶段完成]
项目: notification
主机: prod-ai-1
路径: /srv/workspace/notification
会话: s_xxx
摘要: 当前会话阶段已完成。
建议: 可回到会话查看结果。

5. 安全建议

  • 不要把 webhook 提交到代码仓库
  • 建议在企业微信机器人侧开启关键词、IP 白名单或签名
  • 通知内容应避免携带敏感信息(密钥、完整命令参数等)

6. 发布到 npm(公网)

发布前检查:

  • 确认包名可用(当前使用 scope 包名:@wzzjjboy/opencode-wecom-notify-plugin
  • 确认不包含敏感信息(.env、webhook、token)
  • 确认 npm test 通过

发布步骤:

npm login
npm test
npm pack --dry-run
npm publish --access public

如果是首次发布 scoped 包,通常需要 --access public