opencode-remote-control 0.2.3 → 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 CHANGED
@@ -15,22 +15,50 @@
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
- ## Quick Start
51
+ ## Configuration
30
52
 
31
- ### Telegram Setup
53
+ Run the config command to set up your preferred channel:
54
+
55
+ ```bash
56
+ opencode-remote config
57
+ ```
32
58
 
33
- On first run, you'll be prompted for a Telegram bot token:
59
+ Select **Telegram** or **Feishu** and follow the interactive guide.
60
+
61
+ ### Telegram Setup
34
62
 
35
63
  1. Open Telegram, search **@BotFather**
36
64
  2. Send `/newbot` and follow instructions
@@ -40,13 +68,17 @@ Token is saved to `~/.opencode-remote/.env`
40
68
 
41
69
  ### Feishu Setup
42
70
 
43
- Run the config command for Feishu:
71
+ For detailed Feishu setup instructions, see [Feishu Setup Guide](./docs/FEISHU_SETUP_EN.md) or [飞书配置指南](./docs/FEISHU_SETUP.md).
72
+
73
+ ## Start Service
74
+
75
+ Once configured, start the bot service:
44
76
 
45
77
  ```bash
46
- opencode-remote config-feishu
78
+ opencode-remote
47
79
  ```
48
80
 
49
- Follow the interactive guide to configure your Feishu bot. For detailed setup instructions, see [Feishu Setup Guide](./docs/FEISHU_SETUP_EN.md) or [飞书配置指南](./docs/FEISHU_SETUP.md).
81
+ That's it! You can now send messages to your Telegram bot or Feishu bot to control OpenCode remotely.
50
82
 
51
83
  ## Usage
52
84
 
@@ -56,7 +88,6 @@ opencode-remote start # Start all configured bots
56
88
  opencode-remote telegram # Start Telegram bot only
57
89
  opencode-remote feishu # Start Feishu bot only
58
90
  opencode-remote config # Configure a channel (interactive)
59
- opencode-remote config-feishu # Configure Feishu directly
60
91
  opencode-remote help # Show help
61
92
  ```
62
93
 
@@ -137,14 +168,6 @@ The Telegram bot uses **Polling Mode** to fetch messages from Telegram servers,
137
168
 
138
169
  The Feishu bot uses **Webhook Mode** and requires a tunnel (ngrok/cloudflared) to receive messages.
139
170
 
140
- ## Requirements
141
-
142
- - Node.js >= 18.0.0
143
- - [OpenCode](https://github.com/opencode-ai/opencode) installed
144
- - Telegram account (for Telegram bot)
145
- - Feishu account (for Feishu bot)
146
- - ngrok or cloudflared (for Feishu webhook)
147
-
148
171
  ## Contributing
149
172
 
150
173
  Contributions are welcome! Please feel free to submit a Pull Request.
package/dist/cli.js CHANGED
@@ -24,7 +24,6 @@ Commands:
24
24
  telegram Start Telegram bot only
25
25
  feishu Start Feishu bot only
26
26
  config Configure a channel (interactive selection)
27
- config-feishu Configure Feishu bot directly
28
27
  help Show this help message
29
28
 
30
29
  Examples:
@@ -33,7 +32,6 @@ Examples:
33
32
  opencode-remote telegram # Start Telegram only
34
33
  opencode-remote feishu # Start Feishu only
35
34
  opencode-remote config # Interactive channel selection
36
- opencode-remote config-feishu # Configure Feishu directly
37
35
  `);
38
36
  }
39
37
  async function promptChannel() {
@@ -329,17 +327,6 @@ async function runConfig() {
329
327
  }
330
328
  process.exit(0);
331
329
  }
332
- async function runConfigFeishu() {
333
- printBanner();
334
- const { appId, appSecret } = await promptFeishuConfig();
335
- if (!appId || !appSecret) {
336
- console.log('\n❌ Invalid credentials. Please try again.');
337
- process.exit(1);
338
- }
339
- await saveFeishuConfig(appId, appSecret);
340
- console.log('\n🚀 Ready! Run `opencode-remote` to start the bot.');
341
- process.exit(0);
342
- }
343
330
  function hasTelegramConfig(config) {
344
331
  return !!(config.telegramBotToken?.trim());
345
332
  }
@@ -355,9 +342,7 @@ async function runStart() {
355
342
  const hasFeishu = hasFeishuConfig(config);
356
343
  if (!hasTelegram && !hasFeishu) {
357
344
  console.log('❌ No bots configured!');
358
- console.log('\nRun one of:');
359
- console.log(' opencode-remote config # Configure Telegram');
360
- console.log(' opencode-remote config-feishu # Configure Feishu');
345
+ console.log('\nRun: opencode-remote config');
361
346
  process.exit(1);
362
347
  }
363
348
  // Track shutdown state
@@ -425,7 +410,7 @@ async function runFeishuOnly() {
425
410
  const config = await getConfig();
426
411
  if (!hasFeishuConfig(config)) {
427
412
  console.log('❌ Feishu bot not configured!');
428
- console.log('\nRun: opencode-remote config-feishu');
413
+ console.log('\nRun: opencode-remote config');
429
414
  process.exit(1);
430
415
  }
431
416
  printBanner();
@@ -454,9 +439,6 @@ switch (command) {
454
439
  case 'config':
455
440
  runConfig();
456
441
  break;
457
- case 'config-feishu':
458
- runConfigFeishu();
459
- break;
460
442
  case 'help':
461
443
  case '--help':
462
444
  case '-h':
@@ -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
- opencodeInstance = await createOpencode({
10
- port: 0, // Don't start HTTP server
11
- });
12
- console.log('✅ OpenCode server ready');
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`) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-remote-control",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Control OpenCode from anywhere via Telegram or Feishu",
5
5
  "type": "module",
6
6
  "bin": {