Index of every page on this site: llms.txt
All skills
xenodium avatar

/swiftui-preview

@a158238
by xenodiumxenodium/emacs-skills151 stars
19
Run it yourself

This skill should be used when the user invokes "/swiftui-preview" to render SwiftUI code from the current context to a PNG and output the resulting image path.

Use this Skill: https://skilld.dev/gh/xenodium/emacs-skills/swiftui-preview

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈44 tokens for metadata: the name and description. ≈1k when used: this file.

How this Skill uses context

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

This Skill turns off automatic use in Claude Code. Its description stays out of the automatic Skill list by default.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Render a SwiftUI preview

Generate SwiftUI code from the most recent interaction context, render it to a PNG using ImageRenderer, and output it as a markdown image so it renders inline.

The "context" can take any form: a prose description ("show a profile card with a photo on the left and name above bio on the right"), an attached screenshot or mockup image, an ASCII layout diagram, or actual Swift code. Translate whichever the user provided into a single ContentView.

For example, this ASCII diagram:

+------------------+--------------------------------------+
|                  |           Name                       |
|                  +--------------------------------------+
|    Photo         |                                      |
|                  |           Biography                  |
|                  |                                      |
+------------------+--------------------------------------+

should become an HStack with the photo on the left and a VStack { Name; Biography } on the right, sized so the photo spans the full height. Match proportions and stacking direction faithfully; choose reasonable placeholder content (e.g. Image(systemName: "person.crop.square.fill"), sample text) when the input doesn't specify.

How to render

  1. Derive SwiftUI view code from the current context — prose, image, ASCII diagram, or existing Swift. The root view must be named ContentView. Helper views may be defined alongside.
  2. Locate agent-skill-swiftui.el which lives alongside this skill file at skills/swiftui-preview/agent-skill-swiftui.el in the emacs-skills plugin directory.
  3. Invoke the elisp function in a single Bash call. To avoid shell+elisp quoting issues with arbitrary Swift code, pipe the source through base64 and decode it on the elisp side:
    emacsclient --eval "(progn (load \"/path/to/skills/swiftui-preview/agent-skill-swiftui.el\" nil t) (agent-skill-swiftui-render :swift-source (base64-decode-string \"$(base64 <<'SWIFT' | tr -d '\n'
    struct ContentView: View {
      var body: some View {
        Text("Hello, SwiftUI!")
          .font(.largeTitle)
          .padding(40)
      }
    }
    SWIFT
    )\")))"
    The 'SWIFT' heredoc delimiter is single-quoted so the source passes through verbatim — no shell escaping needed inside.
  4. The function returns the PNG path as a quoted elisp string (e.g. "/var/folders/.../agent-swiftui-XXXX.png") on success, or nil on failure.
  5. On success, output the result as a markdown image on its own line:
    ![description](/var/folders/.../agent-swiftui-XXXX.png)

SwiftUI source template

Do NOT include import SwiftUI — the wrapper imports it. Provide only the view structs:

struct ContentView: View {
  var body: some View {
    VStack(spacing: 20) {
      Text("Hello, SwiftUI!")
        .font(.largeTitle)
      RoundedRectangle(cornerRadius: 12)
        .fill(Color.orange)
        .frame(width: 200, height: 100)
    }
    .padding(40)
  }
}

If the source contains no struct or class definitions, it is wrapped automatically as the body of a generated ContentView. Otherwise it must define ContentView itself.

Rules

  • The root view must be named ContentView when the source contains struct/class definitions.
  • Do not include import SwiftUI in the source — the wrapper adds it.
  • Use one Bash call. Pass the source via the base64 | tr -d '\n' pipe inside the single-quoted 'SWIFT' heredoc — do not write a temp .swift file as an intermediate step.
  • Locate agent-skill-swiftui.el relative to this skill file's directory.
  • Run the emacsclient --eval command via the Bash tool.
  • emacsclient prints the return value as an elisp literal — strip the surrounding " quotes from the path before emitting the markdown image link.
  • On success, output a markdown image (![description](path)) on its own line.
  • On nil return, inform the user that the SwiftUI render failed and show the source so they can debug.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 alert5mo3 checks · Risk MEDIUM
  • Gen Agent Trust Hub5mo

    This skill compiles and executes Swift code generated from user-provided context to render UI previews. While this is its intended function, it creates a significant attack surface where malicious user instructions could be translated into executable code that performs unauthorized local actions.

  • Socket5mo

    No alerts

  • Snyk5mo

    Risk: CRITICAL · 2 issues

Signed by skilld at a158238. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 5 months ago
tools
Bash
disable-model-invocation
true

README badge

README badge for xenodium/emacs-skills/swiftui-preview