cli-setu 0.3.8 → 0.3.10
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 +1 -1
- package/bin/setu.js +172 -172
- package/package.json +4 -2
- package/scripts/postinstall.js +16 -0
- package/src/pair.js +0 -1
- package/src/ptyHelperPerms.js +27 -1
- package/src/supervisor.js +8 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ cli-setu session --cli claude # same, but runs Claude Code inside the bridged s
|
|
|
19
19
|
cli-setu session --cli codex # or Codex
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
The first time you run `cli-setu pair`, it prints a QR code (and an 8-character
|
|
22
|
+
The first time you run `cli-setu pair`, it prints a QR code (and an 8-character code) - in the CLI Setu app tap Pair, then scan the QR with the app's own Pair screen (not the phone's separate camera app) or choose "Enter code" and type the code, which is the most reliable way. Pair each computer once. Pairing alone never opens a terminal session or starts any process - run `cli-setu session` afterward, in whichever folder you want to bridge, whenever you're ready.
|
|
23
23
|
|
|
24
24
|
Once paired, `cli-setu session` in any folder just works - no QR code needed again, unless this is a device you haven't paired before. A device can only ever run a limited number of live sessions at once, and cli-setu refuses to start a second session for the same project folder while one is already running there.
|
|
25
25
|
|
package/bin/setu.js
CHANGED
|
@@ -1,173 +1,173 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Command dispatcher for the `cli-setu` CLI. Kept deliberately thin - each
|
|
3
|
-
// real subcommand's logic lives in src/, this file only parses argv and
|
|
4
|
-
// calls the right one.
|
|
5
|
-
//
|
|
6
|
-
// TEMPORARY: defaults to the DEV server (dev-api.clisetu.com), not
|
|
7
|
-
// production, because only dev-api is live right now. MUST switch back to
|
|
8
|
-
// https://api.clisetu.com and republish before announcing this package to
|
|
9
|
-
// real users as "production ready" - see clisetuapp/backend's deployment
|
|
10
|
-
// guide for when production actually goes live.
|
|
11
|
-
const AUTH_SERVER = process.env.CLI_SETU_SERVER || 'https://dev-api.clisetu.com';
|
|
12
|
-
const AUTH_SERVER_PUBLIC = process.env.CLI_SETU_SERVER_PUBLIC || AUTH_SERVER;
|
|
13
|
-
|
|
14
|
-
// SETU-001/018 (PM brief, 2026-10-25): pairing and session creation are
|
|
15
|
-
// now two distinct lifecycle operations, never bundled. Real product gap
|
|
16
|
-
// this fixes: a prior revision of this file made `cli-setu pair` (and bare
|
|
17
|
-
// `cli-setu`) ALSO immediately start watching the current folder as a
|
|
18
|
-
// live terminal session - meaning simply pairing a laptop silently created
|
|
19
|
-
// a real PTY-backed session, registered it with the backend, and showed up
|
|
20
|
-
// as "live" on the phone, with no explicit ask from the user. `cli-setu
|
|
21
|
-
// pair` now ONLY pairs. `cli-setu session` is the one and only way to
|
|
22
|
-
// start watching a folder as a session (optionally `--cli claude`/
|
|
23
|
-
// `--cli codex` to bridge a specific CLI instead of a plain shell). Bare
|
|
24
|
-
// `cli-setu` (no subcommand) shows help instead of guessing which of the
|
|
25
|
-
// two the user meant.
|
|
26
|
-
//
|
|
27
|
-
// Real bug found by testing (kept from the previous revision of this
|
|
28
|
-
// comment): this used to switch on process.argv[2] directly against the
|
|
29
|
-
// subcommand list, with any other value (including a real --flag) falling
|
|
30
|
-
// through to "Unknown command" - flags are checked first here so a known
|
|
31
|
-
// flag never gets mistaken for an unrecognized subcommand.
|
|
32
|
-
const args = process.argv.slice(2);
|
|
33
|
-
const firstArg = args[0];
|
|
34
|
-
const isSubcommand = firstArg && !firstArg.startsWith('-');
|
|
35
|
-
|
|
36
|
-
// Real bug found by testing: a genuinely unrecognized flag like `-rfesfd`
|
|
37
|
-
// or `-g` (a typo) also starts with "-" - without this check it fell
|
|
38
|
-
// through isSubcommand straight into whatever the fallback path was,
|
|
39
|
-
// silently doing something the user never asked for instead of telling
|
|
40
|
-
// them their command doesn't exist. supervisor.js only ever actually
|
|
41
|
-
// reads `--cli <name>` out of argv (confirmed by reading it directly) -
|
|
42
|
-
// every other `-`-prefixed flag is unrecognized by definition.
|
|
43
|
-
const KNOWN_FLAGS = new Set(['--version', '-v', '--help', '-h', '--update', '--cli']);
|
|
44
|
-
const hasUnknownFlag = args.some((a) => a.startsWith('-') && !KNOWN_FLAGS.has(a));
|
|
45
|
-
|
|
46
|
-
async function main() {
|
|
47
|
-
if (hasUnknownFlag) {
|
|
48
|
-
const bad = args.find((a) => a.startsWith('-') && !KNOWN_FLAGS.has(a));
|
|
49
|
-
console.error(`[cli-setu] Unknown option: ${bad}`);
|
|
50
|
-
console.error('[cli-setu] For more info, run: cli-setu --help');
|
|
51
|
-
process.exit(1);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (args.includes('--version') || args.includes('-v')) {
|
|
55
|
-
console.log(require('../package.json').version);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (args.includes('--help') || args.includes('-h')) {
|
|
60
|
-
printHelp();
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (args.includes('--update')) {
|
|
65
|
-
const { update } = require('../src/update');
|
|
66
|
-
await update();
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (isSubcommand) {
|
|
71
|
-
switch (firstArg) {
|
|
72
|
-
case 'pair': {
|
|
73
|
-
// SETU-001: pairing ONLY pairs - it never starts a session anymore
|
|
74
|
-
// (see this file's top-of-file comment for the real gap this
|
|
75
|
-
// fixes). An already-paired device gets pair.js's own existing
|
|
76
|
-
// "already paired" message and returns, same as before - the only
|
|
77
|
-
// change is that this branch no longer follows up with
|
|
78
|
-
// require('../src/supervisor').
|
|
79
|
-
const { pair } = require('../src/pair');
|
|
80
|
-
// Real bug found by review, fixed before ever shipping: this used
|
|
81
|
-
// to print its own "Device paired successfully..." line
|
|
82
|
-
// UNCONDITIONALLY after calling pair(), even for an already-paired
|
|
83
|
-
// device - confirmed live, it printed BOTH pair.js's own
|
|
84
|
-
// "already paired, run cli-setu session" hint AND this generic
|
|
85
|
-
// success line back to back, a confusing duplicate (and the
|
|
86
|
-
// success line was also just plain wrong in that case - nothing
|
|
87
|
-
// was actually paired this run). alreadyPaired (now returned by
|
|
88
|
-
// pair() itself) means this success line only ever prints for a
|
|
89
|
-
// GENUINELY new pairing.
|
|
90
|
-
const { alreadyPaired } = await pair(AUTH_SERVER, AUTH_SERVER_PUBLIC);
|
|
91
|
-
if (!alreadyPaired) {
|
|
92
|
-
console.log('[cli-setu] Device paired successfully. To start a terminal session, run: cli-setu session');
|
|
93
|
-
}
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
case 'session': {
|
|
97
|
-
// SETU-001/006: `cli-setu session` (optionally `--cli claude` /
|
|
98
|
-
// `--cli codex`) is now the ONLY way to start watching a folder as
|
|
99
|
-
// a live session. supervisor.js itself already refuses to run at
|
|
100
|
-
// all (clear error, not a crash) if this device isn't paired yet -
|
|
101
|
-
// see its own top-of-file guard - so this branch doesn't need to
|
|
102
|
-
// duplicate that check here; it just needs to never silently pair
|
|
103
|
-
// on the user's behalf first, unlike the old bare-`cli-setu` path.
|
|
104
|
-
require('../src/supervisor');
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
case 'status': {
|
|
108
|
-
const { status } = require('../src/status');
|
|
109
|
-
await status(AUTH_SERVER);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
case 'stop': {
|
|
113
|
-
const { stop } = require('../src/stop');
|
|
114
|
-
// args[1] (optional) - a specific sessionId to stop, copied from
|
|
115
|
-
// `cli-setu status`'s own output. Omitted stops every session on
|
|
116
|
-
// this computer, unchanged from before.
|
|
117
|
-
await stop(args[1]);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
case 'unpair': {
|
|
121
|
-
const { unpair } = require('../src/unpair');
|
|
122
|
-
await unpair(AUTH_SERVER);
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
default:
|
|
126
|
-
console.error(`[cli-setu] Unknown command: ${firstArg}`);
|
|
127
|
-
printHelp();
|
|
128
|
-
process.exit(1);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// SETU-001/018: bare `cli-setu` (no subcommand) NO LONGER auto-pairs or
|
|
133
|
-
// auto-starts a session - it used to do both in one step (a real
|
|
134
|
-
// product decision this brief explicitly reverses: pairing and session
|
|
135
|
-
// creation must be two distinct, explicitly-requested operations, never
|
|
136
|
-
// bundled or guessed). Show help instead, same as the project's other
|
|
137
|
-
// "don't guess, tell the user what to type" safe-help behavior
|
|
138
|
-
// (supervisor.js's own unpaired-device message follows the same shape).
|
|
139
|
-
printHelp();
|
|
140
|
-
const { readConfig } = require('../src/config');
|
|
141
|
-
const config = readConfig();
|
|
142
|
-
if (!config || !config.deviceToken) {
|
|
143
|
-
console.log('\n[cli-setu] This computer isn\'t paired yet. Run `cli-setu pair` to get started.');
|
|
144
|
-
} else {
|
|
145
|
-
console.log('\n[cli-setu] Already paired. Run `cli-setu session` to start a terminal session.');
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function printHelp() {
|
|
150
|
-
console.log(`[cli-setu] Bridge your terminal to your phone.
|
|
151
|
-
|
|
152
|
-
Usage:
|
|
153
|
-
cli-setu pair Pair this computer with your phone (does NOT
|
|
154
|
-
start a session)
|
|
155
|
-
cli-setu session Start watching this folder as a live
|
|
156
|
-
terminal session (must be paired first)
|
|
157
|
-
cli-setu session --cli <name> Same, but run a specific CLI inside the
|
|
158
|
-
bridged session instead of the default plain
|
|
159
|
-
shell (e.g. --cli claude, --cli codex)
|
|
160
|
-
cli-setu status Show pairing status and any sessions running now
|
|
161
|
-
cli-setu stop Stop every session running on this computer
|
|
162
|
-
cli-setu stop <sessionId> Stop just one session (see \`cli-setu status\`
|
|
163
|
-
for the exact id to use)
|
|
164
|
-
cli-setu unpair Unpair this computer (asks for confirmation)
|
|
165
|
-
cli-setu --version, -v Print the installed version
|
|
166
|
-
cli-setu --update Check for and install the latest version
|
|
167
|
-
cli-setu --help, -h Show this help`);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
main().catch((err) => {
|
|
171
|
-
console.error('[cli-setu] Error:', err.message);
|
|
172
|
-
process.exit(1);
|
|
173
|
-
});
|
|
2
|
+
// Command dispatcher for the `cli-setu` CLI. Kept deliberately thin - each
|
|
3
|
+
// real subcommand's logic lives in src/, this file only parses argv and
|
|
4
|
+
// calls the right one.
|
|
5
|
+
//
|
|
6
|
+
// TEMPORARY: defaults to the DEV server (dev-api.clisetu.com), not
|
|
7
|
+
// production, because only dev-api is live right now. MUST switch back to
|
|
8
|
+
// https://api.clisetu.com and republish before announcing this package to
|
|
9
|
+
// real users as "production ready" - see clisetuapp/backend's deployment
|
|
10
|
+
// guide for when production actually goes live.
|
|
11
|
+
const AUTH_SERVER = process.env.CLI_SETU_SERVER || 'https://dev-api.clisetu.com';
|
|
12
|
+
const AUTH_SERVER_PUBLIC = process.env.CLI_SETU_SERVER_PUBLIC || AUTH_SERVER;
|
|
13
|
+
|
|
14
|
+
// SETU-001/018 (PM brief, 2026-10-25): pairing and session creation are
|
|
15
|
+
// now two distinct lifecycle operations, never bundled. Real product gap
|
|
16
|
+
// this fixes: a prior revision of this file made `cli-setu pair` (and bare
|
|
17
|
+
// `cli-setu`) ALSO immediately start watching the current folder as a
|
|
18
|
+
// live terminal session - meaning simply pairing a laptop silently created
|
|
19
|
+
// a real PTY-backed session, registered it with the backend, and showed up
|
|
20
|
+
// as "live" on the phone, with no explicit ask from the user. `cli-setu
|
|
21
|
+
// pair` now ONLY pairs. `cli-setu session` is the one and only way to
|
|
22
|
+
// start watching a folder as a session (optionally `--cli claude`/
|
|
23
|
+
// `--cli codex` to bridge a specific CLI instead of a plain shell). Bare
|
|
24
|
+
// `cli-setu` (no subcommand) shows help instead of guessing which of the
|
|
25
|
+
// two the user meant.
|
|
26
|
+
//
|
|
27
|
+
// Real bug found by testing (kept from the previous revision of this
|
|
28
|
+
// comment): this used to switch on process.argv[2] directly against the
|
|
29
|
+
// subcommand list, with any other value (including a real --flag) falling
|
|
30
|
+
// through to "Unknown command" - flags are checked first here so a known
|
|
31
|
+
// flag never gets mistaken for an unrecognized subcommand.
|
|
32
|
+
const args = process.argv.slice(2);
|
|
33
|
+
const firstArg = args[0];
|
|
34
|
+
const isSubcommand = firstArg && !firstArg.startsWith('-');
|
|
35
|
+
|
|
36
|
+
// Real bug found by testing: a genuinely unrecognized flag like `-rfesfd`
|
|
37
|
+
// or `-g` (a typo) also starts with "-" - without this check it fell
|
|
38
|
+
// through isSubcommand straight into whatever the fallback path was,
|
|
39
|
+
// silently doing something the user never asked for instead of telling
|
|
40
|
+
// them their command doesn't exist. supervisor.js only ever actually
|
|
41
|
+
// reads `--cli <name>` out of argv (confirmed by reading it directly) -
|
|
42
|
+
// every other `-`-prefixed flag is unrecognized by definition.
|
|
43
|
+
const KNOWN_FLAGS = new Set(['--version', '-v', '--help', '-h', '--update', '--cli']);
|
|
44
|
+
const hasUnknownFlag = args.some((a) => a.startsWith('-') && !KNOWN_FLAGS.has(a));
|
|
45
|
+
|
|
46
|
+
async function main() {
|
|
47
|
+
if (hasUnknownFlag) {
|
|
48
|
+
const bad = args.find((a) => a.startsWith('-') && !KNOWN_FLAGS.has(a));
|
|
49
|
+
console.error(`[cli-setu] Unknown option: ${bad}`);
|
|
50
|
+
console.error('[cli-setu] For more info, run: cli-setu --help');
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (args.includes('--version') || args.includes('-v')) {
|
|
55
|
+
console.log(require('../package.json').version);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
60
|
+
printHelp();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (args.includes('--update')) {
|
|
65
|
+
const { update } = require('../src/update');
|
|
66
|
+
await update();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (isSubcommand) {
|
|
71
|
+
switch (firstArg) {
|
|
72
|
+
case 'pair': {
|
|
73
|
+
// SETU-001: pairing ONLY pairs - it never starts a session anymore
|
|
74
|
+
// (see this file's top-of-file comment for the real gap this
|
|
75
|
+
// fixes). An already-paired device gets pair.js's own existing
|
|
76
|
+
// "already paired" message and returns, same as before - the only
|
|
77
|
+
// change is that this branch no longer follows up with
|
|
78
|
+
// require('../src/supervisor').
|
|
79
|
+
const { pair } = require('../src/pair');
|
|
80
|
+
// Real bug found by review, fixed before ever shipping: this used
|
|
81
|
+
// to print its own "Device paired successfully..." line
|
|
82
|
+
// UNCONDITIONALLY after calling pair(), even for an already-paired
|
|
83
|
+
// device - confirmed live, it printed BOTH pair.js's own
|
|
84
|
+
// "already paired, run cli-setu session" hint AND this generic
|
|
85
|
+
// success line back to back, a confusing duplicate (and the
|
|
86
|
+
// success line was also just plain wrong in that case - nothing
|
|
87
|
+
// was actually paired this run). alreadyPaired (now returned by
|
|
88
|
+
// pair() itself) means this success line only ever prints for a
|
|
89
|
+
// GENUINELY new pairing.
|
|
90
|
+
const { alreadyPaired } = await pair(AUTH_SERVER, AUTH_SERVER_PUBLIC);
|
|
91
|
+
if (!alreadyPaired) {
|
|
92
|
+
console.log('[cli-setu] Device paired successfully. To start a terminal session, run: cli-setu session');
|
|
93
|
+
}
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
case 'session': {
|
|
97
|
+
// SETU-001/006: `cli-setu session` (optionally `--cli claude` /
|
|
98
|
+
// `--cli codex`) is now the ONLY way to start watching a folder as
|
|
99
|
+
// a live session. supervisor.js itself already refuses to run at
|
|
100
|
+
// all (clear error, not a crash) if this device isn't paired yet -
|
|
101
|
+
// see its own top-of-file guard - so this branch doesn't need to
|
|
102
|
+
// duplicate that check here; it just needs to never silently pair
|
|
103
|
+
// on the user's behalf first, unlike the old bare-`cli-setu` path.
|
|
104
|
+
require('../src/supervisor');
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
case 'status': {
|
|
108
|
+
const { status } = require('../src/status');
|
|
109
|
+
await status(AUTH_SERVER);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
case 'stop': {
|
|
113
|
+
const { stop } = require('../src/stop');
|
|
114
|
+
// args[1] (optional) - a specific sessionId to stop, copied from
|
|
115
|
+
// `cli-setu status`'s own output. Omitted stops every session on
|
|
116
|
+
// this computer, unchanged from before.
|
|
117
|
+
await stop(args[1]);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
case 'unpair': {
|
|
121
|
+
const { unpair } = require('../src/unpair');
|
|
122
|
+
await unpair(AUTH_SERVER);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
default:
|
|
126
|
+
console.error(`[cli-setu] Unknown command: ${firstArg}`);
|
|
127
|
+
printHelp();
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// SETU-001/018: bare `cli-setu` (no subcommand) NO LONGER auto-pairs or
|
|
133
|
+
// auto-starts a session - it used to do both in one step (a real
|
|
134
|
+
// product decision this brief explicitly reverses: pairing and session
|
|
135
|
+
// creation must be two distinct, explicitly-requested operations, never
|
|
136
|
+
// bundled or guessed). Show help instead, same as the project's other
|
|
137
|
+
// "don't guess, tell the user what to type" safe-help behavior
|
|
138
|
+
// (supervisor.js's own unpaired-device message follows the same shape).
|
|
139
|
+
printHelp();
|
|
140
|
+
const { readConfig } = require('../src/config');
|
|
141
|
+
const config = readConfig();
|
|
142
|
+
if (!config || !config.deviceToken) {
|
|
143
|
+
console.log('\n[cli-setu] This computer isn\'t paired yet. Run `cli-setu pair` to get started.');
|
|
144
|
+
} else {
|
|
145
|
+
console.log('\n[cli-setu] Already paired. Run `cli-setu session` to start a terminal session.');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function printHelp() {
|
|
150
|
+
console.log(`[cli-setu] Bridge your terminal to your phone.
|
|
151
|
+
|
|
152
|
+
Usage:
|
|
153
|
+
cli-setu pair Pair this computer with your phone (does NOT
|
|
154
|
+
start a session)
|
|
155
|
+
cli-setu session Start watching this folder as a live
|
|
156
|
+
terminal session (must be paired first)
|
|
157
|
+
cli-setu session --cli <name> Same, but run a specific CLI inside the
|
|
158
|
+
bridged session instead of the default plain
|
|
159
|
+
shell (e.g. --cli claude, --cli codex)
|
|
160
|
+
cli-setu status Show pairing status and any sessions running now
|
|
161
|
+
cli-setu stop Stop every session running on this computer
|
|
162
|
+
cli-setu stop <sessionId> Stop just one session (see \`cli-setu status\`
|
|
163
|
+
for the exact id to use)
|
|
164
|
+
cli-setu unpair Unpair this computer (asks for confirmation)
|
|
165
|
+
cli-setu --version, -v Print the installed version
|
|
166
|
+
cli-setu --update Check for and install the latest version
|
|
167
|
+
cli-setu --help, -h Show this help`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
main().catch((err) => {
|
|
171
|
+
console.error('[cli-setu] Error:', err.message);
|
|
172
|
+
process.exit(1);
|
|
173
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cli-setu",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
4
4
|
"description": "Bridge your terminal to your phone — run and approve Claude Code, Codex CLI and other AI coding agents from anywhere.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"bin": {
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"main": "src/config.js",
|
|
10
10
|
"scripts": {
|
|
11
|
+
"postinstall": "node scripts/postinstall.js",
|
|
11
12
|
"test": "node test/run-all.js"
|
|
12
13
|
},
|
|
13
14
|
"engines": {
|
|
@@ -32,7 +33,8 @@
|
|
|
32
33
|
},
|
|
33
34
|
"files": [
|
|
34
35
|
"bin",
|
|
35
|
-
"src"
|
|
36
|
+
"src",
|
|
37
|
+
"scripts"
|
|
36
38
|
],
|
|
37
39
|
"dependencies": {
|
|
38
40
|
"@xterm/headless": "^6.0.0",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Runs after `npm install -g cli-setu`. node-pty ships its macOS helper program ("spawn-helper") without permission
|
|
2
|
+
// to run, which made every macOS session fail with "posix_spawnp failed". Doing the fix HERE, at install time, also
|
|
3
|
+
// covers `sudo npm install -g` (the script then runs as root, so it may change root-owned files; the CLI itself
|
|
4
|
+
// runs as the normal user and could not). It never fails the install: a problem here only means the CLI tries again
|
|
5
|
+
// at start-up and, if it still cannot, prints the exact fix command (see src/ptyHelperPerms.js).
|
|
6
|
+
// CLISETU_PTY_DIR lets the tests point it at a fake node-pty folder.
|
|
7
|
+
'use strict';
|
|
8
|
+
try {
|
|
9
|
+
const { ensureSpawnHelperExecutable } = require('../src/ptyHelperPerms');
|
|
10
|
+
const ptyDir = process.env.CLISETU_PTY_DIR || undefined;
|
|
11
|
+
const changed = ensureSpawnHelperExecutable(ptyDir ? { ptyDir } : {});
|
|
12
|
+
if (changed.length) console.log('[cli-setu] Made the terminal helper executable.');
|
|
13
|
+
} catch {
|
|
14
|
+
/* never fail the install */
|
|
15
|
+
}
|
|
16
|
+
process.exit(0);
|
package/src/pair.js
CHANGED
|
@@ -97,7 +97,6 @@ async function pair(authServer, authServerPublic) {
|
|
|
97
97
|
// shows "The encryption key for this laptop does not match" and a blank terminal (found on a Linux test). The
|
|
98
98
|
// reliable ways are the app's own Pair button (scan or typed code).
|
|
99
99
|
console.log('[cli-setu] Scan this QR code with the Pair button INSIDE the CLI Setu app (not the phone\'s camera app).');
|
|
100
|
-
console.log(`[cli-setu] (Testing on one PC without a phone? Paste this URL into a browser tab instead: ${scanUrl})`);
|
|
101
100
|
|
|
102
101
|
const codeRes = await fetch(`${authServer}/device/pair/start`, {
|
|
103
102
|
method: 'POST',
|
package/src/ptyHelperPerms.js
CHANGED
|
@@ -37,4 +37,30 @@ function ensureSpawnHelperExecutable(opts = {}) {
|
|
|
37
37
|
return changed;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
// When the terminal could not start ("posix_spawnp failed"), find out whether the cause is this helper: present but
|
|
41
|
+
// not executable. Returns a plain-language explanation with the exact command to run, or null when the helper is
|
|
42
|
+
// fine or not found (so the caller prints nothing misleading). Found on a real Mac (2026-11-16): the package was
|
|
43
|
+
// installed with sudo, the helper was owned by root, and the user saw only "posix_spawnp failed".
|
|
44
|
+
function describeSpawnFailure(opts = {}) {
|
|
45
|
+
const platform = opts.platform || process.platform;
|
|
46
|
+
if (platform === 'win32') return null;
|
|
47
|
+
let ptyDir = opts.ptyDir;
|
|
48
|
+
if (!ptyDir) {
|
|
49
|
+
try { ptyDir = path.dirname(require.resolve('node-pty/package.json')); } catch { return null; }
|
|
50
|
+
}
|
|
51
|
+
for (const file of helperCandidates(ptyDir, platform, opts.arch || process.arch)) {
|
|
52
|
+
let mode;
|
|
53
|
+
try { mode = fs.statSync(file).mode; } catch { continue; }
|
|
54
|
+
if ((mode & 0o111) === 0o111) continue;
|
|
55
|
+
return [
|
|
56
|
+
`The terminal helper that CLI Setu needs is not allowed to run: ${file}`,
|
|
57
|
+
'This usually happens when the package was installed with sudo, or by an installer that did not keep the permission.',
|
|
58
|
+
'Fix it with this command, then start the session again:',
|
|
59
|
+
` sudo chmod +x "${file}"`,
|
|
60
|
+
'To avoid it next time, install without sudo (use Node from Homebrew or nvm, or set a user npm folder) and run `npm install -g cli-setu@latest` again.',
|
|
61
|
+
].join('\n');
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = { ensureSpawnHelperExecutable, helperCandidates, describeSpawnFailure };
|
package/src/supervisor.js
CHANGED
|
@@ -1945,7 +1945,14 @@ async function main() {
|
|
|
1945
1945
|
// the user only that something failed, never why. Re-throwing with
|
|
1946
1946
|
// the actual command and cwd attached turns that into an actionable
|
|
1947
1947
|
// message instead of a dead end.
|
|
1948
|
-
|
|
1948
|
+
// 2026-11-16: on a real Mac this was only ever "posix_spawnp failed". When the cause is node-pty's helper not being
|
|
1949
|
+
// allowed to run (a sudo install leaves it owned by root, so the fix at start-up cannot change it), say so and
|
|
1950
|
+
// print the exact command. See ptyHelperPerms.describeSpawnFailure.
|
|
1951
|
+
let helperHint = null;
|
|
1952
|
+
if (/posix_spawnp/i.test(err.message || '')) {
|
|
1953
|
+
try { helperHint = require('./ptyHelperPerms').describeSpawnFailure(); } catch { helperHint = null; }
|
|
1954
|
+
}
|
|
1955
|
+
throw new Error(`Could not start "${adapter.spawn.command}" in ${WORKING_DIR}: ${err.message}${helperHint ? `\n${helperHint}` : ''}`);
|
|
1949
1956
|
}
|
|
1950
1957
|
|
|
1951
1958
|
// Attach the laptop keyboard IMMEDIATELY, before any other start-up work, so
|