@v11g/agents-rock 1.0.0 → 1.0.2

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.
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+ // Prints (space-joined) the names of plugins whose plugin.json "version"
3
+ // changed between two git revs. Used by .github/workflows/publish.yml to
4
+ // gate npm publishing.
5
+ import { execFileSync } from 'node:child_process';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ const MANIFEST = /^plugins\/([^/]+)\/\.claude-plugin\/plugin\.json$/;
9
+
10
+ export function changedVersions(pairs) {
11
+ return pairs
12
+ .filter(({ before, after }) => after !== null && versionOf(before) !== versionOf(after))
13
+ .map(({ name }) => name);
14
+ }
15
+
16
+ function versionOf(text) {
17
+ return text === null ? null : JSON.parse(text).version;
18
+ }
19
+
20
+ function git(...args) {
21
+ return execFileSync('git', args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
22
+ }
23
+
24
+ function fileAt(rev, file) {
25
+ try {
26
+ return git('show', `${rev}:${file}`);
27
+ } catch {
28
+ return null;
29
+ }
30
+ }
31
+
32
+ // The before-rev is all zeros on a force push or branch creation.
33
+ function resolveRev(rev) {
34
+ try {
35
+ git('cat-file', '-e', rev);
36
+ return rev;
37
+ } catch {
38
+ return 'HEAD^';
39
+ }
40
+ }
41
+
42
+ function changedManifests(beforeRev, afterRev) {
43
+ return git('diff', '--name-only', beforeRev, afterRev, '--', 'plugins/')
44
+ .split('\n')
45
+ .map((file) => MANIFEST.exec(file))
46
+ .filter(Boolean);
47
+ }
48
+
49
+ function main([beforeArg, afterRev]) {
50
+ if (!beforeArg || !afterRev) {
51
+ console.error('usage: changed-versions.mjs <before-rev> <after-rev>');
52
+ return 1;
53
+ }
54
+ const beforeRev = resolveRev(beforeArg);
55
+ const pairs = changedManifests(beforeRev, afterRev).map(([file, name]) => ({
56
+ name,
57
+ before: fileAt(beforeRev, file),
58
+ after: fileAt(afterRev, file),
59
+ }));
60
+ console.log(changedVersions(pairs).join(' '));
61
+ return 0;
62
+ }
63
+
64
+ if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
65
+ process.exitCode = main(process.argv.slice(2));
66
+ }
@@ -1,12 +1,12 @@
1
- import path from 'node:path';
1
+ /**
2
+ * Per-agent home directory plus the env var that relocates it. Both are only
3
+ * consulted for user scope; project scope always nests inside the project root.
4
+ */
5
+ export const AGENT_HOMES = {
6
+ claude: { dir: '.claude', env: 'CLAUDE_CONFIG_DIR' },
7
+ codex: { dir: '.codex', env: 'CODEX_HOME' },
8
+ };
2
9
 
3
- export const AGENT_DIRS = { claude: '.claude', codex: '.codex' };
4
- export const ALL_AGENTS = Object.keys(AGENT_DIRS);
10
+ export const ALL_AGENTS = Object.keys(AGENT_HOMES);
5
11
 
6
- export function agentSkillsDir(agent, cwd) {
7
- return path.join(cwd, AGENT_DIRS[agent], 'skills');
8
- }
9
-
10
- export function canonicalSkillsDir(cwd) {
11
- return path.join(cwd, '.agents', 'skills');
12
- }
12
+ export const AGENT_LABELS = { claude: 'Claude Code', codex: 'Codex' };
package/src/cli/args.mjs CHANGED
@@ -1,13 +1,17 @@
1
1
  import { parseArgs } from 'node:util';
2
+ import { ALL_AGENTS } from './agents.mjs';
2
3
 
3
4
  export class UsageError extends Error {}
4
5
 
5
- export const VALID_AGENTS = ['claude', 'codex'];
6
6
  const COMMANDS = new Set(['install', 'uninstall']);
7
7
 
