MCPcopy Create free account
hub / github.com/Noumena-Network/code / getDynamicSkillAttachments

Function getDynamicSkillAttachments

src/utils/attachments.ts:2554–2608  ·  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

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