Skip to content

Make the Swift port the main line: replace the Go implementation - #77

Closed
Akhrameev wants to merge 32 commits into
MobAI-App:mainfrom
Akhrameev:swift-port
Closed

Akhrameev wants to merge 32 commits into
MobAI-App:mainfrom
Akhrameev:swift-port

Conversation

@Akhrameev

Copy link
Copy Markdown

What

Promotes swift-port to main on this fork. The repo becomes the Swift port of
MobAI's simslim. It is not meant to be merged upstream, as the
README states.

Changes

  • Replaces the Go CLI with a dependency-free Swift CLI (SimSlimKit library + SimSlimCLI
    command layer), built with the Xcode toolchain alone. Every command is covered, including the
    offline disabled.plist fast path.
  • Adds the SwiftUI macOS app under gui/, built by scripts/build-app.sh with no Xcode project.
  • Removes the Go tree. The last Go build stays recoverable at the go-reference-final tag;
    see docs/remove-go.md and docs/parity-check.md for how parity was checked.
  • CI runs Swift lint, tests, the dependency audit and the app build on macos-26 / Xcode 26.6.
  • release.yml publishes the Swift CLI as an Apple Silicon tarball on v* tags. It publishes
    no Go build and no Homebrew bottle; those belong to upstream.
  • LICENSE keeps the Interlap copyright and adds the Swift port's. The README credits MobAI.
  • README documents the prebuilt binary, including the lack of notarization and the Gatekeeper workaround.

About 31 commits and 146 files changed, mostly the Go removal.

Verified

  • make swift-lint, make swift-test, make verify-deps and make app-check pass locally.

Start the Swift port in swift/ (SwiftPM, no third-party packages) so
simslim can be built with the Xcode toolchain alone.

Scaffold:
- closed list of absolute-path executables behind a fakeable runner
- scripts/verify-deps.sh (make verify-deps): fails on packages,
  non-allowlisted imports, network APIs, remote reads, process spawning
  outside Subprocess.swift, fetching build files, non-system linked
  libraries, network symbols, and test hooks in the release binary

Core model (ported from profiles.go, features.go, profile_file.go):
- allowlist of 16 categories / 179 labels, descriptions and 27 features,
  generated from the Go source by swift/Tools/gen_catalog.py
  (make swift-gen / swift-gen-check)
- Profile.desired, platform rules, delta scoped to the managed set,
  feature diagnosis, profile file load/validate/marshal
- 53 tests, including the Go safety invariants (forbidden daemons,
  managed-only mutation, required-enabled services)

Only --version works so far; commands arrive in later milestones.
docs/swift-port-plan.md records the plan and the deferred work.
…or, measure)

Adds the simctl layer, status/verify/measure, and a SimSlimCLI target with an
injected runner so every command is tested against a fake host. Output matches
the GUI's Models.swift (contract test). Verified live on a throwaway simulator.
Int64(Double) crashes on overflow and NaN. Sizes such as 1e30 now parse
to 0, like any other unparseable size.
… hardened dependency gate

Offline disabled.plist route with launchctl fallback, batched unload, 8-worker
pool, operation deadline. Gate now catches private/@_spi imports, non-Swift
sources, a same-named Subprocess.swift and swallowed grep errors. Verified on a
throwaway simulator: 246 -> 83 processes, ~10.5 -> ~2.7 GB.
…t generated code

DisabledStore.write rebuilt the file from the boolean entries only, so any
other value the runtime had stored was silently deleted. It now reads those
entries back and writes them through unchanged. Covered by a new test.

The generated catalog and forbidden-label files carry swift-format-ignore-file,
which clears 155 lint errors that were only in generated code. Add a
`make swift-lint` target.
…M3a tests

Independent review found no safety bug; it found tests that passed vacuously.
The fake host now scopes devices to their --set and treats the store as
authoritative at boot. A zero-byte store is an empty store; non-dictionary or
old-style plists fall back to launchctl instead of being overwritten.
Batched load/unload, per-label fallbacks, neighbour-category and platform rules,
atomic profile writes. Verified on a throwaway simulator.
…on events); review fixes

