feat(cli): invokable skills and import any skill (#11113)
* list all skills using /skills slash command * make skills slash command invokable * load the skill using skills tool * make skills tool allowed by default * add /import-skills slash command * Update extensions/cli/src/tools/skills.ts Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * fix stale in use effect --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> Co-authored-by: Dallin Romney <dallinromney@gmail.com>
This commit is contained in:
parent
bcd514aa55
commit
65c02eabb4
9 changed files with 241 additions and 50 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { vi } from "vitest";
|
||||
|
||||
export const getAllSlashCommands = vi.fn(() => [
|
||||
export const getAllSlashCommands = vi.fn(async () => [
|
||||
{ name: "help", description: "Show help", category: "system" },
|
||||
{ name: "login", description: "Login to Continue", category: "system" },
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ describe("Slash Commands Integration", () => {
|
|||
};
|
||||
|
||||
describe("System Commands Registration", () => {
|
||||
it("should include all system commands in the commands list", () => {
|
||||
const commands = getAllSlashCommands(mockAssistant);
|
||||
it("should include all system commands in the commands list", async () => {
|
||||
const commands = await getAllSlashCommands(mockAssistant);
|
||||
const commandNames = commands.map((cmd) => cmd.name);
|
||||
|
||||
// Check that system commands are present (mode commands have been removed)
|
||||
|
|
@ -33,15 +33,15 @@ describe("Slash Commands Integration", () => {
|
|||
expect(commandNames).toContain("config");
|
||||
});
|
||||
|
||||
it("should include assistant prompt commands", () => {
|
||||
const commands = getAllSlashCommands(mockAssistant);
|
||||
it("should include assistant prompt commands", async () => {
|
||||
const commands = await getAllSlashCommands(mockAssistant);
|
||||
const commandNames = commands.map((cmd) => cmd.name);
|
||||
|
||||
expect(commandNames).toContain("test-prompt");
|
||||
});
|
||||
|
||||
it("should categorize system commands correctly", () => {
|
||||
const commands = getAllSlashCommands(mockAssistant);
|
||||
it("should categorize system commands correctly", async () => {
|
||||
const commands = await getAllSlashCommands(mockAssistant);
|
||||
const systemCommands = commands.filter((cmd) =>
|
||||
[
|
||||
"help",
|
||||
|
|
@ -60,8 +60,8 @@ describe("Slash Commands Integration", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("should categorize assistant commands correctly", () => {
|
||||
const commands = getAllSlashCommands(mockAssistant);
|
||||
it("should categorize assistant commands correctly", async () => {
|
||||
const commands = await getAllSlashCommands(mockAssistant);
|
||||
const assistantCommands = commands.filter(
|
||||
(cmd) => cmd.name === "test-prompt",
|
||||
);
|
||||
|
|
@ -71,8 +71,8 @@ describe("Slash Commands Integration", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("should only show remote mode commands in remote mode", () => {
|
||||
const commands = getAllSlashCommands(mockAssistant, {
|
||||
it("should only show remote mode commands in remote mode", async () => {
|
||||
const commands = await getAllSlashCommands(mockAssistant, {
|
||||
isRemoteMode: true,
|
||||
});
|
||||
const commandNames = commands.map((cmd) => cmd.name);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
import { type AssistantConfig } from "@continuedev/sdk";
|
||||
|
||||
import {
|
||||
getSkillSlashCommandName,
|
||||
loadMarkdownSkills,
|
||||
} from "../util/loadMarkdownSkills.js";
|
||||
|
||||
// Export command functions
|
||||
export { chat } from "./chat.js";
|
||||
export { login } from "./login.js";
|
||||
|
|
@ -116,6 +121,16 @@ export const SYSTEM_SLASH_COMMANDS: SystemCommand[] = [
|
|||
description: "Show all chat sessions",
|
||||
category: "system",
|
||||
},
|
||||
{
|
||||
name: "skills",
|
||||
description: "List all available skills",
|
||||
category: "system",
|
||||
},
|
||||
{
|
||||
name: "import-skill",
|
||||
description: "Import a skill from a URL or name into ~/.continue/skills",
|
||||
category: "system",
|
||||
},
|
||||
];
|
||||
|
||||
// Remote mode specific commands
|
||||
|
|
@ -140,10 +155,10 @@ export const REMOTE_MODE_SLASH_COMMANDS: SlashCommand[] = [
|
|||
/**
|
||||
* Get all available slash commands including system commands and assistant prompts
|
||||
*/
|
||||
export function getAllSlashCommands(
|
||||
export async function getAllSlashCommands(
|
||||
assistant: AssistantConfig,
|
||||
options: { isRemoteMode?: boolean } = {},
|
||||
): SlashCommand[] {
|
||||
): Promise<SlashCommand[]> {
|
||||
const { isRemoteMode = false } = options;
|
||||
|
||||
// In remote mode, only show the exit command
|
||||
|
|
@ -165,7 +180,15 @@ export function getAllSlashCommands(
|
|||
// Get invokable rule commands
|
||||
const invokableRuleCommands = getInvokableRuleSlashCommands(assistant);
|
||||
|
||||
return [...systemCommands, ...assistantCommands, ...invokableRuleCommands];
|
||||
// Get skill commands
|
||||
const skillCommands = await getSkillSlashCommands();
|
||||
|
||||
return [
|
||||
...systemCommands,
|
||||
...assistantCommands,
|
||||
...invokableRuleCommands,
|
||||
...skillCommands,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -212,3 +235,16 @@ export function getInvokableRuleSlashCommands(
|
|||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get skill-based slash commands from Markdown skills
|
||||
*/
|
||||
export async function getSkillSlashCommands(): Promise<SlashCommand[]> {
|
||||
const { skills } = await loadMarkdownSkills();
|
||||
|
||||
return skills.map((skill) => ({
|
||||
name: getSkillSlashCommandName(skill),
|
||||
description: skill.description,
|
||||
category: "assistant" as const,
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ export function getDefaultToolPolicies(
|
|||
{ tool: "AskQuestion", permission: "allow" },
|
||||
{ tool: "Checklist", permission: "allow" },
|
||||
{ tool: "Diff", permission: "allow" },
|
||||
{ tool: "Skills", permission: "allow" },
|
||||
{ tool: "Exit", permission: "allow" }, // Exit tool is generally safe (headless mode only)
|
||||
{ tool: "Fetch", permission: "allow" }, // Technically not read only but edge casey to post w query params
|
||||
{ tool: "List", permission: "allow" },
|
||||
|
|
@ -56,6 +57,7 @@ export const PLAN_MODE_POLICIES: ToolPermissionPolicy[] = [
|
|||
{ tool: "Read", permission: "allow" },
|
||||
{ tool: "ReportFailure", permission: "allow" },
|
||||
{ tool: "Search", permission: "allow" },
|
||||
{ tool: "Skills", permission: "allow" },
|
||||
{ tool: "Status", permission: "allow" },
|
||||
{ tool: "UploadArtifact", permission: "allow" },
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,12 @@ import { reloadService, SERVICE_NAMES, services } from "./services/index.js";
|
|||
import { getCurrentSession, updateSessionTitle } from "./session.js";
|
||||
import { posthogService } from "./telemetry/posthogService.js";
|
||||
import { telemetryService } from "./telemetry/telemetryService.js";
|
||||
import { buildImportSkillPrompt } from "./tools/skills.js";
|
||||
import { SlashCommandResult } from "./ui/hooks/useChat.types.js";
|
||||
import {
|
||||
getSkillSlashCommandName,
|
||||
loadMarkdownSkills,
|
||||
} from "./util/loadMarkdownSkills.js";
|
||||
|
||||
type CommandHandler = (
|
||||
args: string[],
|
||||
|
|
@ -171,6 +176,49 @@ function handleJobs() {
|
|||
return { openJobsSelector: true };
|
||||
}
|
||||
|
||||
async function handleSkills(): Promise<SlashCommandResult> {
|
||||
const { skills } = await loadMarkdownSkills();
|
||||
|
||||
if (!skills.length) {
|
||||
return {
|
||||
exit: false,
|
||||
output: chalk.yellow(
|
||||
"No skills found. Add skills under .continue/skills or .claude/skills.",
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
const header = chalk.bold("Available skills:");
|
||||
const lines = skills.map(
|
||||
(skill) =>
|
||||
`${chalk.cyan(skill.name)} - ${skill.description} ${chalk.gray(
|
||||
`(${skill.path})`,
|
||||
)}`,
|
||||
);
|
||||
|
||||
return {
|
||||
exit: false,
|
||||
output: [header, "", ...lines].join("\n"),
|
||||
};
|
||||
}
|
||||
|
||||
async function handleImportSkill(args: string[]): Promise<SlashCommandResult> {
|
||||
const query = args.join(" ").trim();
|
||||
|
||||
if (!query) {
|
||||
return {
|
||||
exit: false,
|
||||
output: chalk.yellow(
|
||||
"Please provide a skill URL or name. Usage: /import-skill <url-or-name>",
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
newInput: buildImportSkillPrompt(query),
|
||||
};
|
||||
}
|
||||
|
||||
function handleSessions() {
|
||||
return { openSessionSelector: true };
|
||||
}
|
||||
|
|
@ -210,6 +258,8 @@ const commandHandlers: Record<string, CommandHandler> = {
|
|||
return { openUpdateSelector: true };
|
||||
},
|
||||
jobs: handleJobs,
|
||||
skills: () => handleSkills(),
|
||||
"import-skill": (args) => handleImportSkill(args),
|
||||
sessions: handleSessions,
|
||||
};
|
||||
|
||||
|
|
@ -257,8 +307,22 @@ export async function handleSlashCommands(
|
|||
return { newInput };
|
||||
}
|
||||
|
||||
const { skills } = await loadMarkdownSkills();
|
||||
if (skills.length) {
|
||||
const normalizedCommand = command.trim().toLowerCase();
|
||||
const matchingSkill = skills.find(
|
||||
(skill) => getSkillSlashCommandName(skill) === normalizedCommand,
|
||||
);
|
||||
|
||||
if (matchingSkill) {
|
||||
return {
|
||||
newInput: `Load the skill using the **Skills** tool and then set the **skill_name** parameter to "${matchingSkill.name}".`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Check if this command would match any available commands (same logic as UI)
|
||||
const allCommands = getAllSlashCommands(assistant, {
|
||||
const allCommands = await getAllSlashCommands(assistant, {
|
||||
isRemoteMode: options?.isRemoteMode,
|
||||
});
|
||||
const hasMatches = allCommands.some((cmd) =>
|
||||
|
|
|
|||
|
|
@ -80,3 +80,36 @@ ${skills.map((skill) => `\nname: ${skill.name}\ndescription: ${skill.description
|
|||
},
|
||||
};
|
||||
};
|
||||
|
||||
export function buildImportSkillPrompt(identifier: string): string {
|
||||
return `
|
||||
# Overview
|
||||
|
||||
The user wants to import skills.
|
||||
|
||||
User-provided skill identifier:
|
||||
${identifier}
|
||||
|
||||
# Guidelines
|
||||
- There can be multiple skills in a single repository.
|
||||
- Use the available tools to fetch content and write files. When you are done, briefly summarize which skill you imported and where you saved it.
|
||||
- Use the "AskQuestion" tool where required to clarify with the user.
|
||||
|
||||
# Process:
|
||||
|
||||
**Identifier can either be a URL or a skill name**
|
||||
|
||||
- If it looks like a URL (for example, it starts with http:// or https://), open that URL and inspect its contents to find the code or files that define the skill.
|
||||
- If the URL is a GitHub repository, look for the skills folder. There can be multiple skills within subdirectories.
|
||||
- If it looks like a skill name, you should search for the most relevant open-source skill or repository that matches the skill identifier.
|
||||
- Ask questions to the user to clarify which skill they are referring to if there are multiple options in your findings.
|
||||
|
||||
**Create the skill files**
|
||||
|
||||
- The skills should be created under the directory: ~/.continue/skills/<skill-name>
|
||||
- The subdirectory name should match the name of the skill directory in the fetched repository.
|
||||
- The relevant files and folders along with SKILL.md should be present inside the created skill subdirectory.
|
||||
- If the skill already exists, ask question to the user to clarify whether they want to update it.
|
||||
- Important: Before writing any files, ask the user if they want to proceed with the import.
|
||||
`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
import { type AssistantConfig } from "@continuedev/sdk";
|
||||
import { Box, Text } from "ink";
|
||||
import React, { useMemo } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
import { getAllSlashCommands } from "../commands/commands.js";
|
||||
import {
|
||||
getAllSlashCommands,
|
||||
type SlashCommand,
|
||||
} from "../commands/commands.js";
|
||||
|
||||
const MAX_DESCRIPTION_LENGTH = 80;
|
||||
|
||||
|
|
@ -29,20 +32,39 @@ const SlashCommandUI: React.FC<SlashCommandUIProps> = ({
|
|||
selectedIndex,
|
||||
isRemoteMode = false,
|
||||
}) => {
|
||||
// Memoize the slash commands to prevent excessive re-renders
|
||||
const allCommands = useMemo(() => {
|
||||
if (assistant || isRemoteMode) {
|
||||
return getAllSlashCommands(assistant || ({} as AssistantConfig), {
|
||||
isRemoteMode,
|
||||
});
|
||||
}
|
||||
|
||||
const [allCommands, setAllCommands] = useState<SlashCommand[]>(
|
||||
// Fallback - basic commands without assistant
|
||||
return [
|
||||
{ name: "help", description: "Show help message" },
|
||||
{ name: "clear", description: "Clear the chat history" },
|
||||
{ name: "exit", description: "Exit the chat" },
|
||||
];
|
||||
[
|
||||
{ name: "help", description: "Show help message", category: "system" },
|
||||
{
|
||||
name: "clear",
|
||||
description: "Clear the chat history",
|
||||
category: "system",
|
||||
},
|
||||
{ name: "exit", description: "Exit the chat", category: "system" },
|
||||
],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
let stale = false;
|
||||
|
||||
const loadCommands = async () => {
|
||||
if (assistant || isRemoteMode) {
|
||||
const commands = await getAllSlashCommands(
|
||||
assistant || ({} as AssistantConfig),
|
||||
{ isRemoteMode },
|
||||
);
|
||||
if (!stale) {
|
||||
setAllCommands(commands);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void loadCommands();
|
||||
|
||||
return () => {
|
||||
stale = true;
|
||||
};
|
||||
}, [isRemoteMode, assistant?.prompts, assistant?.rules]);
|
||||
|
||||
// Filter commands based on the current filter
|
||||
|
|
|
|||
|
|
@ -2,9 +2,12 @@
|
|||
|
||||
import { type AssistantConfig } from "@continuedev/sdk";
|
||||
import { Box, Text, useApp, useInput } from "ink";
|
||||
import React, { useCallback, useRef, useState } from "react";
|
||||
import React, { useCallback, useEffect, useRef, useState } from "react";
|
||||
|
||||
import { getAllSlashCommands } from "../commands/commands.js";
|
||||
import {
|
||||
getAllSlashCommands,
|
||||
type SlashCommand,
|
||||
} from "../commands/commands.js";
|
||||
import { useServices } from "../hooks/useService.js";
|
||||
import type { PermissionMode } from "../permissions/types.js";
|
||||
import type { FileIndexServiceState } from "../services/FileIndexService.js";
|
||||
|
|
@ -180,20 +183,29 @@ const UserInput: React.FC<UserInputProps> = ({
|
|||
fileIndex: FileIndexServiceState;
|
||||
}>(["fileIndex"]);
|
||||
|
||||
const getSlashCommands = () => {
|
||||
if (assistant || isRemoteMode) {
|
||||
return getAllSlashCommands(assistant || ({} as AssistantConfig), {
|
||||
isRemoteMode,
|
||||
});
|
||||
}
|
||||
const [slashCommands, setSlashCommands] = useState<SlashCommand[]>([
|
||||
{ name: "help", description: "Show help message", category: "system" },
|
||||
{
|
||||
name: "clear",
|
||||
description: "Clear the chat history",
|
||||
category: "system",
|
||||
},
|
||||
{ name: "exit", description: "Exit the chat", category: "system" },
|
||||
]);
|
||||
|
||||
// Fallback - basic commands without assistant
|
||||
return [
|
||||
{ name: "help", description: "Show help message" },
|
||||
{ name: "clear", description: "Clear the chat history" },
|
||||
{ name: "exit", description: "Exit the chat" },
|
||||
];
|
||||
};
|
||||
useEffect(() => {
|
||||
const loadCommands = async () => {
|
||||
if (assistant || isRemoteMode) {
|
||||
const commands = await getAllSlashCommands(
|
||||
assistant || ({} as AssistantConfig),
|
||||
{ isRemoteMode },
|
||||
);
|
||||
setSlashCommands(commands);
|
||||
}
|
||||
};
|
||||
|
||||
void loadCommands();
|
||||
}, [isRemoteMode, assistant?.prompts, assistant?.rules]);
|
||||
|
||||
// Cycle through permission modes
|
||||
const cycleModes = async () => {
|
||||
|
|
@ -255,8 +267,7 @@ const UserInput: React.FC<UserInputProps> = ({
|
|||
const afterSlash = trimmedText.slice(1).split(/[\s\n]/)[0];
|
||||
|
||||
// We're in a slash command context - check if it's a complete command
|
||||
const allCommands = getSlashCommands();
|
||||
const exactMatch = allCommands.find((cmd) => cmd.name === afterSlash);
|
||||
const exactMatch = slashCommands.find((cmd) => cmd.name === afterSlash);
|
||||
|
||||
// Hide selector if we have an exact match and there's any additional content
|
||||
if (exactMatch) {
|
||||
|
|
@ -275,7 +286,7 @@ const UserInput: React.FC<UserInputProps> = ({
|
|||
}
|
||||
|
||||
// Check if there are any matching commands
|
||||
const filteredCommands = allCommands.filter((cmd) =>
|
||||
const filteredCommands = slashCommands.filter((cmd) =>
|
||||
cmd.name.toLowerCase().includes(afterSlash.toLowerCase()),
|
||||
);
|
||||
|
||||
|
|
@ -346,8 +357,7 @@ const UserInput: React.FC<UserInputProps> = ({
|
|||
|
||||
// Get filtered commands for navigation - using the same sorting logic as SlashCommandUI
|
||||
const getFilteredCommands = () => {
|
||||
const allCommands = getSlashCommands();
|
||||
return allCommands
|
||||
return slashCommands
|
||||
.filter((cmd) =>
|
||||
cmd.name.toLowerCase().includes(slashCommandFilter.toLowerCase()),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -144,3 +144,27 @@ export async function loadMarkdownSkills(): Promise<LoadSkillsResult> {
|
|||
|
||||
return { skills, errors };
|
||||
}
|
||||
|
||||
export function getSkillSlashCommandName(skill: Skill): string {
|
||||
// Normalize skill name to lowercase and sanitize for use as command name
|
||||
const base = skill.name.trim().toLowerCase();
|
||||
const safe = base
|
||||
.replace(/[^a-z0-9]+/g, "-")
|
||||
.replace(/^-+/, "")
|
||||
.replace(/-+$/, "");
|
||||
|
||||
if (safe) {
|
||||
return `skill-${safe}`;
|
||||
}
|
||||
|
||||
// Fallback to directory name if skill name is invalid
|
||||
const dirName = path
|
||||
.basename(path.dirname(skill.path))
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, "-")
|
||||
.replace(/^-+/, "")
|
||||
.replace(/-+$/, "");
|
||||
|
||||
const fallback = dirName || "skill";
|
||||
return `skill-${fallback}`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue