@uipath/cli 1.205.0-preview.276 → 1.206.0-preview.279

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 (76) hide show
  1. package/dist/{applicationinsights-s28k1t0d.js → applicationinsights-pwe8sf3y.js} +1269 -1269
  2. package/dist/{browser-strategy-6atc7v8s.js → browser-strategy-p5fhwxqj.js} +6 -7
  3. package/dist/cli-q6fp9ccp.js +23 -0
  4. package/dist/contentStore-c51xqdn2.js +41 -0
  5. package/dist/environmentInfo-fn0za9jw.js +71 -0
  6. package/dist/feedbackPrompts-t1enxv1x.js +144 -0
  7. package/dist/handlers-93z27zrr.js +805 -0
  8. package/dist/index-16d4evd1.js +1051 -0
  9. package/dist/index-1vyte4ma.js +14 -0
  10. package/dist/index-21kns9qg.js +10 -0
  11. package/dist/{index-yhj4pgvt.js → index-2j7ss97f.js} +331 -2595
  12. package/dist/index-2k8rhmad.js +274 -0
  13. package/dist/{index-30618bjs.js → index-2mm750yx.js} +174 -234
  14. package/dist/{index-622x1qb5.js → index-3fvbddpw.js} +7092 -7092
  15. package/dist/{index-d3w0wn6k.js → index-5gce5wfd.js} +16 -16
  16. package/dist/index-5j0bfd3e.js +4744 -0
  17. package/dist/index-68xmrb9x.js +237 -0
  18. package/dist/index-6wj58qka.js +59 -0
  19. package/dist/index-898c4tfz.js +668 -0
  20. package/dist/index-8gr7ny79.js +365 -0
  21. package/dist/index-99emfvtm.js +13 -0
  22. package/dist/{index-pj3g8ftz.js → index-9db5vwx9.js} +2429 -1693
  23. package/dist/index-ayg25v46.js +151 -0
  24. package/dist/index-bf0e4evz.js +6180 -0
  25. package/dist/index-bpqx6f8h.js +92 -0
  26. package/dist/index-bpxh3fqv.js +392 -0
  27. package/dist/index-cc653qc1.js +1327 -0
  28. package/dist/{index-m5nwse9v.js → index-cj4v0jct.js} +21 -69
  29. package/dist/{index-469jgr1w.js → index-dsj3jrm0.js} +105 -106
  30. package/dist/{index-1yh8g550.js → index-epsr41wx.js} +8 -12
  31. package/dist/{index-yb4er9vd.js → index-jjejkkg4.js} +474 -528
  32. package/dist/index-kg1xrq51.js +171 -0
  33. package/dist/index-m8vqyv3g.js +72 -0
  34. package/dist/index-mzqm6xfh.js +45 -0
  35. package/dist/index-nsrrst23.js +44 -0
  36. package/dist/{index-h8cph72k.js → index-nzr4mx5p.js} +2 -22
  37. package/dist/index-p9s0gyrw.js +72 -0
  38. package/dist/index-qadhm1gn.js +271 -0
  39. package/dist/index-qwbyt2q5.js +95 -0
  40. package/dist/index-rbna3w6k.js +200 -0
  41. package/dist/index-rr5hdtcy.js +95 -0
  42. package/dist/{index-qa9gftnj.js → index-xd2w5pct.js} +3 -3
  43. package/dist/index-xpdtagqw.js +30 -0
  44. package/dist/{index-925304r7.js → index-y085rpen.js} +29 -25
  45. package/dist/index-y5ncb93a.js +240 -0
  46. package/dist/index-y7d0cth0.js +93 -0
  47. package/dist/{index-hdxtgckw.js → index-z070caqq.js} +56 -12
  48. package/dist/index-zdqbp34f.js +14 -0
  49. package/dist/index.js +38 -36
  50. package/dist/install-3gw33jcf.js +558 -0
  51. package/dist/{jmespath-e4a59c8w.js → jmespath-ab6tdc42.js} +1 -1
  52. package/dist/js-yaml-0c4svjwq.js +36 -0
  53. package/dist/{mcp-jssaz3wr.js → mcp-s50h6d56.js} +236 -472
  54. package/dist/{node-strategy-ggx3nmyj.js → node-strategy-p1n8wr5s.js} +16 -19
  55. package/dist/project-context-285hydnd.js +94 -0
  56. package/dist/prompt-hxbzt92e.js +13 -0
  57. package/dist/{server-nfjr7xrb.js → server-gkr3c7hv.js} +28 -43
  58. package/dist/skillCatalog-fvw4wgw1.js +22 -0
  59. package/dist/skillsService-20es18vs.js +29 -0
  60. package/dist/{stdio-tmngemcz.js → stdio-kpsab5bz.js} +2 -4
  61. package/dist/{telemetry-drain-r92f0e4r.js → telemetry-drain-bw59e8f5.js} +8 -9
  62. package/dist/tree-j4w7p0pg.js +17 -0
  63. package/dist/updateService-pq7pkd42.js +522 -0
  64. package/dist/updateService.skills-4t1s7z45.js +22 -0
  65. package/dist/updateService.tools-f7tr6kc6.js +16 -0
  66. package/package.json +2 -2
  67. package/dist/cli-r7998zeh.js +0 -19
  68. package/dist/index-0gctz400.js +0 -17
  69. package/dist/index-2dp7m4r8.js +0 -9867
  70. package/dist/index-4cq44eth.js +0 -19427
  71. package/dist/index-7tshyfxx.js +0 -157
  72. package/dist/index-g8ck9tv6.js +0 -2
  73. package/dist/index-ngs0a2he.js +0 -15
  74. package/dist/index-yc4kw997.js +0 -13
  75. package/dist/js-yaml-69tsdrrf.js +0 -37
  76. package/dist/updateService-nrmb1tsc.js +0 -14