Per-device cancellable slim passes, store seeding before boot, directory watcher
on the default/testing/--set sets. Review fixes for --save: follow bare-name
symlinks, trim padded entries, error on unreadable paths, private temp file.
Exact-UDID resolution before every destructive call, shutdown awaited before
erase/delete, Go-compatible name rules and %q output. Refuses erase/delete on a
Booting or Shutting Down simulator (deliberate divergence from Go).
Pure model plus a raw-mode terminal runner; fleet snapshot, per-process and
disk measurement in the library. Verified in a pseudo-terminal and against
real simulators (read-only).
Disk measurement and permanent cleanup of allowlisted per-device directories.
Containment now also rejects an in-tree symlink that redirects a fixed path
into protected data (a hole the Go code shares), lists directories with
readdir so ._ files are not skipped, tolerates vanishing children, and
refuses a Booting or Shutting Down simulator.
… input)

Interactive builder for --profile files. The wizard is a pure state machine
(WizardModel) driven by a termios reader. The output file is created
exclusively and never follows a symlink; a kept daemon covered by any kept
feature is dropped and listed once.
Clone rebases a CoreSimulator copy away from its source (symlinks, property
lists, generated stores), audits the running clone for open source paths and
deletes it if anything fails. repair-clone fixes clones made by older versions.
A clone UDID that names an existing simulator is rejected before any delete;
the open-file audit also catches a symlinked CoreSimulator root.
…pyright headers

- watch: require device.plist's UDID to be a real UDID that matches its
  directory name, and keep a UDID inside the store root in DisabledStore.
  A planted device.plist could otherwise steer the disabled.plist path.
- Reject --boot-timeout/--spawn-timeout values that overflow (inf or more
  than Go's ~292-year limit) instead of trapping on the Int conversion.
- Add tests for both.
- Add "Copyright (c) 2026 Pavel Akhrameev (Swift port)" to every Swift
  file; gen_catalog.py emits it in the generated files too.
- README: say this is a Swift port of MobAI's simslim (not official, not
  meant to merge upstream), credit the original authors, and explain the
  goal of using less technology (Xcode only, no Go). Split install into
  this port and upstream's Go version, and mark the Go library section as
  upstream's package.
- LICENSE, Info.plist: add Pavel Akhrameev (Swift port) next to Interlap.
- Info.plist: bundle ID is now io.github.akhrameev.simslim.
- ci: add a Swift job (lint, catalog sync, tests, verify-deps).
- release: publish only the Swift CLI tarball and checksum, with the
  version taken from the tag. The Go build and Homebrew bottle belong to
  upstream.
- docs/swift-port-plan.md, CLAUDE.md: record M1-M6 as done and document the
  Swift port workflow.
scripts/parity.sh runs the same commands through both CLIs on a Mac and
diffs normalized stdout, stderr and exit codes, optionally mutating a
scratch simulator and comparing the persisted disabled.plist.
…ts failed steps

on and off take no --json, so the mutating phase failed identically in both
tools and passed. Fix that, compare size and disk-plan in shape mode, and
print the non-zero exits so a shared failure is visible.
This file never compiled before (written without a local Go/Swift toolchain);
the literal defaulted to [Int: Int], which doesn't match parseTopMemory's
[Int: Int64] return type.
usageText was a truncated stand-in missing almost every per-flag description
(on, watch, enable/disable, disk-clean) and the closing paragraphs/footer.
scripts/parity.sh now reports 50/50 on the read-only phase.
The host-side disabled.plist is CoreSimulator/launchd_sim's own undocumented
bookkeeping, not simslim's, and snapstore() read it once, immediately, with no
tolerance for that. After on it can be transiently truncated or validly
parseable but incomplete; require two consecutive identical reads before
trusting one. After a live enable/disable/on --no-reboot it can lag
indefinitely since that path never writes the store directly, confirmed by
checking the in-guest launchctl state directly (identical between Go and
Swift); drop the store snapshot after on --no-reboot rather than chase an
unbounded race.

Documented as a TODO in the README and in docs/parity-check.md.
…elp credit URL

- parity.sh: snapshot disabled.plist after shutdown instead of dropping the
  --no-reboot check; treat a store absent for ~1.5s as absent and report a
  store that never settles in stderr; only delete a clone UDID that is new
  and named parity-clone; kill a background watch on exit; --watch asks
  before slimming every simulator (or pass --yes); clean up on INT/TERM.
- README: replace the unverifiable "91 commands, zero differences" with a
  scoped claim, and move the disabled.plist TODO into docs/parity-check.md.
- docs/parity-check.md: describe which steps snapshot the store, that on/off
  are compared as text, and the open disabled.plist question.
