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

opencode-channels

v0.3.3

Published

OpenCode Channels - Multi-channel integration for OpenCode AI

Downloads

1,464

Readme

OpenCode Channels

将 OpenCode AI 编程助手的通知和交互扩展到 Telegram 等即时通讯平台

npm version License: MIT

特性

  • 📱 移动端通知 - 在手机上接收任务完成、错误警告等通知
  • 🔄 远程交互 - 无需在电脑前也能响应 AI 的权限请求和问题
  • 🏢 项目隔离 - 通过 Telegram 群组和主题实现多项目、多会话管理
  • 自动化工作流 - 创建主题自动创建 OpenCode 会话
  • 定时任务 - 支持 Cron 表达式定时执行 AI 任务,智能上下文管理
  • 🛑 会话控制 - 停止、继续、撤回 AI 操作
  • 🧠 AI 思考展示 - 实时查看 AI 推理过程
  • 🔧 工作空间管理 - 创建主题时支持 Git Worktree
  • 📋 动态命令 - 自动同步 OpenCode SDK 命令到 Telegram

快速开始

安装

npm install -g opencode-channels

初始化配置

npx opencode-channels init

交互式配置向导会引导你完成:

  1. 设置工作空间目录
  2. 选择 IM 平台 (Telegram)
  3. 输入 Bot Token
  4. 配置通知选项
  5. 选择启动方式(后台服务/前台服务)

启动服务

后台服务(推荐)

# 启动后台服务
npx opencode-channels daemon

# 查看服务状态
npx opencode-channels status

# 查看日志
npx opencode-channels logs

# 停止服务
npx opencode-channels stop

前台服务

npx opencode-channels start

绑定项目

  1. 创建 Telegram 群组
  2. 添加你的 Bot 到群组
  3. Bot 会自动扫描工作空间并提示选择要绑定的项目
  4. 创建主题(Topic)会自动创建对应的 OpenCode 会话

使用场景

场景 1:接收任务完成通知

当 OpenCode AI 完成任务时,你会在 Telegram 收到通知:

✅ 任务完成

会话 ID: ses_abc123
项目: /path/to/project

场景 2:远程响应权限请求

当 AI 需要权限时,你可以在手机上直接回复:

🔐 权限请求

AI 请求执行: npm install express

回复 'yes' 或 'no'

场景 3:多项目管理

  • 每个 Telegram 群组绑定一个项目
  • 每个主题(Topic)对应一个 OpenCode 会话
  • 清晰的项目和会话隔离

场景 4:定时任务自动化

通过 /schedule 命令创建定时任务:

用户: /schedule
Bot: 请输入你的需求

用户: 每天早上9点搜集最新AI新闻
AI: 确认创建定时任务...

智能上下文管理:

  • 任务执行后,AI 会话自动收到结果通知
  • 上下文使用率 >50% 时自动压缩
  • 消息自动排队,不打断正在进行的对话
  • 用户在 Telegram 看到结果前,AI 已经知道了

场景 5:会话控制

在 Telegram 中直接控制 AI 会话:

  • 点击「停止」暂停 AI 执行
  • 点击「继续」恢复暂停的会话
  • 点击「撤回」撤销最近的操作
  • 点击「好的」快速确认 AI 回复

配置

配置文件位于:

  • Windows: %APPDATA%\opencode\channels.json
  • macOS/Linux: ~/.config/opencode/channels.json

示例配置:

{
  "workspace": "/Users/yang/.workspace",
  "channels": {
    "telegram": {
      "enabled": true,
      "token": "YOUR_BOT_TOKEN"
    }
  },
  "server": {
    "port": 3737,
    "host": "localhost"
  },
  "notifications": {
    "onPermission": true,
    "onComplete": true,
    "onError": true,
    "onIdle": false
  }
}

命令

| 命令 | 说明 | |------|------| | init | 初始化配置 | | start | 启动前台服务 | | daemon | 启动后台服务 | | status | 查看服务状态 | | logs | 查看 PM2 日志 | | log | 查看本地日志文件 | | restart | 重启服务 | | stop | 停止服务 | | /schedule | 管理定时任务 |

架构

OpenCode 项目 → 触发事件 → 全局插件 → HTTP POST → Server → Telegram Bot → 用户
                                                              ↑
用户回复 ← Telegram ← Bot 接收 ← 解析回复 ← 调用 SDK ←────────┘

文档

技术栈

  • 运行时: Bun / Node.js
  • CLI: Commander.js + Inquirer
  • HTTP Server: Hono
  • Telegram Bot: grammY
  • SDK: @opencode-ai/sdk
  • 定时任务: Croner
  • 进程管理: PM2

代理配置

在国内直接访问 Telegram API 会被阻断,需要通过代理连接。

opencode-channels 会自动检测系统代理环境变量,无需额外配置:

# 在 ~/.bashrc 或 ~/.zshrc 中设置代理
export HTTPS_PROXY=http://127.0.0.1:7890
export HTTP_PROXY=http://127.0.0.1:7890

设置后启动服务即可,日志中会显示 [Bot] 使用代理: http://127.0.0.1:7890

支持的环境变量(按优先级):HTTPS_PROXY > HTTP_PROXY > https_proxy > http_proxy

如果使用 PM2 后台服务(opencode-channels daemon),请确保代理环境变量在启动 daemon 的 shell 中已设置,PM2 会自动继承。

开发

# 安装依赖
bun install

# 开发模式
bun run dev

# 运行测试
bun test

# 查看本地日志
bun run dev:log

# 实时查看日志
bun run dev:log:follow

# 构建
npm run build

许可证

MIT

相关链接