feat(plugins): merge Skill management into plugins
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { readFile, readdir } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {
|
||||
BUNDLED_CODING_SKILL_IDS,
|
||||
type CodingSkillId,
|
||||
} from '../../shared/coding-skills';
|
||||
import type {
|
||||
@@ -56,8 +55,9 @@ function selectedSkillIds(
|
||||
const selected = new Set<string>();
|
||||
for (const raw of value) {
|
||||
const id = raw.trim();
|
||||
if (!allowed.has(id)) throw new Error(`Unknown bundled coding skill: ${id}`);
|
||||
selected.add(id);
|
||||
// Old project assignments are retained in project.json, but a removed or
|
||||
// not-yet-installed provider must not break the current capability list.
|
||||
if (allowed.has(id)) selected.add(id);
|
||||
}
|
||||
return selected;
|
||||
}
|
||||
@@ -85,29 +85,21 @@ async function listSkillEntries(
|
||||
}
|
||||
|
||||
export async function listProductCodingSkills(
|
||||
bundledSkillsDir: string,
|
||||
_bundledSkillsDir: string,
|
||||
selectedIds: readonly string[] = [],
|
||||
pluginSkillSources: readonly ProductCodingPluginSkillSource[] = [],
|
||||
): Promise<ProductCodingSkill[]> {
|
||||
const pluginIds = pluginSkillSources.map(({ id }) => id);
|
||||
const allIds = [...BUNDLED_CODING_SKILL_IDS, ...pluginIds];
|
||||
const allIds = [...pluginIds];
|
||||
if (new Set(allIds).size !== allIds.length) {
|
||||
throw new Error('Duplicate coding skill identifier');
|
||||
}
|
||||
const selected = selectedSkillIds(selectedIds, allIds);
|
||||
const sources: ProductCodingPluginSkillSource[] = [
|
||||
...BUNDLED_CODING_SKILL_IDS.map((id) => ({
|
||||
id,
|
||||
directory: path.join(bundledSkillsDir, id),
|
||||
})),
|
||||
...pluginSkillSources,
|
||||
];
|
||||
const sources: ProductCodingPluginSkillSource[] = [...pluginSkillSources];
|
||||
const visibleSources = sources.filter(({ id, available }) => available !== false || selected.has(id));
|
||||
return await Promise.all(visibleSources.map(async ({ id, directory, entryPath, available = true }) => {
|
||||
const sourceLocation = path.resolve(directory);
|
||||
const location = (BUNDLED_CODING_SKILL_IDS as readonly string[]).includes(id)
|
||||
? path.posix.join('resources', 'coding-skills', id)
|
||||
: sourceLocation;
|
||||
const location = sourceLocation;
|
||||
const content = await readFile(path.join(sourceLocation, entryPath ?? 'SKILL.md'), 'utf8');
|
||||
return {
|
||||
id: productSkillId(id),
|
||||
|
||||
Reference in New Issue
Block a user