Skip to content

swapify 0.3.0

Choose a tag to compare

@tornikegomareli tornikegomareli released this 30 Nov 13:56
· 23 commits to main since this release

Security

  • The agent in a simulator or macOS app took commands from any process on the Mac, and from any web page: a browser sends a cross-origin POST to 127.0.0.1 without asking, and the agent skipped the lines it did not know and ran the rest. Such a request could load a library into the app or write a PNG over any file the app can write (#16). Every connection must now start with the token of the launch, as on an iPhone, and anything else closes it. The wire protocol is version 2.

Added

  • The MCP run tool takes target (simulator, device or mac) and udid. Before, an MCP client could only run a project where it ran last, so a new macOS or iPhone project could not start from MCP (#29).

  • Examples/Ticker, a macOS app with no window and an embedded framework, and its end-to-end test, scripts/e2e-mac-headless.py. It never takes the screen or the focus, so make e2e now covers macOS too. make e2e-mac runs the test with a window, Examples/Desk.

Changed

  • The layout guard runs on the Mac before a patch is linked, on every platform. Before, a simulator or macOS patch was loaded first and checked in the app, so a patch that was then refused had already run dlopen: its Objective-C categories had replaced methods, and its types were registered (#19, #21). The check in the app stays as a second one. A reload that puts a class's new property in side storage builds one library, not two, and on macOS saves the scan of the first (#28).
  • A reload compiles the files it is given, and the files changed earlier only when the patch needs them. Before, every reload compiled every file changed since the build, so one large file, edited once, slowed every later reload until the next build (#28).
  • Loading a patch takes about 5 ms in the simulator, down from about 55 ms. One call to the Objective-C runtime for the names of the patch's classes took 50 ms of every reload; the agent now reads the patch's class list itself (#28).
  • swapify run --device with Developer Mode off, and swapify screenshot --full before the first run, end with exit code 1. They were reported as usage errors, with exit code 64 and the usage text.
  • .swapify/session.json has a new shape: the last build and the last launch are two records, and each launch replaces its record whole. A session of an earlier version reads as none. Run swapify run once after the update, which the new agent protocol needs in any case.
  • swapify watch scans when the file system reports a save, not four times a second. It follows the folders of a later swapify run, and says when a file was deleted (#28, #29).
  • .swapify/patches keeps the eight newest patches, and a launch empties it. It grew without limit: one run of the end-to-end tests left 560 MB there (#28).
  • The guard compares a file with the module as it was built, not as it is now. Before, it gave up when the built file no longer compiled against the edited project, for example after a type moved to a new file, and a device then loaded the patch unchecked with a warning (#21). On a device, a file that cannot be checked is no longer loaded.

Fixed

  • The MCP run tool named the simulator of the last launch, so the run failed when that simulator was shut down since. It now takes that simulator if it is still booted, and another one if not, as swapify run does. It also checks Developer Mode on the iPhone before the build, not after it.
  • In the simulator and on macOS, reloaded code got its own copy of a static or global with a constant initial value, such as static var count = 0: it read 0 again, and what it wrote was lost to the rest of the app. The accessor of such a variable is 12 bytes, and the agent left every accessor under 16 bytes alone, without a word (#24). It now redirects them too, and rejects a patch that it cannot bind to the app.
  • @objc methods did not reload, and the screen did not refresh, for a view controller or view that is nested in another type, has an Objective-C name of its own (@objc(Name)), or has a name that repeats a word of the module's name. The agent built each class's Objective-C name from the first two parts of its Swift name (#24). It now asks the Swift runtime for the class.
  • On macOS, edits to a framework embedded in the app did nothing: the agent read the images in Contents/MacOS only (#20). A framework that an app loads after launch is now read too.
  • After about 500 reloads the agent refused more with "too many patches" (#20).
  • A patch now takes effect on the app's main thread, between two of its events, with a memory barrier before old code can reach it. Before, the agent's own thread wrote it while the main thread ran (#18).
  • A rejected patch leaked its symbol tables, and every image's tables held memory for all of its symbols (#19, #28).
  • A view that implements injected() got the call, and then its view controller built the screen again anyway, which threw the view away (#25).
  • A rebuilt UIKit or AppKit screen got viewWillAppear and viewDidAppear again without the disappear calls first, so an observer or timer started in viewWillAppear doubled at each reload. On macOS it also got the two appear calls twice: AppKit makes them itself when the new view enters the window (#25).
  • A reload of a file with a UIHostingController or NSHostingController subclass built its view again, which reset the @State of its SwiftUI views (#25).
  • On macOS, tap on a button in a table row selected the row and did not press the button. ui and tap saw one window, and never a panel, sheet or popover: now every visible window of the app (#25).
  • A view whose class name only contains NSHostingView or _UIHostingView was taken for a SwiftUI hosting view, and a frame that is not a number failed the whole ui reply (#25).
  • Reloaded code got the patch's own copy of a type, a second type to SwiftUI and to ==, in two more places: a static method of a protocol extension called on a private or fixed-layout type, and a type chosen by a condition, flag ? A.self : B.self (#23).
  • A device patch kept its own metadata for a type whose $s…N alias has a linkage word, and the IR parser trapped on a few malformed inputs (#23).
  • A new stored property of an @Observable class needed a rebuild unless its type was a standard library type: var tag = Tag() or var tags: [Tag] = [] was refused (#22).
  • A new weak or unowned property of a class was put in side storage as if it were a strong one, which crashed when its object went away. It is refused now, as is a new property of a generic class, with that reason (#22).
  • A reload with a new method of a class failed to compile when a file called the method both directly, as super.added() does, and through the vtable (#22).
  • A subclass in another file went unnoticed when its declaration ran over several lines, and the reload then went ahead (#22).
  • A Swift file beside the app's files that is not the app's, such as a test file, failed every reload after its own: it borrowed a build command, did not compile with it, and stayed in every later patch, also after swapify run. Coding agents edit tests all the time. Such a file is now forgotten when its own compile fails (#26).
  • A file given through a symlink, or in a project under /tmp or /var, was taken for a new file and compiled twice (#26).
  • Two reloads at once, such as the Claude Code hook and swapify watch on the same save, wrote the session over each other, and the one that started first could load its older code last. One reload, build or launch runs at a time now, across processes (#26).
  • A compile of a built file that was stopped halfway left a part of a file, which later reloads compared layouts with (#26).
  • After a switch between swapify run, --device and --mac in one project, files that the new build did not compile kept the other platform's compile commands, and their reloads failed with "incompatible platform" (#27). Each platform's commands are kept apart now.
  • A run that built for one platform and then failed to launch left the other platform's app running, and reloads tried to load the wrong platform's patches into it (#27). The session records what was built and what runs, and no longer reads either from the app's path.
  • A build's macro plugins, compiled for the Mac, counted as reloadable files of an iOS app. A file in the app and in a widget got the command of whichever target compiled last, and a patch compiled as the widget's module replaced nothing (#27).
  • A scheme that also builds a helper app or a UI test runner could launch that instead of the app, when it was built last (#27).
  • In the simulator and on macOS, a file with a subclass of UIHostingController, or of another class of a library built for library evolution, could not be reloaded: the check in the app took a pointer in the class's descriptor for a changed size, and said "stored properties changed" for any edit (#21).
  • In the simulator and on macOS, two methods of a class in another order, a method with another signature, and a property whose type changed to one with the same name in another type or module were not seen as layout changes (#21).
  • A type that moved to a new file and changed its layout in the same edit was not guarded on a device (#21).
  • A file written while the app was building got a copy "as built" of the text that the build may not have compiled (#21).
  • swapify run failed after 20 s for an app with no accessibility elements on its first screen, such as a game view or a menu bar app, though its agent answered (#29).
  • On macOS, swapify run looked for the app's running copy with pgrep -f and the app's path as a pattern: a path with + or ( matched nothing or too much, a debugger or tail that named the path was quit too, and an app that did not quit stayed (#29). It is now found by its executable's path, and killed after 5 s.
  • swapify mcp left a devicectl in the process table at each run on an iPhone (#29).
  • When the agent's port was in use on the iPhone, the run waited 40 s and blamed the screen (#29).
  • swapify init did nothing for .gitignore when .git is in a folder above the project, and kept the path of a swapify that had moved in the hook and the MCP entry. swapify doctor built the agents in a source checkout, did not check for Xcode 26, and spoke of iOS for a macOS app (#29).
  • MCP results of legacy requests carried resultType, and a parse error had no id (#29).
  • A constant page that the agent wrote to stayed writable, and a failed write to one crashed the app (#18).
  • A label of two lines, as SwiftUI gives a Text with a line break, was sent as two commands: tap matched a different element, and the second line ran as a command of its own (#17).
  • A command longer than 1,088 bytes was cut in two (#17).
  • The app ended with SIGPIPE when the CLI went away before it read a reply, and swapify watch and swapify mcp ended the same way when the app went away (#17).
  • After a reply that did not arrive, a device reload sent the same load again on a new connection (#17).
  • A client that stopped sending, or stopped reading, held the agent for every later command (#17).