uloop-cli 0.62.1 → 0.62.3

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": "uloop-cli",
3
- "version": "0.62.1",
3
+ "version": "0.62.3",
4
4
  "//version": "x-release-please-version",
5
5
  "description": "CLI tool for Unity Editor communication via uLoopMCP",
6
6
  "main": "dist/cli.bundle.cjs",
@@ -0,0 +1,63 @@
1
+ import { resolvePortFromUnitySettings } from '../port-resolver.js';
2
+
3
+ describe('resolvePortFromUnitySettings', () => {
4
+ it('returns serverPort when server is running and serverPort is valid', () => {
5
+ const port = resolvePortFromUnitySettings({
6
+ isServerRunning: true,
7
+ serverPort: 8711,
8
+ customPort: 8700,
9
+ });
10
+
11
+ expect(port).toBe(8711);
12
+ });
13
+
14
+ it('returns customPort when server is not running', () => {
15
+ const port = resolvePortFromUnitySettings({
16
+ isServerRunning: false,
17
+ serverPort: 8711,
18
+ customPort: 8700,
19
+ });
20
+
21
+ expect(port).toBe(8700);
22
+ });
23
+
24
+ it('returns customPort when serverPort is invalid', () => {
25
+ const port = resolvePortFromUnitySettings({
26
+ isServerRunning: false,
27
+ serverPort: 0,
28
+ customPort: 8711,
29
+ });
30
+
31
+ expect(port).toBe(8711);
32
+ });
33
+
34
+ it('falls back to serverPort when customPort is invalid', () => {
35
+ const port = resolvePortFromUnitySettings({
36
+ isServerRunning: false,
37
+ serverPort: 8711,
38
+ customPort: 0,
39
+ });
40
+
41
+ expect(port).toBe(8711);
42
+ });
43
+
44
+ it('returns null when both ports are invalid', () => {
45
+ const port = resolvePortFromUnitySettings({
46
+ isServerRunning: false,
47
+ serverPort: 0,
48
+ customPort: 0,
49
+ });
50
+
51
+ expect(port).toBeNull();
52
+ });
53
+
54
+ it('returns null when port is not an integer', () => {
55
+ const port = resolvePortFromUnitySettings({
56
+ isServerRunning: true,
57
+ serverPort: 8711.5,
58
+ customPort: 8700.1,
59
+ });
60
+
61
+ expect(port).toBeNull();
62
+ });
63
+ });
package/src/cli.ts CHANGED
@@ -38,6 +38,8 @@ interface CliOptions extends GlobalOptions {
38
38
  [key: string]: unknown;
39
39
  }
40
40
 
