@rbbtsn0w/adg 0.5.0-beta.4 → 0.5.0-beta.5

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/bin/adg.js CHANGED
@@ -3,7 +3,7 @@ import { spawnSync } from "node:child_process";
3
3
  import { readFileSync, realpathSync } from "node:fs";
4
4
  import { dirname, join, resolve } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
- import { selfUpdateCommand, parseSelfUpdateArgs, SELF_UPDATE_USAGE } from "../src/self-update.js";
6
+ import { selfUpdateCommand, parseSelfUpdateArgs, SELF_UPDATE_USAGE, selfUpdateSpawnOptions } from "../src/self-update.js";
7
7
  import { checkForUpdate, formatUpdateNotice } from "../src/update-check.js";
8
8
  import { ui } from "../src/render/ui.js";
9
9
  import { TOP_USAGE, fail } from "../src/cli/index.js";
@@ -63,7 +63,11 @@ function runSelfUpdate(args) {
63
63
  return 0;
64
64
  }
65
65
  const command = selfUpdateCommand(options.beta);
66
- const r = spawnSync(command.command, command.args, { stdio: "inherit" });
66
+ const r = spawnSync(command.command, command.args, selfUpdateSpawnOptions());
67
+ if (r.error) {
68
+ console.error(r.error.message);
69
+ return 1;
70
+ }
67
71
  return r.status ?? 1;
68
72
  }