8
8
  const OPTIONS = {
9
9
  plugin: { type: 'string', multiple: true, short: 'p' },
10
10
  agent: { type: 'string', multiple: true, short: 'a' },
11
+ global: { type: 'boolean', short: 'g' },
12
+ project: { type: 'boolean' },
13
+ dir: { type: 'string' },
14
+ yes: { type: 'boolean', short: 'y' },
11
15
  force: { type: 'boolean', short: 'f' },
12
16
  help: { type: 'boolean', short: 'h' },
13
17
  version: { type: 'boolean', short: 'v' },
@@ -23,6 +27,9 @@ export function parseCliArgs(argv) {
23
27
  command,
24
28
  plugins: values.plugin ?? [],
25
29
  agents: values.agent ?? [],
30
+ scope: resolveScope(values),
31
+ dir: values.dir ?? null,
32
+ yes: values.yes ?? false,
26
33
  force: values.force ?? false,
27
34
  help: values.help ?? false,
28
35
  version: values.version ?? false,
@@ -37,10 +44,22 @@ function tryParse(argv) {
37
44
  }
38
45
  }
39
46
 
47
+ function resolveScope(values) {
48
+ if (values.global && values.project) {
49
+ throw new UsageError('Pass either --global or --project, not both.');
50
+ }
51
+ if (values.global && values.dir) {
52
+ throw new UsageError('--dir names a project directory, so it cannot be used with --global.');
53
+ }
54
+ if (values.global) return 'user';
55
+ if (values.project || values.dir) return 'project';
56
+ return null;
57
+ }
58
+
40
59
  function validateAgents(agents) {
41
60
  for (const agent of agents) {
42
- if (!VALID_AGENTS.includes(agent)) {
43
- throw new UsageError(`Unknown agent: ${agent}. Valid agents: ${VALID_AGENTS.join(', ')}`);
61
+ if (!ALL_AGENTS.includes(agent)) {
62
+ throw new UsageError(`Unknown agent: ${agent}. Valid agents: ${ALL_AGENTS.join(', ')}`);
44
63
  }
45
64
  }
46
65
  }
@@ -0,0 +1,85 @@
1
+ import { homedir } from 'node:os';
2
+ import path from 'node:path';
3
+ import { UsageError } from './args.mjs';
4
+ import { ALL_AGENTS } from './agents.mjs';
5
+ import { findProjectRoot } from './scope.mjs';
6
+ import { resolveTargets } from './targets.mjs';
7
+
8
+ /**
9
+ * Turn flags plus prompt answers into a fully resolved install plan.
10
+ * Returns null when the user cancels or declines, so callers exit cleanly.
11
+ */
12
+ export async function buildPlan({ args, registry, prompts, ctx }) {
13
+ const input = withDefaults({ args, registry, prompts, ctx });
14
+ const plugins = await selectPlugins(input);
15
+ if (!plugins) return null;
16
+ const agents = await selectAgents(input);
17
+ if (!agents) return null;
18
+ const scope = await selectScope(input);
19
+ if (!scope) return null;
20
+ const root = scope === 'project' ? await selectRoot(input) : null;
21
+ if (scope === 'project' && !root) return null;
22
+ return confirmPlan(input, { plugins, agents, scope, root });
23
+ }
24
+
25
+ function withDefaults({ args, registry, prompts, ctx }) {
26
+ const full = { cwd: ctx.cwd, stopAt: ctx.stopAt, isTTY: ctx.isTTY ?? false,
27
+ home: ctx.home ?? homedir(), env: ctx.env ?? process.env };
28
+ return { args, registry, prompts, ctx: full, interactive: full.isTTY && !args.yes };
29
+ }
30
+
31
+ async function confirmPlan({ args, prompts, ctx }, selection) {
32
+ const { scope, root } = selection;
33
+ const targets = resolveTargets({ scope, root, home: ctx.home, env: ctx.env });
34
+ const plan = { ...selection, targets, command: args.command, force: args.force };
35
+ prompts.showSummary(plan);
36
+ if (args.yes || !ctx.isTTY) return plan;
37
+ return (await prompts.confirmInstall(plan)) ? plan : null;
38
+ }
39
+
40
+ async function selectPlugins({ args, registry, prompts, interactive }) {
41
+ if (args.plugins.length) return args.plugins.map((name) => findPlugin(registry, name));
42
+ if (!interactive) {
43
+ throw new UsageError('Missing --plugin. Pass --plugin <name>, or run in a terminal to pick.');
44
+ }
45
+ const picked = await prompts.pickPlugins(registry);
46
+ return picked?.length ? picked.map((name) => findPlugin(registry, name)) : null;
47
+ }
48
+
49
+ async function selectAgents({ args, prompts, interactive }) {
50
+ if (args.agents.length) return args.agents;
51
+ if (args.command === 'uninstall') return ALL_AGENTS;
52
+ if (!interactive) {
53
+ throw new UsageError(`Missing --agent. Pass --agent ${ALL_AGENTS.join('|')}, or run in a terminal to pick.`);
54
+ }
55
+ const picked = await prompts.pickAgents(ALL_AGENTS);
56
+ return picked?.length ? picked : null;
57
+ }
58
+
59
+ async function selectScope({ args, prompts, interactive }) {
60
+ if (args.scope) return args.scope;
61
+ if (args.dir || args.yes) return 'project';
62
+ if (!interactive) {
63
+ throw new UsageError('Missing install scope. Pass --global for your home dir or --project for this project.');
64
+ }
65
+ return prompts.pickScope();
66
+ }
67
+
68
+ async function selectRoot({ args, prompts, ctx, interactive }) {
69
+ if (args.dir) return path.resolve(args.dir);
70
+ const found = findProjectRoot(ctx.cwd, ctx.stopAt);
71
+ if (!interactive) return found?.root ?? ctx.cwd;
72
+ if (found?.root === ctx.cwd) return ctx.cwd;
73
+ return prompts.confirmRoot({
74
+ detected: found?.root ?? null,
75
+ marker: found?.marker ?? null,
76
+ cwd: ctx.cwd,
77
+ });
78
+ }
79
+
80
+ function findPlugin(registry, name) {
81
+ const plugin = registry.find((entry) => entry.name === name);
82
+ if (plugin) return plugin;
83
+ const names = registry.map((entry) => entry.name).join(', ');
84
+ throw new UsageError(`Unknown plugin: ${name}. Available: ${names}`);
85
+ }
@@ -1,21 +1,20 @@
1
1
  import { cpSync, existsSync, lstatSync, mkdirSync, readlinkSync, rmSync, symlinkSync } from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { listSkills } from './registry.mjs';
4
- import { agentSkillsDir, canonicalSkillsDir } from './agents.mjs';
5
4
 
6
- export function installPlugin({ pluginDir, cwd, agents, force = false }) {
5
+ export function installPlugin({ pluginDir, targets, agents, force = false }) {
7
6
  const result = { installed: [], skipped: [], reused: [] };
8
7
  for (const skill of listSkills(pluginDir)) {
9
- const canonical = copyCanonical({ skill, cwd, force, result });
8
+ const canonical = copyCanonical({ skill, targets, force, result });
10
9
  for (const agent of agents) {
11
- linkAgent({ skill: skill.name, canonical, agent, cwd, force, result });
10
+ linkAgent({ skill: skill.name, canonical, agent, targets, force, result });
12
11
  }
13
12
  }
14
13
  return result;
15
14
  }
16
15
 
17
- function copyCanonical({ skill, cwd, force, result }) {
18
- const dest = path.join(canonicalSkillsDir(cwd), skill.name);
16
+ function copyCanonical({ skill, targets, force, result }) {
17
+ const dest = path.join(targets.canonical, skill.name);
19
18
  if (existsSync(dest) && !force) {
20
19
  result.reused.push({ skill: skill.name, path: dest });
21
20
  return dest;
@@ -26,8 +25,8 @@ function copyCanonical({ skill, cwd, force, result }) {
26
25
  return dest;
27
26
  }
28
27
 
29
- function linkAgent({ skill, canonical, agent, cwd, force, result }) {
30
- const linkPath = path.join(agentSkillsDir(agent, cwd), skill);
28
+ function linkAgent({ skill, canonical, agent, targets, force, result }) {
29
+ const linkPath = path.join(targets.agentDirs[agent], skill);
31
30
  const status = inspectLink(linkPath, canonical);
32
31
  if (status === 'correct') return result.installed.push({ skill, agent, mode: 'linked' });
33
32
  if (status === 'occupied' && !force) {
package/src/cli/main.mjs CHANGED
@@ -1,12 +1,14 @@
1
1
  import { readFileSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
2
3
  import path from 'node:path';
3
4
  import { fileURLToPath } from 'node:url';
4
- import { parseCliArgs, UsageError, VALID_AGENTS } from './args.mjs';
5
+ import { parseCliArgs } from './args.mjs';
5
6
  import { loadRegistry } from './registry.mjs';
6
- import { runPicker } from './picker.mjs';
7
+ import { buildPlan } from './flow.mjs';
8
+ import { createPrompts } from './prompts.mjs';
7
9
  import { installPlugin } from './install.mjs';
8
10
  import { uninstallPlugin } from './uninstall.mjs';
9
- import { ALL_AGENTS } from './agents.mjs';
11
+ import { printResult } from './report.mjs';
10
12
 
11
13
  const PACKAGE_ROOT = fileURLToPath(new URL('../..', import.meta.url));
12
14
 
@@ -25,92 +27,48 @@ async function run(argv) {
25
27
  if (args.help) return printHelp();
26
28
  if (args.version) return printVersion();
27
29
  const registry = loadRegistry(path.join(PACKAGE_ROOT, 'plugins'));
28
- const plugins = await resolvePlugins(args, registry);
29
- const agents = await resolveAgents(args);
30
- if (!plugins.length || !agents.length) throw new UsageError('Nothing selected.');
31
- return execute({ args, plugins, agents });
32
- }
33
-
34
- async function resolvePlugins(args, registry) {
35
- const names = registry.map((p) => p.name);
36
- for (const name of args.plugins) {
37
- if (!names.includes(name)) {
38
- throw new UsageError(`Unknown plugin: ${name}. Available: ${names.join(', ')}`);
39
- }
30
+ const plan = await buildPlan({ args, registry, prompts: createPrompts(), ctx: processCtx() });
31
+ if (!plan) {
32
+ console.log('Cancelled.');
33
+ return 0;
40
34
  }
41
- if (args.plugins.length) return args.plugins.map((n) => registry.find((p) => p.name === n));
42
- requireInteractive();
43
- const picked = await runPicker({
44
- title: 'Select plugins:',
45
- items: registry.map((p) => ({ value: p.name, label: p.name, hint: p.description })),
46
- });
47
- if (picked === null) throw new UsageError('Cancelled.');
48
- return picked.map((n) => registry.find((p) => p.name === n));
35
+ return execute(plan);
49
36
  }
50
37
 
51
- async function resolveAgents(args) {
52
- if (args.agents.length) return args.agents;
53
- if (args.command === 'uninstall') return ALL_AGENTS;
54
- requireInteractive();
55
- const picked = await runPicker({
56
- title: 'Select agents:',
57
- items: VALID_AGENTS.map((a) => ({ value: a, label: a })),
58
- });
59
- if (picked === null) throw new UsageError('Cancelled.');
60
- return picked;
38
+ function processCtx() {
39
+ return {
40
+ cwd: process.cwd(),
41
+ home: homedir(),
42
+ env: process.env,
43
+ isTTY: Boolean(process.stdin.isTTY && process.stdout.isTTY),
44
+ };
61
45
  }
62
46
 
63
- function requireInteractive() {
64
- if (!process.stdin.isTTY || !process.stdout.isTTY) {
65
- throw new UsageError('Missing --plugin/--agent; interactive mode requires a TTY.');
66
- }
67
- }
68
-
69
- function execute({ args, plugins, agents }) {
47
+ function execute(plan) {
70
48
  let skippedTotal = 0;
71
- for (const plugin of plugins) {
72
- const opts = { pluginDir: plugin.dir, cwd: process.cwd(), agents, force: args.force };
73
- const result = args.command === 'install' ? installPlugin(opts) : uninstallPlugin(opts);
74
- skippedTotal += printSummary(plugin.name, result);
49
+ for (const plugin of plan.plugins) {
50
+ const opts = {
51
+ pluginDir: plugin.dir, targets: plan.targets, agents: plan.agents, force: plan.force,
52
+ };
53
+ const result = plan.command === 'install' ? installPlugin(opts) : uninstallPlugin(opts);
54
+ skippedTotal += printResult(plugin.name, result);
75
55
  }
76
56
  return skippedTotal > 0 ? 1 : 0;
77
57
  }
78
58
 
79
- function printSummary(pluginName, result) {
80
- for (const item of result.reused ?? []) {
81
- console.log(`↻ ${item.skill} (canonical exists, reused)`);
82
- }
83
- for (const item of result.installed ?? []) {
84
- console.log(`✔ ${pluginName}: ${item.skill} → ${item.agent} (${item.mode})`);
85
- warnIfCopyFallback(item);
86
- }
87
- for (const item of result.removed ?? []) {
88
- console.log(`✔ ${pluginName}: removed ${item.skill} ← ${item.agent}`);
89
- }
90
- for (const skill of result.canonicalRemoved ?? []) {
91
- console.log(`✔ ${pluginName}: removed canonical ${skill}`);
92
- }
93
- for (const item of result.skipped ?? []) {
94
- console.error(`✖ skipped ${item.path} — ${item.reason}`);
95
- }
96
- return (result.skipped ?? []).length;
97
- }
98
-
99
- function warnIfCopyFallback(item) {
100
- if (item.mode !== 'copy') return;
101
- console.error(
102
- `⚠ ${item.skill} → ${item.agent} installed as plain copy — updates to .agents/skills will not propagate`,
103
- );
104
- }
105
-
106
59
  function printHelp() {
107
60
  console.log(`Usage: agents-rock [install|uninstall] [options]
108
61
 
109
- Install plugin skills for Claude Code and Codex into the current project.
62
+ Install plugin skills for Claude Code and Codex. Run with no options for an
63
+ interactive picker; pass flags to run unattended.
110
64
 
111
65
  Options:
112
66
  -p, --plugin <name> Plugin to install/uninstall (repeatable)
113
67
  -a, --agent <name> Target agent: claude, codex (repeatable)
68
+ -g, --global User scope: install under your home directory
69
+ --project Project scope: install under the detected project root
70
+ --dir <path> Project scope into <path>, skipping root detection
71
+ -y, --yes Skip confirmations (assumes --project)
114
72
  -f, --force Overwrite/remove collisions
115
73
  -h, --help Show help
116
74
  -v, --version Show version`);
@@ -0,0 +1,84 @@
1
+ import * as clack from '@clack/prompts';
2
+ import pc from 'picocolors';
3
+ import { AGENT_LABELS } from './agents.mjs';
4
+
5
+ const HINT_WIDTH = 64;
6
+ const clip = (text) => (text.length > HINT_WIDTH ? `${text.slice(0, HINT_WIDTH - 1)}…` : text);
7
+
8
+ /** Interactive shell around @clack/prompts. Holds no decisions — flow.mjs owns those. */
9
+ export function createPrompts() {
10
+ return { pickPlugins, pickAgents, pickScope, confirmRoot, showSummary, confirmInstall };
11
+ }
12
+
13
+ async function pickPlugins(registry) {
14
+ return unwrap(await clack.multiselect({
15
+ message: 'Which plugins do you want?',
16
+ options: registry.map((plugin) => ({
17
+ value: plugin.name, label: plugin.name, hint: clip(plugin.description ?? ''),
18
+ })),
19
+ required: true,
20
+ }));
21
+ }
22
+
23
+ async function pickAgents(agents) {
24
+ return unwrap(await clack.multiselect({
25
+ message: 'Which agents should get them?',
26
+ options: agents.map((agent) => ({ value: agent, label: AGENT_LABELS[agent] ?? agent })),
27
+ initialValues: agents,
28
+ required: true,
29
+ }));
30
+ }
31
+
32
+ async function pickScope() {
33
+ return unwrap(await clack.select({
34
+ message: 'Installation scope',
35
+ options: [
36
+ { value: 'project', label: 'Project', hint: 'this project only, committed with your repo' },
37
+ { value: 'user', label: 'User', hint: 'your home dir, available in every project' },
38
+ ],
39
+ }));
40
+ }
41
+
42
+ async function confirmRoot({ detected, marker, cwd }) {
43
+ if (!detected) {
44
+ const ok = unwrap(await clack.confirm({
45
+ message: `No project root found above ${pc.cyan(cwd)}. Install here anyway?`,
46
+ }));
47
+ return ok ? cwd : null;
48
+ }
49
+ return unwrap(await clack.select({
50
+ message: 'Install into which directory?',
51
+ options: [
52
+ { value: detected, label: detected, hint: `project root — found ${marker}` },
53
+ { value: cwd, label: cwd, hint: 'current directory' },
54
+ ],
55
+ }));
56
+ }
57
+
58
+ function showSummary(plan) {
59
+ clack.note(summaryLines(plan).join('\n'), verb(plan) + ' summary');
60
+ }
61
+
62
+ async function confirmInstall(plan) {
63
+ return unwrap(await clack.confirm({ message: `Proceed with ${verb(plan).toLowerCase()}?` }));
64
+ }
65
+
66
+ function summaryLines(plan) {
67
+ const agents = plan.agents.map((agent) => AGENT_LABELS[agent] ?? agent).join(', ');
68
+ const scope = plan.scope === 'user' ? 'user (home dir)' : `project (${plan.root})`;
69
+ return [
70
+ `${pc.dim('scope: ')}${scope}`,
71
+ `${pc.dim('agents:')} ${agents}`,
72
+ `${pc.dim('skills:')} ${pc.cyan(plan.targets.canonical)}`,
73
+ ...plan.plugins.map((plugin) => ` ${plugin.name}`),
74
+ ...plan.agents.map((agent) => `${pc.dim('link: ')} ${plan.targets.agentDirs[agent]}`),
75
+ ];
76
+ }
77
+
78
+ function verb(plan) {
79
+ return plan.command === 'uninstall' ? 'Uninstall' : 'Install';
80
+ }
81
+
82
+ function unwrap(value) {
83
+ return clack.isCancel(value) ? null : value;
84
+ }
@@ -0,0 +1,26 @@
1
+ export function printResult(pluginName, result) {
2
+ for (const item of result.reused ?? []) {
3
+ console.log(`↻ ${item.skill} (canonical exists, reused)`);
4
+ }
5
+ for (const item of result.installed ?? []) {
6
+ console.log(`✔ ${pluginName}: ${item.skill} → ${item.agent} (${item.mode})`);
7
+ warnIfCopyFallback(item);
8
+ }
9
+ for (const item of result.removed ?? []) {
10
+ console.log(`✔ ${pluginName}: removed ${item.skill} ← ${item.agent}`);
11
+ }
12
+ for (const skill of result.canonicalRemoved ?? []) {
13
+ console.log(`✔ ${pluginName}: removed canonical ${skill}`);
14
+ }
15
+ for (const item of result.skipped ?? []) {
16
+ console.error(`✖ skipped ${item.path} — ${item.reason}`);
17
+ }
18
+ return (result.skipped ?? []).length;
19
+ }
20
+
21
+ function warnIfCopyFallback(item) {
22
+ if (item.mode !== 'copy') return;
23
+ console.error(
24
+ `⚠ ${item.skill} → ${item.agent} installed as plain copy — updates to the canonical skill will not propagate`,
25
+ );
26
+ }
@@ -0,0 +1,34 @@
1
+ import { existsSync } from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ const REPO_MARKERS = ['.git'];
5
+ const MANIFEST_MARKERS = ['package.json', 'pyproject.toml', 'go.mod', 'Cargo.toml'];
6
+
7
+ /**
8
+ * Walk up from `cwd` looking for a project root. A repo marker anywhere up the
9
+ * tree outranks a nearer manifest, so a monorepo package resolves to the repo.
10
+ * Returns `{ root, marker }`, or null when nothing is found by `stopAt`.
11
+ */
12
+ export function findProjectRoot(cwd, stopAt = path.parse(path.resolve(cwd)).root) {
13
+ return search(cwd, stopAt, REPO_MARKERS) ?? search(cwd, stopAt, MANIFEST_MARKERS);
14
+ }
15
+
16
+ function search(cwd, stopAt, markers) {
17
+ for (const dir of ancestors(cwd, stopAt)) {
18
+ const marker = markers.find((name) => existsSync(path.join(dir, name)));
19
+ if (marker) return { root: dir, marker };
20
+ }
21
+ return null;
22
+ }
23
+
24
+ function* ancestors(cwd, stopAt) {
25
+ const boundary = path.resolve(stopAt);
26
+ let dir = path.resolve(cwd);
27
+ while (dir !== boundary) {
28
+ yield dir;
29
+ const parent = path.dirname(dir);
30
+ if (parent === dir) return;
31
+ dir = parent;
32
+ }
33
+ yield boundary;
34
+ }
@@ -0,0 +1,45 @@
1
+ import { homedir } from 'node:os';
2
+ import path from 'node:path';
3
+ import { UsageError } from './args.mjs';
4
+ import { AGENT_HOMES, ALL_AGENTS } from './agents.mjs';
5
+
6
+ const CANONICAL = ['.agents', 'skills'];
7
+
8
+ /**
9
+ * Resolve every path an install writes to. Both scopes share one shape —
10
+ * a canonical skills dir plus one skills dir per agent — so install and
11
+ * uninstall stay scope-agnostic.
12
+ */
13
+ export function resolveTargets({ scope, root, home = homedir(), env = process.env }) {
14
+ if (scope === 'project') return projectTargets(requireRoot(root));
15
+ if (scope === 'user') return userTargets(home, env);
16
+ throw new UsageError(`Unknown scope: ${scope}`);
17
+ }
18
+
19
+ function requireRoot(root) {
20
+ if (!root) throw new UsageError('Project scope needs a project root.');
21
+ return root;
22
+ }
23
+
24
+ function projectTargets(root) {
25
+ return {
26
+ canonical: path.join(root, ...CANONICAL),
27
+ agentDirs: mapAgents((agent) => path.join(root, AGENT_HOMES[agent].dir, 'skills')),
28
+ };
29
+ }
30
+
31
+ function userTargets(home, env) {
32
+ return {
33
+ canonical: path.join(home, ...CANONICAL),
34
+ agentDirs: mapAgents((agent) => path.join(agentHome(agent, home, env), 'skills')),
35
+ };
36
+ }
37
+
38
+ function agentHome(agent, home, env) {
39
+ const { dir, env: key } = AGENT_HOMES[agent];
40
+ return env[key]?.trim() || path.join(home, dir);
41
+ }
42
+
43
+ function mapAgents(dirFor) {
44
+ return Object.fromEntries(ALL_AGENTS.map((agent) => [agent, dirFor(agent)]));
45
+ }
@@ -1,21 +1,20 @@
1
1
  import { existsSync, lstatSync, rmSync } from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { listSkills } from './registry.mjs';
4
- import { agentSkillsDir, canonicalSkillsDir, ALL_AGENTS } from './agents.mjs';
5
4
 
6
- export function uninstallPlugin({ pluginDir, cwd, agents, force = false }) {
5
+ export function uninstallPlugin({ pluginDir, targets, agents, force = false }) {
7
6
  const result = { removed: [], canonicalRemoved: [], skipped: [] };
8
7
  for (const skill of listSkills(pluginDir)) {
9
8
  for (const agent of agents) {
10
- removeAgentEntry({ skill: skill.name, agent, cwd, force, result });
9
+ removeAgentEntry({ skill: skill.name, agent, targets, force, result });
11
10
  }
12
- maybeRemoveCanonical(skill.name, cwd, result);
11
+ maybeRemoveCanonical(skill.name, targets, result);
13
12
  }
14
13
  return result;
15
14
  }
16
15
 
17
- function removeAgentEntry({ skill, agent, cwd, force, result }) {
18
- const linkPath = path.join(agentSkillsDir(agent, cwd), skill);
16
+ function removeAgentEntry({ skill, agent, targets, force, result }) {
17
+ const linkPath = path.join(targets.agentDirs[agent], skill);
19
18
  let stat;
20
19
  try { stat = lstatSync(linkPath); } catch { return; }
21
20
  if (!stat.isSymbolicLink() && !force) {
@@ -25,13 +24,13 @@ function removeAgentEntry({ skill, agent, cwd, force, result }) {
25
24
  result.removed.push({ skill, agent });
26
25
  }
27
26
 
28
- function maybeRemoveCanonical(skill, cwd, result) {
29
- const stillReferenced = ALL_AGENTS.some((agent) => {
30
- try { return Boolean(lstatSync(path.join(agentSkillsDir(agent, cwd), skill))); }
27
+ function maybeRemoveCanonical(skill, targets, result) {
28
+ const stillReferenced = Object.values(targets.agentDirs).some((dir) => {
29
+ try { return Boolean(lstatSync(path.join(dir, skill))); }
31
30
  catch { return false; }
32
31
  });
33
32
  if (stillReferenced) return;
34
- const canonical = path.join(canonicalSkillsDir(cwd), skill);
33
+ const canonical = path.join(targets.canonical, skill);
35
34
  if (!existsSync(canonical)) return;
36
35
  rmSync(canonical, { recursive: true, force: true });
37
36
  result.canonicalRemoved.push(skill);