carmoji 0.3.3 → 0.3.4

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.
Files changed (2) hide show
  1. package/carmoji.js +32 -13
  2. package/package.json +1 -1
package/carmoji.js CHANGED
@@ -5,7 +5,8 @@
5
5
  // address + pairing code in ~/.config/carmoji/config.json.
6
6
  //
7
7
  // Commands:
8
- // pair <code> discover the phone on this Wi-Fi and pair with it
8
+ // pair <code> discover phones on this Wi-Fi and pair with the one
9
+ // whose Code Buddy sheet shows <code>
9
10
  // (pairing is additive — events fan out to every device)
10
11
  // unpair [device] forget a paired device by name or ip[:port], or `all`
11
12
  // install <tool> install hooks for a tool (or `all`); see `tools`
@@ -170,8 +171,8 @@ async function askTTY(question) {
170
171
  }
171
172
 
172
173
  /** Let the user pick between several discovered phones. */
173
- async function chooseDevice(devices) {
174
- console.log('Multiple CarMoji devices found:');
174
+ async function chooseDevice(devices, heading = 'Multiple CarMoji devices found:') {
175
+ console.log(heading);
175
176
  devices.forEach((d, i) => console.log(` ${i + 1}. ${d.name} — ${d.host}:${d.port}`));
176
177
  if (!process.stdin.isTTY) {
177
178
  console.error('\nRe-run with the address of the one you want: carmoji pair <code> <ip[:port]>');
@@ -987,10 +988,18 @@ async function main() {
987
988
  let target;
988
989
  const manual = rest[0];
989
990
  if (manual) {
990
- // Manual addressing for networks with several phones (the app's
991
- // Code Buddy sheet shows the address) or when mDNS is blocked.
991
+ // Manual addressing (the app's Code Buddy sheet shows the address)
992
+ // for networks where mDNS is blocked.
992
993
  const [host, port] = manual.split(':');
993
994
  target = { host, port: Number(port) || 8737, name: host };
995
+ const result = await send({ ...target, code: arg },
996
+ { source: 'bridge', event: 'turn_done' });
997
+ if (result !== 'ok') {
998
+ console.error(result === 'bad-code'
999
+ ? `"${target.name}" (${target.host}:${target.port}) rejected the pairing code — check that device’s Code Buddy sheet.`
1000
+ : `Found "${target.name}" at ${target.host}:${target.port} but couldn’t talk to it (${result}).`);
1001
+ process.exit(1);
1002
+ }
994
1003
  } else {
995
1004
  console.log('Looking for CarMoji on this network…');
996
1005
  const devices = await discoverAll();
@@ -999,17 +1008,27 @@ async function main() {
999
1008
  console.error('You can also pair by address: carmoji pair <code> <ip[:port]>');
1000
1009
  process.exit(1);
1001
1010
  }
1002
- target = devices.length === 1 ? devices[0] : await chooseDevice(devices);
1011
+ // The pairing code identifies the phone: probe every discovered
1012
+ // device with it and pair with whichever accepts — no picking from
1013
+ // a list when several phones share the network.
1014
+ const results = await Promise.all(devices.map((d) =>
1015
+ send({ ...d, code: arg }, { source: 'bridge', event: 'turn_done' })));
1016
+ const accepted = devices.filter((_, i) => results[i] === 'ok');
1017
+ if (accepted.length === 0) {
1018
+ console.error(results.includes('bad-code')
1019
+ ? `No device on this network accepted code ${arg} — check the Code Buddy sheet on the phone you want:`
1020
+ : 'Found CarMoji but couldn’t talk to it:');
1021
+ devices.forEach((d, i) =>
1022
+ console.error(` ${deviceLabel(d)}: ${results[i]}`));
1023
+ process.exit(1);
1024
+ }
1025
+ // Two phones drew the same 4-digit code — let the user break the
1026
+ // tie instead of guessing.
1027
+ target = accepted.length === 1 ? accepted[0]
1028
+ : await chooseDevice(accepted, 'Several devices accepted this pairing code:');
1003
1029
  }
1004
1030
  const device = { name: target.name, host: target.host,
1005
1031
  port: target.port, code: arg };
1006
- const result = await send(device, { source: 'bridge', event: 'turn_done' });
1007
- if (result !== 'ok') {
1008
- console.error(result === 'bad-code'
1009
- ? `"${target.name}" (${target.host}:${target.port}) rejected the pairing code — check that device’s Code Buddy sheet. (Wrong phone? Pass its address: carmoji pair <code> <ip[:port]>)`
1010
- : `Found "${target.name}" at ${target.host}:${target.port} but couldn’t talk to it (${result}).`);
1011
- process.exit(1);
1012
- }
1013
1032
  // Pairing the same device again just refreshes its code; other
1014
1033
  // devices stay paired unless the user says otherwise here.
1015
1034
  const others = loadDevices().filter(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carmoji",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Bring your CarMoji pet to life from Claude Code / Codex — a LAN bridge that streams coding events to the CarMoji iOS app",
5
5
  "type": "module",
6
6
  "bin": {