@sp1in/pi-agent

Pi extension — type /wechat, scan QR code, chat with Pi from WeChat

Package details

extension

Install @sp1in/pi-agent from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:@sp1in/pi-agent
Package
@sp1in/pi-agent
Version
0.1.3
Published
Apr 29, 2026
Downloads
not available
Author
sp1in
License
MIT
Types
extension
Size
16.6 KB
Dependencies
2 dependencies · 1 peer
Pi manifest JSON
{
  "extensions": [
    "./src/index.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

@wechatanybot/pi-agent

Pi extension — type /wechat in pi, scan QR code in terminal, chat with Pi from WeChat.

Install

From npm (recommended)

pi install npm:@wechatanybot/pi-agent

Done. The extension auto-loads on next pi session. Type /wechat to start.

From git

pi install https://github.com/jiweiyuan/wechatanybot

Quick test (no install)

pi -e npm:@wechatanybot/pi-agent

Manual (local development)

git clone https://github.com/jiweiyuan/wechatanybot
cd wechatanybot/pi-agent && npm install

# Load directly
pi -e ./src/index.ts

# Or copy to auto-discovery directory
cp -r . ~/.pi/agent/extensions/wechat/

Usage

/wechat              Scan QR code → connect WeChat to this pi session
/weixin              Alias for /wechat
/wechat --force      Force re-login (new QR code)
/wechat-disconnect   Disconnect
/wechat-send <text>  Send text to WeChat user manually

What happens

> /wechat

  📱 Scan this QR code in WeChat:

    ▄▄▄▄▄▄▄ ▄▄▄ ▄▄▄▄▄▄▄
    █ ▄▄▄ █ █▀█ █ ▄▄▄ █
    █ ███ █ ▄▀▄ █ ███ █
    █▄▄▄▄▄█ █ ▄ █▄▄▄▄▄█
    ▄▄▄▄▄ ▄▄▄█▄▄▄ ▄▄▄▄▄
    █▄█▀█▄▄ ▀▀▄▀▀█▄▀█▀▄
    ▄▄▄▄▄▄▄ ▀▄ █▀▄█▄█▀▄
    █▄▄▄▄▄█ █▀▄█▀▀█▀███

  [wechat] ✓ Connected: e06c1ceea05e@im.bot

# Now send "帮我看看这个bug" from WeChat...
# Pi processes it, sends reply back to WeChat.
# "对方正在输入中..." shown while Pi thinks.

How It Works

WeChat User (phone)
    │
    ▼
iLink API (Tencent) ←── @wechatanybot/wechatanybot SDK
    │
    ▼
Pi Extension
    │
    ├── WeChat msg → pi.sendUserMessage(text)  → pi processes as prompt
    │
    └── pi.on('agent_end') → bot.reply(text)   → sent back to WeChat
  1. /wechat creates a WeChatAnyBot instance (SDK)
  2. SDK calls iLink API → gets QR URL
  3. qrcode-terminal renders QR code in pi TUI via ctx.ui.setWidget()
  4. User scans QR in WeChat → login confirmed → credentials saved
  5. SDK starts long-poll → incoming WeChat messages trigger pi.sendUserMessage()
  6. When pi finishes (agent_end event), response is sent back via bot.reply()
  7. bot.sendTyping() shows "对方正在输入中..." while pi thinks

QR Code Display

The QR code is rendered using qrcode-terminal — a real scannable QR code in the terminal.

The SDK does NOT render QR codes — that is the developer's responsibility. This extension is the developer. It receives the URL via onQrUrl callback and renders it.

Dependencies

Package Purpose
@wechatanybot/wechatanybot WeChat iLink Bot SDK — login, poll, send, typing, context_token
qrcode-terminal Render scannable QR code in terminal
@mariozechner/pi-coding-agent Pi extension API (peer dependency)

Pi Package

This is a pi package. It declares "keywords": ["pi-package"] and "pi": { "extensions": [...] } in package.json. Pi auto-discovers the extension after install.