omp-wechat 0.2.0 → 1.1.0

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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +29 -21
  3. package/dist/index.js +652 -705545
  4. package/package.json +3 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -12,26 +12,28 @@ WeChat user → iLink Bot API → [OMP/Pi process] → SDK → AI provider
12
12
  └──── reply ← message_end ─┘
13
13
  ```
14
14
 
15
- The extension runs **inside** the OMP/Pi process. On `session_start`, the iLink long-poll loop starts in-process. The host keeps the process alive; the poll loop runs as a background promise. When the process exits, the poll loop stops and all sessions are disposed.
15
+ The extension runs **inside** the OMP/Pi process. On `session_start`, the iLink long-poll loop starts in-process as a background promise. A singleton port lock ensures only one process runs the poll loop at a time other OMP/Pi processes standby with a 30s failover timer to take over if the lock holder crashes.
16
16
 
17
17
  For boot-time persistence, install a launchd/systemd service via `/wechat install`. The service runs `omp --mode rpc` (or `pi --mode rpc`) with `KeepAlive`/`Restart=always`, so the host (and the poll loop) survive crashes and reboots.
18
18
 
19
- - **Typing indicator**: shows "Typing..." on WeChat while the model is thinking
20
19
  - **No external `bun` required** — OMP/Pi is a standalone binary with an embedded runtime
21
- - **No detached daemon** — the poll loop runs in-process, lifecycle tied to the host
22
- - **Cross-platform** — launchd (macOS) or systemd (Linux), no sudo on macOS
20
+ - **Singleton** — port lock guarantees one poll loop across all concurrent OMP/Pi processes
21
+ - **Failover** — non-lock-holder processes check every 30s and take over if the lock holder dies
23
22
  - **iLink layer**: long-polls `getupdates` for inbound messages, sends replies via `sendmessage`
24
23
  - **AI engine**: one in-memory session per WeChat chat, prompts injected via `session.prompt()`
24
+ - **Typing indicator**: shows "Typing..." on WeChat while the model is thinking
25
25
  - **Access control**: pairing-based — strangers must pair before their messages are delivered
26
26
 
27
27
  ## Features
28
28
 
29
29
  - **OMP/Pi extension**: installs via `omp plugin link .` or `pi plugin link .`, auto-starts poll loop on `session_start`
30
30
  - **Slash commands**: `/wechat login`, `/wechat status`, `/wechat pair`, `/wechat allow`, `/wechat revoke`, `/wechat list`, `/wechat stop`, `/wechat install`, `/wechat uninstall`
31
+ - **Singleton**: port lock guarantees one poll loop across all concurrent OMP/Pi processes — no duplicate replies
32
+ - **Failover**: 30s timer takes over automatically if the lock holder crashes
31
33
  - **Bidirectional**: receive and reply to WeChat text messages
32
34
  - **Per-chat sessions**: each WeChat chat gets an independent AI session (concurrent, isolated)
33
35
  - **LRU pool**: caps memory usage by evicting least-recently-used sessions (default: 50)
34
- - **Typing indicator**: native WeChat "typing..." shown during AI processing
36
+ - **Typing indicator**: native WeChat "Typing..." shown during AI processing
35
37
  - **Access control**: pairing / allowlist / disabled modes
36
38
  - **Long text chunking**: splits replies >2000 chars at paragraph/line/space boundaries
37
39
  - **Boot service**: optional launchd/systemd service for auto-start on boot
@@ -46,7 +48,7 @@ For boot-time persistence, install a launchd/systemd service via `/wechat instal
46
48
  ### Install
47
49
 
48
50
  ```bash
49
- git clone <your-repo-url> OMP-Wechat
51
+ git clone https://github.com/mentalfl0w/omp-wechat.git OMP-Wechat
50
52
  cd OMP-Wechat
51
53
  bun install # build dependency only
52
54
  bun run build
@@ -90,6 +92,7 @@ Configuration is loaded from `~/.omp-wechat/config.yml`, falling back to built-i
90
92
  # ~/.omp-wechat/config.yml
91
93
  maxSessions: 50
92
94
  dmPolicy: pairing
95
+ model: "@smol" # default model (role alias or provider/id)
93
96
  systemPrompt: |
94
97
  You are an AI assistant chatting via WeChat.
95
98
  Keep replies concise and in plain text.
@@ -99,8 +102,8 @@ systemPrompt: |
99
102
  |---|---|---|
100
103
  | `maxSessions` | `50` | Session pool cap (LRU eviction) |
101
104
  | `dmPolicy` | `pairing` | Access policy: `pairing` / `allowlist` / `disabled` |
105
+ | `model` | OMP default | Default model: role alias (`@smol`, `@slow`) or `provider/id` |
102
106
  | `systemPrompt` | Built-in | System prompt for WeChat chat sessions |
103
-
104
107
  > **Model, working directory, and tools are managed by OMP/Pi.** `createAgentSession()` automatically calls `discoverAuthStorage()`, reusing your existing `omp login` / `pi login` OAuth, `~/.omp/agent/agent.db` API keys, or `models.yml` config. This project never touches API keys.
105
108
 
106
109
  ## Slash Commands
@@ -117,6 +120,14 @@ systemPrompt: |
117
120
  | `/wechat install` | Install boot-time launchd/systemd service |
118
121
  | `/wechat uninstall` | Remove boot-time service |
119
122
 
123
+ ### Chat Commands (via WeChat message)
124
+
125
+ | Command | Description |
126
+ |---|---|
127
+ | `/model` | Show current AI model |
128
+ | `/models` | List all available models |
129
+ | `/model provider/id` | Switch model for this chat (e.g. `/model anthropic/claude-haiku-4-5`) |
130
+
120
131
  ## Access Control
121
132
 
122
133
  | Mode | Behavior |
@@ -131,34 +142,32 @@ The logged-in user (who scanned the QR code) is automatically added to the allow
131
142
 
132
143
  | Scenario | Behavior |
133
144
  |---|---|
134
- | Host session starts | Poll loop starts automatically |
135
- | Host session exits | Poll loop stops, all sessions disposed |
136
- | Host crashes | launchd/systemd restarts the host (if `/wechat install` was run) |
145
+ | Host process starts | Poll loop starts automatically (acquires singleton lock) |
146
+ | Other host processes | Standby with 30s failover timer, take over if lock holder dies |
147
+ | Host process exits | Poll loop stops, lock released, all sessions disposed |
148
+ | Host crashes | Failover timer in another process detects dead lock and takes over; or launchd/systemd restarts the host (if `/wechat install` was run) |
137
149
  | Machine reboots | Service auto-starts the host (if installed), poll loop resumes |
138
- | No boot service | Poll loop only runs while a host session is active |
150
+ | No boot service | Poll loop only runs while a host process is active |
139
151
 
140
- Logs: `~/.omp-wechat/logs/daemon.log`
152
+ Logs: `~/.omp-wechat/logs/daemon.log` (poll loop) and `~/.omp-wechat/logs/rpc.log` (boot service RPC output)
141
153
 
142
154
  ## Project Structure
143
155
 
144
156
  ```
145
157
  OMP-Wechat/
146
158
  ├── package.json # omp.extensions / pi.extensions manifest
147
- ├── tsconfig.json
148
- ├── .env.example
149
159
  ├── src/
150
160
  │ ├── index.ts # OMP/Pi extension entry (session_start + /wechat commands)
151
- │ ├── bridge.ts # In-process poll loop + message handling
161
+ │ ├── bridge.ts # In-process poll loop + message handling + singleton port lock
152
162
  │ ├── service.ts # Boot-time launchd/systemd install
153
- │ ├── config.ts # Config loading (env + config.yml + defaults)
163
+ │ ├── config.ts # Config loading (config.yml + defaults)
154
164
  │ ├── ilink/
155
165
  │ │ ├── types.ts # iLink Bot API type definitions
156
166
  │ │ ├── client.ts # iLink API client (poll/send/typing)
157
167
  │ │ └── login.ts # QR code login flow
158
168
  │ ├── engine/
159
169
  │ │ ├── session.ts # AI session creation + reply subscription
160
- │ │ ├── pool.ts # Session pool (LRU eviction, concurrency)
161
- │ │ └── prompt.ts # Barrel exports
170
+ │ │ └── pool.ts # Session pool (LRU eviction, concurrency)
162
171
  │ ├── access/
163
172
  │ │ └── control.ts # Access control (pairing/allowlist/disabled)
164
173
  │ ├── utils/
@@ -174,15 +183,14 @@ OMP-Wechat/
174
183
 
175
184
  - **Reply-only**: iLink requires `context_token` from an inbound message; you cannot initiate conversations
176
185
  - **1:1 only**: iLink Bot API does not support group chats
177
- - **No message history**: WeChat provides no history API; session context is lost on restart (in-memory sessions)
178
186
  - **Single instance**: iLink allows only one bot connection per account
179
187
  - **Text only (Phase 1)**: images/voice/video are represented as `(image)` / `(voice)` placeholders; media support is planned
180
188
 
181
189
  ## Roadmap
182
190
 
183
191
  - [ ] **Phase 2**: Media support (inbound images as base64, voice transcription)
184
- - [ ] **Phase 3**: Persistent sessions (`SessionManager.create()` per chat directory)
185
- - [ ] **Phase 4**: Per-chat model selection (smol for simple questions, slow for complex)
192
+ - [x] **Phase 3**: Persistent sessions `SessionManager.continueRecent()` per chat, context survives restarts
193
+ - [x] **Phase 4**: Per-chat model selection `/model` `/models` chat commands for manual switching
186
194
  - [ ] **Phase 5**: Fine-grained permissions (per-user tool restrictions, bash approval via WeChat)
187
195
 
188
196
  ## License