MCPcopy Create free account
hub / github.com/WJX20/claude-code / getDynamicSkillAttachments

Function getDynamicSkillAttachments

src/utils/attachments.ts:2548–2602  ·  view source on GitHub ↗

* Processes skill directories that were discovered during file operations. * Uses dynamicSkillDirTriggers field from ToolUseContext

(
  toolUseContext: ToolUseContext,
)

Source from the content-addressed store, hash-verified

2546 * Uses dynamicSkillDirTriggers field from ToolUseContext
2547 */
2548async function getDynamicSkillAttachments(
2549 toolUseContext: ToolUseContext,
2550): Promise<Attachment[]> {
2551 const attachments: Attachment[] = []
2552
2553 if (
2554 toolUseContext.dynamicSkillDirTriggers &&
2555 toolUseContext.dynamicSkillDirTriggers.size > 0
2556 ) {
2557 // Parallelize: readdir all skill dirs concurrently
2558 const perDirResults = await Promise.all(
2559 Array.from(toolUseContext.dynamicSkillDirTriggers).map(async skillDir => {
2560 try {
2561 const entries = await readdir(skillDir, { withFileTypes: true })
2562 const candidates = entries
2563 .filter(e => e.isDirectory() || e.isSymbolicLink())
2564 .map(e => e.name)
2565 // Parallelize: stat all SKILL.md candidates concurrently
2566 const checked = await Promise.all(
2567 candidates.map(async name => {
2568 try {
2569 await stat(resolve(skillDir, name, 'SKILL.md'))
2570 return name
2571 } catch {
2572 return null // SKILL.md doesn't exist, skip this entry
2573 }
2574 }),
2575 )
2576 return {
2577 skillDir,
2578 skillNames: checked.filter((n): n is string => n !== null),
2579 }
2580 } catch {
2581 // Ignore errors reading skill directories (e.g., directory doesn't exist)
2582 return { skillDir, skillNames: [] }
2583 }
2584 }),
2585 )
2586
2587 for (const { skillDir, skillNames } of perDirResults) {
2588 if (skillNames.length > 0) {
2589 attachments.push({
2590 type: 'dynamic_skill',
2591 skillDir,
2592 skillNames,
2593 displayPath: relative(getCwd(), skillDir),
2594 })
2595 }
2596 }
2597
2598 toolUseContext.dynamicSkillDirTriggers.clear()
2599 }
2600
2601 return attachments
2602}
2603
2604// Track which skills have been sent to avoid re-sending. Keyed by agentId
2605// (empty string = main thread) so subagents get their own turn-0 listing —

Callers 1

getAttachmentsFunction · 0.85

Calls 5

readdirFunction · 0.85
statFunction · 0.85
getCwdFunction · 0.85
resolveFunction · 0.70
clearMethod · 0.45

Tested by

no test coverage detected