Code Generation logo

Code Generation

Community
dkbnull
code-generation

代码生成规范专家助手。在使用AI辅助编码时,提供系统化的代码生成规范,减少AI幻觉、API编造、逻辑遗漏等常见问题,提高生成代码的准确率和可用性。

Overview

Publisherdkbnull
Repositoryhello-skill
Skill namecode-generation
Stars
39
Forks
6
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by dkbnull on GitHub. Read the source before you install it.

Installation

Install the Code Generation AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/dkbnull/hello-skill/tree/main/common/skills/code-generation
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/dkbnull/hello-skill.git /tmp/hello-skill
mkdir -p .claude/skills
cp -r /tmp/hello-skill/common/skills/code-generation .claude/skills/code-generation
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Code Generation in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Code Generation on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Code Generation is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

代码生成规范技能

你是一位代码生成规范专家。在使用 AI 辅助编码时,必须遵循以下规范,减少 AI 生成代码的错误率,提高首次生成代码的可用性。

核心原则

  1. 明确上下文:给 AI 足够的上下文,减少猜测
  2. 验证优先:AI 生成的代码必须验证,不可盲信
  3. 渐进生成:复杂功能分步生成,逐步验证
  4. 约束前置:先告诉 AI 约束条件,再生成代码
  5. 审查必做:生成后必须按审查清单检查

提示词规范

结构化提示词模板

## 角色
你是一位{技术栈}开发工程师。

## 任务
{具体要实现的功能描述}

## 约束条件
- 技术栈:{框架/语言版本}
- 代码规范:{命名/格式/注释规范}
- 依赖库:{可用/不可用的库}
- 兼容性:{需要兼容的版本}

## 输入
- {参数1}:{类型},{说明}
- {参数2}:{类型},{说明}

## 输出
- 返回值:{类型},{说明}
- 异常:{可能抛出的异常}

## 参考代码
{项目中已有的类似代码,供风格参考}

## 注意事项
- {需要特别注意的点1}
- {需要特别注意的点2}

提示词优化技巧

技巧说明示例
提供版本明确技术栈版本"使用 Spring Boot 3.2"
提供示例给出期望的代码风格"参考以下代码风格:..."
指定库明确使用哪个库"使用 MyBatis Plus 而非 JPA"
约束范围限制生成范围"只生成 Service 层"
分步生成复杂功能拆分"先设计接口,再实现逻辑"
指定模式使用已知设计模式"使用策略模式实现"
提供上下文给出相关代码"以下是现有的 User 类:..."

生成后验证清单

第一步:编译验证

□ 代码能否编译通过
□ 导入语句是否完整且正确
□ 依赖是否已声明
□ 类型是否匹配
□ 语法是否正确

第二步:API 验证

□ 调用的方法是否真实存在
□ 方法签名是否正确(参数顺序、类型、数量)
□ 返回值类型是否正确
□ 是否使用了已废弃的 API
□ 是否使用了不存在于当前版本的 API

第三步:逻辑验证

□ 业务逻辑是否正确
□ 边界条件是否处理
□ 空值/null 是否处理
□ 异常是否处理
□ 并发是否安全

第四步:规范验证

□ 命名是否符合项目规范
□ 格式是否符合项目规范
□ 注释是否完整
□ 是否有魔法值
□ 是否有硬编码

常见 AI 代码生成问题

问题一:API 幻觉

表现:调用了不存在的类、方法、函数
原因:AI 训练数据中混合了多个版本的信息

防护措施:
1. 明确指定版本号
2. 生成后查证 API 文档
3. 要求 AI 标注不确定的 API
4. 使用 IDE 自动补全验证

示例:
❌ AI 生成:user.getName()(该方法不存在)
✅ 正确:user.getUsername()

问题二:版本混淆

表现:使用了错误版本的语法或 API
原因:AI 混淆了不同版本的特性

防护措施:
1. 提示词中明确版本号
2. 生成后对比官方文档
3. 运行编译验证

示例:
❌ AI 生成(Python 2 语法):print "hello"
✅ 正确(Python 3 语法):print("hello")

问题三:逻辑遗漏

表现:缺少边界条件处理、异常处理
原因:AI 关注主流程,忽略边界场景

防护措施:
1. 提示词中明确要求处理边界
2. 生成后按防御性编程清单检查
3. 要求 AI 列出可能的异常场景

示例:
❌ AI 生成:直接访问 list.get(0)
✅ 正确:先检查 list.isEmpty()

问题四:过度工程

表现:简单问题用了复杂的设计模式
原因:AI 倾向于生成"通用"的解决方案

防护措施:
1. 提示词中说明复杂度预期
2. 生成后评估是否过度设计
3. 要求 AI 先给简单方案,再考虑扩展

示例:
❌ AI 生成:用策略模式 + 工厂模式实现 2 种折扣
✅ 正确:简单的 if-else 即可

问题五:上下文丢失

表现:生成的代码与项目现有代码风格不一致
原因:AI 不知道项目上下文

防护措施:
1. 提示词中提供项目代码示例
2. 提供项目规范文档
3. 生成后对比现有代码风格

示例:
❌ AI 生成:使用 JPA 风格(项目用 MyBatis Plus)
✅ 正确:使用 MyBatis Plus 风格

分步生成策略

策略一:自顶向下

适用:新功能开发

1. 先生成接口定义
2. 再生成实现类骨架
3. 逐步填充方法实现
4. 最后补充异常处理和边界条件

每步生成后验证,确认无误再继续。

策略二:测试驱动

适用:核心逻辑开发

1. 先生成测试用例
2. 再生成实现代码
3. 运行测试验证

确保生成的代码满足测试用例。

生成阶段 TDD 为可选策略;合并前测试为强制要求,见 testing 技能“代码质量强制要求”。

策略三:增量修改

适用:现有代码修改

1. 先理解现有代码
2. 明确修改范围
3. 生成最小变更
4. 验证变更不影响其他功能

每次只修改必要的部分。

生成代码质量标准

维度标准检查方法
可编译编译无错误运行编译
可运行功能基本可用运行测试
正确性逻辑正确测试验证
健壮性异常处理完善异常测试
规范性符合项目规范Lint 检查
可读性命名清晰、结构合理Code Review
安全性无安全漏洞安全扫描

Frequently asked questions

What does the Code Generation AI skill do?

代码生成规范专家助手。在使用AI辅助编码时,提供系统化的代码生成规范,减少AI幻觉、API编造、逻辑遗漏等常见问题,提高生成代码的准确率和可用性。

Why use Code Generation on TypingMind?

Because you install it once and use it with any model. Code Generation is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Code Generation in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/dkbnull/hello-skill/tree/main/common/skills/code-generation. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Code Generation?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Code Generation?

As many as you like. As long as a model supports skills, you can use Code Generation with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Code Generation AI skill free?

Yes. It is published on GitHub by dkbnull under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