收口 Makelore 客户端变更
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { readdir, readFile } from 'node:fs/promises';
|
||||
import { basename, dirname, join } from 'node:path';
|
||||
import type { OpencodeSkillInfo } from './client';
|
||||
import { basename, dirname, join, relative, sep } from 'node:path';
|
||||
import type { OpencodeSkillEntry, OpencodeSkillInfo } from './client';
|
||||
|
||||
const SKILL_ROOT_NAMES = ['skill', 'skills'] as const;
|
||||
|
||||
@@ -29,6 +29,36 @@ async function collectSkillFiles(root: string): Promise<string[]> {
|
||||
return files;
|
||||
}
|
||||
|
||||
async function collectSkillEntries(root: string, current = root): Promise<OpencodeSkillEntry[]> {
|
||||
let entries;
|
||||
try {
|
||||
entries = await readdir(current, { withFileTypes: true });
|
||||
} catch (error) {
|
||||
if (typeof error === 'object' && error && 'code' in error && error.code === 'ENOENT') {
|
||||
return [];
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
entries.sort((left, right) => {
|
||||
const directoryOrder = Number(right.isDirectory()) - Number(left.isDirectory());
|
||||
return directoryOrder || left.name.localeCompare(right.name);
|
||||
});
|
||||
|
||||
const result: OpencodeSkillEntry[] = [];
|
||||
for (const entry of entries) {
|
||||
const entryPath = join(current, entry.name);
|
||||
const relativePath = relative(root, entryPath).split(sep).join('/');
|
||||
if (entry.isDirectory()) {
|
||||
result.push({ path: relativePath, type: 'directory' });
|
||||
result.push(...await collectSkillEntries(root, entryPath));
|
||||
} else if (entry.isFile()) {
|
||||
result.push({ path: relativePath, type: 'file' });
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function unquoteYamlScalar(value: string): string {
|
||||
const trimmed = value.trim();
|
||||
if (
|
||||
@@ -73,6 +103,7 @@ export async function listInstalledOpencodeSkills(managedConfigDir?: string | nu
|
||||
description: readFrontmatterScalar(content, 'description'),
|
||||
location,
|
||||
content,
|
||||
entries: await collectSkillEntries(dirname(location)),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user