cli-setu 0.3.5 → 0.3.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cli-setu",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
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": {
@@ -161,7 +161,11 @@ const ESC_FOOTER_RE = /esc to cancel/i;
161
161
  // match PROCEED_RE is never mistaken for this one's.
162
162
  function distinguishingTextFor(event) {
163
163
  const { tool_name, tool_input } = event || {};
164
- if ((tool_name === 'Write' || tool_name === 'Edit' || tool_name === 'Read') && tool_input?.file_path) return tool_input.file_path;
164
+ // 2026-11-16 (real bug, found with the owner's own session log): the FULL path (C:\demo\python.txt) was
165
+ // used here, but Claude Code's prompt line only shows the file NAME ("Do you want to create python.txt?"),
166
+ // so isMenuStillOnScreen never found the path, the first 500 ms poll decided the menu was gone and the
167
+ // phone showed "Resolved at the laptop" for a prompt nobody had answered. The file name is what is on screen.
168
+ if ((tool_name === 'Write' || tool_name === 'Edit' || tool_name === 'Read') && tool_input?.file_path) return String(tool_input.file_path).split(/[\\/]/).pop();
165
169
  if ((tool_name === 'Bash' || tool_name === 'PowerShell') && tool_input?.command) return tool_input.command;
166
170
  return null;
167
171
  }
