After each successful application, record it using the record_rule_application tool with rule_id set to the applied rule's ID and outcome set to "applied". Optionally include code_unit_name and file_path.
Output
Report back:
Number of regex rules applied and total replacements made
Number of AI rules applied (approved) and skipped (rejected)
Whether the file was modified
Rules
Always update the local file — do not deploy SQL directly without writing changes to the file first
Regex rules do not need user approval — they are mechanical and deterministic
AI rules always need user approval — present the diff before writing
Re-read the file between rules — earlier fixes may affect later rule matches
Track effectiveness — after testing confirms the fix works, call record_rule_application with outcome = "success"
1---2name: apply3description: Rule Apply4---56# Rule Apply78Apply matched rules to a single converted SQL file. For batch application (multiple files from propagation), see [BATCH.md](BATCH.md).910## Inputs1112- `rules` — matched rules array from `search_rules` (sorted by priority)13- `file_path` — path to the local SQL file to modify14- `object_name` — name of the object being migrated1516## Step 1: Sort by Priority1718Process rules in `priority` order (ascending). Lower priority = runs first. This ensures simple regex fixes happen before structural AI rewrites.1920## Step 2: Apply Regex-Mode Rules2122For each rule where `replacement_mode = 'regex'`:23241. Read the current file content252. Apply the regex substitution: find all matches of `replacement_find` and replace with `replacement_replace`263. Write the updated content back to the file274. Report what changed:28 > Applied **Replace ISNULL with COALESCE**: 3 replacements made2930If `replacement_find` does not match anything in the file (even though `match_pattern` did), skip silently — the pattern may have already been fixed.3132## Step 3: Apply AI-Mode Rules3334For each rule where `replacement_mode = 'ai'`:35361. Read the current file content372. Read the rule's `ai_context` and `examples`383. Use your judgment to identify and fix all instances of the pattern described394. Present the diff to the user for approval before writing:40 > **EXEC to CALL** — proposed changes:41 > ```diff42 > - EXEC schema.ProcName @p1, @p243 > + CALL schema.ProcName(:p1, :p2)44 > ```45 > Apply this fix?465. If approved, write the updated file476. If rejected, skip this rule4849## Step 4: Track5051After each successful application, record it using the `record_rule_application` tool with `rule_id` set to the applied rule's ID and `outcome` set to `"applied"`. Optionally include `code_unit_name` and `file_path`.5253## Output5455Report back:56- Number of regex rules applied and total replacements made57- Number of AI rules applied (approved) and skipped (rejected)58- Whether the file was modified5960## Rules6162- **Always update the local file** — do not deploy SQL directly without writing changes to the file first63- **Regex rules do not need user approval** — they are mechanical and deterministic64- **AI rules always need user approval** — present the diff before writing65- **Re-read the file between rules** — earlier fixes may affect later rule matches66- **Track effectiveness** — after testing confirms the fix works, call `record_rule_application` with `outcome = "success"`
Run npx skillmds@latest add snowflake-labs/apply in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Rule Apply It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
snowflake-labs (@snowflake-labs) published this skill. Their other Agent Skills are listed on their SkillMD profile.