ai-ad-code-adapter

16 stars

Best use case

ai-ad-code-adapter is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Teams using ai-ad-code-adapter should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/ai-ad-code-adapter/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/development/ai-ad-code-adapter/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/ai-ad-code-adapter/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How ai-ad-code-adapter Compares

Feature / Agentai-ad-code-adapterStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

This skill provides specific capabilities for your AI agent. See the About section for full details.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

<skill>
──────────────────────────────────────────────
  <name>ai-ad-code-adapter</name>
  <version>1.0</version>
  <domain>AI_AD_SYSTEM / 代码工厂 / 代码适配</domain>
  <profile>Code-Adapter / AST-Transform / Rule-Based</profile>
──────────────────────────────────────────────


  <!-- ======================================================
       0. 代码来源说明 (Code Sources)
  ====================================================== -->
  <code_sources>
    本 Skill 的设计和实现借鉴了以下开源项目:

    1. **astx** (MIT License)
       - GitHub: https://github.com/codemodsquad/astx
       - 借鉴内容:
         - 结构化搜索替换模式 (pattern → replacement)
         - 通配符匹配语法 ($identifier 占位符)
         - AST 级别代码转换

    2. **refactor** (MIT License)
       - GitHub: https://github.com/isidentical/refactor
       - 借鉴内容:
         - Python AST 重构框架
         - 契约式转换 (assert-based matching)
         - 规则化转换动作 (Rule + Replace)

    3. **ts-morph** (MIT License)
       - GitHub: https://github.com/dsherret/ts-morph
       - 借鉴内容:
         - TypeScript AST 操作模式
         - 代码重构辅助方法

    实现策略:
    - 简单转换: 使用正则表达式模式匹配
    - 复杂转换: 使用 LLM 辅助适配
    - 验证: 适配后进行语法检查
  </code_sources>


  <!-- ======================================================
       1. 核心使命 (Mission)
  ====================================================== -->
  <mission>
    作为代码工厂的适配器,负责将参考代码适配为符合项目规范的代码。

    核心原则:
    - 🔧 保留结构: 保留参考代码的整体结构,只做必要修改
    - 📏 规则驱动: 使用预定义规则进行技术栈适配
    - 📝 标注改动: 所有改动点都添加注释标注
    - ✅ 来源追溯: 保留代码来源信息
  </mission>


  <!-- ======================================================
       2. 输入契约 (Input Contract)
  ====================================================== -->
  <input_contract>
    必填:
    {
      reference: SearchCandidate,   // 选中的参考代码
      requirement: string,          // 原始需求描述
      adaptation_plan: AdaptationPlan  // 适配方案
    }

    可选:
    {
      custom_rules: {               // 自定义适配规则
        [pattern]: replacement
      },
      preserve_comments: boolean,   // 保留原注释 (默认 true)
      add_type_hints: boolean,      // 添加类型提示 (默认 true)
      target_path: string           // 目标文件路径
    }
  </input_contract>


  <!-- ======================================================
       3. 输出契约 (Output Contract)
  ====================================================== -->
  <output_contract>
    {
      success: boolean,
      data: {
        adapted_files: [
          {
            file_path: string,        // 目标文件路径
            content: string,          // 适配后的完整代码
            adaptations: [            // 适配记录
              {
                line: number,
                type: string,         // 适配类型
                original: string,
                adapted: string,
                reason: string
              }
            ],
            source_attribution: {     // 来源标注
              reference: string,
              source: string,
              adaptation_rate: string
            }
          }
        ],
        summary: {
          total_adaptations: number,
          by_type: {
            tech_stack: number,
            project_standard: number,
            sot_compliance: number,
            custom: number
          }
        }
      },
      error: string | null
    }
  </output_contract>


  <!-- ======================================================
       4. 适配层次 (Adaptation Layers)
  ====================================================== -->
  <adaptation_layers>
    <layer id="L1_TECH_STACK" priority="1">
      <name>技术栈适配</name>
      <description>将参考代码适配到项目的技术栈版本</description>

      <rules>
        <!-- Pydantic v1 → v2 -->
        <rule id="PYDANTIC_CONFIG">
          <pattern>class Config:</pattern>
          <replacement>model_config = ConfigDict(</replacement>
          <context>Pydantic v2 使用 model_config 替代 class Config</context>
        </rule>

        <rule id="PYDANTIC_VALIDATOR">
          <pattern>@validator\(([^)]+)\)</pattern>
          <replacement>@field_validator($1)</replacement>
          <context>Pydantic v2 使用 @field_validator 替代 @validator</context>
        </rule>

        <rule id="PYDANTIC_ROOT_VALIDATOR">
          <pattern>@root_validator</pattern>
          <replacement>@model_validator(mode='after')</replacement>
          <context>Pydantic v2 使用 @model_validator 替代 @root_validator</context>
        </rule>

        <!-- SQLAlchemy 1 → 2 -->
        <rule id="SQLALCHEMY_QUERY">
          <pattern>session\.query\((\w+)\)</pattern>
          <replacement>session.execute(select($1))</replacement>
          <context>SQLAlchemy 2.x 推荐使用 select() 语法</context>
        </rule>

        <rule id="SQLALCHEMY_COLUMN">
          <pattern>Column\(</pattern>
          <replacement>mapped_column(</replacement>
          <context>SQLAlchemy 2.x 使用 mapped_column</context>
        </rule>
      </rules>
    </layer>

    <layer id="L2_PROJECT_STANDARD" priority="2">
      <name>项目规范适配</name>
      <description>适配项目的响应格式、错误码、命名等规范</description>

      <rules>
        <rule id="RESPONSE_FORMAT">
          <pattern>return \{[^}]*\}</pattern>
          <replacement>return StandardResponse(data=..., message=...)</replacement>
          <context>使用项目标准响应格式</context>
        </rule>

        <rule id="ERROR_CODE">
          <pattern>raise HTTPException\(status_code=(\d+), detail="([^"]+)"\)</pattern>
          <replacement>raise AppException(code=ErrorCode.XXX, message="$2")</replacement>
          <context>使用项目标准错误码</context>
        </rule>

        <rule id="IMPORT_STANDARD">
          <description>添加项目标准导入</description>
          <imports>
            - from backend.core.response import StandardResponse
            - from backend.core.error_codes import ErrorCode, AppException
          </imports>
        </rule>
      </rules>
    </layer>

    <layer id="L3_SOT_COMPLIANCE" priority="3">
      <name>SoT 合规适配</name>
      <description>确保代码符合 SoT 文档定义</description>

      <checks>
        - 字段名是否在 DATA_SCHEMA 中定义
        - 状态值是否在 STATE_MACHINE 中定义
        - 错误码是否在 ERROR_CODES_SOT 中定义
        - 业务规则是否符合 BUSINESS_RULES
      </checks>

      <actions>
        - 替换不存在的字段为正确字段
        - 替换不存在的状态为正确状态
        - 添加遗漏的业务规则检查
      </actions>
    </layer>

    <layer id="L4_CUSTOM" priority="4">
      <name>功能定制</name>
      <description>根据需求进行功能定制 (使用 LLM)</description>

      <prompt_template>
        你是代码适配器。基于以下参考代码,根据需求进行定制。

        ## 参考代码
        {reference_code}

        ## 需求
        {requirement}

        ## 适配指南
        {adaptation_hint}

        ## 规则
        1. 保留参考代码的整体结构
        2. 只做满足需求的必要修改
        3. 用注释标注所有改动点: # [ADAPTED] 原因: xxx
        4. 不要发明新的状态/字段/错误码

        ## 输出格式
        只输出适配后的完整代码,包含改动标注注释。
      </prompt_template>
    </layer>
  </adaptation_layers>


  <!-- ======================================================
       5. 来源标注格式 (Source Attribution)
  ====================================================== -->
  <source_attribution>
    在每个适配后的文件头部添加来源标注:

    ```python
    """
    [ADAPTED FROM] {source}: {reference_path}
    [ADAPTATION]   基于参考代码适配,非从零生成
    [CHANGES]      技术栈适配 x 处,项目规范适配 x 处,SoT 合规 x 处,功能定制 x 处
    """
    ```

    在每个改动点添加行内标注:

    ```python
    # [ADAPTED] 原因: Pydantic v2 语法 | 原: class Config:
    model_config = ConfigDict(...)
    ```
  </source_attribution>


  <!-- ======================================================
       6. 禁止行为 (Forbidden Actions)
  ====================================================== -->
  <forbidden_actions>
    <forbidden id="ADP-001">
      <action>完全重写参考代码</action>
      <correct_action>只做必要的适配修改,保留原结构</correct_action>
    </forbidden>

    <forbidden id="ADP-002">
      <action>不标注来源和改动</action>
      <correct_action>必须添加来源标注和改动注释</correct_action>
    </forbidden>

    <forbidden id="ADP-003">
      <action>发明 SoT 中不存在的字段/状态/错误码</action>
      <correct_action>只使用 SoT 中已定义的</correct_action>
    </forbidden>

    <forbidden id="ADP-004">
      <action>删除参考代码的有效逻辑</action>
      <correct_action>只修改,不随意删除</correct_action>
    </forbidden>
  </forbidden_actions>


  <!-- ======================================================
       7. 使用示例 (Usage Examples)
  ====================================================== -->
  <usage>
    示例 1: 基础适配
    「
    使用 ai-ad-code-adapter,
    reference = [选中的参考代码],
    requirement = "添加日报批量导出 Excel 功能",
    adaptation_plan = [选型阶段生成的适配方案]
    」

    示例 2: 自定义规则
    「
    使用 ai-ad-code-adapter,
    reference = [...],
    requirement = "...",
    adaptation_plan = [...],
    custom_rules = {
      "old_function_name": "new_function_name",
      "OldClassName": "NewClassName"
    }
    」
  </usage>


  <!-- ======================================================
       8. 版本记录 (Version Notes)
  ====================================================== -->
  <VERSION_NOTES>
    ### v1.0 (2025-12-17)
    - 初始版本
    - 四层适配架构 (技术栈/项目规范/SoT合规/功能定制)
    - 借鉴 astx 的结构化替换模式
    - 借鉴 refactor 的规则化转换框架
    - 来源标注和改动追踪
  </VERSION_NOTES>

