ARTICLE DETAIL

资讯详情

深耕编程入门与网站建设的一线实战洞察。

Caveman Migration 原生技能:让 Agent 以可回滚方式执行 Schema、数据与 API 迁移

Caveman Migration 原生技能:让 Agent 以可回滚方式执行 Schema、数据与 API 迁移 Caveman Migration 原生技能让 Agent 以可回滚方式执行 Schema、数据与 API 迁移【免费下载链接】caveman why use many token when few token do trick — Claude Code skill that cuts 65% of tokens by talking like caveman项目地址: https://gitcode.com/GitHub_Trending/caveman1/cavemanMigration 是 caveman 仓库skills/migration/SKILL.md定义的一条原生nativeAgent 技能专门约束 AI 编码代理在实施 schema、数据、API、协议、配置或依赖迁移时的行为边界先盘点现状、再定义正向与回滚路径、按 expand → migrate → verify → contract 顺序推进且绝不隐式执行破坏性的收缩步骤。读完本文你将理解这条技能完整的方法论条款、它在registry.json中的元数据契约guardrails、entry/stop condition、字节预算以及skills/compile.mjs如何把它编译进各宿主 Agent 的原生包并由 Go 侧Select()按任务类型路由。一、技能定位可逆的、兼容安全的迁移技能正文以 YAML frontmatter 开头声明了它的身份与触发语义--- name: migration description: Implement reversible compatibility-safe transitions. Use for schema, data, API, protocol, configuration, or dependency migrations requiring rollback and preservation proof. ---description明确了六个适用面——schema、数据、API、协议、配置、依赖——并且强调两个前置条件需要回滚能力rollback与需要数据保留证明preservation proof。这说明它不是普通的改数据库指令而是一套兼容性安全过渡的工程纪律任何无法回滚、无法证明旧数据被保留的迁移都不在这条技能承诺的安全范围内。在 registry.json 中该技能的注册信息如下skills数组中id: migration条目{ id: migration, summary: Execute a reversible compatibility-safe transition without hidden destruction., delivery: [native], activation: classified, task_types: [migration], evidence_status: structural-test-only, prompt_byte_budget: 950, guardrails: [preserve_rollback, preserve_data, verify_compatibility], entry_condition: task changes persisted or public shape, stop_condition: requested migration stage passes without implicit contraction }各字段含义delivery: [native]只通过原生注入通道分发即编译进宿主 AgentClaude、Codex、Hermes、Gemini、opencode、aider的系统级提示包而不是走 CLI 或 Web 通道。activation: classified激活方式是任务分类——由上游判断当前任务属于migration类型后注入而非用户显式点名。task_types: [migration]它唯一认领的任务类型。prompt_byte_budget: 950正文frontmatter 之后指令文本的字节预算上限编译期强制校验。guardrails三条护栏——保留回滚能力、保留数据、验证兼容性是机器可读的约束摘要。entry_condition: task changes persisted or public shape进入条件——任务会改变持久化形态或对外暴露的形态时才适用。stop_condition: requested migration stage passes without implicit contraction停止条件——请求的迁移阶段通过即停且不得隐式收缩隐式执行后续破坏性收缩步骤。配套的智能体界面声明在 openai.yamlinterface: display_name: Migration short_description: Plan reversible>const frontmatterEnd body.indexOf(\n---\n, 4); // ... const instructions body.slice(frontmatterEnd 5).trim(); if (native Buffer.byteLength(instructions) meta.prompt_byte_budget) { die(${meta.id}: instruction bytes exceed budget (${Buffer.byteLength(instructions)} ${meta.prompt_byte_budget})); }即截取 YAML frontmatter 之后的纯指令文本按 UTF-8 字节计数超过prompt_byte_budgetmigration 为 950直接构建失败。上面第二节引用的七句指令合计 429 字节约在预算的 45% 处——这意味着预算设计为正文 少量余量而不是留白给自由发挥每一个词都必须挣得自己占用的字节。编译管线的完整链路单一事实源每个技能正文只写一份在skills/id/SKILL.mdregistry.json决定分发面见 compile.mjs 头部注释Every skill body lives once at skills/ /SKILL.md。元数据严格校验exactKeys检查每个技能条目只能含白名单字段id、summary、delivery、suites、activation、task_types、evidence_status、prompt_byte_budget、conflicts、precedence、guardrails、entry_condition、stop_conditionnative 技能必须提供activation classified、非空task_types、guardrails及 entry/stop condition缺一即die。任务类型互斥校验对同一task_type若有多个 owner必须两两声明conflicts且precedence不同migration 独占migration任务类型conflicts: []、precedence: 100无竞争者。生成产物CLI 侧packages/cli/src 下的agent-skills.generated.ts/native-pack.generated.tsGo 运行时侧proxy/internal/nativepack/native-pack.generated.jsonschema 为caveman.native-pack.v1每个宿主一份skills/generated/claude/pack.json、skills/generated/codex/pack.json、skills/generated/gemini/pack.json、skills/generated/hermes/pack.json、skills/generated/opencode/pack.json、skills/generated/aider/pack.json。skills/generated/claude/pack.json 展示了编译后的宿主激活映射与 compile.mjs 中的NATIVE_ACTIVATION表一致targets: { claude: { core: SessionStart, task: UserPromptSubmit }, codex: { core: developer_instructionsSessionStart, task: UserPromptSubmit }, hermes: { core: pre_llm_call, task: pre_llm_call }, gemini: { core: BeforeAgent, task: BeforeAgent }, opencode: { core: experimental.chat.system.transform, task: chat.message }, aider: { core: read_only_conventions, task: native_repository_map_authoritative } }即在 Claude 中核心包Core经SessionStart注入、任务技能含 migration 指令经UserPromptSubmit钩子在用户提交 prompt 时注入其他宿主同理映射到各自的钩子点。migration 的完整指令文本会被原样内嵌进各pack.json的skills[].instructions字段供宿主 Agent 直接消费。四、运行时选择Select(migration) 如何路由Go 侧 proxy/internal/nativepack 提供运行时加载与选择能力。pack_test.go 是理解路由语义的最佳证据wants : map[string]string{ feature: lean-build, bugfix: surgical-patch, investigation: investigate-first, refactor: safe-refactor, migration: migration, verification: verify-and-stop, } for taskType, want : range wants { skill, ok : Select(taskType) if !ok || skill.ID ! want || skill.EvidenceStatus ! structural-test-only || len(skill.Instructions) skill.PromptByteBudget { t.Fatalf(selection %s %v ok%t, taskType, skill, ok) } } if _, ok : Select(review); ok { t.Fatal(unowned task type must fail closed to Core) }该测试断言三件事一型一主六种任务类型feature / bugfix / investigation / refactor / migration / verification各路由到唯一技能Select(migration)必须命中migration且返回的Instructions长度不得超出PromptByteBudget运行时再次校验预算。Core 兜底且失败关闭未被任何技能认领的任务类型如review返回失败回落到必选 Coreskills/native-core.md——Core 第 4 节明确规定simplicity never removes ... migration or rollback safety即即使没有 migration 技能注入默认核心也不许省略迁移与回滚安全。包形状固定编译后恰好 6 个技能、6 个宿主目标与registry.json的native_pack.targets完全一致。从源码结构看Select的输入是宿主侧对当前任务类型的分类结果输出是带instructions全文的技能对象因此entry_conditiontask changes persisted or public shape在工程上由任务被分类为 migration 且确实改变持久化/对外形态共同保证。五、与同族技能的边界什么时候用 migration而不是它skills/目录下的六条 native 技能按任务类型分工见 registry.json技能任务类型核心差异lean-buildfeature加产品行为架构适配优先surgical-patchbugfix修最窄责任层回归证明investigate-firstinvestigation编辑前建立可信机制诊断不授权修复safe-refactorrefactor保持行为不变地重组结构前后证明一致migrationmigration改变持久化/对外形态expand→contract可回滚verify-and-stopverification跑最小充分证明集停止不扩张范围最容易混淆的是 migration 与 safe-refactorsafe-refactor 的护栏是preserve_behavior可观测行为不变而 migration 的护栏是preserve_rollback/preserve_data/verify_compatibility——迁移有意改变形态所以它需要兼容窗口与回滚路径重构有意保持形态所以它需要前后行为证明。边界判定就是entry_conditiontask changes persisted or public shape——只要改变的是持久化形态或对外契约就走 migration。六、把技能落地一次迁移任务的检查清单综合正文与元数据当任务被分类为 migration例如把订单表拆分、API v1 迁移到 v2、JSON 配置格式升级时执行 Agent 应当遵循的操作序列盘点before editing列出全部读路径、写路径、数据形态、新旧版本兼容窗口、每个字段的归属方双路径设计写下 forward path 与 rollback path把其中每一个破坏性步骤单独列出并标注需单独授权expand新增列/字段/端点旧路径保持可用migrate幂等回填部分失败可定位、可观测verify在规定的转换阶段对新旧两条路径各跑一遍验证停请求到的阶段通过即停——收缩删旧列、下旧端点留待下一轮显式请求。这套序列不依赖任何特定框架是纯方法论约束它的工程保障字节预算编译期强制、任务类型唯一路由、Core 兜底则由 skills/compile.mjs、proxy/internal/nativepack/pack_test.go 与 skills/generated 各宿主pack.json共同保证——技能文档、注册元数据、编译产物三者漂移时构建直接失败而不是把过期的迁移纪律悄悄注入到 Agent 提示里。【免费下载链接】caveman why use many token when few token do trick — Claude Code skill that cuts 65% of tokens by talking like caveman项目地址: https://gitcode.com/GitHub_Trending/caveman1/caveman创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表