@hmduc16031996/claude-mb-bridge 1.1.9 → 1.1.11
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/dist/index.js +31 -2
- package/package.json +4 -2
- package/scripts/postinstall.cjs +39 -0
package/dist/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
import { supabase } from './supabase.js';
|
|
4
4
|
import { createRequire } from 'module';
|
|
5
|
+
import { execSync } from 'child_process';
|
|
6
|
+
import * as fs from 'fs';
|
|
5
7
|
const require = createRequire(import.meta.url);
|
|
6
8
|
const pty = require('node-pty');
|
|
7
9
|
const program = new Command();
|
|
@@ -57,11 +59,38 @@ program
|
|
|
57
59
|
// 3. Local pairing server (optional / fallback as per plan)
|
|
58
60
|
// For now, we'll stick to the token-based pairing.
|
|
59
61
|
});
|
|
62
|
+
function findClaudeBinary() {
|
|
63
|
+
// 1. CLAUDE_PATH env var (explicit override)
|
|
64
|
+
if (process.env.CLAUDE_PATH) {
|
|
65
|
+
return process.env.CLAUDE_PATH;
|
|
66
|
+
}
|
|
67
|
+
// 2. 'which claude' — respects user's PATH
|
|
68
|
+
try {
|
|
69
|
+
const result = execSync('which claude', { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim();
|
|
70
|
+
if (result && fs.existsSync(result))
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// continue to fallbacks
|
|
75
|
+
}
|
|
76
|
+
// 3. Common installation paths
|
|
77
|
+
const home = process.env.HOME || '';
|
|
78
|
+
const fallbacks = [
|
|
79
|
+
`${home}/.local/bin/claude`,
|
|
80
|
+
'/usr/local/bin/claude',
|
|
81
|
+
'/opt/homebrew/bin/claude',
|
|
82
|
+
'/usr/bin/claude',
|
|
83
|
+
];
|
|
84
|
+
for (const p of fallbacks) {
|
|
85
|
+
if (fs.existsSync(p))
|
|
86
|
+
return p;
|
|
87
|
+
}
|
|
88
|
+
throw new Error('Could not find claude CLI. Set CLAUDE_PATH env var or ensure claude is in your PATH.');
|
|
89
|
+
}
|
|
60
90
|
async function handleUserPrompt(content, sessionId, cwd) {
|
|
61
91
|
console.log('⏳ Executing Claude Code with PTY...');
|
|
62
|
-
// Spawn claude directly (not via shell) so PTY works reliably across environments
|
|
63
92
|
const isWin = process.platform === 'win32';
|
|
64
|
-
const claudeExe = isWin ? 'cmd.exe' :
|
|
93
|
+
const claudeExe = isWin ? 'cmd.exe' : findClaudeBinary();
|
|
65
94
|
const args = isWin
|
|
66
95
|
? ['/c', 'claude', '--print', content]
|
|
67
96
|
: ['--print', content];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmduc16031996/claude-mb-bridge",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
4
|
"description": "Bridge between Claude Code CLI and your mobile app via Supabase",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsc",
|
|
12
12
|
"start": "node dist/index.js",
|
|
13
|
-
"dev": "tsx src/index.ts"
|
|
13
|
+
"dev": "tsx src/index.ts",
|
|
14
|
+
"postinstall": "node scripts/postinstall.cjs"
|
|
14
15
|
},
|
|
15
16
|
"dependencies": {
|
|
16
17
|
"@supabase/supabase-js": "^2.49.0",
|
|
@@ -27,6 +28,7 @@
|
|
|
27
28
|
},
|
|
28
29
|
"files": [
|
|
29
30
|
"dist",
|
|
31
|
+
"scripts",
|
|
30
32
|
"README.md",
|
|
31
33
|
"appicon.png"
|
|
32
34
|
],
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Postinstall script to fix node-pty spawn-helper permissions on macOS.
|
|
5
|
+
*
|
|
6
|
+
* node-pty's prebuilt binaries for macOS include a spawn-helper executable
|
|
7
|
+
* that sometimes loses its execute permission when installed via npm/npx.
|
|
8
|
+
* This script restores the permission.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
|
|
14
|
+
// Check both nested (local) and flat (npm/npx) node_modules layouts
|
|
15
|
+
const possiblePaths = [
|
|
16
|
+
path.join(__dirname, '..', 'node_modules', 'node-pty', 'prebuilds'),
|
|
17
|
+
path.join(__dirname, '..', '..', 'node-pty', 'prebuilds'),
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
for (const prebuildsPath of possiblePaths) {
|
|
21
|
+
try {
|
|
22
|
+
const entries = fs.readdirSync(prebuildsPath);
|
|
23
|
+
|
|
24
|
+
for (const entry of entries) {
|
|
25
|
+
if (!entry.startsWith('darwin-')) continue;
|
|
26
|
+
|
|
27
|
+
const spawnHelper = path.join(prebuildsPath, entry, 'spawn-helper');
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
fs.chmodSync(spawnHelper, 0o755);
|
|
31
|
+
console.log(`✅ Fixed spawn-helper permissions: ${spawnHelper}`);
|
|
32
|
+
} catch (e) {
|
|
33
|
+
// Ignore errors (file might not exist on some platforms)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
// Directory doesn't exist, skip
|
|
38
|
+
}
|
|
39
|
+
}
|