</skill>

Related Skills

adapter-development

16
from diegosouzapw/awesome-omni-skill

Comprehensive guide for AIDB debug adapter development. Covers component-based architecture, language-specific patterns (Python/debugpy, JavaScript/vscode-js-debug, Java/java-debug), lifecycle hooks, process management, port management, launch orchestration, resource cleanup, child sessions, and common pitfalls. Essential for developing or maintaining AIDB debug adapters.

vllm-ascend-model-adapter

16
from diegosouzapw/awesome-omni-skill

Adapt and debug existing or new models for vLLM on Ascend NPU. Implement in /vllm-workspace/vllm and /vllm-workspace/vllm-ascend, validate via direct vllm serve from /workspace, and deliver one signed commit in the current repo.

bio-read-qc-adapter-trimming

16
from diegosouzapw/awesome-omni-skill

Remove sequencing adapters from FASTQ files using Cutadapt and Trimmomatic. Supports single-end and paired-end reads, Illumina TruSeq, Nextera, and custom adapter sequences. Use when FastQC shows adapter contamination or before alignment of short reads.

bgo

10
from diegosouzapw/awesome-omni-skill

Automates the complete Blender build-go workflow, from building and packaging your extension/add-on to removing old versions, installing, enabling, and launching Blender for quick testing and iteration.

