INNER CODE UNIT · TypeScript
estimateTokens
HoangNguyen0403/agent-skills-standard · mcp/src/tools/index.ts:957
function estimateTokens(text: string): number {
return Math.ceil(text.length / 4);
}
function dedupStub(category: string, id: string, why: string): string {
return `<!-- skill: ${category}/${id} | matched: ${why} | already loaded this session, body omitted (pass force_reload: true to resend) -->`;
}
/**
* Best-practice 1.4 (avoid "not found"): when a load returns no match, return
* what's available so the LLM can pick the next useful action instead of giving up.
*/
function noMatchGuidance(
via: "load_skills_for_files" | "load_skills_for_keywords",
input: string[],
ctx: ToolContext,
): ToolResult {
const categories = ctx.index.listCategories();