Codegen And Toolchain 标志

Codegen And Toolchain

社区
zakariaf
codegen-and-toolchain

Enforces a deterministic build_runner codegen discipline: run one pinned `dart run build_runner build --delete-conflicting-outputs` pass BEFORE `flutter analyze` (never after), fence every builder with `generate_for:` globs in a per-package `build.yaml`, make one deliberate commit-vs-gitignore decision for `*.g.dart`/`*.freezed.dart`/`*.drift.dart` and back it with the matching CI gate (freshness diff if committed, codegen-first if gitignored), mirror the generated-file globs into the analyzer AND coverage excludes, pin the SDK, and never hand-edit generated output. Use when editing build.yaml, analysis_options.yaml, pubspec.yaml, .gitignore, .gitattributes, or CI workflows; wiring drift_dev/freezed/json_serializable/riverpod_generator/ gen-l10n/mockito codegen; fixing "missing part file", "undefined class _$Foo", or "conflicting outputs" errors; deciding whether to commit generated code; or scoping builders so one edit does not regenerate everything.

Add to TypingMind

概览

发布者zakariaf
代码仓库Flutter-Skills
技能名称codegen-and-toolchain
星标数
64
复刻数
15
附带文件
7
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 7 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 zakariaf 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Codegen And Toolchain AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/zakariaf/Flutter-Skills/tree/main/skills/codegen-and-toolchain
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/zakariaf/Flutter-Skills.git /tmp/Flutter-Skills
mkdir -p .claude/skills
cp -r /tmp/Flutter-Skills/skills/codegen-and-toolchain .claude/skills/codegen-and-toolchain
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Codegen And Toolchain,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Codegen And Toolchain。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Codegen And Toolchain 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Codegen and toolchain

One deterministic codegen pass is the source of truth for every generated file; run it first, scope it tightly, and decide once whether its output lives in git. Applies whenever a project uses build_runner or gen-l10n.

Read the reference for the task at hand:

  • references/codegen-scoping.md — the generator inventory, generate_for: scoping tables, error-to-fix recovery map.
  • references/commit-vs-gitignore.md — the two committed/gitignored strategies, their tradeoffs, and the exact CI gate each one requires.
  • references/toolchain-and-workspace.md — SDK pinning, analyzer/coverage excludes, and the multi-package workspace layering (fenced, opt-in).

Run scripts/regen.sh (codegen → format → analyze) before a PR, and scripts/check-codegen-hygiene.sh to verify excludes and commit-policy parity.

Non-negotiable rules

  1. Codegen runs FIRST, before flutter analyze. Generated files may be absent on a fresh clone or stale after editing an annotation. Analyzing that tree emits misleading "missing part file" and "undefined class _$Foo" errors. Regenerate, then analyze — never chase the symptom at the call site.
  2. Always pass --delete-conflicting-outputs. Without it build_runner refuses to overwrite an output from a renamed/deleted source and fails with a wall of "conflicting outputs" text. That is not a bug to investigate.
  3. Never hand-edit a generated file. The next build silently reverts it and takes your edit with it. Change the annotated source and rerun codegen.
  4. Scope every builder with generate_for: in a per-package build.yaml. A change in one directory must not regenerate the whole tree. Point each glob at the narrowest directory that owns the annotation.
  5. Decide commit-vs-gitignore ONCE, back it with the matching CI gate. Gitignored → CI regenerates first, before analyze. Committed → CI regenerates then runs git diff --exit-code as a freshness gate. Either is valid; a policy without its gate is not (see references/commit-vs-gitignore.md).
  6. Mirror generated-file globs into the analyzer AND coverage excludes. A glob that lints machine output wastes review; a glob missing from lcov inflates coverage. Exclude the emitted suffix — verify it, do not guess.
  7. Pin the SDK; local must equal CI. The CI Flutter/Dart version must match the pinned local version (.fvmrc under FVM, or the tool the repo standardizes on). A drift here reproduces "works on my machine" format/codegen churn.
  8. watch is a local edit-loop tool only. CI and the pre-analyze step always use the one-shot build command.

The canonical command

Run from the repository root:

bash
dart run build_runner build --delete-conflicting-outputs

This regenerates every builder — drift_dev, freezed, json_serializable, riverpod_generator, mockito — in one pass. gen-l10n runs through the Flutter tool but is treated identically (regenerated first, same commit policy):

bash
flutter gen-l10n   # if not auto-triggered by `flutter pub get` via l10n.yaml

Fresh clone / after pull / after editing any annotation, the fixed order is:

build_runner build --delete-conflicting-outputs   →   format   →   analyze   →   test

Never reorder codegen after analyze. During an active edit session only, a watcher rebuilds affected outputs on save:

bash
dart run build_runner watch --delete-conflicting-outputs

Scoping builders with build.yaml