@@ -370,7 +374,8 @@ module.exports = {
370
374
  isMenuStillOnScreen: (scrollbackWindow, distinguishingText) => {
371
375
  const clean = stripAnsi(scrollbackWindow);
372
376
  if (!PROCEED_RE.test(clean)) return false;
373
- if (distinguishingText && !clean.includes(distinguishingText)) return false;
377
+ // Whitespace-insensitive: a long command wraps across screen lines, which would otherwise hide it.
378
+ if (distinguishingText && !clean.replace(/\s+/g, '').includes(String(distinguishingText).replace(/\s+/g, ''))) return false;
374
379
  return true;
375
380
  },
376
381
  distinguishingTextFor,
@@ -0,0 +1,40 @@
1
+ // node-pty 1.1.0 ships its macOS "spawn-helper" program WITHOUT the execute bit
2
+ // (-rw-r--r-- in the npm tarball) and its install script does not fix that, so on a Mac every
3
+ // terminal start fails with "posix_spawnp failed". Found 2026-11-15 by the GitHub Actions macOS
4
+ // job (the first real macOS run of this CLI). Linux builds the helper itself (already
5
+ // executable) and Windows has no helper, so only the prebuilt macOS one is affected.
6
+ //
7
+ // ensureSpawnHelperExecutable() runs before node-pty is first used and adds the execute bits to
8
+ // every spawn-helper it can find. It never throws: a read-only install folder or a missing file
9
+ // must not stop the CLI, node-pty then reports its own clear error.
10
+ 'use strict';
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+
14
+ function helperCandidates(ptyDir, platform, arch) {
15
+ return [
16
+ path.join(ptyDir, 'build', 'Release', 'spawn-helper'),
17
+ path.join(ptyDir, 'build', 'Debug', 'spawn-helper'),
18
+ path.join(ptyDir, 'prebuilds', `${platform}-${arch}`, 'spawn-helper'),
19
+ ];
20
+ }
21
+
22
+ // Returns the list of files it changed (for tests and diagnostics).
23
+ function ensureSpawnHelperExecutable(opts = {}) {
24
+ const platform = opts.platform || process.platform;
25
+ if (platform === 'win32') return [];
26
+ let ptyDir = opts.ptyDir;
27
+ if (!ptyDir) {
28
+ try { ptyDir = path.dirname(require.resolve('node-pty/package.json')); } catch { return []; }
29
+ }
30
+ const changed = [];
31
+ for (const file of helperCandidates(ptyDir, platform, opts.arch || process.arch)) {
32
+ try {
33
+ const mode = fs.statSync(file).mode;
34
+ if ((mode & 0o111) !== 0o111) { fs.chmodSync(file, mode | 0o755); changed.push(file); }
35
+ } catch { /* file not there, or not ours to change: nothing to do */ }
36
+ }
37
+ return changed;
38
+ }
39
+
40
+ module.exports = { ensureSpawnHelperExecutable, helperCandidates };
@@ -12,6 +12,15 @@
12
12
 
13
13
  const crypto = require('node:crypto');
14
14
 
15
+ // The readable prefix of a session ID. It is the device name from ~/.cli-setu/config.json (what the
16
+ // Devices tab shows, and what the owner can rename) when there is one, else the machine name, so a
17
+ // renamed device no longer leaks the real computer name through the session ID shown on the phone.
18
+ // Only letters, digits and dashes are kept. Added 2026-11-16 for Play Console screenshots.
19
+ function sessionPrefix(deviceName, hostname) {
20
+ const clean = String(deviceName || '').replace(/[^a-zA-Z0-9-]+/g, '-').replace(/^-+|-+$/g, '');
21
+ return clean || hostname;
22
+ }
23
+
15
24
  function newSessionId({ hostname, workingDir }) {
16
25
  const dirHash = crypto.createHash('sha1').update(workingDir).digest('hex').slice(0, 8);
17
26
  return `${hostname}-${dirHash}-${crypto.randomBytes(8).toString('hex')}`;
@@ -42,4 +51,4 @@ function isSessionEndedResponse(res) {
42
51
  return !!res && res.status === 410;
43
52
  }
44
53
 
45
- module.exports = { newSessionId, endSessionOnBackend, isSessionEndedResponse };
54
+ module.exports = { newSessionId, sessionPrefix, endSessionOnBackend, isSessionEndedResponse };
package/src/supervisor.js CHANGED
@@ -28,6 +28,8 @@
28
28
  // card, no usage tracking) instead of refusing to start. See
29
29
  // cli-adapters/README.md for the adapter interface this script drives.
30
30
 
31
+ // macOS: node-pty's prebuilt spawn-helper ships without the execute bit (see ptyHelperPerms.js).
32
+ require('./ptyHelperPerms').ensureSpawnHelperExecutable();
31
33
  const pty = require('node-pty');
32
34
  const { Terminal: HeadlessTerminal } = require('@xterm/headless');
33
35
  const fs = require('fs');
@@ -45,7 +47,7 @@ const { createDiagnostics } = require('./diagnostics');
45
47
  const { attachStdinForwarder } = require('./stdinForwarder');
46
48
  const { adoptPhoneKey } = require('./sharedKey');
47
49
  const { approvalFingerprint, createApprovalDeduper, relayWithRetry } = require('./approvalRelay');
48
- const { newSessionId, endSessionOnBackend, isSessionEndedResponse } = require('./sessionLifecycle');
50
+ const { newSessionId, sessionPrefix, endSessionOnBackend, isSessionEndedResponse } = require('./sessionLifecycle');
49
51
 
50
52
  // Real bug found by testing: this script's own console.log/console.error
51
53
  // calls write to the SAME process.stdout the PTY's raw output is echoed
@@ -146,7 +148,8 @@ const WORKING_DIR = process.cwd();
146
148
  // `cli-setu` in the same folder twice at once (e.g. two terminal tabs) never
147
149
  // silently shares one session.
148
150
  // PROD-003: minted fresh every run and never reused (see sessionLifecycle.js).
149
- const SESSION_ID = newSessionId({ hostname: os.hostname(), workingDir: WORKING_DIR });
151
+ // The prefix is the device name from config.json (renamable, shown on the phone) when set, else the machine name.
152
+ const SESSION_ID = newSessionId({ hostname: sessionPrefix(config.deviceName, os.hostname()), workingDir: WORKING_DIR });
150
153
 
151
154
  // SETU-005: the real identity a duplicate-session check needs - resolves
152
155
  // symlinks (fs.realpathSync) so two different-looking paths to the SAME
@@ -2249,7 +2252,18 @@ async function main() {
2249
2252
  const cleanupAndExit = () => {
2250
2253
  process.exitCode = 0;
2251
2254
  ptyProcess.kill();
2252
- setTimeout(() => process.exit(0), 1500).unref(); // safety net - see onExit's own comment
2255
+ // Safety net - see onExit's own comment. 2026-11-15: on a slow machine the shell can take longer
2256
+ // than this timer to die (the Actions Linux node 20 job lost the end notice once), and onExit is
2257
+ // the only place that tells the backend the session ended. So when the net fires first, send
2258
+ // that notice here (bounded to 2 s, best effort) and only then exit. finishedExiting stops the
2259
+ // notice being sent twice (onExit sets it the moment it runs).
2260
+ setTimeout(() => {
2261
+ if (finishedExiting) return; // onExit is already ending the process, with its own notice
2262
+ finishedExiting = true;
2263
+ endSessionOnBackend({ fetchImpl: fetch, authServer: AUTH_SERVER, deviceToken, sessionId: SESSION_ID, reason: 'exit' })
2264
+ .catch(() => {})
2265
+ .finally(() => process.exit(0));
2266
+ }, 1500).unref();
2253
2267
  };
2254
2268
  process.on('SIGINT', cleanupAndExit);
2255
2269
  process.on('SIGTERM', cleanupAndExit);