69
73
  /**
@@ -10,6 +10,76 @@ import { getTracer, sanitizeArgs } from "../telemetry.js";
10
10
  export function skippedResult(agent) {
11
11
  return { agent, affected: [], skipped: true };
12
12
  }
13
+ function clipText(value, max = 512) {
14
+ return value.length <= max ? value : `${value.slice(0, max - 1)}…`;
15
+ }
16
+ function summarizeFailure(r) {
17
+ const stderr = r.stderr?.trim();
18
+ if (stderr)
19
+ return { stream: "stderr", text: clipText(stderr) };
20
+ const stdout = r.stdout?.trim();
21
+ if (stdout)
22
+ return { stream: "stdout", text: clipText(stdout) };
23
+ return undefined;
24
+ }
25
+ function recordFailureExcerpt(span, summary) {
26
+ if (!summary)
27
+ return;
28
+ span.setAttribute(summary.stream === "stderr" ? "cli.stderr_excerpt" : "cli.stdout_excerpt", summary.text);
29
+ }
30
+ /**
31
+ * Record CLI process telemetry in one place so success/failure semantics stay
32
+ * consistent across every agent wrapper.
33
+ */
34
+ export function annotateCliRun(span, bin, args, r) {
35
+ if (r.pid !== undefined) {
36
+ span.setAttribute("process.pid", r.pid);
37
+ }
38
+ if (r.status !== null) {
39
+ span.setAttribute("process.exit.code", r.status);
40
+ if (r.status !== 0) {
41
+ const summary = summarizeFailure(r);
42
+ const command = sanitizeArgs([bin, ...args]).join(" ");
43
+ const message = summary ? `${command} exited with status ${r.status}: ${summary.text}` : `${command} exited with status ${r.status}`;
44
+ span.setAttribute("error.type", `EXIT_CODE_${r.status}`);
45
+ span.setAttribute("exception.slug", "cli-nonzero-exit");
46
+ recordFailureExcerpt(span, summary);
47
+ span.recordException(new Error(message));
48
+ span.setStatus({
49
+ code: SpanStatusCode.ERROR,
50
+ message,
51
+ });
52
+ }
53
+ return;
54
+ }
55
+ if (r.signal) {
56
+ const summary = summarizeFailure(r);
57
+ const command = sanitizeArgs([bin, ...args]).join(" ");
58
+ const message = summary ? `${command} terminated by signal ${r.signal}: ${summary.text}` : `${command} terminated by signal ${r.signal}`;
59
+ span.setAttribute("process.exit.code", -1);
60
+ span.setAttribute("process.exit.signal", r.signal);
61
+ span.setAttribute("error.type", `SIGNAL_${r.signal}`);
62
+ span.setAttribute("exception.slug", "cli-signal-exit");
63
+ recordFailureExcerpt(span, summary);
64
+ span.recordException(new Error(message));
65
+ span.setStatus({
66
+ code: SpanStatusCode.ERROR,
67
+ message,
68
+ });
69
+ return;
70
+ }
71
+ if (r.error) {
72
+ const errCode = r.error.code;
73
+ span.setAttribute("process.exit.code", -1);
74
+ span.setAttribute("error.type", (typeof errCode === "string" || typeof errCode === "number" ? String(errCode) : null) || r.error.name || "SpawnError");
75
+ span.setAttribute("exception.slug", "cli-spawn-failure");
76
+ span.recordException(r.error);
77
+ span.setStatus({
78
+ code: SpanStatusCode.ERROR,
79
+ message: r.error.message,
80
+ });
81
+ }
82
+ }
13
83
  /**
14
84
  * Build the shared `available()` / `run()` pair for an agent that drives an
15
85
  * external plugin CLI. Centralizing the `spawnSync` here keeps error handling,
@@ -32,29 +102,7 @@ export function makeCli(bin, opts) {
32
102
  span.setAttribute("process.executable.name", bin);
33
103
  span.setAttribute("process.command_args", sanitizeArgs([bin, ...args]));
34
104
  const r = spawnSync(bin, args, { encoding: "utf8" });
35
- if (r.pid !== undefined) {
36
- span.setAttribute("process.pid", r.pid);
37
- }
38
- if (r.status !== null) {
39
- span.setAttribute("process.exit.code", r.status);
40
- if (r.status !== 0) {
41
- span.setAttribute("error.type", `EXIT_CODE_${r.status}`);
42
- span.setStatus({
43
- code: SpanStatusCode.ERROR,
44
- message: `Command exited with non-zero status ${r.status}`,
45
- });
46
- }
47
- }
48
- else if (r.error) {
49
- span.setAttribute("process.exit.code", -1);
50
- const errCode = r.error.code;
51
- span.setAttribute("error.type", (typeof errCode === "string" || typeof errCode === "number" ? String(errCode) : null) || r.error.name || "SpawnError");
52
- span.recordException(r.error);
53
- span.setStatus({
54
- code: SpanStatusCode.ERROR,
55
- message: r.error.message,
56
- });
57
- }
105
+ annotateCliRun(span, bin, args, r);
58
106
  const ok = r.status === 0 && !r.error;
59
107
  if (!ok && opts.echoStderr) {
60
108
  if (r.error)
@@ -74,11 +74,37 @@ export function writeClaudeCatalog(pluginsDir, name = claudeMarketplaceName(plug
74
74
  writeJson(file, catalog);
75
75
  return { file, name };
76
76
  }
77
- /** Register the ADG store as a Claude marketplace (add, or update if present). */
78
- function syncMarketplace(pluginsDir, name) {
79
- const update = run(["plugin", "marketplace", "update", name]);
80
- if (!update.ok)
81
- run(["plugin", "marketplace", "add", pluginsDir]);
77
+ /** Parse `claude plugin marketplace list --json` into configured marketplace names. */
78
+ export function parseClaudeMarketplaceList(out) {
79
+ try {
80
+ const parsed = JSON.parse(out);
81
+ if (!Array.isArray(parsed))
82
+ return [];
83
+ return parsed
84
+ .map((entry) => {
85
+ if (typeof entry !== "object" || entry === null)
86
+ return undefined;
87
+ const name = entry["name"];
88
+ return typeof name === "string" ? name : undefined;
89
+ })
90
+ .filter((name) => Boolean(name));
91
+ }
92
+ catch {
93
+ return [];
94
+ }
95
+ }
96
+ /** Register or refresh the ADG store as a Claude marketplace, failing open. */
97
+ export function syncMarketplace(pluginsDir, name, runner = run) {
98
+ const listed = runner(["plugin", "marketplace", "list", "--json"]);
99
+ if (listed.ok && parseClaudeMarketplaceList(listed.out).includes(name)) {
100
+ // Claude's marketplace update path can fail on existing installs (for
101
+ // example, merge-conflict-style failures on older CLI builds). When that
102
+ // happens, fall back to re-adding the marketplace so the refresh remains
103
+ // best-effort instead of surfacing a hard EXIT_CODE_1 in the ADG timeline.
104
+ if (runner(["plugin", "marketplace", "update", name]).ok)
105
+ return;
106
+ }
107
+ runner(["plugin", "marketplace", "add", pluginsDir]);
82
108
  }
83
109
  export const claudeAgent = {
84
110
  id: "claude",
@@ -214,13 +214,13 @@ function sameRemoteSource(entry, parsed, ref) {
214
214
  * (`--plugin one` after previously installing `--all`) without leaving stale
215
215
  * runtime exports behind.
216
216
  */
217
- function reconcileRemotePlugins(opts, parsed, ref, desired) {
217
+ function reconcileRemotePlugins(opts, parsed, ref, narrowed, desired) {
218
218
  if (parsed.kind === "local")
219
219
  return [];
220
220
  // A path/sparse install does not prove the full source shape, so it must not
221
221
  // prune sibling plugins from the same repo that were intentionally excluded
222
222
  // from the checkout/selection window.
223
- if (opts.path || opts.sparse?.length)
223
+ if (narrowed || opts.sparse?.length)
224
224
  return [];
225
225
  const lock = readLock(lockPath(opts.pluginsDir));
226
226
  const stale = Object.entries(lock.plugins)
@@ -255,6 +255,8 @@ function reconcileRemotePlugins(opts, parsed, ref, desired) {
255
255
  export async function addPlugins(opts) {
256
256
  const parsed = parseSource(opts.spec);
257
257
  const sourceRef = parsed.kind === "local" ? undefined : (opts.ref ?? parsed.ref);
258
+ const inferredPath = parsed.kind === "github" ? parsed.path : undefined;
259
+ const path = opts.path ?? inferredPath;
258
260
  let workRoot;
259
261
  let buildOrigin;
260
262
  let cleanup;
@@ -279,7 +281,7 @@ export async function addPlugins(opts) {
279
281
  if (candidates.size === 0) {
280
282
  throw new Error(`no plugin found in "${opts.spec}" (no .agents/.plugin.json, .claude-plugin or .codex-plugin manifest).`);
281
283
  }
282
- const selected = await selectPluginNames(opts, candidates, workRoot, converted);
284
+ const selected = await selectPluginNames({ ...opts, path }, candidates, workRoot, converted);
283
285
  // Resolve adapter targets after the plugin choice (lets a CLI agent picker
284
286
  // run once we know what's being installed). undefined → installPlugin's all.
285
287
  const targets = opts.targets ?? (opts.selectTargets ? await opts.selectTargets() : undefined);
@@ -289,7 +291,7 @@ export async function addPlugins(opts) {
289
291
  // upstream: don't abort — return what the source still offers so the
290
292
  // caller can report the deletions.
291
293
  if (opts.missingPlugins === "skip") {
292
- const removed = reconcileRemotePlugins(opts, parsed, sourceRef, new Set(selected));
294
+ const removed = reconcileRemotePlugins(opts, parsed, sourceRef, Boolean(path), new Set(selected));
293
295
  return { order: [], installed: [], removed, converted, available };
294
296
  }
295
297
  throw new Error("no plugins selected");
@@ -308,7 +310,7 @@ export async function addPlugins(opts) {
308
310
  }
309
311
  }
310
312
  }
311
- const removed = reconcileRemotePlugins(opts, parsed, sourceRef, new Set(order));
313
+ const removed = reconcileRemotePlugins(opts, parsed, sourceRef, Boolean(path), new Set(order));
312
314
  // Snapshot which plugins already existed before this call mutates the lock,
313
315
  // so the activation step below can tell brand-new installs from updates.
314
316
  const existingPlugins = new Set(Object.keys(readLock(lockPath(opts.pluginsDir)).plugins));
@@ -26,8 +26,16 @@ export function selfUpdateCommand(beta, npmBin = "npm") {
26
26
  args: ["install", "-g", `${PACKAGE_NAME}@${selfUpdateTarget(beta)}`],
27
27
  };
28
28
  }
29
+ export function selfUpdateSpawnOptions(platform = process.platform) {
30
+ return { stdio: "inherit", shell: platform === "win32" };
31
+ }
29
32
  export function selfUpdateHint(latestVersion) {
30
- return prereleaseChannel(latestVersion) ? "adg update --beta" : "adg update";
33
+ const channel = prereleaseChannel(latestVersion);
34
+ if (channel === "beta")
35
+ return "adg update --beta";
36
+ if (channel)
37
+ return `npm install -g ${PACKAGE_NAME}@${latestVersion}`;
38
+ return "adg update";
31
39
  }
32
40
  export const SELF_UPDATE_USAGE = `adg update — upgrade the ADG CLI
33
41
 
@@ -6,6 +6,31 @@ import { SpanKind, SpanStatusCode } from "@opentelemetry/api";
6
6
  import { getTracer, sanitizeArgs } from "./telemetry.js";
7
7
  const GH_SHORTHAND = /^([\w.-]+)\/([\w.-]+?)(?:@(.+))?$/;
8
8
  const GH_URL = /^(?:https?:\/\/github\.com\/|git@github\.com:)([\w.-]+)\/([\w.-]+?)(?:\.git)?(?:@(.+))?$/;
9
+ const GH_BLOB_URL = /^(?:https?:\/\/github\.com\/)([\w.-]+)\/([\w.-]+?)(?:\.git)?\/(?:blob|tree)\/([^/]+)\/(.+)$/;
10
+ function stripKnownManifestSuffix(path) {
11
+ const normalized = path.replace(/\\/g, "/");
12
+ const suffixes = [
13
+ ".agents/.plugin.json",
14
+ ".claude-plugin/plugin.json",
15
+ ".codex-plugin/plugin.json",
16
+ ".adg-plugin/plugin.json",
17
+ ];
18
+ for (const suffix of suffixes) {
19
+ if (normalized === suffix)
20
+ return "";
21
+ if (normalized.endsWith(`/${suffix}`))
22
+ return normalized.slice(0, -(suffix.length + 1));
23
+ }
24
+ return normalized;
25
+ }
26
+ function decodeGitHubUrlPart(value) {
27
+ try {
28
+ return decodeURIComponent(value);
29
+ }
30
+ catch {
31
+ return value;
32
+ }
33
+ }
9
34
  /**
10
35
  * Parse an install spec into a local directory or a GitHub source.
11
36
  *
@@ -15,12 +40,20 @@ const GH_URL = /^(?:https?:\/\/github\.com\/|git@github\.com:)([\w.-]+)\/([\w.-]
15
40
  export function parseSource(spec) {
16
41
  if (existsSync(spec))
17
42
  return { kind: "local", dir: spec };
18
- const url = spec.match(GH_URL);
43
+ const clean = spec.replace(/[?#].*$/, "");
44
+ const blob = clean.match(GH_BLOB_URL);
45
+ if (blob) {
46
+ const [, owner, repo, ref, path] = blob;
47
+ const decodedRef = decodeGitHubUrlPart(ref);
48
+ const decodedPath = decodeGitHubUrlPart(path);
49
+ return { ...gh(owner, repo, decodedRef), path: stripKnownManifestSuffix(decodedPath) };
50
+ }
51
+ const url = clean.match(GH_URL);
19
52
  if (url) {
20
53
  const [, owner, repo, ref] = url;
21
54
  return gh(owner, repo, ref);
22
55
  }
23
- const short = spec.match(GH_SHORTHAND);
56
+ const short = clean.match(GH_SHORTHAND);
24
57
  if (short) {
25
58
  const [, owner, repo, ref] = short;
26
59
  return gh(owner, repo, ref);
@@ -158,7 +158,9 @@ export function checkForUpdate(currentVersion, env = process.env, refresh = sche
158
158
  }
159
159
  /** Format an update notice for display on stderr. */
160
160
  export function formatUpdateNotice(currentVersion, latestVersion) {
161
+ const channel = prereleaseChannel(latestVersion);
162
+ const npmTarget = channel ? latestVersion : "latest";
161
163
  return (`\n Update available: ${currentVersion} → ${latestVersion}\n` +
162
164
  ` Run: ${selfUpdateHint(latestVersion)}\n` +
163
- ` npm: npm install -g ${PACKAGE_NAME}@${prereleaseChannel(latestVersion) ? "beta" : "latest"}\n`);
165
+ ` npm: npm install -g ${PACKAGE_NAME}@${npmTarget}\n`);
164
166
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbbtsn0w/adg",
3
- "version": "0.5.0-beta.4",
3
+ "version": "0.5.0-beta.5",
4
4
  "description": "Agent Directory Group (ADG) toolkit — two domains: plugins and skills.",
5
5
  "type": "module",
6
6
  "license": "MIT",