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
15 changes: 9 additions & 6 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getPreferredAgents, savePreferredAgents } from './config.ts';
import { loadCredentials, saveCredentials, clearCredentials, maskToken } from './credentials.ts';
import { extractDependencies, isValidDependencySpec, parseDependency, dependencyToSlug, parseSkillMd } from './parser.ts';
import { parseSource, type ParsedSource } from './source-parser.ts';
import { getRequestedSkill } from './install-request.ts';
import { discoverSkills, filterSkills, type DiscoveredSkill } from './discover.ts';
import { getCollectionInstallRefs } from './collection.ts';
import { cloneRepo, cleanupTempDir, GitCloneError } from './git.ts';
Expand Down Expand Up @@ -704,22 +705,23 @@ async function runInstallJson(skillName: string, options: InstallOptions): Promi

const spinner = createSpinner(true);
const { skills: discoveredSkills, parsed: sourceParsed, tempDir } = await resolveSkills(skillName, spinner, options);
const requestedSkill = getRequestedSkill(skillName, sourceParsed, options.skill);

const cleanup = async () => {
if (tempDir) await cleanupTempDir(tempDir).catch(() => {});
};

try {
if (discoveredSkills.length === 0) {
if (options.skill) {
if (requestedSkill) {
printJson({
ok: false,
error: {
code: 'SKILL_NOT_FOUND',
message: `Skill "${options.skill}" not found in source`,
message: `Skill "${requestedSkill.name}" not found in source`,
details: {
source: skillName,
requestedSkill: options.skill,
source: requestedSkill.source,
requestedSkill: requestedSkill.name,
},
},
});
Expand Down Expand Up @@ -1096,6 +1098,7 @@ async function runInstall(args: string[]): Promise<void> {

// Step 1: Resolve skills (clone or API)
const { skills: discoveredSkills, parsed: sourceParsed, tempDir } = await resolveSkills(skillName, spinner, options);
const requestedSkill = getRequestedSkill(skillName, sourceParsed, options.skill);

// Ensure tempDir is always cleaned up, even on cancel/error/process.exit
const cleanup = async () => {
Expand All @@ -1105,8 +1108,8 @@ async function runInstall(args: string[]): Promise<void> {
try {

if (discoveredSkills.length === 0) {
if (options.skill) {
p.log.error(`Skill "${options.skill}" not found in ${pc.cyan(skillName)}`);
if (requestedSkill) {
p.log.error(`Skill "${requestedSkill.name}" not found in ${pc.cyan(requestedSkill.source)}`);
process.exitCode = 1;
return;
}
Expand Down
29 changes: 29 additions & 0 deletions src/install-request.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import test from 'node:test';
import assert from 'node:assert/strict';

import { getRequestedSkill } from './install-request.ts';
import { parseSource } from './source-parser.ts';

test('getRequestedSkill resolves source@name as an explicit skill request', () => {
const input = 'gh:openclaw/openclaw@tavily';

assert.deepEqual(getRequestedSkill(input, parseSource(input)), {
name: 'tavily',
source: 'gh:openclaw/openclaw',
});
});

test('getRequestedSkill preserves the base source for --skill requests', () => {
const input = 'gh:openclaw/openclaw';

assert.deepEqual(getRequestedSkill(input, parseSource(input), 'tavily'), {
name: 'tavily',
source: 'gh:openclaw/openclaw',
});
});

test('getRequestedSkill returns null when no skill was explicitly requested', () => {
const input = 'gh:openclaw/openclaw';

assert.equal(getRequestedSkill(input, parseSource(input)), null);
});
33 changes: 33 additions & 0 deletions src/install-request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { ParsedSource } from './source-parser.ts';

export interface RequestedSkill {
name: string;
source: string;
}

export function getRequestedSkill(
sourceInput: string,
sourceParsed: Pick<ParsedSource, 'skillFilter'>,
explicitSkill?: string,
): RequestedSkill | null {
if (explicitSkill) {
return {
name: explicitSkill,
source: sourceInput,
};
}

if (!sourceParsed.skillFilter) {
return null;
}

const selectorSuffix = `@${sourceParsed.skillFilter}`;
const source = sourceInput.endsWith(selectorSuffix)
? sourceInput.slice(0, -selectorSuffix.length)
: sourceInput;

return {
name: sourceParsed.skillFilter,
source,
};
}
Loading