allagents 0.5.0 → 0.5.2
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/dist/index.js +81 -35
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -19365,25 +19365,43 @@ function parseGitHubUrl(url) {
|
|
|
19365
19365
|
}
|
|
19366
19366
|
return null;
|
|
19367
19367
|
}
|
|
19368
|
-
const
|
|
19369
|
-
|
|
19370
|
-
|
|
19371
|
-
const
|
|
19372
|
-
const
|
|
19373
|
-
|
|
19374
|
-
|
|
19375
|
-
|
|
19376
|
-
|
|
19377
|
-
|
|
19378
|
-
|
|
19379
|
-
|
|
19380
|
-
|
|
19381
|
-
|
|
19382
|
-
|
|
19383
|
-
|
|
19384
|
-
|
|
19385
|
-
|
|
19386
|
-
|
|
19368
|
+
const treeMatch = normalized.match(/^https?:\/\/(?:www\.)?github\.com\/([^/]+)\/([^/]+?)\/tree\/(.+)$/);
|
|
19369
|
+
if (treeMatch) {
|
|
19370
|
+
const owner = treeMatch[1];
|
|
19371
|
+
const repo = treeMatch[2]?.replace(/\.git$/, "");
|
|
19372
|
+
const afterTree = treeMatch[3];
|
|
19373
|
+
if (owner && repo && afterTree) {
|
|
19374
|
+
const parts = afterTree.split("/");
|
|
19375
|
+
if (parts.length === 1) {
|
|
19376
|
+
const branch2 = parts[0];
|
|
19377
|
+
return branch2 ? { owner, repo, branch: branch2 } : { owner, repo };
|
|
19378
|
+
}
|
|
19379
|
+
const commonPathDirs = new Set([
|
|
19380
|
+
"plugins",
|
|
19381
|
+
"src",
|
|
19382
|
+
"docs",
|
|
19383
|
+
"examples",
|
|
19384
|
+
"lib",
|
|
19385
|
+
"test",
|
|
19386
|
+
"tests",
|
|
19387
|
+
"spec",
|
|
19388
|
+
"scripts",
|
|
19389
|
+
"config",
|
|
19390
|
+
".allagents",
|
|
19391
|
+
"dist",
|
|
19392
|
+
"build"
|
|
19393
|
+
]);
|
|
19394
|
+
for (let i2 = 1;i2 < parts.length; i2++) {
|
|
19395
|
+
const part = parts[i2];
|
|
19396
|
+
if (part && commonPathDirs.has(part)) {
|
|
19397
|
+
const branch2 = parts.slice(0, i2).join("/");
|
|
19398
|
+
const subpath2 = parts.slice(i2).join("/");
|
|
19399
|
+
return { owner, repo, branch: branch2, subpath: subpath2 };
|
|
19400
|
+
}
|
|
19401
|
+
}
|
|
19402
|
+
const branch = parts[0];
|
|
19403
|
+
const subpath = parts.slice(1).join("/");
|
|
19404
|
+
return branch ? { owner, repo, branch, subpath } : { owner, repo };
|
|
19387
19405
|
}
|
|
19388
19406
|
}
|
|
19389
19407
|
const basicPattern = /^https?:\/\/(?:www\.)?github\.com\/([^/]+)\/([^/]+?)(?:\.git)?(?:\/.*)?$/;
|
|
@@ -19423,9 +19441,14 @@ function parsePluginSource(source, baseDir = process.cwd()) {
|
|
|
19423
19441
|
normalized: normalizePluginPath(source, baseDir)
|
|
19424
19442
|
};
|
|
19425
19443
|
}
|
|
19426
|
-
function
|
|
19444
|
+
function sanitizeBranchForPath(branch) {
|
|
19445
|
+
return branch.replace(/[/\\:*?"<>|]/g, "_");
|
|
19446
|
+
}
|
|
19447
|
+
function getPluginCachePath(owner, repo, branch) {
|
|
19427
19448
|
const homeDir = process.env.HOME || process.env.USERPROFILE || "~";
|
|
19428
|
-
|
|
19449
|
+
const basePath = `${owner}-${repo}`;
|
|
19450
|
+
const cacheName = branch ? `${basePath}@${sanitizeBranchForPath(branch)}` : basePath;
|
|
19451
|
+
return resolve(homeDir, ".allagents", "plugins", "marketplaces", cacheName);
|
|
19429
19452
|
}
|
|
19430
19453
|
function validatePluginSource(source) {
|
|
19431
19454
|
if (!source || source.trim() === "") {
|
|
@@ -19539,7 +19562,7 @@ import { mkdir, readdir, stat } from "node:fs/promises";
|
|
|
19539
19562
|
import { existsSync } from "node:fs";
|
|
19540
19563
|
import { dirname, join, resolve as resolve2 } from "node:path";
|
|
19541
19564
|
async function fetchPlugin(url, options2 = {}) {
|
|
19542
|
-
const { force = false } = options2;
|
|
19565
|
+
const { force = false, branch } = options2;
|
|
19543
19566
|
const validation = validatePluginSource(url);
|
|
19544
19567
|
if (!validation.valid) {
|
|
19545
19568
|
return {
|
|
@@ -19559,7 +19582,7 @@ async function fetchPlugin(url, options2 = {}) {
|
|
|
19559
19582
|
};
|
|
19560
19583
|
}
|
|
19561
19584
|
const { owner, repo } = parsed;
|
|
19562
|
-
const cachePath = getPluginCachePath(owner, repo);
|
|
19585
|
+
const cachePath = getPluginCachePath(owner, repo, branch);
|
|
19563
19586
|
try {
|
|
19564
19587
|
await execa("gh", ["--version"]);
|
|
19565
19588
|
} catch {
|
|
@@ -19590,7 +19613,11 @@ async function fetchPlugin(url, options2 = {}) {
|
|
|
19590
19613
|
}
|
|
19591
19614
|
const parentDir = dirname(cachePath);
|
|
19592
19615
|
await mkdir(parentDir, { recursive: true });
|
|
19593
|
-
|
|
19616
|
+
if (branch) {
|
|
19617
|
+
await execa("gh", ["repo", "clone", `${owner}/${repo}`, cachePath, "--", "--branch", branch]);
|
|
19618
|
+
} else {
|
|
19619
|
+
await execa("gh", ["repo", "clone", `${owner}/${repo}`, cachePath]);
|
|
19620
|
+
}
|
|
19594
19621
|
return {
|
|
19595
19622
|
success: true,
|
|
19596
19623
|
action: "fetched",
|
|
@@ -20763,7 +20790,11 @@ async function validatePlugin(pluginSource, workspacePath, force) {
|
|
|
20763
20790
|
};
|
|
20764
20791
|
}
|
|
20765
20792
|
if (isGitHubUrl(pluginSource)) {
|
|
20766
|
-
const
|
|
20793
|
+
const parsed = parseGitHubUrl(pluginSource);
|
|
20794
|
+
const fetchResult = await fetchPlugin(pluginSource, {
|
|
20795
|
+
force,
|
|
20796
|
+
...parsed?.branch && { branch: parsed.branch }
|
|
20797
|
+
});
|
|
20767
20798
|
if (!fetchResult.success) {
|
|
20768
20799
|
return {
|
|
20769
20800
|
plugin: pluginSource,
|
|
@@ -20772,7 +20803,6 @@ async function validatePlugin(pluginSource, workspacePath, force) {
|
|
|
20772
20803
|
...fetchResult.error && { error: fetchResult.error }
|
|
20773
20804
|
};
|
|
20774
20805
|
}
|
|
20775
|
-
const parsed = parseGitHubUrl(pluginSource);
|
|
20776
20806
|
const resolvedPath2 = parsed?.subpath ? join7(fetchResult.cachePath, parsed.subpath) : fetchResult.cachePath;
|
|
20777
20807
|
return {
|
|
20778
20808
|
plugin: pluginSource,
|
|
@@ -21230,8 +21260,9 @@ async function initWorkspace(targetPath = ".", options2 = {}) {
|
|
|
21230
21260
|
if (parsedUrl) {
|
|
21231
21261
|
const basePath = parsedUrl.subpath || "";
|
|
21232
21262
|
const baseDir = basePath.replace(/\/?\.allagents\/workspace\.yaml$/, "").replace(/\/?workspace\.yaml$/, "");
|
|
21233
|
-
const sourcePath = baseDir ? `${baseDir}/${source}` : source;
|
|
21234
|
-
|
|
21263
|
+
const sourcePath = source === "." ? baseDir : baseDir ? `${baseDir}/${source}` : source;
|
|
21264
|
+
const branch = parsedUrl.branch || "main";
|
|
21265
|
+
workspace.source = `https://github.com/${parsedUrl.owner}/${parsedUrl.repo}/tree/${branch}/${sourcePath}`;
|
|
21235
21266
|
workspaceYamlContent = dump(parsed2, { lineWidth: -1 });
|
|
21236
21267
|
}
|
|
21237
21268
|
}
|
|
@@ -21290,13 +21321,28 @@ async function initWorkspace(targetPath = ".", options2 = {}) {
|
|
|
21290
21321
|
}
|
|
21291
21322
|
await writeFile4(configPath, workspaceYamlContent, "utf-8");
|
|
21292
21323
|
const copiedAgentFiles = [];
|
|
21293
|
-
|
|
21294
|
-
|
|
21295
|
-
|
|
21296
|
-
|
|
21297
|
-
const
|
|
21298
|
-
|
|
21299
|
-
|
|
21324
|
+
if (options2.from && isGitHubUrl(options2.from)) {
|
|
21325
|
+
const parsedUrl = parseGitHubUrl(options2.from);
|
|
21326
|
+
if (parsedUrl) {
|
|
21327
|
+
const basePath = parsedUrl.subpath || "";
|
|
21328
|
+
for (const agentFile of AGENT_FILES) {
|
|
21329
|
+
const filePath = basePath ? `${basePath}/${agentFile}` : agentFile;
|
|
21330
|
+
const content = await fetchFileFromGitHub(parsedUrl.owner, parsedUrl.repo, filePath, parsedUrl.branch);
|
|
21331
|
+
if (content) {
|
|
21332
|
+
await writeFile4(join8(absoluteTarget, agentFile), content, "utf-8");
|
|
21333
|
+
copiedAgentFiles.push(agentFile);
|
|
21334
|
+
}
|
|
21335
|
+
}
|
|
21336
|
+
}
|
|
21337
|
+
} else {
|
|
21338
|
+
const effectiveSourceDir = sourceDir ?? defaultTemplatePath;
|
|
21339
|
+
for (const agentFile of AGENT_FILES) {
|
|
21340
|
+
const sourcePath = join8(effectiveSourceDir, agentFile);
|
|
21341
|
+
if (existsSync7(sourcePath)) {
|
|
21342
|
+
const content = await readFile6(sourcePath, "utf-8");
|
|
21343
|
+
await writeFile4(join8(absoluteTarget, agentFile), content, "utf-8");
|
|
21344
|
+
copiedAgentFiles.push(agentFile);
|
|
21345
|
+
}
|
|
21300
21346
|
}
|
|
21301
21347
|
}
|
|
21302
21348
|
if (copiedAgentFiles.length === 0) {
|