Communitygithub.com

MySwallow/mockplus-context

Agent Skill — 让 AI 看懂 Mockplus(摹客)设计稿。贴 URL 即得结构化 YAML + 切图,AI 直接生成 Vue/React/Flutter 代码,无需看 PNG 猜规格。装到 Claude Code / Cursor / Codex 等。

mockplus-context 是什么?

mockplus-context is a Claude Code agent skill that agent Skill — 让 AI 看懂 Mockplus(摹客)设计稿。贴 URL 即得结构化 YAML + 切图,AI 直接生成 Vue/React/Flutter 代码,无需看 PNG 猜规格。装到 Claude Code / Cursor / Codex 等。.

兼容平台✓Claude Code✓Codex CLI✓Cursor
npx skills add MySwallow/mockplus-context

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Mockplus Context (v0.7.0)

Convert a Mockplus develop URL to structured YAML that LLMs can directly consume. Since v0.6, output is processed through inclusion tree reconstruction: elements visually layered over backgrounds/cards are properly nested as child nodes, and locationRelativeToParent reflects true parent-relative coordinates (v0.5 and earlier gave canvas-absolute coordinates; when reading old cache files, check _meta.coordinateSpace to distinguish).

Since v0.7, YAML by default undergoes mechanical distillation (scripts/distill.py, measured −45~48%): layout_* lookup tables are inlined into node rows as pos: {x, y, w, h} (non-default mode/sizing retained as mode:/hsz:/vsz: keys), UUIDs are truncated to first 8 characters (deterministic, stable across pulls; IDs whose first 8 characters resemble YAML numbers keep full UUID — e.g., 03450216 would be parsed as a number if truncated); imageRef asset hashes, fill/textStyle tables, and text content remain untouched. Output invariants are self-checked; if any invariant fails, the entire output reverts to the undistilled original (stderr WARN), ensuring no half-baked results; the product is tagged _meta.distilled: true. For v0.6 original form, append --raw; offline distillation of old files: python3 scripts/distill.py <in> [<out>] [--check-only].

Two consumption warnings: ① Distilling v0.5 old files will note in _meta.distillWarnings that the coordinate space is not parent-relative (pos is original semantics = canvas-absolute, do not treat as parent-relative); ② TEXT nodes with textSegments: N (N>1) mean the original had N style segments but only the first is taken; textStyle may not represent the entire segment (check sharedStyle name first for font weight/color decisions).

On startup, it declares: "Using mockplus-context to extract <PAGE_ID> from Mockplus."

When to Trigger

  • User provides a URL of the form https://app.mockplus.cn/app/<APPID>/develop/design/<TARGET_ID>
  • User asks to "read Mockplus design draft", "recreate UI from Mockplus", "export Mockplus sliced assets"
  • As a preliminary step for generating code (Vue / React / Flutter / Mini Program) from Mockplus data

Do NOT trigger:

  • Input is a Figma URL (use figma-context MCP)
  • Input is just an isolated PNG (ask user to find the corresponding Mockplus page URL first)

Prerequisites (User One-Time Cookie Configuration)

python3 skills/mockplus-context/scripts/mockplus.py cookie set
# Browser (logged into mockplus.cn) F12 → Application → Cookies → app.mockplus.cn
# Paste all cookies as one line, press Enter to finish

Cookies are stored by default in ~/.config/mockplus/cookie, valid for approximately 30 days. On 401, ask user to cookie set again.

LLM Workflow (Follow This Order When Receiving a URL)

  1. Check cookie: mockplus cookie status, if not configured, guide user to cookie set
  2. If URL is not confirmed as a page (points to group / only has APP_ID): mockplus tree <APP_ID> to browse, pick the specific page id from the tree
  3. Fetch YAML data: mockplus data <URL> --out page.yaml (default YAML)
  4. Scan YAML for sliced assets: Look for fills with type: IMAGE in globalVars.styles, collect imageRef: <hash>
  5. Download sliced assets as needed: mockplus download <URL> --nodes <hash1>,<hash2> --out ./assets
  6. Proceed to downstream tasks (code generation / visual comparison / etc.)

Need visual comparison? Add --include-design or use mockplus all <URL> to get everything in one go.

Quick Command Reference

mockplus data <URL> [--out PATH] [--format yaml|json] [--coords relative|absolute] [--raw] [--stats] [--refresh]
mockplus download <URL> [--nodes all|h1,h2] [--out DIR] [--include-design]
mockplus all <URL> [<OUT_DIR>] [--coords relative|absolute]   # = data + download(all + design)
mockplus tree <APP_ID> [--format text|json] [--refresh]
mockplus cookie {set|test|status|clear|path}