@@ -0,0 +1,1327 @@
1
+ import {
2
+ getFileSystem2
3
+ } from "./index-z070caqq.js";
4
+ import {
5
+ catchError,
6
+ logger,
7
+ UIPATH_HOME_DIR
8
+ } from "./index-9db5vwx9.js";
9
+ import {
10
+ yaml
11
+ } from "./index-5gce5wfd.js";
12
+ import {
13
+ withSystemCaEnv,
14
+ mergeEnvCaseInsensitive,
15
+ NPM_FETCH_RETRY_ENV,
16
+ RegistryTlsError,
17
+ npmTlsErrorCode
18
+ } from "./index-qwbyt2q5.js";
19
+ import {
20
+ SkillSourceError,
21
+ SkillsRegistryAuthError,
22
+ SkillsPackageMetadataError,
23
+ SkillsPackOutputError
24
+ } from "./index-nsrrst23.js";
25
+ import {
26
+ commandOnPath
27
+ } from "./index-bpqx6f8h.js";
28
+ import {
29
+ package_default
30
+ } from "./index-p9s0gyrw.js";
31
+
32
+ // src/commands/skills/contentStore.ts
33
+ import { createHash, randomUUID } from "node:crypto";
34
+ import { createRequire } from "node:module";
35
+ import { dirname } from "node:path";
36
+ import { gunzipSync } from "node:zlib";
37
+ var SKILLS_PACKAGE_NAME = "@uipath/skills";
38
+ var SKILLS_REGISTRY_URL = "https://registry.npmjs.org";
39
+ var REPO_URL2 = "https://www.npmjs.com/package/@uipath/skills";
40
+ var SOURCE_MARKER_NAME = ".uipath-skills-source.json";
41
+ var STORE_NAME = `${UIPATH_HOME_DIR}/.skills`;
42
+ var TAR_BLOCK_SIZE = 512;
43
+ var NPM_VIEW_TIMEOUT_MS = 30000;
44
+ var NPM_PACK_TIMEOUT_MS = 60000;
45
+ var SHELL_SAFE_ARG = /^[a-zA-Z0-9@/._~-]+$/;
46
+ var SHELL_SAFE_COMMAND_LINE = /^[a-zA-Z0-9@/._~\- ]+$/;
47
+ var PM_PREFERENCE = ["npm", "pnpm", "bun", "yarn"];
48
+ var PM_OVERRIDE_ENV = "UIP_SKILLS_PM";
49
+ var childProcessModulePromise;
50
+ function loadChildProcess() {
51
+ childProcessModulePromise ??= import("node:child_process");
52
+ return childProcessModulePromise;
53
+ }
54
+ var DEFAULT_SOURCE2 = {
55
+ repoUrl: REPO_URL2,
56
+ branch: null,
57
+ storeName: STORE_NAME,
58
+ isDefault: true,
59
+ zipUrl: null,
60
+ localDir: null
61
+ };
62
+ function parseGitHub(input) {
63
+ const https = input.match(/^https?:\/\/github\.com\/([^/]+)\/([^/]+?)(?:\.git)?\/?$/i);
64
+ if (https)
65
+ return { owner: https[1], repo: https[2] };
66
+ const ssh = input.match(/^git@github\.com:([^/]+)\/([^/]+?)(?:\.git)?\/?$/i);
67
+ if (ssh)
68
+ return { owner: ssh[1], repo: ssh[2] };
69
+ const slash = input.indexOf("/");
70
+ if (slash > 0 && input.indexOf("/", slash + 1) === -1) {
71
+ const owner = input.slice(0, slash);
72
+ const repo = input.slice(slash + 1).replace(/\.git$/, "");
73
+ const namePart = /^[\w.-]+$/;
74
+ if (namePart.test(owner) && namePart.test(repo)) {
75
+ return { owner, repo };
76
+ }
77
+ }
78
+ return null;
79
+ }
80
+ function looksLikeLocalPath(input) {
81
+ return input === "." || input === ".." || input.startsWith("./") || input.startsWith("../") || input.startsWith("~") || input.startsWith("/") || input.includes("\\") || /^[a-zA-Z]:[\\/]/.test(input);
82
+ }
83
+ function resolveLocalRepoPath(input) {
84
+ const fs = getFileSystem2();
85
+ if (input === "~" || input.startsWith("~/") || input.startsWith("~\\")) {
86
+ return fs.path.resolve(fs.path.join(fs.env.homedir(), input.slice(1)));
87
+ }
88
+ return fs.path.resolve(input);
89
+ }
90
+ var MAX_LABEL_CHARS = 32;
91
+ var MAX_BRANCH_CHARS = MAX_LABEL_CHARS / 2;
92
+ function slugify(input, maxChars = MAX_LABEL_CHARS) {
93
+ const collapsed = input.toLowerCase().replace(/^[a-z]+:\/\//, "").replace(/[^a-z0-9]+/g, "-");
94
+ let start = 0;
95
+ let end = collapsed.length;
96
+ while (start < end && collapsed[start] === "-")
97
+ start++;
98
+ while (end > start && collapsed[end - 1] === "-")
99
+ end--;
100
+ if (end - start > maxChars) {
101
+ start = end - maxChars;
102
+ while (start < end && collapsed[start] === "-")
103
+ start++;
104
+ }
105
+ return collapsed.slice(start, end) || "repo";
106
+ }
107
+ function shortHash(input) {
108
+ return createHash("sha256").update(input).digest("hex").slice(0, 10);
109
+ }
110
+ function customStoreName(sourceKey, branch) {
111
+ const suffix = branch ? `@${slugify(branch, MAX_BRANCH_CHARS)}` : "";
112
+ const hash = shortHash(`${sourceKey}
113
+ ${branch ?? ""}`);
114
+ const label = slugify(sourceKey, MAX_LABEL_CHARS - suffix.length);
115
+ return `${UIPATH_HOME_DIR}/.skill-repos/${label}${suffix}-${hash}`;
116
+ }
117
+ function resolveSkillSource2(repo, branch) {
118
+ const trimmedRepo = repo?.trim();
119
+ const trimmedBranch = branch?.trim() || null;
120
+ if (!trimmedRepo) {
121
+ if (trimmedBranch) {
122
+ throw new SkillSourceError("--branch can only be used together with --repo: the built-in UiPath skills come from a versioned npm package, not a git branch.", "Pass --repo together with --branch, or drop --branch to use the built-in UiPath skills.");
123
+ }
124
+ return DEFAULT_SOURCE2;
125
+ }
126
+ if (looksLikeLocalPath(trimmedRepo)) {
127
+ if (trimmedBranch) {
128
+ throw new SkillSourceError("--branch cannot be combined with a local --repo directory: local skills are copied from disk, not fetched from a git branch.", "Drop --branch, or pass a git repository (owner/repo, https, or git URL) to fetch a specific branch.");
129
+ }
130
+ const localDir = resolveLocalRepoPath(trimmedRepo);
131
+ return {
132
+ repoUrl: localDir,
133
+ branch: null,
134
+ storeName: customStoreName(localDir, null),
135
+ isDefault: false,
136
+ zipUrl: null,
137
+ localDir
138
+ };
139
+ }
140
+ const gh = parseGitHub(trimmedRepo);
141
+ if (gh) {
142
+ const zipUrl = trimmedBranch ? `https://github.com/${gh.owner}/${gh.repo}/archive/refs/heads/${trimmedBranch}.zip` : `https://github.com/${gh.owner}/${gh.repo}/archive/HEAD.zip`;
143
+ return {
144
+ repoUrl: `https://github.com/${gh.owner}/${gh.repo}.git`,
145
+ branch: trimmedBranch,
146
+ storeName: customStoreName(`${gh.owner}/${gh.repo}`, trimmedBranch),
147
+ isDefault: false,
148
+ zipUrl,
149
+ localDir: null
150
+ };
151
+ }
152
+ return {
153
+ repoUrl: trimmedRepo,
154
+ branch: trimmedBranch,
155
+ storeName: customStoreName(trimmedRepo, trimmedBranch),
156
+ isDefault: false,
157
+ zipUrl: null,
158
+ localDir: null
159
+ };
160
+ }
161
+ async function resolveLocalSkillsStore(fs) {
162
+ const hasSkillsDir = async (d) => !!d && await fs.exists(fs.path.join(d, "skills"));
163
+ const envDir = process.env.UIPATH_SKILLS_LOCAL_DIR?.trim();
164
+ if (envDir && await hasSkillsDir(envDir))
165
+ return envDir;
166
+ const [reqErr, require2] = catchError(() => createRequire(import.meta.url));
167
+ if (reqErr || !require2)
168
+ return;
169
+ const [resErr, pkgJsonPath] = catchError(() => require2.resolve(`${SKILLS_PACKAGE_NAME}/package.json`));
170
+ if (resErr || !pkgJsonPath)
171
+ return;
172
+ const dir = dirname(pkgJsonPath);
173
+ return await hasSkillsDir(dir) ? dir : undefined;
174
+ }
175
+ async function removeStoreForSwap(fs, targetPath) {
176
+ const [rmError] = await catchError(fs.rm(targetPath));
177
+ if (!rmError)
178
+ return;
179
+ if (!await fs.exists(targetPath))
180
+ throw rmError;
181
+ if (await isDirWritable(fs, targetPath))
182
+ throw rmError;
183
+ const permissionError = new Error(`EACCES: permission denied, cannot replace the skills store at '${targetPath}' (${rmError.message})`);
184
+ permissionError.code = "EACCES";
185
+ throw permissionError;
186
+ }
187
+ async function isDirWritable(fs, dirPath) {
188
+ const probePath = fs.path.join(dirPath, `.write-probe-${randomUUID()}`);
189
+ const [probeError] = await catchError(fs.writeFile(probePath, ""));
190
+ if (probeError)
191
+ return false;
192
+ await catchError(fs.rm(probePath));
193
+ return true;
194
+ }
195
+ async function copySkillsStore(fs, sourceDir, targetPath) {
196
+ const manifestPath = fs.path.join(targetPath, MANIFEST_NAME2);
197
+ let savedManifest = null;
198
+ if (await fs.exists(targetPath)) {
199
+ savedManifest = await fs.readFile(manifestPath, { encoding: "utf-8" });
200
+ await removeStoreForSwap(fs, targetPath);
201
+ }
202
+ await fs.mkdir(targetPath);
203
+ await fs.copyDirectory(sourceDir, targetPath);
204
+ if (savedManifest !== null) {
205
+ await fs.writeFile(manifestPath, savedManifest);
206
+ }
207
+ }
208
+ async function fetchSkillsTo2(targetPath, rootDir, source = DEFAULT_SOURCE2, targetVersion) {
209
+ const fs = getFileSystem2();
210
+ if (source.localDir) {
211
+ await fetchSkillsFromLocalDir(targetPath, source.localDir);
212
+ return;
213
+ }
214
+ if (!source.isDefault) {
215
+ await fetchSkillsFromGit(targetPath, rootDir, source);
216
+ return;
217
+ }
218
+ const [infoErr, resolved] = await catchError(resolveSkillsDownload(targetVersion));
219
+ if (infoErr || !resolved) {
220
+ const localStore = await resolveLocalSkillsStore(fs);
221
+ if (localStore) {
222
+ logger.info(`Could not resolve ${SKILLS_PACKAGE_NAME} from a registry (${infoErr?.message ?? "unknown error"}); using the locally-installed package at ${localStore}.`);
223
+ await copySkillsStore(fs, localStore, targetPath);
224
+ return;
225
+ }
226
+ throw infoErr ?? new Error(`Could not resolve ${SKILLS_PACKAGE_NAME}.`);
227
+ }
228
+ const { pm, packageInfo } = resolved;
229
+ logger.info(`Downloading ${SKILLS_PACKAGE_NAME}@${packageInfo.version} content store with ${pm}...`);
230
+ const tmpPath = fs.path.join(fs.env.tmpdir(), `uipath-skills-store-${randomUUID()}`);
231
+ try {
232
+ await fs.mkdir(tmpPath);
233
+ await materializePackage(pm, packageInfo, tmpPath);
234
+ if (!await fs.exists(fs.path.join(tmpPath, "skills"))) {
235
+ throw new Error(`${SKILLS_PACKAGE_NAME}@${packageInfo.version} does not contain a skills/ directory`);
236
+ }
237
+ await writeSourceMarker(tmpPath, packageInfo);
238
+ await copySkillsStore(fs, tmpPath, targetPath);
239
+ } finally {
240
+ await catchError(fs.rm(tmpPath));
241
+ }
242
+ }
243
+ async function resolveSkillsDownload(targetVersion) {
244
+ const pm = await resolvePackageManager();
245
+ const packageInfo = await fetchMatchingSkillsPackageInfo(pm, targetVersion ?? package_default.version);
246
+ return { pm, packageInfo };
247
+ }
248
+ async function fetchSkillsFromGit(targetPath, rootDir, source) {
249
+ const fs = getFileSystem2();
250
+ if (await fs.exists(fs.path.join(targetPath, ".git"))) {
251
+ logger.info("Updating content store...");
252
+ const [pullError] = await catchError(runGit(["pull", "--ff-only"], targetPath));
253
+ if (!pullError)
254
+ return;
255
+ logger.warn("git pull failed, re-cloning...");
256
+ }
257
+ logger.info("Downloading content store...");
258
+ const parentDir = fs.path.dirname(targetPath);
259
+ await fs.mkdir(parentDir);
260
+ const stagingPath = fs.path.join(parentDir, `.staging-${randomUUID()}`);
261
+ const manifestPath = fs.path.join(targetPath, MANIFEST_NAME2);
262
+ let savedManifest = null;
263
+ if (await fs.exists(targetPath)) {
264
+ savedManifest = await fs.readFile(manifestPath, { encoding: "utf-8" });
265
+ }
266
+ try {
267
+ await cloneOrZipInto(stagingPath, rootDir, source);
268
+ if (await fs.exists(targetPath)) {
269
+ await removeStoreForSwap(fs, targetPath);
270
+ }
271
+ await fs.rename(stagingPath, targetPath);
272
+ if (savedManifest !== null) {
273
+ await fs.writeFile(manifestPath, savedManifest);
274
+ }
275
+ } finally {
276
+ await catchError(fs.rm(stagingPath));
277
+ }
278
+ }
279
+ async function fetchSkillsFromLocalDir(targetPath, localDir) {
280
+ const fs = getFileSystem2();
281
+ const stat = await fs.stat(localDir);
282
+ if (!stat?.isDirectory()) {
283
+ throw new SkillSourceError(`Local skills repo not found or not a directory: ${localDir}`, "Pass --repo pointing to an existing folder of skills (containing skills/<skill>/SKILL.md or <skill>/SKILL.md).");
284
+ }
285
+ const rel = fs.path.relative(localDir, targetPath);
286
+ if (rel === "" || !rel.startsWith("..") && !fs.path.isAbsolute(rel)) {
287
+ throw new SkillSourceError(`Local skills repo ${localDir} encloses the target store; pick a folder that does not contain the install target.`, "Point --repo at a dedicated skills folder, not a parent of the install target.");
288
+ }
289
+ const parentDir = fs.path.dirname(targetPath);
290
+ await fs.mkdir(parentDir);
291
+ const gitCwd = await fs.getTempDir();
292
+ let missing;
293
+ try {
294
+ missing = await missingTrackedFiles(localDir, gitCwd);
295
+ } finally {
296
+ await catchError(fs.rm(gitCwd));
297
+ }
298
+ if (missing.length > 0) {
299
+ const shown = missing.slice(0, 3).join(", ");
300
+ const more = missing.length > 3 ? `, and ${missing.length - 3} more` : "";
301
+ throw new SkillSourceError(`Local skills repo ${localDir} is missing ${missing.length} file(s) that git tracks (${shown}${more}), so installing from it would leave skills out.`, "Finish the checkout, then re-run. On Windows this is usually paths longer than 260 characters: in the clone run `git config core.longpaths true`. Back up or stash any local edits before `git restore --source=HEAD :/`: it resets every tracked file in the clone. If you removed the files on purpose, commit the removal.");
302
+ }
303
+ logger.info(`Copying skills from ${localDir}...`);
304
+ const stagingPath = fs.path.join(parentDir, `.staging-${randomUUID()}`);
305
+ const manifestPath = fs.path.join(targetPath, MANIFEST_NAME2);
306
+ let savedManifest = null;
307
+ if (await fs.exists(targetPath)) {
308
+ savedManifest = await fs.readFile(manifestPath, { encoding: "utf-8" });
309
+ }
310
+ try {
311
+ await fs.mkdir(stagingPath);
312
+ await fs.copyDirectory(localDir, stagingPath);
313
+ if (await fs.exists(targetPath)) {
314
+ await removeStoreForSwap(fs, targetPath);
315
+ }
316
+ await fs.rename(stagingPath, targetPath);
317
+ if (savedManifest !== null) {
318
+ await fs.writeFile(manifestPath, savedManifest);
319
+ }
320
+ } finally {
321
+ await catchError(fs.rm(stagingPath));
322
+ }
323
+ }
324
+ async function cloneOrZipInto(stagingPath, rootDir, source) {
325
+ const fs = getFileSystem2();
326
+ const cloneArgs = ["clone", "--depth", "1"];
327
+ if (source.branch)
328
+ cloneArgs.push("--branch", source.branch);
329
+ cloneArgs.push(source.repoUrl, stagingPath);
330
+ const [cloneError] = await catchError(runGit(cloneArgs, rootDir));
331
+ if (!cloneError)
332
+ return;
333
+ if (!source.zipUrl) {
334
+ throw new Error(`Failed to clone ${source.repoUrl}: ${cloneError.message}`);
335
+ }
336
+ logger.info("git clone failed, falling back to zip download...");
337
+ await fs.rm(stagingPath);
338
+ await fs.mkdir(stagingPath);
339
+ await downloadAndExtractZip(stagingPath, source);
340
+ }
341
+ async function runGit(args, cwd) {
342
+ const { spawn } = await loadChildProcess();
343
+ return await new Promise((resolve, reject) => {
344
+ const proc = spawn("git", args, {
345
+ cwd,
346
+ stdio: ["inherit", "pipe", "pipe"]
347
+ });
348
+ let stdout = "";
349
+ let stderr = "";
350
+ proc.stdout?.on("data", (data) => {
351
+ stdout += data.toString();
352
+ });
353
+ proc.stderr?.on("data", (data) => {
354
+ stderr += data.toString();
355
+ });
356
+ const timer = setTimeout(() => {
357
+ proc.kill("SIGTERM");
358
+ reject(new Error(`git ${args[0]} timed out after 120s`));
359
+ }, 120000);
360
+ proc.on("error", (error) => {
361
+ clearTimeout(timer);
362
+ reject(error);
363
+ });
364
+ proc.on("close", (code) => {
365
+ clearTimeout(timer);
366
+ if (code === 0) {
367
+ resolve(stdout.trim());
368
+ return;
369
+ }
370
+ reject(new Error(stderr.trim() || `git ${args[0]} failed with code ${code}`));
371
+ });
372
+ });
373
+ }
374
+ async function missingTrackedFiles(dir, trustedCwd) {
375
+ const [error, output] = await catchError(runGit([
376
+ "-C",
377
+ dir,
378
+ "ls-tree",
379
+ "-r",
380
+ "-z",
381
+ "--name-only",
382
+ "HEAD",
383
+ "--",
384
+ "."
385
+ ], trustedCwd));
386
+ if (error || !output)
387
+ return [];
388
+ const fs = getFileSystem2();
389
+ const missing = [];
390
+ for (const relative of output.split("\x00")) {
391
+ if (relative.length === 0)
392
+ continue;
393
+ if (!await fs.exists(fs.path.join(dir, relative))) {
394
+ missing.push(relative);
395
+ }
396
+ }
397
+ return missing;
398
+ }
399
+ async function downloadAndExtractZip(storePath, source) {
400
+ const fs = getFileSystem2();
401
+ if (!source.zipUrl) {
402
+ throw new Error(`No zip fallback available for ${source.repoUrl}`);
403
+ }
404
+ const { spawn } = await loadChildProcess();
405
+ const response = await fetch(source.zipUrl, {
406
+ signal: AbortSignal.timeout(60000)
407
+ });
408
+ if (!response.ok) {
409
+ throw new Error(`Failed to download zip: ${response.status}`);
410
+ }
411
+ const zipPath = fs.path.join(fs.env.tmpdir(), `uipath-skills-${randomUUID()}.zip`);
412
+ const arrayBuffer = await response.arrayBuffer();
413
+ await fs.writeFile(zipPath, Buffer.from(arrayBuffer));
414
+ try {
415
+ await extractZipArchive(spawn, zipPath, storePath);
416
+ await flattenSingleTopLevelDir(fs, storePath);
417
+ } finally {
418
+ await catchError(fs.rm(zipPath));
419
+ }
420
+ }
421
+ async function extractZipArchive(spawn, zipPath, destPath) {
422
+ if (process.platform === "win32") {
423
+ await runExtractor(spawn, "powershell", [
424
+ "-NoProfile",
425
+ "-NonInteractive",
426
+ "-Command",
427
+ "Expand-Archive -LiteralPath $env:UIP_SKILLS_ZIP -DestinationPath $env:UIP_SKILLS_DEST -Force"
428
+ ], { UIP_SKILLS_ZIP: zipPath, UIP_SKILLS_DEST: destPath });
429
+ return;
430
+ }
431
+ await runExtractor(spawn, "unzip", ["-o", zipPath, "-d", destPath]);
432
+ }
433
+ function runExtractor(spawn, command, args, extraEnv) {
434
+ return new Promise((resolve, reject) => {
435
+ const proc = spawn(command, args, {
436
+ stdio: "inherit",
437
+ ...extraEnv ? { env: { ...process.env, ...extraEnv } } : {}
438
+ });
439
+ proc.on("error", reject);
440
+ proc.on("close", (code) => {
441
+ if (code === 0) {
442
+ resolve();
443
+ return;
444
+ }
445
+ reject(new Error(`${command} failed with code ${code}`));
446
+ });
447
+ });
448
+ }
449
+ async function flattenSingleTopLevelDir(fs, storePath) {
450
+ const entries = await fs.readdir(storePath);
451
+ if (entries.length !== 1)
452
+ return;
453
+ const nestedDir = fs.path.join(storePath, entries[0]);
454
+ const stat = await fs.stat(nestedDir);
455
+ if (!stat?.isDirectory())
456
+ return;
457
+ for (const entry of await fs.readdir(nestedDir)) {
458
+ await fs.rename(fs.path.join(nestedDir, entry), fs.path.join(storePath, entry));
459
+ }
460
+ await fs.rm(nestedDir);
461
+ }
462
+ async function getContentStore2(rootDir, source = DEFAULT_SOURCE2, targetVersion) {
463
+ const fs = getFileSystem2();
464
+ const storePath = fs.path.join(rootDir, source.storeName);
465
+ await fetchSkillsTo2(storePath, rootDir, source, targetVersion);
466
+ return storePath;
467
+ }
468
+ async function getContentStoreForRead2(rootDir, source = DEFAULT_SOURCE2, targetVersion) {
469
+ const fs = getFileSystem2();
470
+ const storePath = fs.path.join(rootDir, source.storeName);
471
+ if (source.isDefault && await storeMatchesVersionLine(fs, storePath, targetVersion)) {
472
+ logger.debug(`Reading skills from the existing store at ${storePath} (no fetch).`);
473
+ return storePath;
474
+ }
475
+ await fetchSkillsTo2(storePath, rootDir, source, targetVersion);
476
+ return storePath;
477
+ }
478
+ async function storeMatchesVersionLine(fs, storePath, targetVersion) {
479
+ const line = parseSemver(targetVersion ?? package_default.version) ?? parseVersionLine(targetVersion ?? package_default.version);
480
+ if (!line)
481
+ return false;
482
+ const skillsDir = fs.path.join(storePath, "skills");
483
+ const [entriesErr, entries] = await catchError(fs.readdir(skillsDir));
484
+ if (entriesErr || !entries?.length)
485
+ return false;
486
+ const [markerErr, markerText] = await catchError(fs.readFile(fs.path.join(storePath, SOURCE_MARKER_NAME), {
487
+ encoding: "utf-8"
488
+ }));
489
+ if (markerErr || !markerText)
490
+ return false;
491
+ const [parseErr, marker] = catchError(() => JSON.parse(markerText));
492
+ if (parseErr)
493
+ return false;
494
+ const version = asRecord(marker)?.version;
495
+ return typeof version === "string" && matchesCliVersionLine(version, line);
496
+ }
497
+ async function readSkillFrontmatter(fs, skillMdPath) {
498
+ const [err, content] = await catchError(fs.readFile(skillMdPath, { encoding: "utf-8" }));
499
+ if (err || !content)
500
+ return {};
501
+ const { meta } = parseSkillMd2(content);
502
+ return meta["user-invocable"] === true ? { description: meta.description, userInvocable: true } : { description: meta.description };
503
+ }
504
+ var MAX_SKILL_SCAN_DEPTH = 16;
505
+ async function collectSkillDirs(fs, dir, depth = 0, visited = new Set, report) {
506
+ if (depth > MAX_SKILL_SCAN_DEPTH) {
507
+ logger.debug(`Skipping ${dir}: max skill scan depth exceeded.`);
508
+ return [];
509
+ }
510
+ const [, canonical] = await catchError(fs.realpath(dir));
511
+ const visitKey = canonical ?? dir;
512
+ if (visited.has(visitKey))
513
+ return [];
514
+ visited.add(visitKey);
515
+ const [readErr, rawEntries] = await catchError(fs.readdir(dir));
516
+ if (readErr || !rawEntries) {
517
+ if (readErr && report)
518
+ report.hadReadErrors = true;
519
+ logger.debug(`Skipping ${dir}: ${readErr?.message ?? "unreadable"}`);
520
+ return [];
521
+ }
522
+ const entries = [...rawEntries].sort((a, b) => a.localeCompare(b));
523
+ const skills = [];
524
+ for (const entry of entries) {
525
+ if (entry.startsWith("."))
526
+ continue;
527
+ const entryPath = fs.path.join(dir, entry);
528
+ const [statErr, stat] = await catchError(fs.stat(entryPath));
529
+ if (statErr && report)
530
+ report.hadReadErrors = true;
531
+ if (statErr || !stat?.isDirectory())
532
+ continue;
533
+ const skillMdPath = fs.path.join(entryPath, "SKILL.md");
534
+ if (await fs.exists(skillMdPath)) {
535
+ const frontmatter = await readSkillFrontmatter(fs, skillMdPath);
536
+ skills.push({ name: entry, skillDir: entryPath, ...frontmatter });
537
+ continue;
538
+ }
539
+ skills.push(...await collectSkillDirs(fs, entryPath, depth + 1, visited, report));
540
+ }
541
+ return skills;
542
+ }
543
+ async function getAvailableSkills2(storePath, shadowed, report) {
544
+ const fs = getFileSystem2();
545
+ const collected = [];
546
+ const rootSkillsDir = fs.path.join(storePath, "skills");
547
+ if (await fs.exists(rootSkillsDir)) {
548
+ collected.push(...await collectSkillDirs(fs, rootSkillsDir, 0, new Set, report));
549
+ }
550
+ const [topErr, topLevelEntries] = await catchError(fs.readdir(storePath));
551
+ if (topErr && report)
552
+ report.hadReadErrors = true;
553
+ for (const entry of [...topLevelEntries ?? []].sort((a, b) => a.localeCompare(b))) {
554
+ if (entry.startsWith("."))
555
+ continue;
556
+ if (entry === "skills")
557
+ continue;
558
+ const entryPath = fs.path.join(storePath, entry);
559
+ const [statErr, entryStat] = await catchError(fs.stat(entryPath));
560
+ if (statErr && report)
561
+ report.hadReadErrors = true;
562
+ if (statErr || !entryStat?.isDirectory())
563
+ continue;
564
+ const entrySkillsDir = fs.path.join(entryPath, "skills");
565
+ if (!await fs.exists(entrySkillsDir))
566
+ continue;
567
+ collected.push(...await collectSkillDirs(fs, entrySkillsDir, 0, new Set, report));
568
+ }
569
+ const byName = new Map;
570
+ for (const skill of collected) {
571
+ const winner = byName.get(skill.name);
572
+ if (winner) {
573
+ shadowed?.push(skill);
574
+ logger.warn(`Duplicate skill "${skill.name}": using ${winner.skillDir}, ignoring ${skill.skillDir}.`);
575
+ continue;
576
+ }
577
+ byName.set(skill.name, skill);
578
+ }
579
+ return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
580
+ }
581
+ function parseSkillMd2(content) {
582
+ const fmMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/);
583
+ if (!fmMatch) {
584
+ return { meta: { name: "" }, body: content };
585
+ }
586
+ const meta = yaml.load(fmMatch[1]) ?? {};
587
+ return { meta, body: fmMatch[2] };
588
+ }
589
+ async function addToGitignore2(rootDir, entry) {
590
+ const fs = getFileSystem2();
591
+ const gitignorePath = fs.path.join(rootDir, ".gitignore");
592
+ const content = await fs.readFile(gitignorePath, { encoding: "utf-8" }) ?? "";
593
+ const lines = content.split(`
594
+ `);
595
+ if (!lines.some((line) => line.trim() === entry)) {
596
+ const separator = content.length > 0 && !content.endsWith(`
597
+ `) ? `
598
+ ` : "";
599
+ await fs.writeFile(gitignorePath, `${content + separator + entry}
600
+ `);
601
+ }
602
+ }
603
+ var MANIFEST_NAME2 = "manifest.json";
604
+ async function readManifest2(storePath) {
605
+ const fs = getFileSystem2();
606
+ const manifestPath = fs.path.join(storePath, MANIFEST_NAME2);
607
+ const content = await fs.readFile(manifestPath, { encoding: "utf-8" });
608
+ if (content === null) {
609
+ return { skills: {} };
610
+ }
611
+ const [parseError, parsed] = catchError(() => JSON.parse(content));
612
+ if (parseError)
613
+ return { skills: {} };
614
+ return parsed;
615
+ }
616
+ async function writeManifest(storePath, manifest) {
617
+ const fs = getFileSystem2();
618
+ const manifestPath = fs.path.join(storePath, MANIFEST_NAME2);
619
+ await fs.writeFile(manifestPath, `${JSON.stringify(manifest, null, 4)}
620
+ `);
621
+ }
622
+ async function updateManifestAfterInstall2(storePath, skillNames, agents) {
623
+ const manifest = await readManifest2(storePath);
624
+ const now = new Date().toISOString();
625
+ for (const name of skillNames) {
626
+ const existing = manifest.skills[name];
627
+ if (existing) {
628
+ const merged = [...new Set([...existing.agents, ...agents])];
629
+ existing.agents = merged;
630
+ } else {
631
+ manifest.skills[name] = { agents: [...agents], installedAt: now };
632
+ }
633
+ }
634
+ await writeManifest(storePath, manifest);
635
+ }
636
+ async function removeFromManifest2(storePath, skillNames, agents) {
637
+ const manifest = await readManifest2(storePath);
638
+ for (const name of skillNames) {
639
+ const entry = manifest.skills[name];
640
+ if (!entry)
641
+ continue;
642
+ entry.agents = entry.agents.filter((a) => !agents.includes(a));
643
+ if (entry.agents.length === 0) {
644
+ delete manifest.skills[name];
645
+ }
646
+ }
647
+ if (manifest.extraFiles) {
648
+ const remaining = Object.values(manifest.skills);
649
+ for (const agent of agents) {
650
+ if (remaining.some((entry) => entry.agents.includes(agent))) {
651
+ continue;
652
+ }
653
+ delete manifest.extraFiles[agent];
654
+ }
655
+ if (Object.keys(manifest.extraFiles).length === 0) {
656
+ manifest.extraFiles = undefined;
657
+ }
658
+ }
659
+ await writeManifest(storePath, manifest);
660
+ }
661
+ async function readExtraFiles2(storePath, agent) {
662
+ const manifest = await readManifest2(storePath);
663
+ return manifest.extraFiles?.[agent] ?? [];
664
+ }
665
+ async function recordExtraFiles2(storePath, agent, files) {
666
+ const manifest = await readManifest2(storePath);
667
+ const extraFiles = manifest.extraFiles ?? {};
668
+ if (files.length > 0) {
669
+ extraFiles[agent] = files;
670
+ } else {
671
+ delete extraFiles[agent];
672
+ }
673
+ manifest.extraFiles = Object.keys(extraFiles).length > 0 ? extraFiles : undefined;
674
+ await writeManifest(storePath, manifest);
675
+ }
676
+ function asRecord(value) {
677
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
678
+ return;
679
+ }
680
+ return value;
681
+ }
682
+ function isDecimalInteger(value) {
683
+ return value.length > 0 && Array.from(value).every((char) => char >= "0" && char <= "9");
684
+ }
685
+ function isSemverIdentifierChar(char) {
686
+ const code = char.codePointAt(0);
687
+ return code !== undefined && (code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "-");
688
+ }
689
+ function isSemverIdentifierList(value) {
690
+ return value.length > 0 && value.split(".").every((part) => part.length > 0 && Array.from(part).every(isSemverIdentifierChar));
691
+ }
692
+ function stripSemverBuild(version) {
693
+ const parts = version.split("+");
694
+ if (parts.length > 2)
695
+ return null;
696
+ const build = parts[1];
697
+ if (build !== undefined && !isSemverIdentifierList(build))
698
+ return null;
699
+ return parts[0];
700
+ }
701
+ function splitSemverPrerelease(version) {
702
+ const prereleaseSeparator = version.indexOf("-");
703
+ if (prereleaseSeparator === -1) {
704
+ return { core: version };
705
+ }
706
+ const prerelease = version.slice(prereleaseSeparator + 1);
707
+ if (!isSemverIdentifierList(prerelease))
708
+ return null;
709
+ return {
710
+ core: version.slice(0, prereleaseSeparator),
711
+ prerelease
712
+ };
713
+ }
714
+ function parseSemver(version) {
715
+ const versionWithoutBuild = stripSemverBuild(version);
716
+ if (!versionWithoutBuild)
717
+ return null;
718
+ const parsed = splitSemverPrerelease(versionWithoutBuild);
719
+ if (!parsed)
720
+ return null;
721
+ const coreParts = parsed.core.split(".");
722
+ if (coreParts.length !== 3 || !coreParts.every(isDecimalInteger)) {
723
+ return null;
724
+ }
725
+ return {
726
+ major: Number.parseInt(coreParts[0], 10),
727
+ minor: Number.parseInt(coreParts[1], 10),
728
+ patch: Number.parseInt(coreParts[2], 10),
729
+ ...parsed.prerelease ? { prerelease: parsed.prerelease } : {}
730
+ };
731
+ }
732
+ function parsePrereleasePart(value) {
733
+ if (!isDecimalInteger(value))
734
+ return { value };
735
+ return { value, numericValue: Number.parseInt(value, 10) };
736
+ }
737
+ function comparePrereleasePart(left, right) {
738
+ const leftNumericValue = left.numericValue;
739
+ const rightNumericValue = right.numericValue;
740
+ const leftIsNumeric = leftNumericValue !== undefined;
741
+ const rightIsNumeric = rightNumericValue !== undefined;
742
+ if (leftNumericValue !== undefined && rightNumericValue !== undefined) {
743
+ const numericDiff = leftNumericValue - rightNumericValue;
744
+ if (numericDiff !== 0)
745
+ return numericDiff;
746
+ }
747
+ if (leftIsNumeric !== rightIsNumeric) {
748
+ return leftIsNumeric ? -1 : 1;
749
+ }
750
+ if (left.value === right.value)
751
+ return 0;
752
+ return left.value.localeCompare(right.value);
753
+ }
754
+ function compareOptionalPrereleasePart(left, right) {
755
+ if (left === undefined)
756
+ return right === undefined ? 0 : -1;
757
+ if (right === undefined)
758
+ return 1;
759
+ return comparePrereleasePart(parsePrereleasePart(left), parsePrereleasePart(right));
760
+ }
761
+ function comparePrerelease(a, b) {
762
+ const aParts = a.split(".");
763
+ const bParts = b.split(".");
764
+ const length = Math.max(aParts.length, bParts.length);
765
+ for (let i = 0;i < length; i++) {
766
+ const comparison = compareOptionalPrereleasePart(aParts[i], bParts[i]);
767
+ if (comparison !== 0)
768
+ return comparison;
769
+ }
770
+ return 0;
771
+ }
772
+ function compareSemver(a, b) {
773
+ const left = parseSemver(a);
774
+ const right = parseSemver(b);
775
+ if (!left || !right)
776
+ return a.localeCompare(b);
777
+ const coreDiff = left.major - right.major || left.minor - right.minor || left.patch - right.patch;
778
+ if (coreDiff !== 0)
779
+ return coreDiff;
780
+ if (!left.prerelease && !right.prerelease)
781
+ return 0;
782
+ if (!left.prerelease)
783
+ return 1;
784
+ if (!right.prerelease)
785
+ return -1;
786
+ return comparePrerelease(left.prerelease, right.prerelease);
787
+ }
788
+ function matchesCliVersionLine(version, cliVersion) {
789
+ const parsed = parseSemver(version);
790
+ if (!parsed)
791
+ return false;
792
+ if (parsed.major !== cliVersion.major || parsed.minor !== cliVersion.minor) {
793
+ return false;
794
+ }
795
+ return true;
796
+ }
797
+ function isStableVersion(version) {
798
+ return parseSemver(version)?.prerelease === undefined;
799
+ }
800
+ function isPackageManager(value) {
801
+ return PM_PREFERENCE.includes(value);
802
+ }
803
+ var cachedPackageManager = null;
804
+ async function resolvePackageManager() {
805
+ const override = getFileSystem2().env.getenv(PM_OVERRIDE_ENV)?.toLowerCase();
806
+ if (override) {
807
+ if (!isPackageManager(override)) {
808
+ throw new Error(`${PM_OVERRIDE_ENV}="${override}" is not supported. Use one of: ${PM_PREFERENCE.join(", ")}.`);
809
+ }
810
+ return override;
811
+ }
812
+ if (!cachedPackageManager) {
813
+ cachedPackageManager = detectPackageManager();
814
+ }
815
+ return cachedPackageManager;
816
+ }
817
+ async function detectPackageManager() {
818
+ for (const pm of PM_PREFERENCE) {
819
+ if (await commandOnPath(pm)) {
820
+ logger.debug(`Using ${pm} to download ${SKILLS_PACKAGE_NAME}`);
821
+ return pm;
822
+ }
823
+ }
824
+ throw new Error(`No supported package manager found on PATH to download ${SKILLS_PACKAGE_NAME}. Install one of: ${PM_PREFERENCE.join(", ")}.`);
825
+ }
826
+ function validatePmArgument(arg) {
827
+ if (!SHELL_SAFE_ARG.test(arg)) {
828
+ throw new Error(`Unsafe package-manager argument: '${arg}'`);
829
+ }
830
+ }
831
+ function validatePmArguments(args) {
832
+ for (const arg of args) {
833
+ validatePmArgument(arg);
834
+ }
835
+ }
836
+ async function runPmCommand(pm, args, label, timeoutMs, cwd, extraEnv) {
837
+ validatePmArguments(args);
838
+ const { spawn } = await loadChildProcess();
839
+ const isWindows = process.platform === "win32";
840
+ const overrides = pm === "npm" ? { ...extraEnv, ...NPM_FETCH_RETRY_ENV } : extraEnv;
841
+ const env = withSystemCaEnv(overrides ? mergeEnvCaseInsensitive(process.env, overrides) : process.env);
842
+ return await new Promise((resolve, reject) => {
843
+ let proc;
844
+ if (isWindows) {
845
+ const commandLine = [pm, ...args].join(" ");
846
+ if (!SHELL_SAFE_COMMAND_LINE.test(commandLine)) {
847
+ reject(new Error(`Unsafe command line: '${commandLine}'`));
848
+ return;
849
+ }
850
+ proc = spawn(commandLine, [], { cwd, shell: true, env });
851
+ } else {
852
+ proc = spawn(pm, args, { cwd, env });
853
+ }
854
+ let stdout = "";
855
+ let stderr = "";
856
+ const MAX_STDERR = 65536;
857
+ proc.stdout?.on("data", (data) => {
858
+ stdout += data.toString();
859
+ });
860
+ proc.stderr?.on("data", (data) => {
861
+ if (stderr.length < MAX_STDERR) {
862
+ stderr += data.toString();
863
+ }
864
+ });
865
+ const timer = setTimeout(() => {
866
+ proc.kill("SIGTERM");
867
+ reject(new Error(`${pm} ${label} timed out after ${timeoutMs / 1000}s`));
868
+ }, timeoutMs);
869
+ proc.on("error", (error) => {
870
+ clearTimeout(timer);
871
+ reject(mapPmError(pm, label, stderr, stdout, error));
872
+ });
873
+ proc.on("close", (code) => {
874
+ clearTimeout(timer);
875
+ if (code === 0) {
876
+ resolve(stdout);
877
+ return;
878
+ }
879
+ reject(mapPmError(pm, label, stderr, stdout, code));
880
+ });
881
+ });
882
+ }
883
+ var REGISTRY_AUTH_HINT = "The package manager could not authenticate to the registry. If you are installing an alpha/internal build from GitHub Packages, add to your .npmrc: '@uipath:registry=https://npm.pkg.github.com/' and '//npm.pkg.github.com/:_authToken=<token>', where <token> is a GitHub PAT with the 'read:packages' scope, authorized for the UiPath org via 'Configure SSO'. This is a different credential from your 'uip login' token.";
884
+ function mapPmError(pm, label, stderr, stdout, codeOrError) {
885
+ const tlsCode = npmTlsErrorCode(stderr, stdout);
886
+ if (tlsCode) {
887
+ return new RegistryTlsError(`${pm} ${label} failed`, tlsCode);
888
+ }
889
+ if (/E404|\b404\b|not found|Couldn't find|no matching version/i.test(stderr)) {
890
+ return new Error(`${SKILLS_PACKAGE_NAME} not found in the registry`);
891
+ }
892
+ if (/E401|E403|\b401\b|\b403\b|ENEEDAUTH|unauthor|forbidden|need(s)? auth|authentication/i.test(stderr)) {
893
+ return new SkillsRegistryAuthError(`Authentication required for ${SKILLS_PACKAGE_NAME}. ${REGISTRY_AUTH_HINT}`);
894
+ }
895
+ const detail = stderr.trim() || (codeOrError instanceof Error ? codeOrError.message : `exit ${codeOrError}`);
896
+ return new Error(`${pm} ${label} failed: ${detail}`);
897
+ }
898
+ function parsePmJson(pm, stdout, label) {
899
+ const [parseError, parsed] = catchError(() => JSON.parse(stdout));
900
+ if (parseError) {
901
+ const message = `Unexpected ${pm} ${label} output`;
902
+ if (label.startsWith(`view ${SKILLS_PACKAGE_NAME}`)) {
903
+ throw new SkillsPackageMetadataError(message);
904
+ }
905
+ throw new Error(message);
906
+ }
907
+ return parsed;
908
+ }
909
+ async function pmViewJson(pm, args) {
910
+ const label = `view ${args.join(" ")}`;
911
+ const pmArgs = pm === "bun" ? ["info", ...args, "--json"] : ["view", ...args, "--json"];
912
+ return await withTempProject(async (dir) => {
913
+ const stdout = await runPmCommand(pm, pmArgs, label, NPM_VIEW_TIMEOUT_MS, dir);
914
+ return parseViewOutput(pm, stdout, label);
915
+ });
916
+ }
917
+ function parseViewOutput(pm, stdout, label) {
918
+ if (!stdout.trim())
919
+ return;
920
+ return parsePmJson(pm, stdout, label);
921
+ }
922
+ async function yarnInfo(args) {
923
+ const label = `info ${args.join(" ")}`;
924
+ const stdout = await withTempProject((dir) => runPmCommand("yarn", ["info", ...args, "--json"], label, NPM_VIEW_TIMEOUT_MS, dir));
925
+ if (!stdout.trim())
926
+ return;
927
+ for (const line of stdout.split(`
928
+ `)) {
929
+ const trimmed = line.trim();
930
+ if (!trimmed)
931
+ continue;
932
+ const [, parsed] = catchError(() => JSON.parse(trimmed));
933
+ const record = asRecord(parsed);
934
+ if (record && "data" in record) {
935
+ return record.data;
936
+ }
937
+ }
938
+ throw new Error(`Unexpected yarn ${label} output`);
939
+ }
940
+ async function queryVersions(pm, spec) {
941
+ const raw = pm === "yarn" ? await yarnInfo([spec, "versions"]) : await pmViewJson(pm, [spec, "versions"]);
942
+ return normalizeVersionList(raw);
943
+ }
944
+ async function pmListVersions(pm, cliVersion) {
945
+ const primary = await queryVersions(pm, SKILLS_PACKAGE_NAME);
946
+ if (primary.length > 0)
947
+ return primary;
948
+ const lineSpec = `${SKILLS_PACKAGE_NAME}@~${cliVersion.major}.${cliVersion.minor}.0-0`;
949
+ const [err, versions] = await catchError(queryVersions(pm, lineSpec));
950
+ if (err) {
951
+ logger.debug(`Line-scoped version lookup for ${lineSpec} failed: ${err.message}`);
952
+ return [];
953
+ }
954
+ return versions;
955
+ }
956
+ async function pmResolveTarball(pm, version) {
957
+ const spec = `${SKILLS_PACKAGE_NAME}@${version}`;
958
+ const [error, value] = await catchError(pm === "yarn" ? yarnInfo([spec, "dist.tarball"]) : pmViewJson(pm, [spec, "dist.tarball"]));
959
+ if (error) {
960
+ logger.debug(`Could not resolve dist.tarball for ${spec}: ${error}`);
961
+ return;
962
+ }
963
+ return coerceViewString(value);
964
+ }
965
+ function normalizeVersionList(value) {
966
+ const collected = new Set;
967
+ const walk = (node) => {
968
+ if (typeof node === "string") {
969
+ collected.add(node);
970
+ } else if (Array.isArray(node)) {
971
+ for (const child of node)
972
+ walk(child);
973
+ }
974
+ };
975
+ walk(value);
976
+ return [...collected];
977
+ }
978
+ function recordVersion(record) {
979
+ const version = record.version;
980
+ return typeof version === "string" && parseSemver(version) ? version : undefined;
981
+ }
982
+ function recordDistTarball(record) {
983
+ const dist = asRecord(record.dist);
984
+ const tarball = dist?.tarball;
985
+ return typeof tarball === "string" && tarball.length > 0 ? tarball : undefined;
986
+ }
987
+ function versionFromTarballText(value) {
988
+ const [urlError, parsedUrl] = catchError(() => new URL(value));
989
+ const pathText = urlError ? value : parsedUrl.pathname;
990
+ const segments = pathText.split("/").map((segment) => decodeURIComponent(segment)).filter((segment) => segment.length > 0);
991
+ for (const segment of segments) {
992
+ if (parseSemver(segment))
993
+ return segment;
994
+ }
995
+ const fileName = segments.at(-1);
996
+ if (!fileName)
997
+ return;
998
+ const stem = fileName.endsWith(".tgz") ? fileName.slice(0, -".tgz".length) : fileName;
999
+ for (let i = 0;i < stem.length - 1; i++) {
1000
+ if (stem[i] !== "-")
1001
+ continue;
1002
+ const version = stem.slice(i + 1);
1003
+ if (startsWithDigit(version) && parseSemver(version)) {
1004
+ return version;
1005
+ }
1006
+ }
1007
+ return;
1008
+ }
1009
+ function startsWithDigit(value) {
1010
+ const first = value.charCodeAt(0);
1011
+ return first >= 48 && first <= 57;
1012
+ }
1013
+ function pickHighestVersionedString(values) {
1014
+ const candidates = values.filter((value) => typeof value === "string" && value.length > 0).map((value) => ({
1015
+ value,
1016
+ version: versionFromTarballText(value)
1017
+ })).filter((candidate) => candidate.version !== undefined);
1018
+ candidates.sort((a, b) => compareSemver(b.version, a.version));
1019
+ return candidates[0]?.value;
1020
+ }
1021
+ function pickHighestVersionedRecordTarball(values) {
1022
+ const candidates = values.map(asRecord).filter((record) => record !== undefined).map((record) => ({
1023
+ version: recordVersion(record),
1024
+ tarball: recordDistTarball(record)
1025
+ })).filter((candidate) => candidate.version !== undefined && candidate.tarball !== undefined);
1026
+ candidates.sort((a, b) => compareSemver(b.version, a.version));
1027
+ return candidates[0]?.tarball;
1028
+ }
1029
+ function coerceViewString(value) {
1030
+ let node = value;
1031
+ while (Array.isArray(node) && node.length === 1) {
1032
+ node = node[0];
1033
+ }
1034
+ if (typeof node === "string" && node.length > 0)
1035
+ return node;
1036
+ const record = asRecord(node);
1037
+ const recordTarball = record ? recordDistTarball(record) : undefined;
1038
+ if (recordTarball)
1039
+ return recordTarball;
1040
+ if (Array.isArray(node)) {
1041
+ return pickHighestVersionedRecordTarball(node) ?? pickHighestVersionedString(node);
1042
+ }
1043
+ return;
1044
+ }
1045
+ function registryFromTarball(tarballUrl) {
1046
+ const [urlError, parsedUrl] = catchError(() => new URL(tarballUrl));
1047
+ return urlError ? SKILLS_REGISTRY_URL : parsedUrl.origin;
1048
+ }
1049
+ async function fetchMatchingSkillsPackageInfo(pm, targetVersion) {
1050
+ const cliVersion = parseSemver(targetVersion) ?? parseVersionLine(targetVersion);
1051
+ if (!cliVersion) {
1052
+ throw new Error(`Invalid CLI version ${targetVersion}; expected major.minor or major.minor.patch`);
1053
+ }
1054
+ const versions = await pmListVersions(pm, cliVersion);
1055
+ const selectedVersion = pickMatchingSkillsVersion(versions, cliVersion);
1056
+ const tarballUrl = pm === "npm" || pm === "pnpm" ? requireSkillsTarballUrl(selectedVersion, coerceViewString(await pmViewJson(pm, [
1057
+ `${SKILLS_PACKAGE_NAME}@${selectedVersion}`,
1058
+ "dist.tarball"
1059
+ ]))) : await pmResolveTarball(pm, selectedVersion);
1060
+ return {
1061
+ version: selectedVersion,
1062
+ tarballUrl: tarballUrl ?? "",
1063
+ registryUrl: tarballUrl ? registryFromTarball(tarballUrl) : SKILLS_REGISTRY_URL
1064
+ };
1065
+ }
1066
+ function requireSkillsTarballUrl(selectedVersion, tarballUrl) {
1067
+ if (tarballUrl)
1068
+ return tarballUrl;
1069
+ throw new SkillsPackageMetadataError(`npm view ${SKILLS_PACKAGE_NAME}@${selectedVersion} dist.tarball returned no usable tarball URL`);
1070
+ }
1071
+ function parseVersionLine(version) {
1072
+ const match = /^(\d+)\.(\d+)$/.exec(version.trim());
1073
+ if (!match)
1074
+ return null;
1075
+ return {
1076
+ major: Number.parseInt(match[1], 10),
1077
+ minor: Number.parseInt(match[2], 10),
1078
+ patch: 0
1079
+ };
1080
+ }
1081
+ function pickMatchingSkillsVersion(versions, cliVersion) {
1082
+ const matchingVersions = versions.filter((version) => matchesCliVersionLine(version, cliVersion));
1083
+ const preferredVersions = cliVersion.prerelease === undefined ? matchingVersions.filter(isStableVersion) : matchingVersions;
1084
+ const selectedVersion = (preferredVersions.length > 0 ? preferredVersions : matchingVersions).sort((a, b) => compareSemver(b, a))[0];
1085
+ if (!selectedVersion) {
1086
+ throw new Error(`${SKILLS_PACKAGE_NAME} has no published version matching CLI ${cliVersion.major}.${cliVersion.minor}.x`);
1087
+ }
1088
+ return selectedVersion;
1089
+ }
1090
+ async function withTempProject(fn) {
1091
+ const fs = getFileSystem2();
1092
+ const projectDir = fs.path.join(fs.env.tmpdir(), `uipath-skills-pm-${randomUUID()}`);
1093
+ try {
1094
+ await fs.mkdir(projectDir);
1095
+ await fs.writeFile(fs.path.join(projectDir, "package.json"), `${JSON.stringify({ name: "uipath-skills-fetch", version: "0.0.0", private: true }, null, 2)}
1096
+ `);
1097
+ return await fn(projectDir);
1098
+ } finally {
1099
+ await catchError(fs.rm(projectDir));
1100
+ }
1101
+ }
1102
+ async function materializePackage(pm, packageInfo, destinationPath) {
1103
+ if (pm === "npm") {
1104
+ await packAndExtractWithNpm(packageInfo, destinationPath);
1105
+ return;
1106
+ }
1107
+ await addAndCopyPackage(pm, packageInfo, destinationPath);
1108
+ }
1109
+ async function packAndExtractWithNpm(packageInfo, destinationPath) {
1110
+ const fs = getFileSystem2();
1111
+ const packDir = fs.path.join(fs.env.tmpdir(), `uipath-skills-pack-${randomUUID()}`);
1112
+ try {
1113
+ await fs.mkdir(packDir);
1114
+ const stdout = await runPmCommand("npm", ["pack", `${SKILLS_PACKAGE_NAME}@${packageInfo.version}`, "--json"], `pack ${SKILLS_PACKAGE_NAME}@${packageInfo.version}`, NPM_PACK_TIMEOUT_MS, packDir);
1115
+ const packOutput = parsePmJson("npm", stdout, "pack");
1116
+ const packedFile = readPackedFileName(packOutput);
1117
+ const packedPath = fs.path.join(packDir, packedFile);
1118
+ const packedContent = await fs.readFile(packedPath);
1119
+ if (!packedContent) {
1120
+ throw new Error(`npm pack did not create ${packedFile}`);
1121
+ }
1122
+ const tarData = gunzipSync(new Uint8Array(packedContent));
1123
+ await extractNpmTarballToDir(tarData, destinationPath);
1124
+ } finally {
1125
+ await catchError(fs.rm(packDir));
1126
+ }
1127
+ }
1128
+ async function addAndCopyPackage(pm, packageInfo, destinationPath) {
1129
+ const fs = getFileSystem2();
1130
+ const spec = `${SKILLS_PACKAGE_NAME}@${packageInfo.version}`;
1131
+ const extraEnv = pm === "yarn" ? { YARN_NODE_LINKER: "node-modules" } : undefined;
1132
+ await withTempProject(async (projectDir) => {
1133
+ await runPmCommand(pm, ["add", spec, "--ignore-scripts"], `add ${spec}`, NPM_PACK_TIMEOUT_MS, projectDir, extraEnv);
1134
+ const installed = fs.path.join(projectDir, "node_modules", SKILLS_PACKAGE_NAME);
1135
+ if (!await fs.exists(installed)) {
1136
+ throw new Error(`${pm} add did not install ${SKILLS_PACKAGE_NAME}`);
1137
+ }
1138
+ const realInstalled = await fs.realpath(installed);
1139
+ await fs.copyDirectory(realInstalled, destinationPath);
1140
+ });
1141
+ }
1142
+ function readPackedFileName(packOutput) {
1143
+ const entries = Array.isArray(packOutput) ? packOutput : packOutputObjectEntries(packOutput);
1144
+ const filename = entries.map((entry) => asRecord(entry)?.filename).find((value) => typeof value === "string" && value.length > 0);
1145
+ if (!filename) {
1146
+ throw new SkillsPackOutputError(`Unexpected npm pack output for ${SKILLS_PACKAGE_NAME}`);
1147
+ }
1148
+ if (filename.includes("/") || filename.includes("\\")) {
1149
+ throw new Error(`Unsafe npm pack filename for ${SKILLS_PACKAGE_NAME}`);
1150
+ }
1151
+ return filename;
1152
+ }
1153
+ function packOutputObjectEntries(packOutput) {
1154
+ const record = asRecord(packOutput);
1155
+ if (!record)
1156
+ return [];
1157
+ const named = record[SKILLS_PACKAGE_NAME];
1158
+ return named === undefined ? Object.values(record) : [named];
1159
+ }
1160
+ async function writeSourceMarker(storePath, packageInfo) {
1161
+ const fs = getFileSystem2();
1162
+ const marker = {
1163
+ source: "npm",
1164
+ package: SKILLS_PACKAGE_NAME,
1165
+ version: packageInfo.version,
1166
+ registry: packageInfo.registryUrl,
1167
+ tarball: packageInfo.tarballUrl,
1168
+ fetchedAt: new Date().toISOString()
1169
+ };
1170
+ await fs.writeFile(fs.path.join(storePath, SOURCE_MARKER_NAME), `${JSON.stringify(marker, null, 4)}
1171
+ `);
1172
+ }
1173
+ function readTarString(data, offset, length) {
1174
+ const field = data.subarray(offset, offset + length);
1175
+ const nullIndex = field.indexOf(0);
1176
+ const end = nullIndex >= 0 ? nullIndex : field.length;
1177
+ return Buffer.from(field.subarray(0, end)).toString("utf-8");
1178
+ }
1179
+ function readTarOctal(data, offset, length) {
1180
+ const raw = readTarString(data, offset, length).trim();
1181
+ if (!raw)
1182
+ return 0;
1183
+ const parsed = Number.parseInt(raw, 8);
1184
+ if (Number.isNaN(parsed)) {
1185
+ throw new TypeError(`Invalid tar numeric field: ${raw}`);
1186
+ }
1187
+ return parsed;
1188
+ }
1189
+ function readTarPath(data, headerOffset) {
1190
+ const name = readTarString(data, headerOffset, 100);
1191
+ const prefix = readTarString(data, headerOffset + 345, 155);
1192
+ return prefix ? `${prefix}/${name}` : name;
1193
+ }
1194
+ function isZeroBlock(data, offset) {
1195
+ for (let i = offset;i < offset + TAR_BLOCK_SIZE; i++) {
1196
+ if (data[i] !== 0)
1197
+ return false;
1198
+ }
1199
+ return true;
1200
+ }
1201
+ function parsePaxAttributes(data) {
1202
+ const text = Buffer.from(data).toString("utf-8");
1203
+ const attributes = {};
1204
+ let offset = 0;
1205
+ while (offset < text.length) {
1206
+ const spaceIndex = text.indexOf(" ", offset);
1207
+ if (spaceIndex === -1)
1208
+ break;
1209
+ const lengthText = text.slice(offset, spaceIndex);
1210
+ const recordLength = Number.parseInt(lengthText, 10);
1211
+ if (!Number.isFinite(recordLength) || recordLength <= 0)
1212
+ break;
1213
+ const record = text.slice(spaceIndex + 1, offset + recordLength);
1214
+ const equalsIndex = record.indexOf("=");
1215
+ if (equalsIndex > 0) {
1216
+ const key = record.slice(0, equalsIndex);
1217
+ const rawValue = record.slice(equalsIndex + 1);
1218
+ const value = rawValue.endsWith(`
1219
+ `) ? rawValue.slice(0, -1) : rawValue;
1220
+ attributes[key] = value;
1221
+ }
1222
+ offset += recordLength;
1223
+ }
1224
+ return attributes;
1225
+ }
1226
+ function stripNpmPackageRoot(entryName) {
1227
+ const normalized = entryName.replaceAll("\\", "/");
1228
+ if (normalized === "package" || normalized === "package/")
1229
+ return "";
1230
+ if (!normalized.startsWith("package/")) {
1231
+ throw new Error(`Unexpected tarball root entry: ${entryName}`);
1232
+ }
1233
+ return normalized.slice("package/".length);
1234
+ }
1235
+ function resolveTarEntryPath(fs, destinationDir, entryName) {
1236
+ if (entryName.includes("\x00")) {
1237
+ throw new Error(`Invalid tar entry path: ${entryName}`);
1238
+ }
1239
+ if (entryName.startsWith("/")) {
1240
+ throw new Error(`Unsafe absolute tar entry path: ${entryName}`);
1241
+ }
1242
+ const root = fs.path.resolve(destinationDir);
1243
+ const target = fs.path.resolve(root, entryName);
1244
+ const relative = fs.path.relative(root, target);
1245
+ if (relative.startsWith("..") || fs.path.isAbsolute(relative)) {
1246
+ throw new Error(`Unsafe tar entry path: ${entryName}`);
1247
+ }
1248
+ return target;
1249
+ }
1250
+ function readNullTerminatedUtf8(data) {
1251
+ const nullIndex = data.indexOf(0);
1252
+ const end = nullIndex >= 0 ? nullIndex : data.length;
1253
+ return Buffer.from(data.subarray(0, end)).toString("utf-8");
1254
+ }
1255
+ function readTarEntry(tarData, headerOffset) {
1256
+ const typeFlag = String.fromCodePoint(tarData[headerOffset + 156] || 0);
1257
+ const size = readTarOctal(tarData, headerOffset + 124, 12);
1258
+ const dataOffset = headerOffset + TAR_BLOCK_SIZE;
1259
+ const dataEnd = dataOffset + size;
1260
+ if (dataEnd > tarData.length) {
1261
+ throw new Error("Invalid tarball: entry extends past archive end");
1262
+ }
1263
+ const padding = (TAR_BLOCK_SIZE - size % TAR_BLOCK_SIZE) % TAR_BLOCK_SIZE;
1264
+ return {
1265
+ typeFlag,
1266
+ headerPath: readTarPath(tarData, headerOffset),
1267
+ entryData: tarData.subarray(dataOffset, dataEnd),
1268
+ nextOffset: dataEnd + padding
1269
+ };
1270
+ }
1271
+ function readTarPathOverride(typeFlag, entryData) {
1272
+ if (typeFlag === "x")
1273
+ return parsePaxAttributes(entryData).path;
1274
+ if (typeFlag === "L")
1275
+ return readNullTerminatedUtf8(entryData);
1276
+ return;
1277
+ }
1278
+ function isTarPathOverrideEntry(typeFlag) {
1279
+ return typeFlag === "x" || typeFlag === "L";
1280
+ }
1281
+ function isTarDirectoryEntry(typeFlag, entryName) {
1282
+ return typeFlag === "5" || entryName.endsWith("/");
1283
+ }
1284
+ function isTarRegularFileEntry(typeFlag) {
1285
+ return typeFlag === "0" || typeFlag === "\x00";
1286
+ }
1287
+ async function extractTarEntry(fs, destinationDir, entryName, entry) {
1288
+ if (isTarDirectoryEntry(entry.typeFlag, entryName)) {
1289
+ await fs.mkdir(resolveTarEntryPath(fs, destinationDir, entryName));
1290
+ return;
1291
+ }
1292
+ if (!isTarRegularFileEntry(entry.typeFlag)) {
1293
+ logger.debug(`Skipping unsupported tar entry type '${entry.typeFlag}' for ${entryName}`);
1294
+ return;
1295
+ }
1296
+ const target = resolveTarEntryPath(fs, destinationDir, entryName);
1297
+ await fs.writeFile(target, entry.entryData);
1298
+ }
1299
+ async function extractNpmTarballToDir(tarData, destinationDir) {
1300
+ const fs = getFileSystem2();
1301
+ await fs.mkdir(destinationDir);
1302
+ let offset = 0;
1303
+ let nextPath;
1304
+ while (offset + TAR_BLOCK_SIZE <= tarData.length) {
1305
+ if (isZeroBlock(tarData, offset))
1306
+ break;
1307
+ const entry = readTarEntry(tarData, offset);
1308
+ offset = entry.nextOffset;
1309
+ if (isTarPathOverrideEntry(entry.typeFlag)) {
1310
+ nextPath = readTarPathOverride(entry.typeFlag, entry.entryData);
1311
+ continue;
1312
+ }
1313
+ if (entry.typeFlag === "g") {
1314
+ continue;
1315
+ }
1316
+ const rawPath = nextPath ?? entry.headerPath;
1317
+ nextPath = undefined;
1318
+ const entryName = stripNpmPackageRoot(rawPath);
1319
+ if (!entryName)
1320
+ continue;
1321
+ await extractTarEntry(fs, destinationDir, entryName, entry);
1322
+ }
1323
+ }
1324
+
1325
+ export { REPO_URL2, DEFAULT_SOURCE2, resolveSkillSource2, fetchSkillsTo2, getContentStore2, getContentStoreForRead2, getAvailableSkills2, parseSkillMd2, addToGitignore2, MANIFEST_NAME2, readManifest2, updateManifestAfterInstall2, removeFromManifest2, readExtraFiles2, recordExtraFiles2 };
1326
+
1327
+ //# debugId=A8E0E8E12341A80264756E2164756E21