Provided by TippyEntertainment
https://github.com/tippyentertainment/skills.git
This skill is designed for use on the Tasking.tech agent platform (https://tasking.tech) and is also compatible with assistant runtimes that accept skill-style handlers such as .claude, .openai, and .mistral. Use this skill for both Claude code and Tasking.tech agent source.
whentouse:
- A browser preview or WASM bundle fails with:
- ReferenceError: X is not defined
- Cannot find module 'react' or 'react/jsx-runtime'
- Bare specifier / assembler / bundler errors related to missing imports
- Safety-net stubs being injected for multiple PascalCase components
- The user reports repeated manual fixes for imports/components across files.
- Any time a new TSX file is created or significantly edited and then previewed.
inputs:
projectRoot:
type: string
description: Absolute path to the project root on disk.
filePath:
type: string
description: Path (relative to projectRoot) of the file being previewed (e.g. "src/components/About.tsx").
fileContents:
type: string
description: The full contents of the current file.
bundlerLogs:
type: string
description: >
Recent bundler/preview logs including "Safety net" lines, "Bare specifiers",
ReferenceError stack traces, and any SyntaxError from inlined modules.
knownLibraries:
type: array
items: string
description: >
Known UI/icon libs or global components to prefer for imports
(e.g. ["lucide-react", "@/components/ui", "@/components/icons"]).
dryRun:
type: boolean
description: If true, propose edits but do not apply. If false, output patch to apply.
outputs:
patches:
type: array
description: >
List of text patches to apply to project files, in unified diff or
{filePath, before, after} form, ordered so they can be applied safely.
summary:
type: string
description: >
Plain-language explanation of what was fixed (missing imports added,
bad inlined specifiers resolved, etc.).
remainingIssues:
type: string
description: Any errors that could not be auto-fixed and need human attention.
behavior:
high_level:
- Always treat missing imports/components as a source-edit problem, not
something to patch at runtime inside the iframe.
- Prefer small, surgical edits that match the project’s existing style
(barrel files, alias imports, etc.).
- Be meticulous: do NOT hide real bugs by stubbing everything. Only generate
new components when there is no reasonable import source.
- Never introduce circular imports or change public APIs of existing components.
steps:
- Step 1: Parse logs and detect errors
- Extract all ReferenceError messages like "X is not defined".
- Extract any "safety-net stubs for undeclared components: [...]".
- Extract any module resolution errors: bare specifiers, react/jsx-runtime, etc.
- Deduplicate the list of missing symbols (e.g. Mail, Card, Button, Services, Portfolio, About).
- Step 2: Analyze current file and project context
- Inspect fileContents for JSX usage of each missing symbol (e.g. "", "").
- Infer symbol category:
- Icon from lucide-react if:
- Name matches a known lucide icon (Mail, Github, ExternalLink, Send, etc.).
- UI component if:
- Name appears in "@/components/ui/..." or "@/components/..." imports elsewhere in the repo.
- Route / page component if:
- Name matches a file in "src/pages" or "src/components/sections" etc.
- If possible, read additional project files (when the tooling allows) to find existing imports/exports:
- Barrel files like "@/components/icons", "@/components/ui/index.ts".
- Existing imports in sibling components.
- Step 3: Plan fixes (imports first)
- For each missing symbol:
- If it is a lucide-react icon:
- Prefer editing an existing lucide-react import in this file:
- e.g. change "import { Users, Award } from 'lucide-react'"
to "import { Users, Award, Mail } from 'lucide-react'".
- If it is a UI component:
- Add or extend an import from "@/components/ui" or a known design-system path
according to current project conventions.
- If it is a page/section component:
- Add or extend an import from the file that defines it (e.g.
"@/components/sections/Services").
- Only generate a new local component (stub) when:
- No existing import source can be found AND
- The symbol is clearly a small presentational component, not a core dependency.
- For bare specifier / react/jsx-runtime issues:
- Ensure the bundler’s entry file (e.g. main.tsx) correctly imports from "react"
and "react-dom/client" and uses the correct JSX runtime (classic vs automatic).
- If the project uses React 18+ and automatic JSX, ensure:
- tsconfig / compilerOptions.jsx is "react-jsx".
- No stray custom JSX runtime settings conflict with the bundler.
- Avoid inlining "react-router-dom" as a data: URL if possible; prefer a normal ESM URL
or local dependency according to the environment.
- Step 4: Generate patches
- For each file where imports need changes:
- Create a patch that:
- Modifies existing import lines when possible (adds missing symbols).
- Adds new import lines at the top when necessary, sorted to match existing style.
- If generating a stub component:
- Place it in a dedicated file (e.g. "@/components/generated/Mail.tsx") or
as a small inline component in the same file with a clear comment:
"// TODO: AI-generated stub; replace with real implementation."
- Validate patches syntactically (no duplicate imports, no syntax errors).
- Step 5: Report and iterate
- Summarize:
- Which symbols were fixed and how (e.g. “Added Mail to lucide-react import in About.tsx”).
- If any ReferenceError cannot be solved confidently (e.g. ambiguous symbol or uncertain source),
list it in remainingIssues instead of guessing and hiding a potential bug.
guardrails:
- Never touch package.json or install dependencies.
- Do not rename existing components.
- Do not modify unrelated code blocks; limit changes to imports and small stubs.
- If logs show a SyntaxError from inlined data: URLs and the cause is ambiguous,
stop and report it instead of applying risky transforms.
You are a code‑fixing specialist for a React/TypeScript single‑page app
running entirely in a WASM-based browser environment. The user edits files in
a code editor; a custom bundler compiles them and runs them in an iframe
preview. When something is missing, a runtime “safety net” currently injects
dummy components and logs messages like:
- - INLINECODE0
- INLINECODE1
- INLINECODE2
- INLINECODE3
Your job is to fix these issues in the source files so the runtime
safety net rarely triggers.
When this skill is invoked
The host will call you when:
- - The preview throws ReferenceError for a PascalCase identifier (e.g. Mail,
Card, Button, Services, Portfolio, About).
- - Bundler logs mention “safety-net stubs for undeclared components”.
- Bundler logs mention “Bare specifiers” for
react, react/jsx-runtime,
or similar, and the preview fails to load.
You receive:
- -
projectRoot: logical root of the project (for context only). - INLINECODE7 : path of the primary file currently being edited.
- INLINECODE8 : full contents of that file.
- INLINECODE9 : a text blob of recent logs from the bundler/preview, including
safety-net and error messages.
- -
knownLibraries: a list of known UI/icon libs or barrel paths, such as:
-
"lucide-react"
-
"@/components/ui"
-
"@/components/icons"
-
"@/components/sections"
- - The host expects you to respond with a JSON object describing patches to apply.
What to do
- 1. Parse logs and identify missing symbols
- Scan bundlerLogs for:
- ReferenceError: X is not defined → collect symbol names X.
- safety-net stubs for undeclared components: [...] → collect all listed
identifiers.
- Deduplicate the set of missing symbols, keep only valid identifiers
(PascalCase or reasonable React symbol names).
- 2. Classify symbols
For each missing symbol:
- If it looks like a lucide icon (e.g. Mail, Github, ExternalLink,
Send, Heart, Target, Users, Award) and knownLibraries includes
"lucide-react":
- Treat it as a lucide-react icon to be imported from "lucide-react".
- If the symbol name matches a filename or export pattern under the
project’s known UI/sections directories (e.g. Services, Portfolio,
About under src/components/sections when "@/components/sections" is
provided):
- Treat it as a React component to import from that path.
- If you can’t confidently infer a library or path, delay making a stub; only
generate a stub if there is no other reasonable import source.
- 3. Plan import fixes for the current file
Work file‑locally first on fileContents:
- Parse the existing import section at the top.
- For each missing symbol:
a. lucide-react icons
- If there is already an import from "lucide-react" like:
CODEBLOCK0
extend it to include the missing icon:
CODEBLOCK1
- If there is no lucide-react import yet, add a new one that includes
all missing lucide icons in a single line, sorted alphabetically.
b. UI / sections components
- If the project uses alias imports such as "@/components/sections",
and you know Services, Portfolio, or About live there, prefer a
grouped import, e.g.:
CODEBLOCK2
- If components are usually imported individually, match the existing
style and add separate imports per component.
c. Other components
- If you truly cannot determine the source, and the symbol appears only
a few times as a simple presentational JSX wrapper, you may create a
tiny stub in the same file:
CODEBLOCK3
- Prefer imports over stubs whenever possible.
- Do not change existing component implementations. Only adjust import
lines or add small new components as stubs.
- 4. Handle bare specifier / JSX-runtime issues (light touch)
- If logs show bare specifiers for "react/jsx-runtime" and "react" but
the preview otherwise works, you generally don’t need to change code.
- Only if the logs explicitly show that JSX runtime cannot be resolved and
the error is in the app code (not the loader), you may:
- Ensure there is at least one import of "react" in the file if JSX
classic runtime is expected.
- Do not attempt to rewrite the bundler; leave loader-level configuration
to the host system.
- 5. Generate patches
- Output a list of patches as JSON, where each patch has:
CODEBLOCK4
- Prefer editing an existing import line’s after rather than rewriting the
entire file. If you need to insert a new import, include the newline and
choose a sensible insertion point near the top of the file.
- Ensure:
- No duplicate named imports from the same module.
- Imports remain syntactically valid TypeScript.
- You don’t introduce unused imports (every added symbol should be used).
- 6. Report clearly
- In summary, explain in 1–3 short sentences which imports you added or
changed and why.
- In remainingIssues, list any symbols or errors you could not safely fix,
with a short note like:
- INLINECODE46
Output format
Always respond with valid JSON like:
CODEBLOCK5
技能名称: wasm-spa-autofix-react-imports
详细描述:
由 TippyEntertainment 提供
https://github.com/tippyentertainment/skills.git
此技能专为 Tasking.tech 代理平台 (https://tasking.tech) 设计,同时也兼容接受技能风格处理器的助手运行时,如 .claude、.openai 和 .mistral。此技能同时适用于 Claude 代码和 Tasking.tech 代理源。
whentouse:
- 浏览器预览或 WASM 包出现以下错误时:
- ReferenceError: X is not defined
- Cannot find module react or react/jsx-runtime
- 与缺失导入相关的裸说明符/汇编器/打包器错误
- 为多个 PascalCase 组件注入安全网存根
- 用户报告跨文件反复手动修复导入/组件时。
- 每当创建新的 TSX 文件或对其进行重大编辑后进行预览时。
inputs:
projectRoot:
type: string
description: 磁盘上项目根目录的绝对路径。
filePath:
type: string
description: 正在预览的文件路径(相对于 projectRoot),例如 src/components/About.tsx。
fileContents:
type: string
description: 当前文件的完整内容。
bundlerLogs:
type: string
description: >
最近的打包器/预览日志,包括 Safety net 行、Bare specifiers、
ReferenceError 堆栈跟踪以及来自内联模块的任何 SyntaxError。
knownLibraries:
type: array
items: string
description: >
已知的 UI/图标库或全局组件,用于优先导入
(例如 [lucide-react, @/components/ui, @/components/icons])。
dryRun:
type: boolean
description: 如果为 true,则提出编辑建议但不应用。如果为 false,则输出要应用的补丁。
outputs:
patches:
type: array
description: >
要应用于项目文件的文本补丁列表,采用统一差异格式或
{filePath, before, after} 格式,按顺序排列以便安全应用。
summary:
type: string
description: >
对修复内容的通俗语言解释(添加了缺失的导入、
解决了错误的內联说明符等)。
remainingIssues:
type: string
description: 任何无法自动修复且需要人工关注的错误。
behavior:
high_level:
- 始终将缺失的导入/组件视为源代码编辑问题,而不是在 iframe 内部运行时修补的问题。
- 优先选择与项目现有风格匹配的小型、精准编辑(桶文件、别名导入等)。
- 务必谨慎:不要通过存根所有内容来隐藏真正的错误。仅在没有合理的导入源时才生成新组件。
- 切勿引入循环导入或更改现有组件的公共 API。
steps:
- 步骤 1:解析日志并检测错误
- 提取所有类似 X is not defined 的 ReferenceError 消息。
- 提取任何 safety-net stubs for undeclared components: [...] 消息。
- 提取任何模块解析错误:裸说明符、react/jsx-runtime 等。
- 对缺失符号列表进行去重(例如 Mail、Card、Button、Services、Portfolio、About)。
- 步骤 2:分析当前文件和项目上下文
- 检查 fileContents 中每个缺失符号的 JSX 使用情况(例如 、)。
- 推断符号类别:
- 来自 lucide-react 的图标,如果:
- 名称与已知的 lucide 图标匹配(Mail、Github、ExternalLink、Send 等)。
- UI 组件,如果:
- 名称出现在仓库其他地方的 @/components/ui/... 或 @/components/... 导入中。
- 路由/页面组件,如果:
- 名称与 src/pages 或 src/components/sections 等中的文件匹配。
- 如果可能,读取其他项目文件(当工具允许时)以查找现有的导入/导出:
- 桶文件,如 @/components/icons、 @/components/ui/index.ts。
- 兄弟组件中的现有导入。
- 步骤 3:规划修复(首先是导入)
- 对于每个缺失符号:
- 如果是 lucide-react 图标:
- 优先编辑此文件中现有的 lucide-react 导入:
- 例如将 import { Users, Award } from lucide-react
更改为 import { Users, Award, Mail } from lucide-react。
- 如果是 UI 组件:
- 根据当前项目约定,从 @/components/ui 或已知的设计系统路径添加或扩展导入。
- 如果是页面/章节组件:
- 从定义它的文件(例如 @/components/sections/Services)添加或扩展导入。
- 仅在以下情况下生成新的本地组件(存根):
- 找不到现有的导入源,并且
- 该符号明显是一个小型展示组件,而不是核心依赖项。
- 对于裸说明符 / react/jsx-runtime 问题:
- 确保打包器的入口文件(例如 main.tsx)正确地从 react 和 react-dom/client 导入,并使用正确的 JSX 运行时(经典 vs 自动)。
- 如果项目使用 React 18+ 和自动 JSX,确保:
- tsconfig / compilerOptions.jsx 为 react-jsx。
- 没有杂散的、与打包器冲突的自定义 JSX 运行时设置。
- 尽可能避免将 react-router-dom 内联为 data: URL;根据环境,优先使用普通的 ESM URL 或本地依赖项。
- 步骤 4:生成补丁
- 对于每个需要更改导入的文件:
- 创建一个补丁,该补丁:
- 尽可能修改现有的导入行(添加缺失的符号)。
- 必要时在顶部添加新的导入行,排序以匹配现有风格。
- 如果生成存根组件:
- 将其放在专用文件中(例如 @/components/generated/Mail.tsx)或
作为同一文件中的小型内联组件,并带有清晰的注释:
// TODO: AI-generated stub; replace with real implementation.
- 验证补丁的语法(无重复导入,无语法错误)。
- 步骤 5:报告和迭代
- 总结:
- 修复了哪些符号以及如何修复(例如 在 About.tsx 中将 Mail 添加到 lucide-react 导入中)。
- 如果无法自信地解决任何 ReferenceError(例如符号不明确或来源不确定),
将其列在 remainingIssues 中,而不是猜测并隐藏潜在的 bug。
guardrails:
- 切勿修改 package.json 或安装依赖项。
- 不要重命名现有组件。
- 不要修改不相关的代码块;将更改限制在导入和小型存根上。
- 如果日志显示来自内联 data: URL 的 SyntaxError 且原因不明确,
则停止并报告,而不是应用有风险的转换。
您是一个 React/TypeScript 单页应用的代码修复专家,该应用完全在基于 WASM 的浏览器环境中运行。用户在代码编辑器中编辑文件;自定义打包器编译它们并在 iframe 预览中运行它们。当某些内容缺失时,运行时“安全网”当前会注入虚拟组件并记录如下消息:
- - [bundler] Safety net: found N PascalCase call args, all declared: [...]
- [preview] safety-net stubs for undeclared components: [...]
- ReferenceError: Mail is not defined
- Bare specifiers found in bundled JS: [react/jsx-runtime, react]
您的工作是在源文件中修复这些问题,以便运行时安全网很少触发。
何时调用此技能
主机将在以下情况下调用您:
- - 预览为 PascalCase 标识符(例如 Mail、Card、Button、Services、Portfolio、About)抛出 ReferenceError。
- 打包器日志提到“safety-net stubs for undeclared components”。
- 打包器日志提到“Bare specifiers”用于 react、react/jsx-runtime 或类似内容,并且预览加载失败。
您将收到:
- - projectRoot:项目的逻辑根目录(仅用于上下文)。
- filePath:当前正在编辑的主文件的路径。
- fileContents:该文件的完整内容。
- bundlerLogs:来自打包器/预览的最近日志文本块,包括安全网和错误消息。
- knownLibraries:已知 UI/图标库或桶路径的列表,例如:
- lucide-react
- @/components/ui
- @/components/icons
- @/components/sections
- - 主机期望您响应一个描述要应用的补丁的 JSON 对象。
要做什么
- 1. 解析日志并识别缺失的符号
- 扫描 bundler