一键导入
codemod
Mechanical, multi-file, type-aware refactors powered by ts-morph. Use when a pattern repeats across many files and regex is too fragile.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Mechanical, multi-file, type-aware refactors powered by ts-morph. Use when a pattern repeats across many files and regex is too fragile.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
How authenticated HTTP calls to the Opal backend work — the host/guest architecture, fetchWithCreds, the fetch allowlist, and the OpalBackendClient migration. Read this before adding, modifying, or debugging any backend call.
Learn how to make widgets on canvas
Produce high-quality React apps from natural language descriptions.
Teaches you how to properly operate in the sandboxed environment you're in.
Learn how to present your work as a structured surface — a curated manifest of artifacts that the user's application renders in real time.
Learn how to use `window.opalSDK` inside your sandboxed React component to read files, call host services, and listen for events from the application.
| name | codemod |
| description | Mechanical, multi-file, type-aware refactors powered by ts-morph. Use when a pattern repeats across many files and regex is too fragile. |
Mechanical, multi-file, type-aware refactors powered by
ts-morph. Use when a pattern repeats across many
files and regex is too fragile.
| Situation | Approach |
|---|---|
| < 5 files, simple rename | Find-and-replace or manual |
| 5–20 files, structural pattern | Codemod |
| Cross-package type migration | Codemod + build verification |
| One-off exploratory refactor | Codemod in dry-run as a scout |
# Dry run (default) — reports what would change without writing:
npx tsx codemods/run.ts <transform-name>
# Apply for real:
npx tsx codemods/run.ts <transform-name> --apply
Always dry-run first to scout the pattern before committing to a rewrite shape.
Create codemods/transforms/<name>.ts exporting three things:
import type { SourceFile } from "ts-morph";
/** Human-readable summary shown by the runner. */
export const description = "Short summary of what this does";
/** Glob patterns relative to repo root. */
export const include = ["packages/visual-editor/src/**/*.ts"];
/**
* Called once per matched file. Mutate `file` in place via ts-morph's API.
* Return `true` if changes were made, `false` otherwise.
*/
export function transform(file: SourceFile): boolean {
// ... your transform logic
return changed;
}
The runner (codemods/run.ts) handles Project creation, file matching, dry-run
reporting, and saving — transforms only need to focus on the AST logic.
false
always) to find and count all instances before deciding on the rewrite shape.replaceWithText, which invalidates the
node reference.tsc --noEmit and the
relevant test suite. Codemods can introduce type errors in consumers.| Transform | Description |
|---|---|
unseen-cast | Rewrites unsafe (evt as StateEvent<T>).detail casts in actions to typed parameters |