Skip to content

About

Native SwiftUI shell for Mac over a pinned Craft Anything engine

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

CraftAnythingNative

A native SwiftUI shell for Mac, built over a pinned Craft Anything engine. This is stage 1 of the plan in ../craft-anything-swift-review.md. The app starts our fork's craft-anything-cli mcp as a child process and drives it the same way any MCP client would. No engine code is ported yet.

Run it

Tools/engine/pin-engine.sh     # build the pinned engine into Engine/bin (needs the ../craft-anything clone at the pin)
swift build
.build/debug/CraftAnythingNative
Tools/make-app.sh              # or: a development app bundle with all three programs, at .build/CraftAnythingNative.app

swift test runs the engine-connection tests. When Engine/bin holds an engine, the tests also start it, list its tools, call some of them, and check the approval round trip. They use temp folders for its settings and projects.

To capture a window without the person's data, run with --screenshot <file.png> [--section new|tools|<project folder>]. That draws the window into a PNG and quits. The engine's settings, projects and inbox go to a fresh temp folder.

To drive the app in a check, start it with --check: the engine's settings, projects and inbox go to a fresh temporary folder, so your own projects are neither listed nor changed (--check-folder <folder> keeps them in a folder you name). Docs/hand-test/SMOKE.scenario.md is the smoke check AppProbe runs that way after the engine pin moves: the engine starts, the screens reach it, and no build is started. The main controls carry accessibility identifiers (request, startBuilding, sidebar.tools, tool.<id>, runTool, toolResult, engineBadge…).

Releases

Pushing a v<version> tag that matches VERSION runs .github/workflows/release.yml, which runs Tools/release.sh and publishes the GitHub Release. The release script:

  • builds the pinned engine (from the private fork, through a read-only deploy key, ENGINE_DEPLOY_KEY)
  • runs swift test
  • bundles the app, the tool server, the WebKit plugin and the engine
  • signs everything with Developer ID
  • smoke-tests the bundle with the build folders hidden: the bundled engine serves the WebKit browser set through the bundled plugin, and the app draws its window
  • notarizes and staples the app, then the DMG
  • publishes the DMG, its .sha256 and Docs/releases/<version>.md as the notes

The signing and notary secrets are organization secrets on xocialize-code, the same ones Gaea uses. Running the workflow by hand (Actions › release › Run workflow) builds, checks and notarizes any ref without publishing.

The script runs the same way on this Mac: Tools/release.sh signs with the keychain's Developer ID, notarizes with the mlx-notary profile when it exists, and leaves everything in dist/. PUBLISH=yes also publishes. Its header lists the other settings, such as SIGN_IDENTITY=- for an ad hoc test build.

