opencode-remote-control 0.2.4 → 0.2.5
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.
- package/README.md +35 -11
- package/dist/opencode/client.js +79 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,15 +15,37 @@
|
|
|
15
15
|
Control OpenCode from anywhere via Telegram or Feishu.
|
|
16
16
|
</p>
|
|
17
17
|
|
|
18
|
+
## Requirements
|
|
19
|
+
|
|
20
|
+
- Node.js >= 18.0.0
|
|
21
|
+
- [OpenCode](https://github.com/opencode-ai/opencode) installed and accessible in PATH
|
|
22
|
+
- Telegram account (for Telegram bot)
|
|
23
|
+
- Feishu account (for Feishu bot)
|
|
24
|
+
- ngrok or cloudflared (for Feishu webhook)
|
|
25
|
+
|
|
26
|
+
### Verify OpenCode Installation
|
|
27
|
+
|
|
28
|
+
Before starting, make sure OpenCode is installed and accessible:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
opencode --version
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
If you see `command not found`, install OpenCode first:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install -g @opencode-ai/opencode
|
|
38
|
+
```
|
|
39
|
+
|
|
18
40
|
## Installation
|
|
19
41
|
|
|
20
42
|
```bash
|
|
21
43
|
# Install globally with npm, pnpm, or bun
|
|
22
|
-
npm install -g opencode-remote-control
|
|
44
|
+
npm install -g opencode-remote-control@latest
|
|
23
45
|
# or
|
|
24
|
-
pnpm install -g opencode-remote-control
|
|
46
|
+
pnpm install -g opencode-remote-control@latest
|
|
25
47
|
# or
|
|
26
|
-
bun install -g opencode-remote-control
|
|
48
|
+
bun install -g opencode-remote-control@latest
|
|
27
49
|
```
|
|
28
50
|
|
|
29
51
|
## Configuration
|
|
@@ -48,6 +70,16 @@ Token is saved to `~/.opencode-remote/.env`
|
|
|
48
70
|
|
|
49
71
|
For detailed Feishu setup instructions, see [Feishu Setup Guide](./docs/FEISHU_SETUP_EN.md) or [飞书配置指南](./docs/FEISHU_SETUP.md).
|
|
50
72
|
|
|
73
|
+
## Start Service
|
|
74
|
+
|
|
75
|
+
Once configured, start the bot service:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
opencode-remote
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
That's it! You can now send messages to your Telegram bot or Feishu bot to control OpenCode remotely.
|
|
82
|
+
|
|
51
83
|
## Usage
|
|
52
84
|
|
|
53
85
|
```bash
|
|
@@ -136,14 +168,6 @@ The Telegram bot uses **Polling Mode** to fetch messages from Telegram servers,
|
|
|
136
168
|
|
|
137
169
|
The Feishu bot uses **Webhook Mode** and requires a tunnel (ngrok/cloudflared) to receive messages.
|
|
138
170
|
|
|
139
|
-
## Requirements
|
|
140
|
-
|
|
141
|
-
- Node.js >= 18.0.0
|
|
142
|
-
- [OpenCode](https://github.com/opencode-ai/opencode) installed
|
|
143
|
-
- Telegram account (for Telegram bot)
|
|
144
|
-
- Feishu account (for Feishu bot)
|
|
145
|
-
- ngrok or cloudflared (for Feishu webhook)
|
|
146
|
-
|
|
147
171
|
## Contributing
|
|
148
172
|
|
|
149
173
|
Contributions are welcome! Please feel free to submit a Pull Request.
|
package/dist/opencode/client.js
CHANGED
|
@@ -1,15 +1,90 @@
|
|
|
1
1
|
// OpenCode SDK client for remote control
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { platform } from 'node:os';
|
|
2
4
|
import { createOpencode } from '@opencode-ai/sdk';
|
|
5
|
+
// Windows compatibility: patch child_process.spawn to use shell for 'opencode' command
|
|
6
|
+
// This is needed because Windows requires shell: true to execute .cmd files
|
|
7
|
+
if (platform() === 'win32') {
|
|
8
|
+
const originalSpawn = spawn;
|
|
9
|
+
// @ts-ignore - monkey patching for Windows compatibility
|
|
10
|
+
require('node:child_process').spawn = function (command, args, options = {}) {
|
|
11
|
+
if (command === 'opencode' && !options.shell) {
|
|
12
|
+
options.shell = true;
|
|
13
|
+
}
|
|
14
|
+
return originalSpawn(command, args, options);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Verify that OpenCode is installed and accessible
|
|
19
|
+
* This helps catch issues early before the SDK tries to spawn the process
|
|
20
|
+
*/
|
|
21
|
+
export async function verifyOpenCodeInstalled() {
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
const isWindows = platform() === 'win32';
|
|
24
|
+
const command = isWindows ? 'where' : 'which';
|
|
25
|
+
const proc = spawn(command, ['opencode'], { shell: isWindows });
|
|
26
|
+
let output = '';
|
|
27
|
+
let errorOutput = '';
|
|
28
|
+
proc.stdout?.on('data', (chunk) => {
|
|
29
|
+
output += chunk.toString();
|
|
30
|
+
});
|
|
31
|
+
proc.stderr?.on('data', (chunk) => {
|
|
32
|
+
errorOutput += chunk.toString();
|
|
33
|
+
});
|
|
34
|
+
proc.on('close', (code) => {
|
|
35
|
+
if (code === 0 && output.trim()) {
|
|
36
|
+
resolve({ ok: true });
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
resolve({
|
|
40
|
+
ok: false,
|
|
41
|
+
error: `OpenCode not found in PATH. Please install it first:\n npm install -g @opencode-ai/opencode\n\nThen verify with:\n opencode --version`
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
proc.on('error', (err) => {
|
|
46
|
+
resolve({
|
|
47
|
+
ok: false,
|
|
48
|
+
error: `Failed to check OpenCode installation: ${err.message}\n\nPlease ensure OpenCode is installed:\n npm install -g @opencode-ai/opencode`
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
3
53
|
let opencodeInstance = null;
|
|
54
|
+
let verificationDone = false;
|
|
4
55
|
export async function initOpenCode() {
|
|
5
56
|
if (opencodeInstance) {
|
|
6
57
|
return opencodeInstance;
|
|
7
58
|
}
|
|
59
|
+
// Verify OpenCode is installed (only once)
|
|
60
|
+
if (!verificationDone) {
|
|
61
|
+
verificationDone = true;
|
|
62
|
+
console.log('🔧 Verifying OpenCode installation...');
|
|
63
|
+
const verification = await verifyOpenCodeInstalled();
|
|
64
|
+
if (!verification.ok) {
|
|
65
|
+
console.error('\n❌ ' + verification.error);
|
|
66
|
+
throw new Error('OpenCode not found. Please install it first: npm install -g @opencode-ai/opencode');
|
|
67
|
+
}
|
|
68
|
+
console.log('✅ OpenCode found');
|
|
69
|
+
}
|
|
8
70
|
console.log('🚀 Starting OpenCode server...');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
71
|
+
try {
|
|
72
|
+
opencodeInstance = await createOpencode({
|
|
73
|
+
port: 0, // Don't start HTTP server
|
|
74
|
+
});
|
|
75
|
+
console.log('✅ OpenCode server ready');
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
const isWindows = platform() === 'win32';
|
|
79
|
+
if (isWindows) {
|
|
80
|
+
console.error('\n❌ Failed to start OpenCode server.');
|
|
81
|
+
console.error('This may be a Windows compatibility issue.');
|
|
82
|
+
console.error('Please ensure OpenCode is installed correctly:');
|
|
83
|
+
console.error(' 1. Run: npm install -g @opencode-ai/opencode');
|
|
84
|
+
console.error(' 2. Verify: opencode --version');
|
|
85
|
+
}
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
13
88
|
return opencodeInstance;
|
|
14
89
|
}
|
|
15
90
|
export async function createSession(_threadId, title = `Remote control session`) {
|