@rbbtsn0w/adg 0.7.1-beta.2 → 0.7.1-beta.4

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.
@@ -1,9 +1,10 @@
1
1
  import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { join, resolve } from "node:path";
3
3
  import { isExposed } from "../components.js";
4
- import { mcpConfigPath } from "../mcp.js";
4
+ import { extractMcpServers, mcpConfigPath } from "../mcp.js";
5
5
  export const ANTIGRAVITY_MCP_CONFIG = "mcp_config.json";
6
6
  const ANTIGRAVITY_MCP_SERVER_KEYS = new Set([
7
+ "type",
7
8
  "command",
8
9
  "serverUrl",
9
10
  "args",
@@ -40,15 +41,12 @@ function toAntigravityMcpConfig(source) {
40
41
  const parsed = JSON.parse(readFileSync(source, "utf8"));
41
42
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
42
43
  return parsed;
43
- const config = parsed;
44
- const servers = config.mcpServers ?? config.servers;
45
- if (!servers || typeof servers !== "object" || Array.isArray(servers))
46
- return config;
44
+ const servers = extractMcpServers(parsed);
45
+ if (!servers)
46
+ return parsed;
47
47
  const projected = {
48
- ...config,
49
48
  mcpServers: {},
50
49
  };
51
- delete projected.servers;
52
50
  for (const [name, value] of Object.entries(servers)) {
53
51
  projected.mcpServers[name] = toAntigravityMcpServer(value);
54
52
  }
@@ -355,13 +355,18 @@ export async function addPlugins(opts) {
355
355
  try {
356
356
  let { candidates, converted } = discoverPlugins(workRoot);
357
357
  const existingLock = readLock(lockPath(opts.pluginsDir));
358
- if (candidates.size > 0 && opts.as) {
359
- throw new Error("--as is only supported for a default structural plugin source");
358
+ if (candidates.size > 0) {
359
+ if (opts.structuralIdentity && !candidates.has(opts.structuralIdentity)) {
360
+ throw new Error(`source definition changed from Default DSL to explicit plugin(s), but none match the installed identity "${opts.structuralIdentity}"; re-add or migrate the plugin explicitly`);
361
+ }
362
+ if (opts.as && !opts.structuralIdentity) {
363
+ throw new Error("--as is only supported for a default structural plugin source");
364
+ }
360
365
  }
361
366
  if (candidates.size === 0) {
362
367
  if (parsed.kind === "github" && !opts.preparedSourceDir && !opts.defaultDescription)
363
368
  defaultDescription = await githubRepositoryDescription(parsed.source);
364
- const structuralIdentity = opts.as ?? (parsed.kind === "github" ? parsed.source : basename(workRoot));
369
+ const structuralIdentity = opts.as ?? opts.structuralIdentity ?? (parsed.kind === "github" ? parsed.source : basename(workRoot));
365
370
  const generated = resolveDefaultDsl(workRoot, {
366
371
  name: structuralIdentity,
367
372
  description: defaultDescription ?? opts.defaultDescription ?? structuralIdentity,
@@ -423,7 +428,9 @@ export async function addPlugins(opts) {
423
428
  }
424
429
  // A generated Default DSL replay retains its definition profile. Only an
425
430
  // explicit manifest discovered from the source may replace that profile.
426
- const definitionSwitches = definition ? [] : order.filter((name) => existingLock.plugins[name]?.definition);
431
+ const definitionSwitches = definition
432
+ ? []
433
+ : order.filter((name) => existingLock.plugins[name]?.definition && name !== opts.structuralIdentity);
427
434
  if (definitionSwitches.length > 0) {
428
435
  const names = definitionSwitches.sort().map((name) => `"${name}"`).join(", ");
429
436
  throw new Error(`source definition changed from default DSL to a manifest for ${names}; re-add or migrate the plugin explicitly`);
@@ -136,6 +136,7 @@ export async function updatePlugins(opts) {
136
136
  ...structural.map(({ name, definition, selection }) => ({
137
137
  plugins: [name],
138
138
  as: definition.as,
139
+ structuralIdentity: name,
139
140
  defaultDescription: definition.description,
140
141
  authorizedComponents: definition.authorizedComponents,
141
142
  replaySelection: selection ?? (definition.authorizedComponents ? { components: definition.authorizedComponents } : undefined),
@@ -163,6 +164,7 @@ export async function updatePlugins(opts) {
163
164
  skipUnchanged: true,
164
165
  nonInteractive: true,
165
166
  ...(request.authorizedComponents ? { authorizedComponents: request.authorizedComponents } : {}),
167
+ ...(request.structuralIdentity ? { structuralIdentity: request.structuralIdentity } : {}),
166
168
  ...(request.replaySelection ? { replaySelection: request.replaySelection } : {}),
167
169
  targets: opts.targets,
168
170
  marketplaceName: group.source,
@@ -2,7 +2,7 @@ import { existsSync, readFileSync, readdirSync } from "node:fs";
2
2
  import { basename, join } from "node:path";
3
3
  import { resolveSkills } from "./skills.js";
4
4
  import { COMPONENT_TYPES } from "./types.js";
5
- import { mcpConfigPath } from "./mcp.js";
5
+ import { extractMcpServers, mcpConfigPath } from "./mcp.js";
6
6
  export { COMPONENT_TYPES };
7
7
  /** Recursively collect regular (non-dotfile) file basenames, without extension. */
8
8
  function collectFiles(dir) {
@@ -39,14 +39,14 @@ function membersOf(dir, rel) {
39
39
  return files;
40
40
  return [fileMemberName(abs)]; // a single file
41
41
  }
42
- /** Server names declared in an MCP config file (mcpServers/servers map). */
42
+ /** Server names declared in an MCP config file (mcpServers/servers map or flat map). */
43
43
  function mcpServers(file) {
44
44
  if (!existsSync(file))
45
45
  return [];
46
46
  try {
47
47
  const json = JSON.parse(readFileSync(file, "utf8"));
48
- const servers = (json.mcpServers ?? json.servers);
49
- return servers && typeof servers === "object" ? Object.keys(servers).sort() : [];
48
+ const servers = extractMcpServers(json);
49
+ return servers ? Object.keys(servers).sort() : [];
50
50
  }
51
51
  catch {
52
52
  return [];
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
2
2
  import { existsSync, lstatSync, readFileSync, readdirSync } from "node:fs";
3
3
  import { join } from "node:path";
4
4
  import { ADG_SCHEMA_VERSION } from "./types.js";
5
+ import { extractMcpServers } from "./mcp.js";
5
6
  import { readSkillDescription } from "./skills.js";
6
7
  import { recordTelemetryEvent } from "./telemetry.js";
7
8
  /** Convert a repository directory name into the manifest's stable kebab-case identity. */
@@ -121,11 +122,13 @@ function isRegularFile(path) {
121
122
  function validMcp(file) {
122
123
  if (!validJson(file))
123
124
  return false;
124
- const json = JSON.parse(readFileSync(file, "utf8"));
125
- if (json === null || typeof json !== "object" || Array.isArray(json))
125
+ try {
126
+ const json = JSON.parse(readFileSync(file, "utf8"));
127
+ return extractMcpServers(json) !== undefined;
128
+ }
129
+ catch {
126
130
  return false;
127
- const servers = json.mcpServers ?? json.servers;
128
- return typeof servers === "object" && servers !== null && !Array.isArray(servers);
131
+ }
129
132
  }
130
133
  function hashTree(hasher, dir, rel) {
131
134
  for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) {
package/dist/src/mcp.js CHANGED
@@ -3,31 +3,52 @@ import { readFileSync, writeFileSync, existsSync } from "node:fs";
3
3
  export function mcpConfigPath(manifest) {
4
4
  return manifest.mcpServers;
5
5
  }
6
+ const MCP_SERVER_DISCRIMINATOR_KEYS = new Set([
7
+ "command",
8
+ "url",
9
+ "serverUrl",
10
+ "type",
11
+ "args",
12
+ "env",
13
+ "headers",
14
+ "http_headers",
15
+ "cwd",
16
+ ]);
17
+ function isMcpServerConfig(val) {
18
+ if (val === null || typeof val !== "object" || Array.isArray(val))
19
+ return false;
20
+ const obj = val;
21
+ return Object.keys(obj).some((k) => MCP_SERVER_DISCRIMINATOR_KEYS.has(k));
22
+ }
23
+ /** Extract the MCP servers map from canonical, legacy, or flat server map roots. */
24
+ export function extractMcpServers(json) {
25
+ if (json === null || typeof json !== "object" || Array.isArray(json))
26
+ return undefined;
27
+ const obj = json;
28
+ const servers = obj.mcpServers ?? obj.servers;
29
+ if (servers && typeof servers === "object" && !Array.isArray(servers)) {
30
+ return servers;
31
+ }
32
+ const keys = Object.keys(obj);
33
+ if (keys.length > 0) {
34
+ const isServerMap = keys.every((k) => isMcpServerConfig(obj[k]));
35
+ if (isServerMap)
36
+ return obj;
37
+ }
38
+ return undefined;
39
+ }
6
40
  /** Filter the servers defined in the MCP config file. */
7
41
  export function filterMcpConfig(file, allowedNames) {
8
42
  if (!existsSync(file))
9
43
  return;
10
44
  try {
11
45
  const json = JSON.parse(readFileSync(file, "utf8"));
12
- if (typeof json !== "object" || json === null) {
46
+ const servers = extractMcpServers(json);
47
+ if (!servers) {
13
48
  throw new Error("MCP config root must be an object");
14
49
  }
15
- // Find and validate all defined server names
16
- const definedNames = new Set();
17
- let hasMcpServersOrServers = false;
18
- for (const key of ["mcpServers", "servers"]) {
19
- const servers = json[key];
20
- if (servers !== undefined) {
21
- if (typeof servers !== "object" || servers === null || Array.isArray(servers)) {
22
- throw new Error(`MCP config "${key}" must be an object`);
23
- }
24
- hasMcpServersOrServers = true;
25
- for (const name of Object.keys(servers)) {
26
- definedNames.add(name);
27
- }
28
- }
29
- }
30
- if (allowedNames.length > 0 && !hasMcpServersOrServers) {
50
+ const definedNames = new Set(Object.keys(servers));
51
+ if (allowedNames.length > 0 && definedNames.size === 0) {
31
52
  throw new Error("MCP config does not define any servers");
32
53
  }
33
54
  const missing = allowedNames.filter((name) => !definedNames.has(name));
@@ -35,24 +56,31 @@ export function filterMcpConfig(file, allowedNames) {
35
56
  throw new Error(`selected mcp server(s) not declared: ${missing.join(", ")}`);
36
57
  }
37
58
  const allowed = new Set(allowedNames);
59
+ const newServers = {};
38
60
  let changed = false;
39
- for (const key of ["mcpServers", "servers"]) {
40
- const servers = json[key];
41
- if (servers && typeof servers === "object" && !Array.isArray(servers)) {
42
- const obj = servers;
43
- const newObj = {};
44
- for (const [name, config] of Object.entries(obj)) {
45
- if (allowed.has(name)) {
46
- newObj[name] = config;
47
- }
48
- else {
49
- changed = true;
50
- }
51
- }
52
- json[key] = newObj;
61
+ for (const [name, config] of Object.entries(servers)) {
62
+ if (allowed.has(name)) {
63
+ newServers[name] = config;
64
+ }
65
+ else {
66
+ changed = true;
53
67
  }
54
68
  }
55
69
  if (changed) {
70
+ const root = json;
71
+ if (root.mcpServers && typeof root.mcpServers === "object") {
72
+ root.mcpServers = newServers;
73
+ }
74
+ else if (root.servers && typeof root.servers === "object") {
75
+ root.servers = newServers;
76
+ }
77
+ else {
78
+ // Flat server map: update in-place
79
+ for (const key of Object.keys(root)) {
80
+ if (!allowed.has(key))
81
+ delete root[key];
82
+ }
83
+ }
56
84
  writeFileSync(file, JSON.stringify(json, null, 2), "utf8");
57
85
  }
58
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbbtsn0w/adg",
3
- "version": "0.7.1-beta.2",
3
+ "version": "0.7.1-beta.4",
4
4
  "description": "Agent Directory Group (ADG) toolkit — two domains: plugins and skills.",
5
5
  "type": "module",
6
6
  "license": "MIT",