@rbbtsn0w/adg 0.4.0-beta.2 → 0.4.0-beta.3

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.
@@ -21,7 +21,7 @@ import { globalPluginsDir, projectPluginsDir, lockPath } from "../paths.js";
21
21
  import { getAgent } from "../agents/index.js";
22
22
  import { ui } from "../render/ui.js";
23
23
  import { renderAgentReport, renderMarketplaceList, renderPluginList, renderStatus, renderUpdateReport, } from "../render/plugins.js";
24
- import { MARKETPLACE_USAGE, PLUGIN_ALIASES, PLUGIN_COMMANDS, SCOPE, fail, parseVerb, renderPluginsHelp, renderVerbHelp, requireSingleTarget, resolveComponents, resolveScopeDir, resolveTargets, scopeInfo, scopeOf, wantsHelp, } from "./index.js";
24
+ import { MARKETPLACE_USAGE, PLUGIN_ALIASES, PLUGIN_COMMANDS, SCOPE, fail, parseVerb, renderPluginsHelp, renderVerbHelp, requireSingleTarget, resolveComponents, resolveScopeDir, resolveTargets, scopeOf, wantsHelp, } from "./index.js";
25
25
  /**
26
26
  * Resolve which scope(s) `plugins update` should refresh, mirroring
27
27
  * `adg skills update`: an explicit --dir is a single ad-hoc location; otherwise
@@ -46,6 +46,13 @@ async function resolveUpdateScopes(values) {
46
46
  choice = await selectUpdateScopeInteractive();
47
47
  else
48
48
  choice = existsSync(lockPath(projectPluginsDir())) ? "project" : "global";
49
+ // Home==global trap: a "project" (or "both") scope whose store resolves to the
50
+ // global store would re-pin global plugins to the cwd. Collapse to global.
51
+ // Reuse the dirs already resolved above instead of walking the filesystem again.
52
+ if (choice !== "global" && project.dir === global.dir) {
53
+ console.error(ui.warn(`note: the project store resolves to the global store (${global.dir}); updating global only so plugins aren't pinned to a project (cwd) scope.`));
54
+ choice = "global";
55
+ }
49
56
  if (choice === "both") {
50
57
  return [{ ...project, heading: "Project plugins" }, { ...global, heading: "Global plugins" }];
51
58
  }
@@ -58,6 +65,70 @@ function printUpdateReport(result) {
58
65
  for (const line of renderAgentReport(result.agents, "re-synced"))
59
66
  console.log(line);
60
67
  }
68
+ /**
69
+ * A "project" store that resolves to the *global* store path is a trap: running
70
+ * a mutating verb there reads the global plugin set but writes the agent install
71
+ * at project scope, pinning it to the cwd (e.g. the home directory). Promote
72
+ * such a case to global. Pure so it is unit-testable.
73
+ */
74
+ export function projectStoreIsGlobalTrap(global, projectDir, globalDir) {
75
+ return !global && projectDir === globalDir;
76
+ }
77
+ /**
78
+ * Apply the home==global guard to a chosen scope: a project scope whose store
79
+ * resolves to the global store would pin plugins to the cwd (e.g. the home
80
+ * directory), so warn and promote it to global. Returns the effective global
81
+ * flag. Shared by every scope-resolving verb (add/update plus resolveActionScope)
82
+ * so the guard can't be forgotten on one path. Callers that already resolved the
83
+ * store dirs may pass them in to avoid recomputing the (filesystem-walking)
84
+ * `projectPluginsDir`. Exported for unit testing the promotion side effect.
85
+ */
86
+ export function promoteGlobalTrap(global, projectDir = projectPluginsDir(), globalDir = globalPluginsDir()) {
87
+ if (!projectStoreIsGlobalTrap(global, projectDir, globalDir))
88
+ return global;
89
+ console.error(ui.warn(`note: the project store resolves to the global store (${globalDir}); using --global so plugins aren't pinned to a project (cwd) scope.`));
90
+ return true;
91
+ }
92
+ /**
93
+ * Resolve scope for a mutating verb (sync/link/unlink/remove/migrate/…). Unlike
94
+ * the silent `resolveScopeDir`/`scopeOf`, this:
95
+ * - honors an explicit --dir/--global/--project,
96
+ * - rejects a contradictory --global + --project (a single-scope projection),
97
+ * - prompts (project/global) in a terminal when none was given,
98
+ * - fails in a non-interactive run rather than silently defaulting to project,
99
+ * - promotes the home==global trap to global with a warning.
100
+ */
101
+ async function resolveActionScope(values, verb) {
102
+ if (typeof values.dir === "string") {
103
+ // --dir is an explicit ad-hoc store; --global still selects the user agent
104
+ // scope (matching the old scopeOf behavior), the trap guard doesn't apply.
105
+ const dir = resolve(values.dir);
106
+ const global = Boolean(values.global);
107
+ return { pluginsDir: dir, global, agentScope: global ? "user" : "project", info: { label: dir, globalDir: globalPluginsDir() } };
108
+ }
109
+ if (values.global && values.project)
110
+ fail(`plugins ${verb} takes only one of --global / --project`);
111
+ let global;
112
+ if (values.global)
113
+ global = true;
114
+ else if (values.project)
115
+ global = false;
116
+ else if (process.stdin.isTTY)
117
+ global = await selectScopeInteractive();
118
+ else
119
+ fail(`plugins ${verb} needs an explicit scope in a non-interactive run: pass --global or --project`);
120
+ // Resolve the store dirs once (projectPluginsDir walks the filesystem) and
121
+ // reuse them for the trap guard, the store path, and the info label.
122
+ const projectDir = projectPluginsDir();
123
+ const globalDir = globalPluginsDir();
124
+ global = promoteGlobalTrap(global, projectDir, globalDir);
125
+ return {
126
+ pluginsDir: global ? globalDir : projectDir,
127
+ global,
128
+ agentScope: global ? "user" : "project",
129
+ info: { label: global ? "global" : "project", globalDir },
130
+ };
131
+ }
61
132
  /**
62
133
  * Top-level dispatcher for `adg plugins <verb>`: render help, resolve aliases,
63
134
  * look the verb up in the command table, then hand off to the per-verb handler
@@ -140,6 +211,10 @@ async function runPluginsVerb(verb, rest, cmd) {
140
211
  if (!values.dir && values.global === undefined && values.project === undefined && tty) {
141
212
  global = await selectScopeInteractive();
142
213
  }
214
+ // Guard the home==global trap: installing global plugins at project scope
215
+ // would pin them to the cwd. Skip for an explicit --dir store.
216
+ if (!values.dir)
217
+ global = promoteGlobalTrap(global);
143
218
  const pluginsDir = values.dir
144
219
  ? resolve(values.dir)
145
220
  : global
@@ -194,11 +269,12 @@ async function runPluginsVerb(verb, rest, cmd) {
194
269
  fail("plugins import-skills requires a <skills-dir>");
195
270
  if (!values.as)
196
271
  fail("plugins import-skills requires --as <plugin-name>");
272
+ const sc = await resolveActionScope(values, "import-skills");
197
273
  const res = importSkills({
198
274
  skillsDir: resolve(dir),
199
275
  as: values.as,
200
276
  prefix: values.prefix,
201
- pluginsDir: resolveScopeDir(values),
277
+ pluginsDir: sc.pluginsDir,
202
278
  description: values.description,
203
279
  });
204
280
  console.log(`${ui.ok("imported skills into")} ${ui.name(res.name)} ${ui.meta(`-> ${res.installedTo}`)}`);
@@ -209,9 +285,10 @@ async function runPluginsVerb(verb, rest, cmd) {
209
285
  const targets = values.target === "all"
210
286
  ? resolveTargets("all")
211
287
  : [requireSingleTarget(values.target, "link")];
288
+ const sc = await resolveActionScope(values, "link");
212
289
  const names = positionals.length > 0 ? positionals : undefined;
213
290
  for (const target of targets) {
214
- const res = linkPlugins({ pluginsDir: resolveScopeDir(values), target, global: Boolean(values.global), names });
291
+ const res = linkPlugins({ pluginsDir: sc.pluginsDir, target, global: sc.global, names });
215
292
  for (const a of res.actions) {
216
293
  console.log(`${ui.ok("linked")} ${ui.name(a.name)} ${ui.meta(`[${res.target}]`)}${a.linkedTo ? ui.meta(` -> ${a.linkedTo}`) : ""}`);
217
294
  for (const f of a.adapted)
@@ -228,9 +305,10 @@ async function runPluginsVerb(verb, rest, cmd) {
228
305
  const targets = values.target === "all"
229
306
  ? resolveTargets("all")
230
307
  : [requireSingleTarget(values.target, "unlink")];
308
+ const sc = await resolveActionScope(values, "unlink");
231
309
  const names = positionals.length > 0 ? positionals : undefined;
232
310
  for (const target of targets) {
233
- const res = unlinkPlugins({ pluginsDir: resolveScopeDir(values), target, global: Boolean(values.global), names });
311
+ const res = unlinkPlugins({ pluginsDir: sc.pluginsDir, target, global: sc.global, names });
234
312
  for (const name of res.unlinked)
235
313
  console.log(`${ui.ok("unlinked")} ${ui.name(name)} ${ui.meta(`[${res.target}]`)}`);
236
314
  if (res.cliSkipped) {
@@ -249,9 +327,10 @@ async function runPluginsVerb(verb, rest, cmd) {
249
327
  const targets = values.target === "all"
250
328
  ? resolveTargets("all")
251
329
  : [requireSingleTarget(values.target, "sync")];
330
+ const sc = await resolveActionScope(values, "sync");
252
331
  const names = positionals.length > 0 ? positionals : undefined;
253
332
  for (const target of targets) {
254
- const res = syncPlugins({ pluginsDir: resolveScopeDir(values), target, global: Boolean(values.global), names });
333
+ const res = syncPlugins({ pluginsDir: sc.pluginsDir, target, global: sc.global, names });
255
334
  for (const a of res.actions) {
256
335
  const tail = a.synced ? ui.meta(` -> ${res.target}`) : "";
257
336
  console.log(`${ui.ok("synced")} ${ui.name(a.name)} ${ui.meta(`[${res.target}]`)}${tail}`);
@@ -290,12 +369,13 @@ async function runPluginsVerb(verb, rest, cmd) {
290
369
  const name = positionals[0];
291
370
  if (!name)
292
371
  fail("plugins remove requires a <name>");
372
+ const sc = await resolveActionScope(values, "remove");
293
373
  const res = removePlugin({
294
- pluginsDir: resolveScopeDir(values),
374
+ pluginsDir: sc.pluginsDir,
295
375
  name,
296
376
  force: values.force,
297
377
  deactivate: true,
298
- scope: scopeOf(values),
378
+ scope: sc.agentScope,
299
379
  });
300
380
  if (res.removedDir)
301
381
  console.log(`${ui.ok("removed")} ${ui.name(res.name)} ${ui.meta(`-> ${res.removedDir}`)}`);
@@ -337,7 +417,8 @@ async function runPluginsVerb(verb, rest, cmd) {
337
417
  }
338
418
  case "migrate": {
339
419
  const { values } = parseVerb(verb, cmd.flags, rest);
340
- const res = migrateLayout(resolveScopeDir(values));
420
+ const sc = await resolveActionScope(values, "migrate");
421
+ const res = migrateLayout(sc.pluginsDir);
341
422
  for (const m of res.moved)
342
423
  console.log(`${ui.ok("moved")} ${ui.name(m.name)}: ${ui.meta(`${m.from} -> ${m.to}`)}`);
343
424
  for (const m of res.missing)
@@ -383,23 +464,30 @@ async function runMarketplace(args) {
383
464
  // report) so there is no second implementation to drift.
384
465
  console.error(ui.warn("note: `marketplace upgrade` is a deprecated alias for `adg plugins update`."));
385
466
  const { values, positionals } = parseVerb("marketplace", ["all", "target", ...SCOPE], rest);
386
- // Mirror `plugins update`'s error handling: report a failed re-fetch and
387
- // exit cleanly rather than throwing to the top-level catch, so the two
388
- // alias paths behave identically.
389
- try {
390
- const result = await updatePlugins({
391
- pluginsDir: resolveScopeDir(values),
392
- scope: scopeInfo(values),
393
- activate: true,
394
- agentScope: scopeOf(values),
395
- source: positionals[0],
396
- all: values.all,
397
- targets: values.target !== undefined ? resolveTargets(values.target) : undefined,
398
- });
399
- printUpdateReport(result);
400
- }
401
- catch (err) {
402
- console.error(`${ui.err("error:")} ${err instanceof Error ? err.message : String(err)}`);
467
+ // Drive the exact same scope resolution + per-scope loop as `plugins update`
468
+ // (project/global/both, with the home==global trap guard) so the deprecated
469
+ // alias can't drift from the verb it aliases. `--target` narrows the runtimes.
470
+ const targets = values.target !== undefined ? resolveTargets(values.target) : undefined;
471
+ for (const sc of await resolveUpdateScopes(values)) {
472
+ if (sc.heading)
473
+ console.log(`${ui.name(sc.heading)}`);
474
+ // Mirror `plugins update`'s error handling: report a failed re-fetch and
475
+ // exit cleanly rather than throwing to the top-level catch.
476
+ try {
477
+ const result = await updatePlugins({
478
+ pluginsDir: sc.dir,
479
+ scope: { label: sc.label, globalDir: globalPluginsDir() },
480
+ activate: true,
481
+ agentScope: sc.agentScope,
482
+ source: positionals[0],
483
+ all: values.all,
484
+ targets,
485
+ });
486
+ printUpdateReport(result);
487
+ }
488
+ catch (err) {
489
+ console.error(`${ui.err("error:")} ${err instanceof Error ? err.message : String(err)}`);
490
+ }
403
491
  }
404
492
  return;
405
493
  }
@@ -409,10 +497,11 @@ async function runMarketplace(args) {
409
497
  const source = positionals[0];
410
498
  if (!source)
411
499
  fail("marketplace remove requires a <source>");
500
+ const sc = await resolveActionScope(values, "marketplace remove");
412
501
  const res = marketplaceRemove({
413
- pluginsDir: resolveScopeDir(values),
414
- scope: scopeInfo(values),
415
- agentScope: scopeOf(values),
502
+ pluginsDir: sc.pluginsDir,
503
+ scope: sc.info,
504
+ agentScope: sc.agentScope,
416
505
  source,
417
506
  force: values.force,
418
507
  deactivate: true,
@@ -428,13 +517,14 @@ async function runMarketplace(args) {
428
517
  const targets = values.target === "all"
429
518
  ? resolveTargets("all")
430
519
  : [requireSingleTarget(values.target, "marketplace sync")];
520
+ const sc = await resolveActionScope(values, "marketplace sync");
431
521
  for (const target of targets) {
432
522
  const res = marketplaceSync({
433
- pluginsDir: resolveScopeDir(values),
434
- scope: scopeInfo(values),
523
+ pluginsDir: sc.pluginsDir,
524
+ scope: sc.info,
435
525
  source,
436
526
  target,
437
- global: Boolean(values.global),
527
+ global: sc.global,
438
528
  });
439
529
  for (const a of res.actions) {
440
530
  console.log(`${ui.ok("synced")} ${ui.name(a.name)} ${ui.meta(`[${res.target}]`)}${a.synced ? ui.meta(` -> ${res.target}`) : ""}`);
@@ -229,7 +229,11 @@ ${rows.join("\n")}
229
229
 
230
230
  Scope (most commands): --project (default) | --global | --dir <dir>
231
231
  --global honors XDG_STATE_HOME / ADG_PLUGINS_HOME. Only the plugins/ subtree is
232
- touched; AGENTS.md and skills/ are never modified.`;
232
+ touched; AGENTS.md and skills/ are never modified.
233
+ Mutating verbs ask project/global in a terminal when no scope flag is given.
234
+ sync/link/unlink/remove/migrate/import-skills require one in a non-interactive
235
+ run (rather than assuming project); add/update fall back to a safe default. A
236
+ project store that resolves to the global path is auto-promoted to global.`;
233
237
  }
234
238
  /** L2: `adg plugins <verb> -h` — just this command's region. */
235
239
  export function renderVerbHelp(name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbbtsn0w/adg",
3
- "version": "0.4.0-beta.2",
3
+ "version": "0.4.0-beta.3",
4
4
  "description": "Agent Directory Group (ADG) toolkit — two domains: plugins and skills.",
5
5
  "type": "module",
6
6
  "license": "MIT",