agentsmesh 0.13.0 → 0.15.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/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  import { stringify, parse } from 'yaml';
3
3
  import { access, readdir, readFile, realpath, stat, rm, mkdir, lstat, unlink, writeFile, rename } from 'fs/promises';
4
4
  import { join, basename, dirname, relative, win32, posix, resolve, extname } from 'path';
5
- import { constants, existsSync, realpathSync, statSync } from 'fs';
5
+ import { constants, existsSync, realpathSync, statSync, readFileSync } from 'fs';
6
6
  import { parse as parse$1 } from 'smol-toml';
7
7
  import { Buffer } from 'buffer';
8
8
  import { homedir } from 'os';
@@ -1385,12 +1385,12 @@ function topLevelDotfilePrefixes(descriptor19) {
1385
1385
  ...layouts.flatMap((l) => l.managedOutputs?.dirs ?? []),
1386
1386
  ...layouts.flatMap((l) => l.managedOutputs?.files ?? [])
1387
1387
  ];
1388
- const out = /* @__PURE__ */ new Set();
1388
+ const out2 = /* @__PURE__ */ new Set();
1389
1389
  for (const candidate of candidates) {
1390
1390
  const top = candidate.split("/")[0];
1391
- if (top && top.startsWith(".") && top.length > 1) out.add(`${top}/`);
1391
+ if (top && top.startsWith(".") && top.length > 1) out2.add(`${top}/`);
1392
1392
  }
1393
- return out;
1393
+ return out2;
1394
1394
  }
