wasm-spa-autofix-react-imports

TotalClaw 作者 totalclaw

仔细检测并修复缺失的 React/TSX 导入、未定义的组件、 以及 WASM SPA 构建/预览管道中的捆绑器运行时错误。 确保正确导入或定义 JSX 组件、图标和挂钩 在运行浏览器预览之前,因此运行时安全网很少触发。

安装 / 下载方式

TotalClaw CLI推荐
totalclaw install totalclaw:totalclaw~tippyentertainment-wasm-spa-autofix-react-imports
cURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/totalclaw%3Atotalclaw~tippyentertainment-wasm-spa-autofix-react-imports/file -o tippyentertainment-wasm-spa-autofix-react-imports.md
## 概述(中文)

仔细检测并修复缺失的 React/TSX 导入、未定义的组件、
以及 WASM SPA 构建/预览管道中的捆绑器运行时错误。
确保正确导入或定义 JSX 组件、图标和挂钩
在运行浏览器预览之前,因此运行时安全网很少触发。

## 原文

# 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.



when_to_use:
  - 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. "<Mail />", "<Services ...>").
      - 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:

- `[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']`

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).
- `filePath`: path of