- verify-deps.sh: exempt the one credit-line URL that `simslim help` prints
  (copied from the Go CLI); any other URL in source still fails.
- Untrack .vscode/launch.json and ignore .vscode/.
… app`

- build-app.sh: build the Swift CLI with `swift build -c release --arch`
  and bundle it. SIMSLIM_CLI_IMPL=go keeps the old Go build as an
  opt-in fallback. The default is swift.
- Stamp $VERSION into Version.swift for the build and restore the file
  on exit (trap), so a failed build leaves the tree clean.
- Ad-hoc codesign the bundled binary before signing the bundle.
- Makefile: split app-check (gui lint, zsh -n, plutil) from the
  Go-only check target.
- CI: the swift job now builds and verifies the app bundle; the Go
  checks move to a separate go-reference job with setup-go.
- GUIContractTests: decode boot/shutdown with the app's
  SimulatorMutationResult, and assert empty stderr under --json for
  the commands the app calls (it reads stdout+stderr through one pipe).
- README: build the app with Xcode alone.
- CLAUDE.md: make app is Swift + swiftc; document SIMSLIM_CLI_IMPL=go,
  the app-check vs check split, and the CI job layout.
- swift-port-plan: M8 (app cutover) done; Go tree removal is a later step.
- CONTRIBUTING, parity-check: make check is now only go test + go vet;
  gui lint, build-app.sh syntax and plist lint moved to make app-check.
  List app-check in the "Go available" gate.
- CONTRIBUTING: Swift-only/gui-only changes have a Go-free gate.
- parity-check: note that make app works without Go.
- CLAUDE.md: replace "full CI gate" with the Go gate plus app-check
Lists what to tag, delete and edit to leave only the Swift port: the
last parity run and go-reference-final tag, the Go files and generator,
Makefile/CI/build-app.sh/parity.sh/CLAUDE.md/README changes, the
Generated/ files becoming hand-maintained, and a post-removal grep and
build check
The Swift port reached parity (scripts/parity.sh: read-only, --mutating,
and --watch all clean) and the app already bundled the Swift CLI, so the
Go tree is no longer needed day to day. Tagged go-reference-final before
deleting, per docs/remove-go.md.

- Delete *.go, cmd/, go.mod, go.sum, packaging/homebrew/, and
  swift/Tools/gen_catalog.py (nothing left for it to read). The
  Generated/ catalog files it produced become ordinary hand-maintained
  source; drop their "generated, do not edit" banners.
- Makefile: drop cli/test/check/swift-gen/swift-gen-check; format no
  longer runs gofmt.
- scripts/build-app.sh: drop SIMSLIM_CLI_IMPL and the Go build branch;
  the Swift build is now the only path.
- .github/workflows/ci.yml: drop the go-reference job and
  swift-gen-check; one job covers lint, test, deps audit, and the app
  build/verify.
- scripts/parity.sh: kept as a regression check against the tagged Go
  build, built from a sibling worktree (../simslim-go-reference)
  instead of this repo's tree.
- README, CLAUDE.md, CONTRIBUTING.md, docs/*: updated to describe a
  single Swift implementation; CLAUDE.md's architecture section now
  names the Swift files and identifiers instead of the Go ones.

Verified locally: make app-check/swift-lint/swift-test/verify-deps all
pass, VERSION=0.0.0 make app builds and codesigns with no Go toolchain
involved, and scripts/parity.sh's read-only pass against the tag-built
Go binary still compares clean (50/50).
…r Go removal

- parity.sh: absolute --out (the Go build runs from the worktree dir),
  prune stale worktrees, refuse a worktree that isn't at
  go-reference-final, --help prints the full header.
- build-app.sh: describe --match 'v*' so the go-reference-final tag
  can't become the bundled CLI's version.
- README: SimSlimKit isn't a package product; say so. Rescope the
  parity claim (not a proof; watch run-order effect).
- CLAUDE.md: fix identifiers (Watcher.run, Watcher.Pass, Catalog.features,
  timeouts), restore the copyright-header rule and the Generated/ editing
  and test-guard notes.
- Makefile, CONTRIBUTING, parity-check, remove-go: stale or wrong text
@Akhrameev Akhrameev closed this Nov 19, 2026
@Akhrameev

Copy link
Copy Markdown
Author

Sorry, incorrect target was selected. Ported it into Swift as go is restricted in company, but idea of using less RAM is very valuable

@Akhrameev
Akhrameev deleted the swift-port branch November 19, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant