AgentSkillsCN

add-ktnip-collector

【库贡献者】为 ktnip KSP 处理器新增一个全新的收集器。适用于实现新的处理器类型(例如,新增 @MyHandler 注解),为全新活动模式添加收集器,或扩展 ktnip 处理器以收集更多带有注解的函数时使用。

SKILL.md
--- frontmatter
name: add-ktnip-collector
description: [Library contributor] Adds a new collector to the ktnip KSP processor. Use when implementing a new handler type (e.g. new annotation like @MyHandler), adding a collector for a new activity pattern, or extending the ktnip processor to collect additional annotated functions.

Add Ktnip Collector

Workflow

1. Create Annotation (if new)

  • Define annotation in telegram-bot module (annotations package)
  • Ensure it can be discovered via findAnnotationRecursively (meta-annotations supported)

2. Add Annotation Parser (if new annotation)

  • In AnnotationParser.kt: add parseMyAnnotation(arguments) returning parsed data
  • Use parseValueList, parseScopes patterns from existing parsers

3. Create Collector Class

4. Collector Implementation

  • Discovery: resolver.getAnnotatedFnSymbols(ctx.pkg, MyAnnotation::class)
  • Parse: function.annotations.findAnnotationRecursively(MyAnnotation::class)?.arguments
  • Metadata: extractActivityMetadata(function) (from BaseCollector)
  • Generate: generateAndRegisterActivity(function, metadata, ctx, parameters, updateType)
  • Register: ctx.loadFun.addStatement("registerX(%S, %L.id)", id, activityId)

5. Register in ActivityProcessor

  • Add to collectors list in ActivityProcessor.kt processPackage:
    • Order matters: BotCtxCollector, CommandCollector, InputCollector, CommonCollector, UpdateHandlerCollector, UnprocessedHandlerCollector, WizardCollector

6. ResolverExtensions (if needed)

  • getAnnotatedFnSymbols(pkg, MyAnnotation::class) works for any annotation (generic)
  • Custom discovery logic only if collecting non-function symbols

Reference