41
+ const LAUNCH_COMMAND = 'launch' as const;
42
+
41
43
  const BUILTIN_COMMANDS = [
42
44
  'list',
43
45
  'sync',
@@ -45,7 +47,7 @@ const BUILTIN_COMMANDS = [
45
47
  'update',
46
48
  'fix',
47
49
  'skills',
48
- 'launch',
50
+ LAUNCH_COMMAND,
49
51
  'focus-window',
50
52
  ] as const;
51
53
 
@@ -751,24 +753,30 @@ async function main(): Promise<void> {
751
753
  return;
752
754
  }
753
755
 
754
- // Check if cache version is outdated and auto-sync if needed
755
- const cachedVersion = loadToolsCache().version;
756
- if (hasCacheFile() && cachedVersion !== VERSION) {
757
- console.log(
758
- `\x1b[33mCache outdated (${cachedVersion} ${VERSION}). Syncing tools from Unity...\x1b[0m`,
759
- );
760
- try {
761
- await syncTools({});
762
- console.log('\x1b[32m✓ Tools synced successfully.\x1b[0m\n');
763
- } catch (error) {
764
- const message = error instanceof Error ? error.message : String(error);
765
- if (isConnectionError(message)) {
766
- console.error('\x1b[33mWarning: Failed to sync tools. Using cached definitions.\x1b[0m');
767
- console.error("\x1b[33mRun 'uloop sync' manually when Unity is available.\x1b[0m\n");
768
- } else {
769
- console.error('\x1b[33mWarning: Failed to sync tools. Using cached definitions.\x1b[0m');
770
- console.error(`\x1b[33mError: ${message}\x1b[0m`);
771
- console.error("\x1b[33mRun 'uloop sync' manually when Unity is available.\x1b[0m\n");
756
+ const args = process.argv.slice(2);
757
+ const cmdName = args.find((arg) => !arg.startsWith('-'));
758
+
759
+ // launch starts Unity, so it cannot connect to Unity for sync
760
+ if (cmdName !== LAUNCH_COMMAND) {
761
+ // Check if cache version is outdated and auto-sync if needed
762
+ const cachedVersion = loadToolsCache().version;
763
+ if (hasCacheFile() && cachedVersion !== VERSION) {
764
+ console.log(
765
+ `\x1b[33mCache outdated (${cachedVersion} ${VERSION}). Syncing tools from Unity...\x1b[0m`,
766
+ );
767
+ try {
768
+ await syncTools({});
769
+ console.log('\x1b[32m✓ Tools synced successfully.\x1b[0m\n');
770
+ } catch (error) {
771
+ const message = error instanceof Error ? error.message : String(error);
772
+ if (isConnectionError(message)) {
773
+ console.error('\x1b[33mWarning: Failed to sync tools. Using cached definitions.\x1b[0m');
774
+ console.error("\x1b[33mRun 'uloop sync' manually when Unity is available.\x1b[0m\n");
775
+ } else {
776
+ console.error('\x1b[33mWarning: Failed to sync tools. Using cached definitions.\x1b[0m');
777
+ console.error(`\x1b[33mError: ${message}\x1b[0m`);
778
+ console.error("\x1b[33mRun 'uloop sync' manually when Unity is available.\x1b[0m\n");
779
+ }
772
780
  }
773
781
  }
774
782
  }
@@ -779,9 +787,6 @@ async function main(): Promise<void> {
779
787
  registerToolCommand(tool);
780
788
  }
781
789
 
782
- const args = process.argv.slice(2);
783
- const cmdName = args.find((arg) => !arg.startsWith('-'));
784
-
785
790
  if (cmdName && !commandExists(cmdName)) {
786
791
  console.log(`\x1b[33mUnknown command '${cmdName}'. Syncing tools from Unity...\x1b[0m`);
787
792
  try {
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.62.1",
2
+ "version": "0.62.3",
3
3
  "tools": [
4
4
  {
5
5
  "name": "compile",
@@ -14,10 +14,46 @@ import { findUnityProjectRoot } from './project-root.js';
14
14
  const DEFAULT_PORT = 8700;
15
15
 
16
16
  interface UnityMcpSettings {
17
+ isServerRunning?: boolean;
17
18
  serverPort?: number;
18
19
  customPort?: number;
19
20
  }
20
21
 
22
+ function normalizePort(port: unknown): number | null {
23
+ if (typeof port !== 'number') {
24
+ return null;
25
+ }
26
+
27
+ if (!Number.isInteger(port)) {
28
+ return null;
29
+ }
30
+
31
+ if (port < 1 || port > 65535) {
32
+ return null;
33
+ }
34
+
35
+ return port;
36
+ }
37
+
38
+ export function resolvePortFromUnitySettings(settings: UnityMcpSettings): number | null {
39
+ const serverPort = normalizePort(settings.serverPort);
40
+ const customPort = normalizePort(settings.customPort);
41
+
42
+ if (settings.isServerRunning === true && serverPort !== null) {
43
+ return serverPort;
44
+ }
45
+
46
+ if (customPort !== null) {
47
+ return customPort;
48
+ }
49
+
50
+ if (serverPort !== null) {
51
+ return serverPort;
52
+ }
53
+
54
+ return null;
55
+ }
56
+
21
57
  export async function resolveUnityPort(explicitPort?: number): Promise<number> {
22
58
  if (explicitPort !== undefined) {
23
59
  return explicitPort;
@@ -57,13 +93,5 @@ async function readPortFromSettings(projectRoot: string): Promise<number | null>
57
93
  return null;
58
94
  }
59
95
 
60
- if (typeof settings.serverPort === 'number') {
61
- return settings.serverPort;
62
- }
63
-
64
- if (typeof settings.customPort === 'number') {
65
- return settings.customPort;
66
- }
67
-
68
- return null;
96
+ return resolvePortFromUnitySettings(settings);
69
97
  }
package/src/version.ts CHANGED
@@ -4,4 +4,4 @@
4
4
  * This file exists to avoid bundling the entire package.json into the CLI bundle.
5
5
  * This version is automatically updated by release-please.
6
6
  */
7
- export const VERSION = '0.62.1'; // x-release-please-version
7
+ export const VERSION = '0.62.3'; // x-release-please-version