What's here

  • CraftEngineKit is the engine connection:

    • MCPClient is an actor that speaks newline-delimited JSON-RPC to the engine over stdio. Requests can overlap. Each request has a timeout and sends notifications/cancelled when it expires. The client drains stderr and keeps its last lines for error messages. If the engine stops, every waiting call fails with what it printed.
    • Inbox mirrors the engine's inbox folder. When the engine needs consent for an action (a build, Play), it posts the request there and waits, and the app writes the answer back as a whole file.
    • EngineTool and ToolParameter read the tools' JSON schemas, and ToolResult reads the engine's {"result"} / {"error"} replies.
    • ToolServer stands in front of the engine for the builders it starts. Every message passes through unchanged, except calls to a NativeTool, which are answered in Swift under the engine's own tool id.
    • MCPServer serves NativeTools on their own, as an engine plugin.
  • CraftWebKit is the engine's website browser set served with WebKit: web_site_open, web_site_capture, web_page_states_capture and web_site_close, under the engine's ids and arguments. They run the engine's own page scripts (PageScripts.swift, generated from the pin by Tools/engine/sync-scripts.sh) and write the same files: screenshot-<width>.png, noise-<width>.png, capture.json, README.md, page.html, states.json and state-<n>.png. Clean room comes from the call's _meta, as the engine sends it. The page runs in a private (non-persistent) WKWebView with light appearance and classic scrollbars, in a window nobody sees, at one pixel per CSS pixel. WebKit's window-occlusion check is turned off, so the page believes it's on screen (that switch isn't public API; without it the window is on screen but fully transparent, and the page is flagged if it still thinks it's hidden). Load errors are read from inside the page, so a failed request shows only when the browser reports it there.

  • craft-anything-native-tools is the plugin the engine sends those tools to. In the engine's config.toml (craft-anything-native-tools --print-config prints the entry with its own path):

    [[plugins.mcp]]
    id = "mac_app"
    command = "/…/CraftAnythingNative.app/Contents/MacOS/craft-anything-native-tools"
    replaces = ["web_site_open", "web_site_capture", "web_page_states_capture", "web_site_close"]

    Every engine process reads it, so Study, the checks and the builders all picture websites with WebKit. Each project keeps the browser that pictured its original (browser in its craft.json, set by Study; the project screen shows it), and pictures of its build follow that record, so projects studied with Chromium stay on Chromium after WebKit is turned on. A project pictured with a plugin that's since been removed is refused, not switched; studying it again records the browser set up then. The app doesn't add the entry for you yet. Each call is logged to ~/Library/Logs/CraftAnythingNative/native-tools.log. Tools/parity/webkit-parity.py captures the same pages both ways and reports the differences.

  • craft-anything-tool-server is the program builders get as their tool server. The app sets CRAFT_ANYTHING_TOOL_SERVER (a patch in our fork) and CRAFT_ANYTHING_ENGINE in the engine's environment. mcp … is served through ToolServer; anything else (builder-notes) runs the engine itself. Each call is logged to ~/Library/Logs/CraftAnythingNative/tool-server.log.

  • CraftAnythingNative is the app:

    • New Build: the request, the original (none, a website, or an app or file), the stack, and the number of rounds.
    • Projects: status, the conversation, questions to answer, checks, and the latest screenshot. From here you can send a note or a follow-up, stop the build, play the result, or show it in Finder. The right panel swaps between the project's details and the window's browser. Play shows a website a build made there (project_preview, served on this computer); an app or game is started (project_play). Send Page to Builder saves what the browser shows in the project (shared/page-<time>/page.png, a picture of the visible part, WebGL included, and page.txt, its address, title and text) and sends the builder a note naming both, with the person's words: as a note to a running build, or as a follow-up, after approval. A build of a website original opens the original in the panel's browser as it starts, and a website build that finishes opens its result there, to iterate on (the page it was on, reloaded, when the browser is already on the build's site; a page the builder showed during the build stays).
    • Builders see the panel's browser too: the tool server (craft-anything-tool-server, which stands in front of the engine for every agent) adds two tools of the app's own to the engine's list, in Clean room and Deep alike. person_browser_view returns what the person is looking at (address, title, viewport, scroll, selected text, paged visible text, and a picture saved in the project's shared/), and person_browser_show opens an address there for the person and waits for it to load. A page of the build's own website (a path such as /about, or an address on this computer) is served by the app's engine at the same path, since a preview a builder starts itself stops when its turn ends. person_browser_picks returns what the person picked.
    • Pick (in the project panel's browser bar) points at parts of a page: in pick mode a click picks the element under it instead of using it (the page never sees the click), each pick is numbered on the page, and the Picked list holds a comment for each. Send Page to Builder sends them with the page (picks.json, with each pick's selector, tag, text, trimmed markup, box and key computed styles, and pick-<n>.png), and the builder can fetch them itself with person_browser_picks. The picking script runs in a content world of its own, apart from the page's scripts, and draws its marks in a closed shadow root. Picks belong to the page: going to another clears them. They reach the app over a Unix socket only this user can open (BrowserBridge: ~/Library/Application Support/CraftAnythingNative/browser.sock, or CRAFT_ANYTHING_BROWSER_SOCKET, which the app sets for its engine); with the app closed, they say so. The engine never sees these calls, so they need no approval and leave no evidence.
    • Browser: a WebKit view with an address field, back, forward and reload, for looking at a website and cloning the page it's on with a prompt (rebuild_start with the page's address as the original). One per window, with a private data store and light pages, like the engine's own browser, which studies a site signed out.
    • A tool browser with a form for each tool, built from its schema.
    • A sheet for approvals posted to the app's inbox.
    • Clean room or Deep: a switch in the toolbar, in Settings and in New Build. They all set the engine's saved deep_mode, so every engine process it starts follows it. The engine lists 107 tools in Clean room and 321 in Deep, and doesn't announce the change, so the app lists the tools again after switching. Turning Deep on asks first. Settings shows whether Ghidra is installed and can get it (engines_install). When Clean room refuses something (details.reason = "clean_room"), the Tools form and the project screen offer to turn on Deep mode.
    • New Build's Game assets switch (generate_assets), for game stacks and the builder's choice.
    • Settings › Game assets: who makes a game's pictures and which model. The choices are Gaea on this Mac (free and keyless, the default) or one of fal.ai's models. Settings also shows whether Gaea is answering, lists the picture models it offers (MES GET /operations), and holds the fal.ai key that 3D models still need. Tools/gaea/picture-check.py makes one picture through the pinned engine and a running Gaea, the way a builder does, in a throwaway project.

The engine pin

Tools/engine/pin.env names the engine commit this shell drives: the native branch of our fork (kept private, at xocialize/craft-anything), based on upstream main at a69c3ed (craft-anything 0.6.1, 2026-11-29). It adds:

  • the SwiftUI stack
  • the CRAFT_ANYTHING_TOOL_SERVER setting
  • plugins that replace built-in tools (with the call's _meta)
  • the website page scripts as files
  • each project's record of the browser that pictured it
  • Gaea as a keyless asset provider
    • It's the default for game pictures, sent over MES on loopback. [assets] gaea_url and gaea_model change the address and the model.
    • 3D models stay on fal.ai.

We don't send changes upstream. To take upstream's changes, we rebase those commits onto upstream main and run the engine's checks. After that, move the pin, run pin-engine.sh and run the tests again. Engine/bin/pin.txt records the binary's commit, version and sha256, and the toolbar shows that commit.

License

This shell is MIT (see LICENSE). The engine it drives is storytold/craft-anything, MIT OR Apache-2.0. This shell uses none of its brand assets. Sources/CraftWebKit/PageScripts.swift holds a copy of the engine's website page scripts, under the engine's license, as its header says.

Next (stage 2)

Port the pieces that are better native, behind the same tool ids, as NativeTools the engine sends to craft-anything-native-tools:

  • website capture (WKWebView): done, and each project keeps the browser that studied it
  • window capture (ScreenCaptureKit)
  • driving Claude Code, and the inbox
  • project files, checked byte for byte against the pinned engine

About

Native SwiftUI shell for Mac over a pinned Craft Anything engine

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages