cli-setu 0.3.9 → 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 +1 -1
- package/src/pair.js +0 -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
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',
|