Coding & Development

analyze-rust-optimizations

16
from diegosouzapw/awesome-omni-skill

This skill performs thorough analysis of Rust libraries to find optimization opportunities. It should be used when reviewing Rust code for performance improvements, memory efficiency, or when profiling indicates bottlenecks. Focuses on runtime performance and memory usage through dynamic profiling tools and static code analysis.

analyze-project-architecture

16
from diegosouzapw/awesome-omni-skill

LLM-based architectural analysis that transforms raw project data into meaningful structure

analyze-pr-performance

16
from diegosouzapw/awesome-omni-skill

Analyze code review pipeline performance for a specific PR. Use when investigating slow PRs, identifying bottlenecks, or debugging performance issues in code reviews.

analyze

16
from diegosouzapw/awesome-omni-skill

Deep analysis and investigation

analyze-m1-module-for-migration

16
from diegosouzapw/awesome-omni-skill

Systematically analyze a Magento 1 module to determine its purpose, usage, and migration requirements for Magento 2. Use when you need to decide whether to migrate a M1 module, find alternatives, or skip it.

analyze-function

16
from diegosouzapw/awesome-omni-skill

Deep line-by-line analysis of a function or method. Explains what each line does, why it's written that way, performance implications, edge cases, and design patterns. Use when user says "analyze-function", "analyze {function}", "deep dive on {function}", or "explain {function} line by line".

analyze-friction

16
from diegosouzapw/awesome-omni-skill

Orchestrate 3-stage friction analysis workflow across conversations. Extracts raw friction, abstracts patterns, and presents for approval. Use when user wants to analyze conversation history for improvement opportunities.

analyze-codebase

16
from diegosouzapw/awesome-omni-skill

Analyze a codebase to generate a comprehensive architecture and structure report. Use when user wants to understand a codebase, explore project structure, or generate analysis.