Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/src/content/docs/docs/reference/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,15 @@ Only enable specific skills from the plugin. Can be specified multiple times:
allagents plugin install superpowers@marketplace --skill brainstorming --skill tdd
```

When used, all other skills from the plugin are implicitly disabled. Skills can be added later with `skill add`.
On a new installation, only the named skills are enabled. Reinstalling a plugin
with an existing allowlist extends that list. Skills can also be added later
with `skill add`.

AllAgents discovers and validates the requested names before saving the plugin
declaration or synchronizing client files. It does not install other skills as
an intermediate discovery step. Unknown names fail without changing the plugin
declaration or client files. A plugin using `skills.exclude` must use `skill add`
to enable an individual skill rather than `plugin install --skill`.

When the selected client uses native install mode, this command validates the
runtime, source, scope, and live inventory before editing `workspace.yaml`.
Expand Down
130 changes: 65 additions & 65 deletions src/cli/commands/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import {
buildPluginSyncPlans,
nativeIdentityMatches,
preflightNativePluginDeclaration,
validateAllPlugins,
type SyncOptions,
} from '../../core/sync.js';
import type { NativeEffectData } from '../../core/native/types.js';
import { loadSyncState } from '../../core/sync-state.js';
import {
addPluginForTarget,
removePlugin,
addEnabledSkill,
extractPluginNames,
mergeTargetedPluginEntry,
resolveMarketplacePluginDeclaration,
} from '../../core/workspace-modify.js';
import {
Expand All @@ -42,7 +42,6 @@ import {
getInstalledUserPlugins,
getInstalledProjectPlugins,
getUserWorkspaceConfig,
addUserEnabledSkill,
type InstalledPluginInfo,
} from '../../core/user-workspace.js';
import {
Expand All @@ -52,7 +51,7 @@ import {
type PluginUpdateCheck,
} from '../../core/plugin.js';
import { UpdateContext } from '../../core/update-context.js';
import { getAllSkillsFromPlugins } from '../../core/skills.js';
import { discoverSkillEntriesFromPluginRoot } from '../../core/skills.js';
import { validateLocalPlugin } from '../../validators/plugin.js';
import {
getWorkspaceStatus,
Expand Down Expand Up @@ -100,6 +99,7 @@ import {
getPluginDisplayName,
isRemotePluginSource,
parseRemotePluginSource,
normalizePluginPath,
} from '../../utils/plugin-path.js';
import {
parseUserWorkspaceConfig,
Expand Down Expand Up @@ -1270,6 +1270,34 @@ const pluginInstallCmd = command({
}
prospectiveDeclaration = resolution.declaration;
registeredMarketplace = resolution.registeredAs;
if (skills.length > 0) {
const config = isUser
? await getUserWorkspaceConfig()
: existsSync(projectConfigPath)
? await parseWorkspaceConfig(projectConfigPath)
: undefined;
const source = getPluginSource(prospectiveDeclaration);
const existing = config?.plugins.find((entry) => getPluginSource(entry) === source);
prospectiveDeclaration = mergeTargetedPluginEntry(
existing,
prospectiveDeclaration,
source,
config?.clients ?? target.clients,
);
}
}

if (skills.length > 0) {
const entry = typeof prospectiveDeclaration === 'string'
? { source: prospectiveDeclaration }
: prospectiveDeclaration;
if (entry.skills && !Array.isArray(entry.skills)) {
throw new Error('Plugin is in blocklist mode; use skill add to enable an individual skill.');
}
prospectiveDeclaration = {
...entry,
skills: [...new Set([...(entry.skills ?? []), ...skills])],
};
}

// Emit override warnings for project-scope installs
Expand Down Expand Up @@ -1306,6 +1334,37 @@ const pluginInstallCmd = command({
installPlan.clients.length === 0 &&
installPlan.nativeClients.length > 0;

if (skills.length > 0 && installPlan) {
const discoveryPlan = {
...installPlan,
source: isPluginSpec(installPlan.source) || isRemotePluginSource(installPlan.source)
? installPlan.source
: normalizePluginPath(installPlan.source, workspacePath),
};
const [validated] = await withPluginProgress((onProgress) =>
validateAllPlugins(
[discoveryPlan],
isUser ? getHomeDir() : workspacePath,
false,
onProgress,
),
);
if (!validated?.success) {
throw new Error(validated?.error ?? 'Plugin discovery failed');
}
const entries = await discoverSkillEntriesFromPluginRoot(
validated.resolved,
[],
validated.components,
validated.exclude,
);
const availableNames = entries.map((entry) => entry.name);
const invalid = skills.filter((name) => !availableNames.includes(name));
if (invalid.length > 0) {
throw new Error(`Unknown skills: ${invalid.join(', ')}. Available: ${availableNames.join(', ')}`);
}
}

const installTarget = {
declaration: prospectiveDeclaration,
clients: target.clients,
Expand Down Expand Up @@ -1335,66 +1394,8 @@ const pluginInstallCmd = command({

const displayPlugin = result.normalizedPlugin ?? plugin;

// Handle --skill flag: write enabledSkills BEFORE sync so only one sync pass is needed
if (skills.length > 0) {
const workspacePath = isUser ? getHomeDir() : process.cwd();

// Do an initial sync to fetch the plugin so we can discover its skills.
const initialSync = isUser
? await syncUserWorkspace()
: await syncProjectWorkspace(workspacePath, { yes });

if (!initialSync.success) {
const error = `Initial sync failed: ${initialSync.error ?? 'Unknown error'}`;
if (isJsonMode()) {
jsonOutput({ success: false, command: 'plugin install', error });
process.exit(1);
}
console.error(`Error: ${error}`);
process.exit(1);
}

const allSkills = await getAllSkillsFromPlugins(workspacePath);
const displayNames = extractPluginNames(displayPlugin);
const pluginSkills = allSkills.filter((s) =>
s.pluginSource === displayPlugin || displayNames.includes(s.pluginName),
);

if (pluginSkills.length === 0) {
if (!isJsonMode()) {
console.error(`Warning: No skills found in plugin ${displayPlugin}`);
}
} else {
const pluginName = pluginSkills[0]?.pluginName;
const availableNames = pluginSkills.map((s) => s.name);

// Validate requested skill names
const invalid = skills.filter((s) => !availableNames.includes(s));
if (invalid.length > 0) {
const error = `Unknown skills: ${invalid.join(', ')}. Available: ${availableNames.join(', ')}`;
if (isJsonMode()) {
jsonOutput({ success: false, command: 'plugin install', error });
process.exit(1);
}
console.error(`Error: ${error}`);
process.exit(1);
}

// Add each skill to enabledSkills
for (const skillName of skills) {
const skillKey = `${pluginName}:${skillName}`;
const addResult = isUser
? await addUserEnabledSkill(skillKey)
: await addEnabledSkill(skillKey, workspacePath);
if (!addResult.success && !isJsonMode()) {
console.error(`Warning: ${addResult.error}`);
}
}

if (!isJsonMode()) {
console.log(`\nEnabled skills: ${skills.join(', ')}`);
}
}
if (skills.length > 0 && !isJsonMode()) {
console.log(`\nEnabled skills: ${skills.join(', ')}`);
}

if (result.replaced && !isJsonMode()) {
Expand All @@ -1408,7 +1409,6 @@ const pluginInstallCmd = command({
console.log(`Installing plugin "${displayPlugin}"...\n`);
}

// Single sync pass (enabledSkills already written if --skill was used)
const { ok: syncOk, syncData, error: syncError } = isUser
? await runUserSyncAndPrint()
: await runSyncAndPrint({ yes });
Expand Down
39 changes: 39 additions & 0 deletions tests/e2e/plugin-git-remotes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:te
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { parse as load } from 'yaml';

const repoRoot = join(import.meta.dir, '../..');
const cli = join(repoRoot, 'dist/index.js');
Expand Down Expand Up @@ -81,6 +82,44 @@ beforeEach(() => {
afterEach(() => rmSync(root, { recursive: true, force: true }));

describe('file-mode Git remotes through the built CLI', () => {
test.each(['project', 'user'] as const)('extends the canonical marketplace allowlist when reinstalling its repository alias at %s scope', (scope) => {
for (const name of ['fixture', 'unselected']) {
const directory = join(upstream, 'plugins', 'bundle', 'skills', name);
mkdirSync(directory, { recursive: true });
writeFileSync(join(directory, 'SKILL.md'), `---\nname: ${name}\ndescription: ${name}\n---\n`);
}
mkdirSync(join(upstream, '.claude-plugin'), { recursive: true });
writeFileSync(join(upstream, '.claude-plugin', 'marketplace.json'), JSON.stringify({
name: 'canonical-market',
plugins: [{ name: 'bundle', source: './plugins/bundle' }],
}));
git(upstream, 'add', '.claude-plugin', 'plugins');
git(upstream, 'commit', '-m', 'add marketplace fixture');
git(upstream, 'push', remote, 'main');
writeFileSync(gitConfig, readFileSync(gitConfig, 'utf8') + `[url "file://${remote}"]\n\tinsteadOf = https://github.com/fixture/selection-market.git\n`);
const source = 'bundle@fixture/selection-market';
const install = (skill: string) => run(['plugin', 'install', source, '--scope', scope, '--client', 'codex', '--skill', skill, '--yes']);
const first = install('fixture');
expect(first.exit, first.stdout + first.stderr).toBe(0);
const destination = scope === 'user' ? home : project;
const configPath = join(destination, '.allagents', 'workspace.yaml');
writeFileSync(configPath, 'version: 2\nrepositories: []\nclients: [codex]\nplugins:\n - source: bundle@canonical-market\n skills: [fixture]\n exclude: [private/**]\n hooks: false\n');

const second = install('unselected');

expect(second.exit, second.stdout + second.stderr).toBe(0);
const config = load(readFileSync(configPath, 'utf8')) as { plugins: unknown[] };
expect(config.plugins).toEqual([{
source: 'bundle@canonical-market',
skills: ['fixture', 'unselected'],
exclude: ['private/**'],
hooks: false,
}]);
for (const skill of ['fixture', 'unselected']) {
expect(existsSync(join(destination, '.codex', 'skills', skill, 'SKILL.md'))).toBe(true);
}
}, 30_000);

test('local plugin installation checks an unchanged remote once and still applies later upstream changes', () => {
const source = 'https://github.com/fixture/refresh/tree/main/collection/fixture';
writeFileSync(gitConfig, readFileSync(gitConfig, 'utf8') + `[url "file://${remote}"]\n\tinsteadOf = https://github.com/fixture/refresh.git\n`);
Expand Down
Loading
Loading