Give every codegen-carrying package (or the single app package) its own build.yaml, and fence each builder's generate_for: at the narrowest directory that owns its annotation. An unscoped root config fans out to every annotation in the tree, so editing one Task model regenerates unrelated Order and Account outputs. Copy examples/build.yaml; references/codegen-scoping.md has the full generator-to-suffix table and per-builder globs.

Commit vs gitignore: pick one, wire its gate

Both strategies are legitimate; they trade different risks (see rule 5). Gitignore keeps the tree clean but needs a working toolchain to build. Committing survives a broken future toolchain and makes schema diffs reviewable, but needs a .gitattributes diff-collapse (examples/gitattributes.example) AND a mandatory freshness gate — regenerate, then git diff --exit-code -- '*.g.dart' '*.freezed.dart' '*.drift.dart'. A policy without its gate is not a policy. Both strategies, their tradeoffs, and the exact gate each requires: references/commit-vs-gitignore.md.

Analyzer and coverage excludes

Committed OR gitignored, every emitted generated suffix must be excluded from BOTH the analyzer and the lcov coverage filter — verify the suffix the config actually emits first, do not guess. A missed analyzer glob wastes review on machine output; a missed (or mis-anchored) lcov glob inflates coverage with untested code. A migration-test baseline dir that holds generated era-correct data classes needs the analyzer exclude too — an autofix inside an exported schema snapshot would corrupt migration verification (see run-migration). The canonical exclude blocks and the correctly anchored lcov patterns live in references/toolchain-and-workspace.md.

When multi-package (workspace)

Only for a repo that has genuinely outgrown one package. A single-app project needs none of this.

  • Link members with a native Dart pub workspace: resolution: workspace in every member pubspec plus a workspace: list at the root, producing ONE root pubspec.lock. Never add a per-package lockfile.
  • If you layer Melos on top, use it for script orchestration only (melos run gen/format/analyze/test), never for path linking — pub does the linking. Filter the gen script to packages that depend on build_runner.
  • Run build_runner once at the workspace root so every member regenerates in the same pass; running inside one package dir leaves the others stale.

Anti-patterns

  • Analyzing before regenerating — every downstream error is a phantom; fix the order, not the code.
  • Omitting --delete-conflicting-outputs — turns a routine rename into a build wall.
  • Hand-editing .g.dart/.drift.dart to silence an error — reverted on the next build; the real fix is in the annotated source.
  • Committing generated code with no freshness gate — output silently drifts from source and reviewers trust a lie.
  • One unscoped root build.yaml — every trivial edit regenerates the whole tree and slows every build.
  • Coverage/analyzer glob that matches the wrong suffix — fails silently in the analyzer, loudly in lcov 2.x, and quietly inflates coverage.
  • CI Flutter version ≠ pinned local version — reproducible format/codegen churn nobody can explain.
  • A generated migration test left with empty data lists — passes vacuously ([] == []) while proving nothing; fill it or delete it (see run-migration).

Definition of done

  • dart run build_runner build --delete-conflicting-outputs succeeds from a clean tree, then flutter analyze is clean.
  • Every codegen-carrying package has a build.yaml with scoped generate_for: globs.
  • The commit-vs-gitignore decision is made and its CI gate exists (freshness diff, or codegen-first).
  • The emitted generated suffixes are excluded from BOTH analysis_options.yaml and the lcov coverage filter.
  • SDK is pinned and the CI toolchain version matches it.
  • No generated file is hand-edited; no watch in CI.

Related skills

  • See run-codegen for the operational, low-freedom "run this exact command" loop and its troubleshooting table.
  • See run-migration for the Drift schema-snapshot and migration-test ritual the codegen pass produces.
  • See persistence-drift for the Drift/DAO data layer these generators feed.
  • See lint-and-style-config for the analyzer ruleset and the excludes mirrored here.
  • See ci-pipeline-and-gates for where codegen and the freshness gate sit in the pipeline.
  • See dependency-hygiene for the lockfile and SDK-pinning mechanics.

References

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Codegen And Toolchain AI 技能有什么作用?

Enforces a deterministic build_runner codegen discipline: run one pinned `dart run build_runner build --delete-conflicting-outputs` pass BEFORE `flutter analyze` (never after), fence every builder with `generate_for:` globs in a per-package `build.yaml`, make one deliberate commit-vs-gitignore decision for `*.g.dart`/`*.freezed.dart`/`*.drift.dart` and back it with the matching CI gate (freshness diff if committed, codegen-first if gitignored), mirror the generated-file globs into the analyzer AND coverage excludes, pin the SDK, and never hand-edit generated output. Use when editing build.y...

为什么在 TypingMind 中使用 Codegen And Toolchain?

因为您只需安装一次,就能搭配任何模型使用。Codegen And Toolchain 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Codegen And Toolchain?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/zakariaf/Flutter-Skills/tree/main/skills/codegen-and-toolchain。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Codegen And Toolchain?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Codegen And Toolchain 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Codegen And Toolchain 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Codegen And Toolchain AI 技能免费吗?

是的。zakariaf 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