cli-setu 0.3.7 → 0.3.9
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/package.json +4 -2
- package/scripts/postinstall.js +16 -0
- package/src/pair.js +7 -3
- package/src/ptyHelperPerms.js +27 -1
- package/src/supervisor.js +40 -1
- package/src/unpairedDetector.js +37 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cli-setu",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
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
|
@@ -92,8 +92,12 @@ async function pair(authServer, authServerPublic) {
|
|
|
92
92
|
|
|
93
93
|
console.log('');
|
|
94
94
|
qrcode.generate(scanUrl, { small: true });
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
// 2026-11-16: this used to say "Scan this with your phone camera". A QR scanned with the phone's CAMERA app opens
|
|
96
|
+
// a web page, which registers an encryption key that lives in the browser: the app never gets the matching key,
|
|
97
|
+
// shows "The encryption key for this laptop does not match" and a blank terminal (found on a Linux test). The
|
|
98
|
+
// reliable ways are the app's own Pair button (scan or typed code).
|
|
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})`);
|
|
97
101
|
|
|
98
102
|
const codeRes = await fetch(`${authServer}/device/pair/start`, {
|
|
99
103
|
method: 'POST',
|
|
@@ -101,7 +105,7 @@ async function pair(authServer, authServerPublic) {
|
|
|
101
105
|
body: JSON.stringify({ deviceName: config.deviceName, devicePublicKey: config.devicePublicKey }),
|
|
102
106
|
});
|
|
103
107
|
const { code: typedCode, pairId: typedPairId } = await codeRes.json();
|
|
104
|
-
console.log(`[cli-setu] Or
|
|
108
|
+
console.log(`[cli-setu] Or, most reliable: in the CLI Setu app tap Pair, choose "Enter code" and type this code: ${typedCode}`);
|
|
105
109
|
console.log('[cli-setu] Waiting for scan or code entry...');
|
|
106
110
|
|
|
107
111
|
let confirmed = false;
|
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
|
@@ -48,6 +48,7 @@ const { attachStdinForwarder } = require('./stdinForwarder');
|
|
|
48
48
|
const { adoptPhoneKey } = require('./sharedKey');
|
|
49
49
|
const { approvalFingerprint, createApprovalDeduper, relayWithRetry } = require('./approvalRelay');
|
|
50
50
|
const { newSessionId, sessionPrefix, endSessionOnBackend, isSessionEndedResponse } = require('./sessionLifecycle');
|
|
51
|
+
const { createUnpairedDetector } = require('./unpairedDetector');
|
|
51
52
|
|
|
52
53
|
// Real bug found by testing: this script's own console.log/console.error
|
|
53
54
|
// calls write to the SAME process.stdout the PTY's raw output is echoed
|
|
@@ -373,7 +374,36 @@ async function pollFocus() {
|
|
|
373
374
|
}
|
|
374
375
|
}
|
|
375
376
|
|
|
377
|
+
// 2026-11-16 (real bug, found on a Linux/WSL test): a session that was already running when its device was unpaired
|
|
378
|
+
// (or paired again) kept sending output, got HTTP 401 for every piece and only logged it: the phone showed a blank
|
|
379
|
+
// terminal and the laptop never said why. Three 401s in a row from the output relay now stop the session with a
|
|
380
|
+
// clear message, the same way /device/connect already does for a 401. See unpairedDetector.js.
|
|
381
|
+
function stopBecauseUnpaired() {
|
|
382
|
+
diag.say('[supervisor] This device is no longer paired (it was unpaired, or paired again, from the app or another terminal), so your phone cannot see this session.', { error: true, showAtExit: true });
|
|
383
|
+
diag.say('[supervisor] This session is stopping. Pair again with `cli-setu pair`, then start a new session with `cli-setu session`.', { error: true, showAtExit: true });
|
|
384
|
+
log('[supervisor] The relay rejected this device token (HTTP 401) several times in a row: the device is no longer paired. Stopping this session.');
|
|
385
|
+
process.exitCode = 1;
|
|
386
|
+
if (ptyProcess) { ptyProcess.kill(); } else { process.exit(1); return; }
|
|
387
|
+
setTimeout(() => process.exit(1), 1500).unref();
|
|
388
|
+
}
|
|
389
|
+
const unpairedDetector = createUnpairedDetector({ onUnpaired: stopBecauseUnpaired });
|
|
390
|
+
|
|
391
|
+
// 2026-11-16 (real bug, found on a Linux/WSL test): when the very first /device/connect call could not even reach
|
|
392
|
+
// the server (connection timed out, DNS failure, refused), fetch() THROWS instead of returning a failed response.
|
|
393
|
+
// Only a failed RESPONSE was handled (retry with backoff), so a thrown network error became an unhandled promise
|
|
394
|
+
// rejection and crashed the whole session with a raw stack trace ("TypeError: fetch failed"). Every call now goes
|
|
395
|
+
// through this wrapper: any failure is logged and retried with the same backoff as a failed response.
|
|
376
396
|
async function connectToAzure() {
|
|
397
|
+
try {
|
|
398
|
+
await connectToAzureOnce();
|
|
399
|
+
} catch (err) {
|
|
400
|
+
const why = (err && err.cause && (err.cause.code || err.cause.message)) || (err && err.message) || String(err);
|
|
401
|
+
log(`[supervisor] /device/connect could not complete (${why}); will retry.`);
|
|
402
|
+
reconnectManager.scheduleRetry();
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
async function connectToAzureOnce() {
|
|
377
407
|
// cliType lets Devices/Profile show which CLI this paired laptop is
|
|
378
408
|
// actually running (see auth-server.js's /device/connect handler and
|
|
379
409
|
// db.js's devices.cli_type column) - sent on every connect (not just
|
|
@@ -743,6 +773,7 @@ async function sendSnapshot() {
|
|
|
743
773
|
});
|
|
744
774
|
if (!res.ok) {
|
|
745
775
|
log(`[supervisor] Snapshot part ${i + 1}/${parts.length} was refused by the backend (HTTP ${res.status}); stopping.`);
|
|
776
|
+
unpairedDetector.note(res.status);
|
|
746
777
|
return;
|
|
747
778
|
}
|
|
748
779
|
}
|
|
@@ -865,6 +896,7 @@ function flushOutputBuffer() {
|
|
|
865
896
|
body: JSON.stringify({ sessionId: SESSION_ID, seq: ++outputSeq, data, encrypted: true }),
|
|
866
897
|
});
|
|
867
898
|
if (!res.ok) log(`[supervisor] Output piece seq=${outputSeq} was refused by the backend (HTTP ${res.status}, ${data.length} chars).`);
|
|
899
|
+
unpairedDetector.note(res.status);
|
|
868
900
|
} catch (err) {
|
|
869
901
|
// A dropped terminal.output batch isn't fatal the way a dropped
|
|
870
902
|
// confirmation would be - the next batch (or a fresh session.attach
|
|
@@ -1913,7 +1945,14 @@ async function main() {
|
|
|
1913
1945
|
// the user only that something failed, never why. Re-throwing with
|
|
1914
1946
|
// the actual command and cwd attached turns that into an actionable
|
|
1915
1947
|
// message instead of a dead end.
|
|
1916
|
-
|
|
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}` : ''}`);
|
|
1917
1956
|
}
|
|
1918
1957
|
|
|
1919
1958
|
// Attach the laptop keyboard IMMEDIATELY, before any other start-up work, so
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Notices that this device is no longer paired (found 2026-11-16 on a Linux test).
|
|
2
|
+
// After `cli-setu unpair`, or after the same device is paired again, the server rejects the old device token with
|
|
3
|
+
// HTTP 401. /device/connect already stopped the session on a 401, but a session that was ALREADY running kept sending
|
|
4
|
+
// output, got HTTP 401 for every piece, logged it and carried on: the phone showed a blank terminal and the laptop
|
|
5
|
+
// never said why. The output sender now reports every response status here; a few 401s in a row mean "no longer
|
|
6
|
+
// paired", and the session stops with a clear message.
|
|
7
|
+
//
|
|
8
|
+
// "In a row" matters: one odd 401 must not end a session. Any successful response resets the count. Pure and tested
|
|
9
|
+
// (test/unpairedDetector.test.js).
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
const DEFAULT_THRESHOLD = 3;
|
|
13
|
+
|
|
14
|
+
function createUnpairedDetector({ threshold = DEFAULT_THRESHOLD, onUnpaired }) {
|
|
15
|
+
let consecutive = 0;
|
|
16
|
+
let fired = false;
|
|
17
|
+
return {
|
|
18
|
+
// Call with the HTTP status of every authenticated relay response.
|
|
19
|
+
note(status) {
|
|
20
|
+
if (fired) return;
|
|
21
|
+
if (status === 401) {
|
|
22
|
+
consecutive += 1;
|
|
23
|
+
if (consecutive >= threshold) {
|
|
24
|
+
fired = true;
|
|
25
|
+
if (typeof onUnpaired === 'function') onUnpaired();
|
|
26
|
+
}
|
|
27
|
+
} else if (status >= 200 && status < 300) {
|
|
28
|
+
consecutive = 0;
|
|
29
|
+
}
|
|
30
|
+
// Other statuses (403, 410, 429, 5xx) neither count nor reset: they mean something else.
|
|
31
|
+
},
|
|
32
|
+
get consecutive() { return consecutive; },
|
|
33
|
+
get fired() { return fired; },
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = { createUnpairedDetector, DEFAULT_THRESHOLD };
|