334
335
private async _validateAndSanitizeSkillFile(uri: URI, token: CancellationToken): Promise<{ name: string; description: string | undefined }> {
337
>
const folderName = getSkillFolderName(uri);
338
>
339
>
let name = parsedFile.header?.name;
340
>
if (!name) {
341
this.logger.debug(`[validateAndSanitizeSkillFile] Agent skill file missing name attribute, using folder name "${folderName}": ${uri}`);
342
name = folderName;
343
}
345
>
const description = parsedFile.header?.description;
346
>
347
>
// Sanitize the name first (remove XML tags and truncate)
348
>
let sanitizedName = this._truncateAgentSkillName(name, uri);
349
>
350
>
// If sanitized name doesn't match folder name, use folder name (consistent with computeSkillDiscoveryInfo)
351
>
if (sanitizedName !== folderName) {
352
this.logger.debug(`[validateAndSanitizeSkillFile] Agent skill name "${sanitizedName}" does not match folder name "${folderName}", using folder name: ${uri}`);
353
sanitizedName = folderName;
354
}
356
>
const sanitizedDescription = description ? this._truncateAgentSkillDescription(description, uri) : undefined;
357
>
return { name: sanitizedName, description: sanitizedDescription };
358
>
}
359
360
private async _parsePromptFile(uri: URI, token: CancellationToken): Promise<ParsedPromptFile> {
362
>
if (model) {
363
return new PromptFileParser().parse(uri, model.getValue());
364
}
366
>
if (token.isCancellationRequested) {
367
throw new CancellationError();
368
}
370
>
}
371
372
private _sanitizeAgentSkillText(text: string): string {
374
>
return text.replace(/<[^>]+>/g, '');
375
>
}
376
377
private _truncateAgentSkillName(name: string, uri: URI): string {
379
>
const sanitized = this._sanitizeAgentSkillText(name);
380
>
if (sanitized !== name) {
381
this.logger.debug(`[findAgentSkills] Agent skill name contains XML tags, removed: ${uri}`);
382
}
384
this.logger.debug(`[findAgentSkills] Agent skill name exceeds ${MAX_NAME_LENGTH} characters, truncated: ${uri}`);
385
return sanitized.substring(0, MAX_NAME_LENGTH);
386
}
388
>
}
389
390
private _truncateAgentSkillDescription(description: string, uri: URI): string {