Mockplus API physical constraint: Data can only be fetched per entire page. Groups/sub-groups have no node-level API, so data only accepts page URLs; group browsing is done via tree.

Output YAML Quick Overview (data output)

metadata:
  name: Sample Page
  pageId: pgA1bC2X3
  device: ios1x
  size: { width: 375, height: 812 }
  backgroundColor: '#f5f5f5'
  components:                          # Inferred from SymbolInstance
    <libId>/<path>: { id, name, libraryName }

nodes:
  - id: 2F11A218                       # v0.7:UUID truncated to first 8 chars (--raw for full UUID)
    name: Submit Bar                   # Bottom bar background (reconstructed as container)
    type: VECTOR                       # FRAME/TEXT/INSTANCE/RECTANGLE/ELLIPSE/VECTOR/IMAGE/SLICE/MASK
    pos: {x: 0, y: 718, w: 375, h: 48} # v0.7:layout table inlined as inline pos (--raw for layout: layout_000003)
    absolutePosition: { x: 0, y: 718 } # Only container nodes: canvas absolute anchor
    children:
      - id: 67C9DB5F
        name: Submit Action
        type: TEXT
        pos: {x: 266, y: 19, w: 80, h: 22}   # True parent-relative coordinates (v0.6 semantics unchanged)
        fills: fill_000001             # Optional
        text: "Submit Action"
        textStyle: Body/16px/Semibold/Center Style   # Designer's naming

globalVars:
  styles:                              # v0.7: Only fill / textStyle remain (layout_* inlined)
    fill_000003:                       # Slice fill
      - type: IMAGE
        imageRef: 2b417ea8...          # ← LLM uses this to call download (40-char hash, unchanged by distillation)
        scaleMode: FILL
    Body/16px/Semibold/Center Style:
      fontFamily: PingFang SC
      fontWeight: 600
      fontSize: 16

_meta:
  coordinateSpace: parent-relative     # absolute-artboard = v0.5 semantics (old file / fallback)
  relayout:                            # Inclusion tree reconstruction statistics
    reparented: 21                     # Number of nodes re-parented into visual containers
    zFilter: 'on'                      # Pages with insufficient z-evidence automatically set to 'off' with a warning
  unhandledFields: []                  # Mockplus schema upgrade fields listed here

Key Design Decisions:

  • Inclusion tree reconstruction (v0.6): Authorized groups are hard boundaries; siblings within a group are nested by geometric containment (smallest-area container wins); INSTANCE internal structure is frozen and does not adopt foreign nodes; canvas-absolute position of any leaf = nearest container's absolutePosition + own relative position, a single addition
  • Element positioning directly uses locationRelativeToParent for CSS (parent container position:relative + child absolute), no subtraction needed
  • Token reuse: identical fill/layout/effect are automatically deduplicated; nodes only hold references (after relativization, internal elements of duplicated cards share the same layout token; repeated patterns are immediately visible)
  • Text style keys use the designer's naming (sharedStyle.name), preserving semantics
  • Slice nodes write IMAGE fill in the fills array; LLM uses imageRef to call download
  • Nodes with adoptedBy: geometry are cross-boundary adoptions into authorized groups; this tag can be ignored if semantics are questionable

Common Failures

PhenomenonAction
Cookie not configured (exit 10)mockplus cookie set
API code != 0 (exit 21)Cookie expired → mockplus cookie set to reconfigure
URL points to group, use tree first (exit 22)URL is not a page; first tree to find the correct page id
_meta.unhandledFields not emptyMockplus schema upgraded; report an issue
_meta.coordinateSpace is absolute-artboardInclusion tree reconstruction was reverted (check _meta.warnings) or reading v0.5 old file/--coords absolute output — in this case, locationRelativeToParent is canvas-absolute coordinates
Slice download failureCDN temporarily unavailable; rerun download (existing files are skipped)
Timeout for nodes outside Chinaimg02.mockplus.cn is an East China CDN; nodes outside China should route through a VPN back to China

Cache and Privacy

  • Intermediate artifacts: ~/.cache/mockplus/<APP_ID>/ (overridable via MOCKPLUS_CACHE_DIR)
  • Cookie is read-only and not uploaded; ~/.config/mockplus/cookie is automatically chmod 600
  • User's slice output is placed in their specified directory, not polluting the git repository

Advanced Reference

  • references/examples.md — End-to-end invocation examples
  • references/troubleshooting.md — Complete error codes + diagnostics

相关技能