MCPcopy Create free account
hub / github.com/allocnode/oh-my-sage / readSkillFile

Function readSkillFile

src/server/skills/loader.ts:259–285  ·  view source on GitHub ↗
(skillName: string, filePath: string)

Source from the content-addressed store, hash-verified

257/**
258 * 读取 Skill 目录中的文件(渐进式披露第三层)
259 */
260export function readSkillFile(skillName: string, filePath: string): string | null {
261 const skill = getSkillByName(skillName);
262 if (!skill) {
263 console.error(`[Skill] Skill 不存在: ${skillName}`);
264 return null;
265 }
266
267 const absolutePath = path.resolve(skill.baseDir, filePath);
268 const relativePath = path.relative(skill.baseDir, absolutePath);
269
270 // 安全检查:确保引用在 Skill 目录内
271 if (relativePath.startsWith('..') || path.isAbsolute(relativePath)) {
272 console.warn(`[Skill] 引用路径超出 Skill 目录: ${filePath}`);
273 return null;
274 }
275
276 try {
277 if (fs.existsSync(absolutePath)) {
278 const realBaseDir = fs.realpathSync(skill.baseDir);
279 const realPath = fs.realpathSync(absolutePath);
280 const realRelativePath = path.relative(realBaseDir, realPath);
281 if (realRelativePath.startsWith('..') || path.isAbsolute(realRelativePath)) {
282 console.warn(`[Skill] 符号链接路径超出 Skill 目录: ${filePath}`);
283 return null;
284 }
285 return fs.readFileSync(absolutePath, 'utf8');
286 } else {
287 console.warn(`[Skill] 文件不存在: ${absolutePath}`);
288 }

Callers 1

createCoreToolsFunction · 0.90

Calls 1

getSkillByNameFunction · 0.85

Tested by

no test coverage detected