1395
1395
  function buildDefaultRootRelativePrefixes() {
1396
1396
  const set = /* @__PURE__ */ new Set([".agentsmesh/"]);
@@ -2133,12 +2133,12 @@ async function readExistingServers(path) {
2133
2133
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
2134
2134
  const raw = parsed.mcpServers;
2135
2135
  if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
2136
- const out = {};
2136
+ const out2 = {};
2137
2137
  for (const [name, value] of Object.entries(raw)) {
2138
2138
  if (!value || typeof value !== "object" || Array.isArray(value)) continue;
2139
- out[name] = value;
2139
+ out2[name] = value;
2140
2140
  }
2141
- return out;
2141
+ return out2;
2142
2142
  }
2143
2143
  var init_mcp_merge = __esm({
2144
2144
  "src/targets/import/mcp-merge.ts"() {
@@ -2421,13 +2421,13 @@ function parseMcpJson(content) {
2421
2421
  if (!parsed || typeof parsed !== "object") return {};
2422
2422
  const raw = parsed.mcpServers;
2423
2423
  if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
2424
- const out = {};
2424
+ const out2 = {};
2425
2425
  for (const [name, value] of Object.entries(raw)) {
2426
2426
  if (!value || typeof value !== "object" || Array.isArray(value)) continue;
2427
2427
  const server = value;
2428
2428
  const description = typeof server.description === "string" ? server.description : void 0;
2429
2429
  if (typeof server.command === "string") {
2430
- out[name] = {
2430
+ out2[name] = {
2431
2431
  type: typeof server.type === "string" ? server.type : "stdio",
2432
2432
  command: server.command,
2433
2433
  args: toStringArray5(server.args),
@@ -2437,7 +2437,7 @@ function parseMcpJson(content) {
2437
2437
  continue;
2438
2438
  }
2439
2439
  if (typeof server.url === "string") {
2440
- out[name] = {
2440
+ out2[name] = {
2441
2441
  type: typeof server.type === "string" ? server.type : "http",
2442
2442
  url: server.url,
2443
2443
  headers: toStringRecord(server.headers),
@@ -2446,7 +2446,7 @@ function parseMcpJson(content) {
2446
2446
  };
2447
2447
  }
2448
2448
  }
2449
- return out;
2449
+ return out2;
2450
2450
  }
2451
2451
  async function runMcpJson(spec, sources, projectRoot, fromTool) {
2452
2452
  if (!spec.canonicalFilename) {
@@ -10737,18 +10737,18 @@ function generateRules11(canonical) {
10737
10737
  return outputs;
10738
10738
  }
10739
10739
  function toJunieMcpServer(server) {
10740
- const out = {};
10741
- if (server.description) out.description = server.description;
10742
- if (server.type !== "stdio") out.type = server.type;
10740
+ const out2 = {};
10741
+ if (server.description) out2.description = server.description;
10742
+ if (server.type !== "stdio") out2.type = server.type;
10743
10743
  if (isStdioMcpServer(server)) {
10744
- out.command = server.command;
10745
- out.args = server.args;
10744
+ out2.command = server.command;
10745
+ out2.args = server.args;
10746
10746
  } else {
10747
- out.url = server.url;
10748
- if (Object.keys(server.headers).length > 0) out.headers = server.headers;
10747
+ out2.url = server.url;
10748
+ if (Object.keys(server.headers).length > 0) out2.headers = server.headers;
10749
10749
  }
10750
- if (Object.keys(server.env).length > 0) out.env = server.env;
10751
- return out;
10750
+ if (Object.keys(server.env).length > 0) out2.env = server.env;
10751
+ return out2;
10752
10752
  }
10753
10753
  function generateMcp7(canonical) {
10754
10754
  if (!canonical.mcp || Object.keys(canonical.mcp.mcpServers).length === 0) return [];
@@ -12217,11 +12217,11 @@ var init_generator17 = __esm({
12217
12217
  });
12218
12218
  function toStringRecord2(value) {
12219
12219
  if (!value || typeof value !== "object" || Array.isArray(value)) return {};
12220
- const out = {};
12220
+ const out2 = {};
12221
12221
  for (const [k, v] of Object.entries(value)) {
12222
- if (typeof v === "string") out[k] = v;
12222
+ if (typeof v === "string") out2[k] = v;
12223
12223
  }
12224
- return out;
12224
+ return out2;
12225
12225
  }
12226
12226
  function parseOpenCodeMcp(content) {
12227
12227
  let parsed;
@@ -12233,12 +12233,12 @@ function parseOpenCodeMcp(content) {
12233
12233
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
12234
12234
  const raw = parsed.mcp;
12235
12235
  if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
12236
- const out = {};
12236
+ const out2 = {};
12237
12237
  for (const [name, value] of Object.entries(raw)) {
12238
12238
  if (!value || typeof value !== "object" || Array.isArray(value)) continue;
12239
12239
  const entry = value;
12240
12240
  if (typeof entry.url === "string") {
12241
- out[name] = {
12241
+ out2[name] = {
12242
12242
  type: "url",
12243
12243
  url: entry.url,
12244
12244
  headers: toStringRecord2(entry.headers),
@@ -12252,7 +12252,7 @@ function parseOpenCodeMcp(content) {
12252
12252
  const command = cmdArr[0];
12253
12253
  if (command === void 0) continue;
12254
12254
  const args = cmdArr.slice(1);
12255
- out[name] = {
12255
+ out2[name] = {
12256
12256
  type: "stdio",
12257
12257
  command,
12258
12258
  args,
@@ -12261,7 +12261,7 @@ function parseOpenCodeMcp(content) {
12261
12261
  };
12262
12262
  }
12263
12263
  }
12264
- return out;
12264
+ return out2;
12265
12265
  }
12266
12266
  async function importMcp4(projectRoot, scope, results) {
12267
12267
  const configFile = scope === "global" ? OPENCODE_GLOBAL_CONFIG_FILE : OPENCODE_CONFIG_FILE;
@@ -15219,13 +15219,13 @@ function resolveGeneratedOutputPath(target19, path, scope) {
15219
15219
  resolvedPath = layout.rewriteGeneratedPath ? layout.rewriteGeneratedPath(path) : path;
15220
15220
  return resolvedPath;
15221
15221
  }
15222
- async function emitGeneratedOutput(results, target19, out, projectRoot, scope, options) {
15223
- const resolvedPath = resolveGeneratedOutputPath(target19, out.path, scope);
15222
+ async function emitGeneratedOutput(results, target19, out2, projectRoot, scope, options) {
15223
+ const resolvedPath = resolveGeneratedOutputPath(target19, out2.path, scope);
15224
15224
  if (resolvedPath === null) return null;
15225
15225
  const existing = await readFileSafe(join(projectRoot, resolvedPath));
15226
15226
  const pendingIdx = results.findIndex((r) => r.path === resolvedPath && r.target === target19);
15227
15227
  const pendingResult = pendingIdx >= 0 ? results[pendingIdx] : void 0;
15228
- const content = options?.mergeContent?.(existing, pendingResult, out.content, resolvedPath) ?? out.content;
15228
+ const content = options?.mergeContent?.(existing, pendingResult, out2.content, resolvedPath) ?? out2.content;
15229
15229
  if (pendingIdx >= 0) {
15230
15230
  results.splice(pendingIdx, 1);
15231
15231
  }
@@ -15251,8 +15251,8 @@ async function generateFeature(results, targets, canonical, projectRoot, enabled
15251
15251
  const gen = getGen(target19);
15252
15252
  if (!gen) continue;
15253
15253
  const ctx = featureContext(target19, feature, scope);
15254
- for (const out of gen(canonical, ctx)) {
15255
- const resolvedPath = await emitGeneratedOutput(results, target19, out, projectRoot, scope);
15254
+ for (const out2 of gen(canonical, ctx)) {
15255
+ const resolvedPath = await emitGeneratedOutput(results, target19, out2, projectRoot, scope);
15256
15256
  if (resolvedPath === null) continue;
15257
15257
  const layout = getTargetLayout(target19, scope);
15258
15258
  if (layout?.mirrorGlobalPath) {
@@ -15263,9 +15263,9 @@ async function generateFeature(results, targets, canonical, projectRoot, enabled
15263
15263
  results.push({
15264
15264
  target: target19,
15265
15265
  path: mirrorPath,
15266
- content: out.content,
15266
+ content: out2.content,
15267
15267
  currentContent: existingMirror ?? void 0,
15268
- status: computeStatus6(existingMirror, out.content)
15268
+ status: computeStatus6(existingMirror, out2.content)
15269
15269
  });
15270
15270
  }
15271
15271
  }
@@ -15316,8 +15316,8 @@ async function generatePermissionsFeature(results, targets, canonical, projectRo
15316
15316
  for (const target19 of targets) {
15317
15317
  const gen = resolveTargetFeatureGenerator(target19, "permissions", void 0, scope) ?? getDescriptor(target19)?.generators.generatePermissions;
15318
15318
  if (!gen) continue;
15319
- for (const out of gen(canonical)) {
15320
- await emitGeneratedOutput(results, target19, out, projectRoot, scope, {
15319
+ for (const out2 of gen(canonical)) {
15320
+ await emitGeneratedOutput(results, target19, out2, projectRoot, scope, {
15321
15321
  mergeContent: (existing, pending, newContent, resolvedPath) => mergeOutputContent(target19, existing, pending, newContent, resolvedPath)
15322
15322
  });
15323
15323
  }
@@ -15334,8 +15334,8 @@ async function generateHooksFeature(results, targets, canonical, projectRoot, sc
15334
15334
  if (post) {
15335
15335
  outputs = [...await post(projectRoot, canonical, outputs)];
15336
15336
  }
15337
- for (const out of outputs) {
15338
- await emitGeneratedOutput(results, target19, out, projectRoot, scope, {
15337
+ for (const out2 of outputs) {
15338
+ await emitGeneratedOutput(results, target19, out2, projectRoot, scope, {
15339
15339
  mergeContent: (existing, pending, newContent, resolvedPath) => mergeOutputContent(target19, existing, pending, newContent, resolvedPath)
15340
15340
  });
15341
15341
  }
@@ -15348,8 +15348,8 @@ async function generateScopedSettingsFeature(results, targets, canonical, projec
15348
15348
  if (!emit) continue;
15349
15349
  const outputs = emit(canonical, scope);
15350
15350
  if (outputs.length === 0) continue;
15351
- for (const out of outputs) {
15352
- await emitGeneratedOutput(results, target19, out, projectRoot, scope, {
15351
+ for (const out2 of outputs) {
15352
+ await emitGeneratedOutput(results, target19, out2, projectRoot, scope, {
15353
15353
  mergeContent: (existing, pending, newContent, resolvedPath) => mergeOutputContent(target19, existing, pending, newContent, resolvedPath)
15354
15354
  });
15355
15355
  }
@@ -15479,6 +15479,11 @@ var C = {
15479
15479
  cyan: "\x1B[36m",
15480
15480
  reset: "\x1B[0m"
15481
15481
  };
15482
+ function out(text) {
15483
+ {
15484
+ process.stdout.write(text);
15485
+ }
15486
+ }
15482
15487
  function noColor() {
15483
15488
  return process.env.NO_COLOR !== void 0 && process.env.NO_COLOR !== "";
15484
15489
  }
@@ -15491,7 +15496,7 @@ function pad(str, width) {
15491
15496
  }
15492
15497
  var logger = {
15493
15498
  info(msg) {
15494
- process.stdout.write(c(C.cyan, msg) + "\n");
15499
+ out(c(C.cyan, msg) + "\n");
15495
15500
  },
15496
15501
  warn(msg) {
15497
15502
  process.stderr.write(c(C.yellow, "\u26A0 ") + msg + "\n");
@@ -15500,11 +15505,11 @@ var logger = {
15500
15505
  process.stderr.write(c(C.red, "\u2717 ") + msg + "\n");
15501
15506
  },
15502
15507
  success(msg) {
15503
- process.stdout.write(c(C.green, "\u2713 ") + msg + "\n");
15508
+ out(c(C.green, "\u2713 ") + msg + "\n");
15504
15509
  },
15505
15510
  debug(msg) {
15506
15511
  if (process.env.AGENTSMESH_DEBUG === "1") {
15507
- process.stdout.write(c(C.cyan, "[debug] ") + msg + "\n");
15512
+ out(c(C.cyan, "[debug] ") + msg + "\n");
15508
15513
  }
15509
15514
  },
15510
15515
  table(rows) {
@@ -15520,13 +15525,13 @@ var logger = {
15520
15525
  widths[j] = max;
15521
15526
  }
15522
15527
  const border = "+" + widths.map((w) => "-".repeat(w + 2)).join("+") + "+";
15523
- process.stdout.write(border + "\n");
15528
+ out(border + "\n");
15524
15529
  for (let i = 0; i < rows.length; i++) {
15525
15530
  const row = rows[i];
15526
15531
  const line = "| " + row.map((cell, j) => pad(cell, widths[j])).join(" | ") + " |";
15527
- process.stdout.write(line + "\n");
15532
+ out(line + "\n");
15528
15533
  }
15529
- process.stdout.write(border + "\n");
15534
+ out(border + "\n");
15530
15535
  }
15531
15536
  };
15532
15537
 
@@ -16412,12 +16417,60 @@ function parseServer(raw) {
16412
16417
  env
16413
16418
  };
16414
16419
  }
16420
+ function stripJsonComments(text) {
16421
+ let result = "";
16422
+ let i = 0;
16423
+ const len = text.length;
16424
+ while (i < len) {
16425
+ const ch = text[i];
16426
+ if (ch === '"') {
16427
+ result += ch;
16428
+ i++;
16429
+ while (i < len) {
16430
+ const sc = text[i];
16431
+ result += sc;
16432
+ if (sc === "\\") {
16433
+ i++;
16434
+ if (i < len) {
16435
+ result += text[i];
16436
+ }
16437
+ } else if (sc === '"') {
16438
+ break;
16439
+ }
16440
+ i++;
16441
+ }
16442
+ i++;
16443
+ continue;
16444
+ }
16445
+ if (ch === "/" && text[i + 1] === "*") {
16446
+ i += 2;
16447
+ while (i < len) {
16448
+ if (text[i] === "*" && text[i + 1] === "/") {
16449
+ i += 2;
16450
+ break;
16451
+ }
16452
+ i++;
16453
+ }
16454
+ continue;
16455
+ }
16456
+ if (ch === "/" && text[i + 1] === "/") {
16457
+ i += 2;
16458
+ while (i < len && text[i] !== "\n") {
16459
+ i++;
16460
+ }
16461
+ continue;
16462
+ }
16463
+ result += ch;
16464
+ i++;
16465
+ }
16466
+ return result;
16467
+ }
16415
16468
  async function parseMcp(mcpPath) {
16416
16469
  const content = await readFileSafe(mcpPath);
16417
16470
  if (!content) return null;
16418
16471
  let parsed;
16419
16472
  try {
16420
- parsed = JSON.parse(content);
16473
+ parsed = JSON.parse(stripJsonComments(content));
16421
16474
  } catch {
16422
16475
  return null;
16423
16476
  }
@@ -16619,14 +16672,14 @@ function mergeHooks(base, overlay) {
16619
16672
  }
16620
16673
  function mergeIgnore(base, overlay) {
16621
16674
  const seen = new Set(base);
16622
- const out = [...base];
16675
+ const out2 = [...base];
16623
16676
  for (const p of overlay) {
16624
16677
  if (!seen.has(p)) {
16625
16678
  seen.add(p);
16626
- out.push(p);
16679
+ out2.push(p);
16627
16680
  }
16628
16681
  }
16629
- return out;
16682
+ return out2;
16630
16683
  }
16631
16684
 
16632
16685
  // src/config/resolve/native-format-detector.ts
@@ -17165,15 +17218,35 @@ async function loadCanonicalWithExtends(config, configDir, options = {}, canonic
17165
17218
  // src/plugins/load-plugin.ts
17166
17219
  init_target_descriptor_schema();
17167
17220
  init_registry();
17221
+ function resolveNpmSpecifier(source, projectRoot) {
17222
+ const pkgDir = join(projectRoot, "node_modules", source);
17223
+ const pkgJsonPath = join(pkgDir, "package.json");
17224
+ if (!existsSync(pkgJsonPath)) {
17225
+ throw new Error(`Cannot find package '${source}' in ${join(projectRoot, "node_modules")}`);
17226
+ }
17227
+ const pkgJson = JSON.parse(readFileSync(pkgJsonPath, "utf-8"));
17228
+ const entry = (typeof pkgJson.exports === "string" ? pkgJson.exports : null) ?? (typeof pkgJson.main === "string" ? pkgJson.main : null) ?? "index.js";
17229
+ const resolved = resolve(pkgDir, entry);
17230
+ if (!existsSync(resolved)) {
17231
+ throw new Error(`Package '${source}' entry '${entry}' does not exist at ${resolved}`);
17232
+ }
17233
+ return resolved;
17234
+ }
17235
+ function isLocalSource(source) {
17236
+ return source.startsWith("file:") || source.startsWith("./") || source.startsWith("../") || source.startsWith("/") || // Windows absolute paths: `D:\foo`, `C:/bar`, etc. `node:path`'s `resolve()` produces
17237
+ // these on win32, and they must not be misinterpreted as bare npm package names.
17238
+ /^[A-Za-z]:[/\\]/.test(source);
17239
+ }
17168
17240
  async function importPluginModule(entry, projectRoot) {
17169
17241
  const { source } = entry;
17170
17242
  let importTarget;
17171
- if (source.startsWith("file:") || source.startsWith("./") || source.startsWith("../") || source.startsWith("/")) {
17243
+ if (isLocalSource(source)) {
17172
17244
  const raw = source.startsWith("file:") ? fileURLToPath(source) : source;
17173
17245
  const resolved = resolve(projectRoot, raw);
17174
17246
  importTarget = pathToFileURL(resolved).href;
17175
17247
  } else {
17176
- importTarget = source;
17248
+ const resolved = resolveNpmSpecifier(source, projectRoot);
17249
+ importTarget = pathToFileURL(resolved).href;
17177
17250
  }
17178
17251
  const mod = await import(importTarget);
17179
17252
  return mod;
@@ -17337,13 +17410,13 @@ var PROBES = [
17337
17410
  ];
17338
17411
  function lintSilentFeatureDrops(input) {
17339
17412
  const enabled = new Set(input.enabledFeatures);
17340
- const out = [];
17413
+ const out2 = [];
17341
17414
  for (const probe of PROBES) {
17342
17415
  if (!enabled.has(probe.featureFlag)) continue;
17343
17416
  if (!probe.hasContent(input.canonical)) continue;
17344
17417
  const cap2 = normalizeCapabilityValue(input.capabilities[probe.capabilityKey]);
17345
17418
  if (cap2.level !== "none") continue;
17346
- out.push(
17419
+ out2.push(
17347
17420
  createWarning(
17348
17421
  probe.file,
17349
17422
  input.target,
@@ -17351,7 +17424,7 @@ function lintSilentFeatureDrops(input) {
17351
17424
  )
17352
17425
  );
17353
17426
  }
17354
- return out;
17427
+ return out2;
17355
17428
  }
17356
17429
 
17357
17430
  // src/core/lint/shared/hook-script-references.ts
@@ -17366,14 +17439,14 @@ function lintHookScriptReferences(input) {
17366
17439
  if (input.hasScriptProjection) return [];
17367
17440
  const hooks = input.canonical.hooks;
17368
17441
  if (!hooks) return [];
17369
- const out = [];
17442
+ const out2 = [];
17370
17443
  for (const entries of Object.values(hooks)) {
17371
17444
  if (!Array.isArray(entries)) continue;
17372
17445
  for (const entry of entries) {
17373
17446
  if (typeof entry?.command !== "string") continue;
17374
17447
  const token = extractScriptToken(entry.command);
17375
17448
  if (!token) continue;
17376
- out.push(
17449
+ out2.push(
17377
17450
  createWarning(
17378
17451
  ".agentsmesh/hooks.yaml",
17379
17452
  input.target,
@@ -17382,19 +17455,19 @@ function lintHookScriptReferences(input) {
17382
17455
  );
17383
17456
  }
17384
17457
  }
17385
- return out;
17458
+ return out2;
17386
17459
  }
17387
17460
 
17388
17461
  // src/core/lint/shared/rule-scope-inversion.ts
17389
17462
  init_helpers();
17390
17463
  function lintRuleScopeInversion(input) {
17391
17464
  if (input.preservesManualActivation) return [];
17392
- const out = [];
17465
+ const out2 = [];
17393
17466
  for (const rule of input.canonical.rules) {
17394
17467
  if (rule.root) continue;
17395
17468
  if (rule.trigger !== "manual") continue;
17396
17469
  if (rule.targets.length > 0 && !rule.targets.includes(input.target)) continue;
17397
- out.push(
17470
+ out2.push(
17398
17471
  createWarning(
17399
17472
  rule.source,
17400
17473
  input.target,
@@ -17402,7 +17475,7 @@ function lintRuleScopeInversion(input) {
17402
17475
  )
17403
17476
  );
17404
17477
  }
17405
- return out;
17478
+ return out2;
17406
17479
  }
17407
17480
 
17408
17481
  // src/core/lint/linter.ts