( tools: Tools, getToolPermissionContext: () => Promise<ToolPermissionContext>, agentInfo: AgentDefinitionsResult | null, )
| 553 | } |
| 554 | |
| 555 | async function countSkillTokens( |
| 556 | tools: Tools, |
| 557 | getToolPermissionContext: () => Promise<ToolPermissionContext>, |
| 558 | agentInfo: AgentDefinitionsResult | null, |
| 559 | ): Promise<{ |
| 560 | skillTokens: number |
| 561 | skillInfo: { |
| 562 | totalSkills: number |
| 563 | includedSkills: number |
| 564 | skillFrontmatter: SkillFrontmatter[] |
| 565 | } |
| 566 | }> { |
| 567 | try { |
| 568 | const skills = await getLimitedSkillToolCommands(getCwd()) |
| 569 | |
| 570 | const slashCommandTool = findSkillTool(tools) |
| 571 | if (!slashCommandTool) { |
| 572 | return { |
| 573 | skillTokens: 0, |
| 574 | skillInfo: { totalSkills: 0, includedSkills: 0, skillFrontmatter: [] }, |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | // NOTE: This counts the entire SlashCommandTool (which includes both commands AND skills). |
| 579 | // This is the same tool counted by countSlashCommandTokens(), but we track it separately |
| 580 | // here for display purposes. These tokens should NOT be added to context categories |
| 581 | // to avoid double-counting. |
| 582 | const skillTokens = await countToolDefinitionTokens( |
| 583 | [slashCommandTool], |
| 584 | getToolPermissionContext, |
| 585 | agentInfo, |
| 586 | ) |
| 587 | |
| 588 | // Calculate per-skill token estimates based on frontmatter only |
| 589 | // (name, description, whenToUse) since full content is only loaded on invocation |
| 590 | const skillFrontmatter: SkillFrontmatter[] = skills.map(skill => ({ |
| 591 | name: getCommandName(skill), |
| 592 | source: (skill.type === 'prompt' ? skill.source : 'plugin') as |
| 593 | | SettingSource |
| 594 | | 'plugin', |
| 595 | tokens: estimateSkillFrontmatterTokens(skill), |
| 596 | })) |
| 597 | |
| 598 | return { |
| 599 | skillTokens, |
| 600 | skillInfo: { |
| 601 | totalSkills: skills.length, |
| 602 | includedSkills: skills.length, |
| 603 | skillFrontmatter, |
| 604 | }, |
| 605 | } |
| 606 | } catch (error) { |
| 607 | logError(toError(error)) |
| 608 | |
| 609 | // Return zero values rather than failing the entire context analysis |
| 610 | return { |
| 611 | skillTokens: 0, |
| 612 | skillInfo: { totalSkills: 0, includedSkills: 0, skillFrontmatter: [] }, |
no test coverage detected