agentsmesh 0.8.0 → 0.9.0
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/CHANGELOG.md +43 -0
- package/README.md +190 -107
- package/dist/canonical.js +56 -14
- package/dist/canonical.js.map +1 -1
- package/dist/cli.js +117 -117
- package/dist/engine.d.ts +1 -1
- package/dist/engine.js +68 -28
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +69 -28
- package/dist/index.js.map +1 -1
- package/dist/{target-descriptor-Cb9PXaxr.d.ts → target-descriptor-CkH4Z43u.d.ts} +2 -1
- package/dist/targets.d.ts +21 -3
- package/dist/targets.js +43 -13
- package/dist/targets.js.map +1 -1
- package/package.json +2 -2
package/dist/engine.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { V as ValidatedConfig, b as CanonicalFiles } from './schema-BeGiBqbB.js';
|
|
2
|
-
import { G as GenerateResult, h as TargetLayoutScope, L as LintDiagnostic, d as ImportResult } from './target-descriptor-
|
|
2
|
+
import { G as GenerateResult, h as TargetLayoutScope, L as LintDiagnostic, d as ImportResult } from './target-descriptor-CkH4Z43u.js';
|
|
3
3
|
import 'zod';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/engine.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { readFile, rm, mkdir, readdir, stat, lstat, writeFile, rename, access, realpath } from 'fs/promises';
|
|
2
|
+
import { readFile, rm, mkdir, readdir, stat, lstat, unlink, writeFile, rename, access, realpath } from 'fs/promises';
|
|
3
3
|
import { join, basename, dirname, relative, win32, posix, resolve, normalize, extname, isAbsolute } from 'path';
|
|
4
4
|
import { constants, existsSync, realpathSync, statSync } from 'fs';
|
|
5
5
|
import { stringify, parse } from 'yaml';
|
|
6
6
|
import { parse as parse$1 } from 'smol-toml';
|
|
7
7
|
import { Buffer } from 'buffer';
|
|
8
8
|
import { homedir } from 'os';
|
|
9
|
+
import { createHash } from 'crypto';
|
|
9
10
|
import { execFile } from 'child_process';
|
|
10
11
|
import { fileURLToPath, pathToFileURL, URL } from 'url';
|
|
11
12
|
import { promisify } from 'util';
|
|
12
13
|
import * as tar from 'tar';
|
|
13
14
|
import { createTwoFilesPatch } from 'diff';
|
|
14
|
-
import { createHash } from 'crypto';
|
|
15
15
|
|
|
16
16
|
var __defProp = Object.defineProperty;
|
|
17
17
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -452,6 +452,11 @@ async function writeFileAtomic(path, content) {
|
|
|
452
452
|
{ errnoCode: "EISDIR" }
|
|
453
453
|
);
|
|
454
454
|
}
|
|
455
|
+
if (info.isSymbolicLink()) {
|
|
456
|
+
await unlink(path).catch((e) => {
|
|
457
|
+
if (e.code !== "ENOENT") throw e;
|
|
458
|
+
});
|
|
459
|
+
}
|
|
455
460
|
} catch (err) {
|
|
456
461
|
if (err instanceof FileSystemError) throw err;
|
|
457
462
|
const e = err;
|
|
@@ -460,7 +465,15 @@ async function writeFileAtomic(path, content) {
|
|
|
460
465
|
const tmpPath = `${path}.tmp`;
|
|
461
466
|
const payload = shouldNormalizeLineEndings(path) ? normalizeLineEndings(content) : content;
|
|
462
467
|
try {
|
|
463
|
-
|
|
468
|
+
try {
|
|
469
|
+
const tmpInfo = await lstat(tmpPath);
|
|
470
|
+
if (tmpInfo.isSymbolicLink()) {
|
|
471
|
+
await unlink(tmpPath);
|
|
472
|
+
}
|
|
473
|
+
} catch (tmpErr) {
|
|
474
|
+
if (tmpErr.code !== "ENOENT") throw tmpErr;
|
|
475
|
+
}
|
|
476
|
+
await writeFile(tmpPath, payload, { encoding: "utf-8", flag: "w" });
|
|
464
477
|
await rename(tmpPath, path);
|
|
465
478
|
} catch (err) {
|
|
466
479
|
await rm(tmpPath, { force: true }).catch(() => {
|
|
@@ -2134,18 +2147,24 @@ async function runDirectory(spec, sources, projectRoot, fromTool, normalize) {
|
|
|
2134
2147
|
}
|
|
2135
2148
|
return results;
|
|
2136
2149
|
}
|
|
2150
|
+
function resolveCanonicalFilePath(spec) {
|
|
2151
|
+
const filename = spec.canonicalFilename;
|
|
2152
|
+
if (filename.includes("/") || filename.includes("\\")) return filename;
|
|
2153
|
+
return posix.join(spec.canonicalDir, filename);
|
|
2154
|
+
}
|
|
2137
2155
|
async function runFlatFile(spec, sources, projectRoot, fromTool) {
|
|
2138
2156
|
if (!spec.canonicalFilename) {
|
|
2139
2157
|
throw new Error(`flatFile spec for ${spec.feature} must set canonicalFilename`);
|
|
2140
2158
|
}
|
|
2159
|
+
const canonicalPath = resolveCanonicalFilePath(spec);
|
|
2141
2160
|
for (const rel2 of sources) {
|
|
2142
2161
|
const srcPath = join(projectRoot, rel2);
|
|
2143
2162
|
const content = await readFileSafe(srcPath);
|
|
2144
2163
|
if (content === null) continue;
|
|
2145
|
-
const destPath = join(projectRoot,
|
|
2164
|
+
const destPath = join(projectRoot, canonicalPath);
|
|
2146
2165
|
await mkdirp(dirname(destPath));
|
|
2147
2166
|
await writeFileAtomic(destPath, content.trimEnd());
|
|
2148
|
-
return [{ fromTool, fromPath: srcPath, toPath:
|
|
2167
|
+
return [{ fromTool, fromPath: srcPath, toPath: canonicalPath, feature: spec.feature }];
|
|
2149
2168
|
}
|
|
2150
2169
|
return [];
|
|
2151
2170
|
}
|
|
@@ -2190,24 +2209,21 @@ async function runMcpJson(spec, sources, projectRoot, fromTool) {
|
|
|
2190
2209
|
if (!spec.canonicalFilename) {
|
|
2191
2210
|
throw new Error(`mcpJson spec for ${spec.feature} must set canonicalFilename`);
|
|
2192
2211
|
}
|
|
2212
|
+
const canonicalPath = resolveCanonicalFilePath(spec);
|
|
2193
2213
|
for (const rel2 of sources) {
|
|
2194
2214
|
const srcPath = join(projectRoot, rel2);
|
|
2195
2215
|
const content = await readFileSafe(srcPath);
|
|
2196
2216
|
if (content === null) continue;
|
|
2197
2217
|
const servers = parseMcpJson(content);
|
|
2198
2218
|
if (Object.keys(servers).length === 0) return [];
|
|
2199
|
-
const destPath = join(projectRoot,
|
|
2219
|
+
const destPath = join(projectRoot, canonicalPath);
|
|
2200
2220
|
await mkdirp(dirname(destPath));
|
|
2201
2221
|
await writeFileAtomic(destPath, JSON.stringify({ mcpServers: servers }, null, 2));
|
|
2202
|
-
return [{ fromTool, fromPath: srcPath, toPath:
|
|
2222
|
+
return [{ fromTool, fromPath: srcPath, toPath: canonicalPath, feature: spec.feature }];
|
|
2203
2223
|
}
|
|
2204
2224
|
return [];
|
|
2205
2225
|
}
|
|
2206
|
-
|
|
2207
|
-
const primary = resolveScopedSources(spec.source, scope);
|
|
2208
|
-
const fallback = resolveScopedSources(spec.fallbacks, scope);
|
|
2209
|
-
const sources = primary.length > 0 ? primary : fallback;
|
|
2210
|
-
if (sources.length === 0) return [];
|
|
2226
|
+
function dispatchSpec(spec, sources, projectRoot, fromTool, normalize) {
|
|
2211
2227
|
switch (spec.mode) {
|
|
2212
2228
|
case "singleFile":
|
|
2213
2229
|
return runSingleFile(spec, sources, projectRoot, fromTool, normalize);
|
|
@@ -2219,6 +2235,19 @@ async function runSpec(spec, scope, projectRoot, fromTool, normalize) {
|
|
|
2219
2235
|
return runMcpJson(spec, sources, projectRoot, fromTool);
|
|
2220
2236
|
}
|
|
2221
2237
|
}
|
|
2238
|
+
async function runSpec(spec, scope, projectRoot, fromTool, normalize) {
|
|
2239
|
+
const primary = resolveScopedSources(spec.source, scope);
|
|
2240
|
+
const fallback = resolveScopedSources(spec.fallbacks, scope);
|
|
2241
|
+
if (primary.length === 0 && fallback.length === 0) return [];
|
|
2242
|
+
if (primary.length > 0) {
|
|
2243
|
+
const results = await dispatchSpec(spec, primary, projectRoot, fromTool, normalize);
|
|
2244
|
+
if (results.length > 0) return results;
|
|
2245
|
+
}
|
|
2246
|
+
if (fallback.length > 0) {
|
|
2247
|
+
return dispatchSpec(spec, fallback, projectRoot, fromTool, normalize);
|
|
2248
|
+
}
|
|
2249
|
+
return [];
|
|
2250
|
+
}
|
|
2222
2251
|
function specsForFeature(importer, feature) {
|
|
2223
2252
|
const value = importer[feature];
|
|
2224
2253
|
if (!value) return [];
|
|
@@ -11944,7 +11973,7 @@ function ruleTargetPath(target13, rule, scope = "project") {
|
|
|
11944
11973
|
return layout.rootInstructionPath ?? null;
|
|
11945
11974
|
}
|
|
11946
11975
|
if (rule.targets.length > 0 && !rule.targets.includes(target13)) return null;
|
|
11947
|
-
const slug = basename(rule.source, ".md");
|
|
11976
|
+
const slug = posix.basename(rule.source.replace(/\\/g, "/"), ".md");
|
|
11948
11977
|
return layout.paths.rulePath(slug, rule);
|
|
11949
11978
|
}
|
|
11950
11979
|
function commandTargetPath(target13, name, config, scope = "project") {
|
|
@@ -12206,8 +12235,7 @@ function extraRuleOutputPaths(target13, rule, refs, scope) {
|
|
|
12206
12235
|
|
|
12207
12236
|
// src/core/reference/output-source-map.ts
|
|
12208
12237
|
init_builtin_targets();
|
|
12209
|
-
function
|
|
12210
|
-
if (scope !== "global") return;
|
|
12238
|
+
function addSkillMirrorSourceEntry(target13, scope, primaryOutputPath, source, sourceMap, activeTargets) {
|
|
12211
12239
|
const layout = getTargetLayout(target13, scope);
|
|
12212
12240
|
if (!layout?.mirrorGlobalPath) return;
|
|
12213
12241
|
const raw = layout.mirrorGlobalPath(primaryOutputPath, activeTargets ?? []);
|
|
@@ -12260,7 +12288,7 @@ function buildOutputSourceMap(target13, canonical, config, scope = "project", ac
|
|
|
12260
12288
|
const skillTargetPath = refs.get(canonicalSkillPath(skill));
|
|
12261
12289
|
if (skillTargetPath) {
|
|
12262
12290
|
sourceMap.set(skillTargetPath, skill.source);
|
|
12263
|
-
|
|
12291
|
+
addSkillMirrorSourceEntry(
|
|
12264
12292
|
target13,
|
|
12265
12293
|
scope,
|
|
12266
12294
|
skillTargetPath,
|
|
@@ -12274,7 +12302,7 @@ function buildOutputSourceMap(target13, canonical, config, scope = "project", ac
|
|
|
12274
12302
|
const targetPath = refs.get(canonicalPath);
|
|
12275
12303
|
if (targetPath) {
|
|
12276
12304
|
sourceMap.set(targetPath, file.absolutePath);
|
|
12277
|
-
|
|
12305
|
+
addSkillMirrorSourceEntry(
|
|
12278
12306
|
target13,
|
|
12279
12307
|
scope,
|
|
12280
12308
|
targetPath,
|
|
@@ -12290,11 +12318,12 @@ function buildOutputSourceMap(target13, canonical, config, scope = "project", ac
|
|
|
12290
12318
|
|
|
12291
12319
|
// src/core/reference/rewriter.ts
|
|
12292
12320
|
init_builtin_targets();
|
|
12321
|
+
init_registry();
|
|
12293
12322
|
init_shared_artifact_owner();
|
|
12294
12323
|
function findSharedArtifactOwner(path, activeTargets) {
|
|
12295
12324
|
if (!activeTargets) return null;
|
|
12296
12325
|
for (const targetId of activeTargets) {
|
|
12297
|
-
const descriptor13 =
|
|
12326
|
+
const descriptor13 = getDescriptor(targetId);
|
|
12298
12327
|
if (!descriptor13?.sharedArtifacts) continue;
|
|
12299
12328
|
for (const [pathPrefix, role] of Object.entries(descriptor13.sharedArtifacts)) {
|
|
12300
12329
|
if (role === "owner" && path.startsWith(pathPrefix)) {
|
|
@@ -13426,13 +13455,25 @@ async function sweepStaleCache(cacheDir, maxAgeMs) {
|
|
|
13426
13455
|
}
|
|
13427
13456
|
|
|
13428
13457
|
// src/config/remote/remote-fetcher.ts
|
|
13458
|
+
var MAX_CACHE_KEY_LENGTH = 80;
|
|
13429
13459
|
function buildCacheKey(provider, identifier, ref) {
|
|
13430
|
-
const safe = (value) => value.replace(/[^a-zA-Z0-9_
|
|
13460
|
+
const safe = (value) => value.replace(/[^a-zA-Z0-9_.-]/g, "_").replace(/^\.+/, "_");
|
|
13461
|
+
let key;
|
|
13431
13462
|
if (provider === "github") {
|
|
13432
13463
|
const [org, repo] = identifier.split("/", 2);
|
|
13433
|
-
if (org && repo)
|
|
13464
|
+
if (org && repo) {
|
|
13465
|
+
key = `${safe(org)}--${safe(repo)}--${safe(ref)}`;
|
|
13466
|
+
} else {
|
|
13467
|
+
key = `${safe(provider)}__${safe(identifier)}__${safe(ref)}`;
|
|
13468
|
+
}
|
|
13469
|
+
} else {
|
|
13470
|
+
key = `${safe(provider)}__${safe(identifier)}__${safe(ref)}`;
|
|
13434
13471
|
}
|
|
13435
|
-
|
|
13472
|
+
if (key.length > MAX_CACHE_KEY_LENGTH) {
|
|
13473
|
+
const hash = createHash("sha256").update(key).digest("hex").slice(0, 16);
|
|
13474
|
+
key = `${key.slice(0, MAX_CACHE_KEY_LENGTH - 18)}--${hash}`;
|
|
13475
|
+
}
|
|
13476
|
+
return key;
|
|
13436
13477
|
}
|
|
13437
13478
|
function getCacheDir() {
|
|
13438
13479
|
const env = process.env.AGENTSMESH_CACHE;
|
|
@@ -14525,7 +14566,8 @@ async function importPluginModule(entry, projectRoot) {
|
|
|
14525
14566
|
const { source } = entry;
|
|
14526
14567
|
let importTarget;
|
|
14527
14568
|
if (source.startsWith("file:") || source.startsWith("./") || source.startsWith("../") || source.startsWith("/")) {
|
|
14528
|
-
const
|
|
14569
|
+
const raw = source.startsWith("file:") ? fileURLToPath(source) : source;
|
|
14570
|
+
const resolved = resolve(projectRoot, raw);
|
|
14529
14571
|
importTarget = pathToFileURL(resolved).href;
|
|
14530
14572
|
} else {
|
|
14531
14573
|
importTarget = source;
|
|
@@ -14782,7 +14824,8 @@ async function runLint(config, canonical, projectRoot, targetFilter, options = {
|
|
|
14782
14824
|
const diagnostics = [];
|
|
14783
14825
|
const projectFiles = scope === "global" ? [] : await getProjectFiles(projectRoot);
|
|
14784
14826
|
for (const target13 of targets) {
|
|
14785
|
-
const
|
|
14827
|
+
const fullDesc = getDescriptor(target13);
|
|
14828
|
+
const descriptor13 = isBuiltinTargetId(target13) ? getTargetCatalogEntry(target13) : fullDesc;
|
|
14786
14829
|
if (descriptor13?.capabilities) {
|
|
14787
14830
|
diagnostics.push(
|
|
14788
14831
|
...lintSilentFeatureDrops({
|
|
@@ -14794,29 +14837,26 @@ async function runLint(config, canonical, projectRoot, targetFilter, options = {
|
|
|
14794
14837
|
);
|
|
14795
14838
|
}
|
|
14796
14839
|
if (hasHooks) {
|
|
14797
|
-
const fullDescForHooks = getDescriptor(target13);
|
|
14798
14840
|
diagnostics.push(
|
|
14799
14841
|
...lintHookScriptReferences({
|
|
14800
14842
|
target: target13,
|
|
14801
14843
|
canonical,
|
|
14802
|
-
hasScriptProjection:
|
|
14844
|
+
hasScriptProjection: fullDesc?.postProcessHookOutputs !== void 0
|
|
14803
14845
|
})
|
|
14804
14846
|
);
|
|
14805
14847
|
}
|
|
14806
14848
|
if (hasRules) {
|
|
14807
|
-
const fullDescForRules = getDescriptor(target13);
|
|
14808
14849
|
diagnostics.push(
|
|
14809
14850
|
...lintRuleScopeInversion({
|
|
14810
14851
|
target: target13,
|
|
14811
14852
|
canonical,
|
|
14812
|
-
preservesManualActivation:
|
|
14853
|
+
preservesManualActivation: fullDesc?.preservesManualActivation === true
|
|
14813
14854
|
})
|
|
14814
14855
|
);
|
|
14815
14856
|
}
|
|
14816
14857
|
if (hasRules && descriptor13?.lintRules) {
|
|
14817
14858
|
diagnostics.push(...descriptor13.lintRules(canonical, projectRoot, projectFiles, { scope }));
|
|
14818
14859
|
}
|
|
14819
|
-
const fullDesc = getDescriptor(target13);
|
|
14820
14860
|
if (fullDesc?.generators.lint) {
|
|
14821
14861
|
diagnostics.push(...fullDesc.generators.lint(canonical));
|
|
14822
14862
|
}
|