uloop-cli 0.52.0 → 0.53.1

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.
@@ -5383,7 +5383,7 @@ var require_semver2 = __commonJS({
5383
5383
  });
5384
5384
 
5385
5385
  // src/cli.ts
5386
- var import_fs5 = require("fs");
5386
+ var import_fs6 = require("fs");
5387
5387
  var import_path6 = require("path");
5388
5388
  var import_os2 = require("os");
5389
5389
  var import_child_process = require("child_process");
@@ -5407,7 +5407,7 @@ var {
5407
5407
 
5408
5408
  // src/execute-tool.ts
5409
5409
  var readline = __toESM(require("readline"), 1);
5410
- var import_fs3 = require("fs");
5410
+ var import_fs4 = require("fs");
5411
5411
  var import_path4 = require("path");
5412
5412
  var semver = __toESM(require_semver2(), 1);
5413
5413
 
@@ -5555,19 +5555,72 @@ var DirectUnityClient = class {
5555
5555
 
5556
5556
  // src/port-resolver.ts
5557
5557
  var import_promises = require("fs/promises");
5558
+ var import_fs2 = require("fs");
5558
5559
  var import_path2 = require("path");
5559
5560
 
5560
5561
  // src/project-root.ts
5561
5562
  var import_fs = require("fs");
5562
5563
  var import_path = require("path");
5563
- function findUnityProjectRoot(startPath = process.cwd()) {
5564
+ var CHILD_SEARCH_MAX_DEPTH = 3;
5565
+ var EXCLUDED_DIRS = /* @__PURE__ */ new Set([
5566
+ "node_modules",
5567
+ ".git",
5568
+ "Temp",
5569
+ "obj",
5570
+ "Build",
5571
+ "Builds",
5572
+ "Logs",
5573
+ "Library"
5574
+ ]);
5575
+ function isUnityProjectWithUloop(dirPath) {
5576
+ const hasAssets = (0, import_fs.existsSync)((0, import_path.join)(dirPath, "Assets"));
5577
+ const hasProjectSettings = (0, import_fs.existsSync)((0, import_path.join)(dirPath, "ProjectSettings"));
5578
+ const hasUloopSettings = (0, import_fs.existsSync)((0, import_path.join)(dirPath, "UserSettings/UnityMcpSettings.json"));
5579
+ return hasAssets && hasProjectSettings && hasUloopSettings;
5580
+ }
5581
+ function findUnityProjectsInChildren(startPath, maxDepth) {
5582
+ const projects = [];
5583
+ function scan(currentPath, depth) {
5584
+ if (depth > maxDepth) {
5585
+ return;
5586
+ }
5587
+ if (!(0, import_fs.existsSync)(currentPath)) {
5588
+ return;
5589
+ }
5590
+ if (isUnityProjectWithUloop(currentPath)) {
5591
+ projects.push(currentPath);
5592
+ return;
5593
+ }
5594
+ let entries;
5595
+ try {
5596
+ entries = (0, import_fs.readdirSync)(currentPath, { withFileTypes: true });
5597
+ } catch {
5598
+ return;
5599
+ }
5600
+ for (const entry of entries) {
5601
+ if (!entry.isDirectory()) {
5602
+ continue;
5603
+ }
5604
+ if (EXCLUDED_DIRS.has(entry.name)) {
5605
+ continue;
5606
+ }
5607
+ const fullPath = (0, import_path.join)(currentPath, entry.name);
5608
+ scan(fullPath, depth + 1);
5609
+ }
5610
+ }
5611
+ scan(startPath, 0);
5612
+ return projects.sort();
5613
+ }
5614
+ function findUnityProjectInParents(startPath) {
5564
5615
  let currentPath = startPath;
5565
5616
  while (true) {
5566
- const hasAssets = (0, import_fs.existsSync)((0, import_path.join)(currentPath, "Assets"));
5567
- const hasProjectSettings = (0, import_fs.existsSync)((0, import_path.join)(currentPath, "ProjectSettings"));
5568
- if (hasAssets && hasProjectSettings) {
5617
+ if (isUnityProjectWithUloop(currentPath)) {
5569
5618
  return currentPath;
5570
5619
  }
5620
+ const isGitRoot = (0, import_fs.existsSync)((0, import_path.join)(currentPath, ".git"));
5621
+ if (isGitRoot) {
5622
+ return null;
5623
+ }
5571
5624
  const parentPath = (0, import_path.dirname)(currentPath);
5572
5625
  if (parentPath === currentPath) {
5573
5626
  return null;
@@ -5575,6 +5628,21 @@ function findUnityProjectRoot(startPath = process.cwd()) {
5575
5628
  currentPath = parentPath;
5576
5629
  }
5577
5630
  }
5631
+ function findUnityProjectRoot(startPath = process.cwd()) {
5632
+ const childProjects = findUnityProjectsInChildren(startPath, CHILD_SEARCH_MAX_DEPTH);
5633
+ if (childProjects.length > 0) {
5634
+ if (childProjects.length > 1) {
5635
+ console.error("\x1B[33mWarning: Multiple Unity projects found in child directories:\x1B[0m");
5636
+ for (const project of childProjects) {
5637
+ console.error(` - ${project}`);
5638
+ }
5639
+ console.error(`\x1B[33mUsing: ${childProjects[0]}\x1B[0m`);
5640
+ console.error("");
5641
+ }
5642
+ return childProjects[0];
5643
+ }
5644
+ return findUnityProjectInParents(startPath);
5645
+ }
5578
5646
 
5579
5647
  // src/port-resolver.ts
5580
5648
  var DEFAULT_PORT = 8700;
@@ -5582,18 +5650,21 @@ async function resolveUnityPort(explicitPort) {
5582
5650
  if (explicitPort !== void 0) {
5583
5651
  return explicitPort;
5584
5652
  }
5585
- const settingsPort = await readPortFromSettings();
5653
+ const projectRoot = findUnityProjectRoot();
5654
+ if (projectRoot === null) {
5655
+ throw new Error("Unity project not found. Use --port option to specify the port explicitly.");
5656
+ }
5657
+ const settingsPort = await readPortFromSettings(projectRoot);
5586
5658
  if (settingsPort !== null) {
5587
5659
  return settingsPort;
5588
5660
  }
5589
5661
  return DEFAULT_PORT;
5590
5662
  }
5591
- async function readPortFromSettings() {
5592
- const projectRoot = findUnityProjectRoot();
5593
- if (projectRoot === null) {
5663
+ async function readPortFromSettings(projectRoot) {
5664
+ const settingsPath = (0, import_path2.join)(projectRoot, "UserSettings/UnityMcpSettings.json");
5665
+ if (!(0, import_fs2.existsSync)(settingsPath)) {
5594
5666
  return null;
5595
5667
  }
5596
- const settingsPath = (0, import_path2.join)(projectRoot, "UserSettings/UnityMcpSettings.json");
5597
5668
  let content;
5598
5669
  try {
5599
5670
  content = await (0, import_promises.readFile)(settingsPath, "utf-8");
@@ -5616,12 +5687,12 @@ async function readPortFromSettings() {
5616
5687
  }
5617
5688
 
5618
5689
  // src/tool-cache.ts
5619
- var import_fs2 = require("fs");
5690
+ var import_fs3 = require("fs");
5620
5691
  var import_path3 = require("path");
5621
5692
 
5622
5693
  // src/default-tools.json
5623
5694
  var default_tools_default = {
5624
- version: "0.52.0",
5695
+ version: "0.53.1",
5625
5696
  tools: [
5626
5697
  {
5627
5698
  name: "compile",
@@ -6028,9 +6099,9 @@ function getDefaultTools() {
6028
6099
  }
6029
6100
  function loadToolsCache() {
6030
6101
  const cachePath = getCachePath();
6031
- if ((0, import_fs2.existsSync)(cachePath)) {
6102
+ if ((0, import_fs3.existsSync)(cachePath)) {
6032
6103
  try {
6033
- const content = (0, import_fs2.readFileSync)(cachePath, "utf-8");
6104
+ const content = (0, import_fs3.readFileSync)(cachePath, "utf-8");
6034
6105
  return JSON.parse(content);
6035
6106
  } catch {
6036
6107
  return getDefaultTools();
@@ -6041,18 +6112,18 @@ function loadToolsCache() {
6041
6112
  function saveToolsCache(cache) {
6042
6113
  const cacheDir = getCacheDir();
6043
6114
  const cachePath = getCachePath();
6044
- if (!(0, import_fs2.existsSync)(cacheDir)) {
6045
- (0, import_fs2.mkdirSync)(cacheDir, { recursive: true });
6115
+ if (!(0, import_fs3.existsSync)(cacheDir)) {
6116
+ (0, import_fs3.mkdirSync)(cacheDir, { recursive: true });
6046
6117
  }
6047
6118
  const content = JSON.stringify(cache, null, 2);
6048
- (0, import_fs2.writeFileSync)(cachePath, content, "utf-8");
6119
+ (0, import_fs3.writeFileSync)(cachePath, content, "utf-8");
6049
6120
  }
6050
6121
  function getCacheFilePath() {
6051
6122
  return getCachePath();
6052
6123
  }
6053
6124
 
6054
6125
  // src/version.ts
6055
- var VERSION = "0.52.0";
6126
+ var VERSION = "0.53.1";
6056
6127
 
6057
6128
  // src/spinner.ts
6058
6129
  var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
@@ -6156,15 +6227,15 @@ function checkUnityBusyState() {
6156
6227
  return;
6157
6228
  }
6158
6229
  const compilingLock = (0, import_path4.join)(projectRoot, "Temp", "compiling.lock");
6159
- if ((0, import_fs3.existsSync)(compilingLock)) {
6230
+ if ((0, import_fs4.existsSync)(compilingLock)) {
6160
6231
  throw new Error("UNITY_COMPILING");
6161
6232
  }
6162
6233
  const domainReloadLock = (0, import_path4.join)(projectRoot, "Temp", "domainreload.lock");
6163
- if ((0, import_fs3.existsSync)(domainReloadLock)) {
6234
+ if ((0, import_fs4.existsSync)(domainReloadLock)) {
6164
6235
  throw new Error("UNITY_DOMAIN_RELOAD");
6165
6236
  }
6166
6237
  const serverStartingLock = (0, import_path4.join)(projectRoot, "Temp", "serverstarting.lock");
6167
- if ((0, import_fs3.existsSync)(serverStartingLock)) {
6238
+ if ((0, import_fs4.existsSync)(serverStartingLock)) {
6168
6239
  throw new Error("UNITY_SERVER_STARTING");
6169
6240
  }
6170
6241
  }
@@ -6339,7 +6410,7 @@ function pascalToKebabCase(pascal) {
6339
6410
  }
6340
6411
 
6341
6412
  // src/skills/skills-manager.ts
6342
- var import_fs4 = require("fs");
6413
+ var import_fs5 = require("fs");
6343
6414
  var import_path5 = require("path");
6344
6415
  var import_os = require("os");
6345
6416
 
@@ -8674,7 +8745,7 @@ return "Changed material color (Undo available)";
8674
8745
  ];
8675
8746
 
8676
8747
  // src/skills/skills-manager.ts
8677
- var EXCLUDED_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", "Temp", "obj", "Build", "Builds", "Logs"]);
8748
+ var EXCLUDED_DIRS2 = /* @__PURE__ */ new Set(["node_modules", ".git", "Temp", "obj", "Build", "Builds", "Logs"]);
8678
8749
  function getGlobalSkillsDir(target) {
8679
8750
  return (0, import_path5.join)((0, import_os.homedir)(), target.projectDir, "skills");
8680
8751
  }
@@ -8693,16 +8764,16 @@ function getSkillPath(skillDirName, target, global) {
8693
8764
  }
8694
8765
  function isSkillInstalled(skill, target, global) {
8695
8766
  const skillPath = getSkillPath(skill.dirName, target, global);
8696
- return (0, import_fs4.existsSync)(skillPath);
8767
+ return (0, import_fs5.existsSync)(skillPath);
8697
8768
  }
8698
8769
  function isSkillOutdated(skill, target, global) {
8699
8770
  const baseDir = global ? getGlobalSkillsDir(target) : getProjectSkillsDir(target);
8700
8771
  const skillDir = (0, import_path5.join)(baseDir, skill.dirName);
8701
8772
  const skillPath = (0, import_path5.join)(skillDir, target.skillFileName);
8702
- if (!(0, import_fs4.existsSync)(skillPath)) {
8773
+ if (!(0, import_fs5.existsSync)(skillPath)) {
8703
8774
  return false;
8704
8775
  }
8705
- const installedContent = (0, import_fs4.readFileSync)(skillPath, "utf-8");
8776
+ const installedContent = (0, import_fs5.readFileSync)(skillPath, "utf-8");
8706
8777
  if (installedContent !== skill.content) {
8707
8778
  return true;
8708
8779
  }
@@ -8710,10 +8781,10 @@ function isSkillOutdated(skill, target, global) {
8710
8781
  const additionalFiles = skill.additionalFiles;
8711
8782
  for (const [relativePath, expectedContent] of Object.entries(additionalFiles)) {
8712
8783
  const filePath = (0, import_path5.join)(skillDir, relativePath);
8713
- if (!(0, import_fs4.existsSync)(filePath)) {
8784
+ if (!(0, import_fs5.existsSync)(filePath)) {
8714
8785
  return true;
8715
8786
  }
8716
- const installedFileContent = (0, import_fs4.readFileSync)(filePath, "utf-8");
8787
+ const installedFileContent = (0, import_fs5.readFileSync)(filePath, "utf-8");
8717
8788
  if (installedFileContent !== expectedContent) {
8718
8789
  return true;
8719
8790
  }
@@ -8755,19 +8826,19 @@ function parseFrontmatter(content) {
8755
8826
  return frontmatter;
8756
8827
  }
8757
8828
  function scanEditorFolderForSkills(editorPath, skills) {
8758
- if (!(0, import_fs4.existsSync)(editorPath)) {
8829
+ if (!(0, import_fs5.existsSync)(editorPath)) {
8759
8830
  return;
8760
8831
  }
8761
- const entries = (0, import_fs4.readdirSync)(editorPath, { withFileTypes: true });
8832
+ const entries = (0, import_fs5.readdirSync)(editorPath, { withFileTypes: true });
8762
8833
  for (const entry of entries) {
8763
- if (EXCLUDED_DIRS.has(entry.name)) {
8834
+ if (EXCLUDED_DIRS2.has(entry.name)) {
8764
8835
  continue;
8765
8836
  }
8766
8837
  const fullPath = (0, import_path5.join)(editorPath, entry.name);
8767
8838
  if (entry.isDirectory()) {
8768
8839
  const skillMdPath = (0, import_path5.join)(fullPath, "SKILL.md");
8769
- if ((0, import_fs4.existsSync)(skillMdPath)) {
8770
- const content = (0, import_fs4.readFileSync)(skillMdPath, "utf-8");
8840
+ if ((0, import_fs5.existsSync)(skillMdPath)) {
8841
+ const content = (0, import_fs5.readFileSync)(skillMdPath, "utf-8");
8771
8842
  const frontmatter = parseFrontmatter(content);
8772
8843
  if (frontmatter.internal === true) {
8773
8844
  continue;
@@ -8787,12 +8858,12 @@ function scanEditorFolderForSkills(editorPath, skills) {
8787
8858
  function findEditorFolders(basePath, maxDepth = 2) {
8788
8859
  const editorFolders = [];
8789
8860
  function scan(currentPath, depth) {
8790
- if (depth > maxDepth || !(0, import_fs4.existsSync)(currentPath)) {
8861
+ if (depth > maxDepth || !(0, import_fs5.existsSync)(currentPath)) {
8791
8862
  return;
8792
8863
  }
8793
- const entries = (0, import_fs4.readdirSync)(currentPath, { withFileTypes: true });
8864
+ const entries = (0, import_fs5.readdirSync)(currentPath, { withFileTypes: true });
8794
8865
  for (const entry of entries) {
8795
- if (!entry.isDirectory() || EXCLUDED_DIRS.has(entry.name)) {
8866
+ if (!entry.isDirectory() || EXCLUDED_DIRS2.has(entry.name)) {
8796
8867
  continue;
8797
8868
  }
8798
8869
  const fullPath = (0, import_path5.join)(currentPath, entry.name);
@@ -8819,7 +8890,7 @@ function collectProjectSkills() {
8819
8890
  (0, import_path5.join)(projectRoot, "Library", "PackageCache")
8820
8891
  ];
8821
8892
  for (const searchPath of searchPaths) {
8822
- if (!(0, import_fs4.existsSync)(searchPath)) {
8893
+ if (!(0, import_fs5.existsSync)(searchPath)) {
8823
8894
  continue;
8824
8895
  }
8825
8896
  const editorFolders = findEditorFolders(searchPath, 3);
@@ -8857,24 +8928,24 @@ function installSkill(skill, target, global) {
8857
8928
  const baseDir = global ? getGlobalSkillsDir(target) : getProjectSkillsDir(target);
8858
8929
  const skillDir = (0, import_path5.join)(baseDir, skill.dirName);
8859
8930
  const skillPath = (0, import_path5.join)(skillDir, target.skillFileName);
8860
- (0, import_fs4.mkdirSync)(skillDir, { recursive: true });
8861
- (0, import_fs4.writeFileSync)(skillPath, skill.content, "utf-8");
8931
+ (0, import_fs5.mkdirSync)(skillDir, { recursive: true });
8932
+ (0, import_fs5.writeFileSync)(skillPath, skill.content, "utf-8");
8862
8933
  if ("additionalFiles" in skill && skill.additionalFiles) {
8863
8934
  const additionalFiles = skill.additionalFiles;
8864
8935
  for (const [relativePath, content] of Object.entries(additionalFiles)) {
8865
8936
  const fullPath = (0, import_path5.join)(skillDir, relativePath);
8866
- (0, import_fs4.mkdirSync)((0, import_path5.dirname)(fullPath), { recursive: true });
8867
- (0, import_fs4.writeFileSync)(fullPath, content, "utf-8");
8937
+ (0, import_fs5.mkdirSync)((0, import_path5.dirname)(fullPath), { recursive: true });
8938
+ (0, import_fs5.writeFileSync)(fullPath, content, "utf-8");
8868
8939
  }
8869
8940
  }
8870
8941
  }
8871
8942
  function uninstallSkill(skill, target, global) {
8872
8943
  const baseDir = global ? getGlobalSkillsDir(target) : getProjectSkillsDir(target);
8873
8944
  const skillDir = (0, import_path5.join)(baseDir, skill.dirName);
8874
- if (!(0, import_fs4.existsSync)(skillDir)) {
8945
+ if (!(0, import_fs5.existsSync)(skillDir)) {
8875
8946
  return false;
8876
8947
  }
8877
- (0, import_fs4.rmSync)(skillDir, { recursive: true, force: true });
8948
+ (0, import_fs5.rmSync)(skillDir, { recursive: true, force: true });
8878
8949
  return true;
8879
8950
  }
8880
8951
  function installAllSkills(target, global) {
@@ -9402,8 +9473,8 @@ function cleanupLockFiles() {
9402
9473
  let cleaned = 0;
9403
9474
  for (const lockFile of LOCK_FILES) {
9404
9475
  const lockPath = (0, import_path6.join)(tempDir, lockFile);
9405
- if ((0, import_fs5.existsSync)(lockPath)) {
9406
- (0, import_fs5.unlinkSync)(lockPath);
9476
+ if ((0, import_fs6.existsSync)(lockPath)) {
9477
+ (0, import_fs6.unlinkSync)(lockPath);
9407
9478
  console.log(`Removed: ${lockFile}`);
9408
9479
  cleaned++;
9409
9480
  }
@@ -9439,12 +9510,12 @@ function handleCompletion(install, shellOverride) {
9439
9510
  }
9440
9511
  const configPath = getShellConfigPath(shell);
9441
9512
  const configDir = (0, import_path6.dirname)(configPath);
9442
- if (!(0, import_fs5.existsSync)(configDir)) {
9443
- (0, import_fs5.mkdirSync)(configDir, { recursive: true });
9513
+ if (!(0, import_fs6.existsSync)(configDir)) {
9514
+ (0, import_fs6.mkdirSync)(configDir, { recursive: true });
9444
9515
  }
9445
9516
  let content = "";
9446
- if ((0, import_fs5.existsSync)(configPath)) {
9447
- content = (0, import_fs5.readFileSync)(configPath, "utf-8");
9517
+ if ((0, import_fs6.existsSync)(configPath)) {
9518
+ content = (0, import_fs6.readFileSync)(configPath, "utf-8");
9448
9519
  content = content.replace(
9449
9520
  /\n?# >>> uloop completion >>>[\s\S]*?# <<< uloop completion <<<\n?/g,
9450
9521
  ""
@@ -9458,7 +9529,7 @@ ${startMarker}
9458
9529
  ${script}
9459
9530
  ${endMarker}
9460
9531
  `;
9461
- (0, import_fs5.writeFileSync)(configPath, content + lineToAdd, "utf-8");
9532
+ (0, import_fs6.writeFileSync)(configPath, content + lineToAdd, "utf-8");
9462
9533
  } else {
9463
9534
  const evalLine = `eval "$(uloop completion --shell ${shell})"`;
9464
9535
  const lineToAdd = `
@@ -9466,7 +9537,7 @@ ${startMarker}
9466
9537
  ${evalLine}
9467
9538
  ${endMarker}
9468
9539
  `;
9469
- (0, import_fs5.writeFileSync)(configPath, content + lineToAdd, "utf-8");
9540
+ (0, import_fs6.writeFileSync)(configPath, content + lineToAdd, "utf-8");
9470
9541
  }
9471
9542
  console.log(`Completion installed to ${configPath}`);
9472
9543
  if (shell === "powershell") {