Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,17 @@
<string>NSApplication</string>
<key>NSSupportsAutomaticTermination</key>
<false/>
<key>SUFeedURL</key>
<string>https://kernel-hunter.github.io/mudroom/appcast.xml</string>
<key>SUPublicEDKey</key>
<string>QKKfpvfADDZDhLbEDTOZ4QKgc5EgHgxP3hGulato8T8=</string>
<key>SURequireSignedFeed</key>
<true/>
<key>SUVerifyUpdateBeforeExtraction</key>
<true/>
<key>SUEnableSystemProfiling</key>
<false/>
<key>SUAllowsAutomaticUpdates</key>
<false/>
</dict>
</plist>
11 changes: 10 additions & 1 deletion Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 17 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,31 @@ var targets: [Target] = [
.testTarget(name: "MudroomCoreTests", dependencies: ["MudroomCore"]),
]

var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"),
.package(url: "https://github.com/apple/swift-crypto", "3.0.0"..<"5.0.0"),
]

#if os(macOS)
products.append(.executable(name: "MudroomApp", targets: ["MudroomApp"]))
targets.append(.executableTarget(name: "MudroomApp", dependencies: ["MudroomCore"]))
targets.append(.executableTarget(
name: "MudroomApp",
dependencies: ["MudroomCore", .product(name: "Sparkle", package: "Sparkle")],
linkerSettings: [
// scripts/build-app.sh puts Sparkle.framework in Contents/Frameworks.
.unsafeFlags(["-Xlinker", "-rpath", "-Xlinker", "@executable_path/../Frameworks"]),
]
))
// The app's updater. Pinned: an update to it is a change to how Mudroom
// replaces itself, so it should be a deliberate one.
dependencies.append(.package(url: "https://github.com/sparkle-project/Sparkle", exact: "2.10.0"))
#endif

let package = Package(
name: "Mudroom",
platforms: [.macOS(.v26)],
products: products,
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"),
.package(url: "https://github.com/apple/swift-crypto", "3.0.0"..<"5.0.0"),
],
dependencies: dependencies,
targets: targets,
swiftLanguageModes: [.v6]
)
103 changes: 101 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ Copy-Item "$env:TEMP\$name\*" $dir -Force
[Environment]::SetEnvironmentVariable('Path', [Environment]::GetEnvironmentVariable('Path', 'User') + ";$dir", 'User')
```

To upgrade, run the same lines with the new version, without the PATH
line. `mudroom.exe` isn't code-signed; if Windows blocks it after you unzip
To upgrade, run `mudroom update`, or the same lines with the new version
without the PATH line. `mudroom.exe` isn't code-signed; if Windows blocks it after you unzip
with Explorer, run `Get-ChildItem $dir | Unblock-File`.

The Scoop and winget manifests are in [packaging/scoop](packaging/scoop)
Expand Down Expand Up @@ -162,6 +162,71 @@ mudroom network check --backend docker # see what the sandbox can reach

</details>

### Updating

**Mac app.** Mudroom.app updates itself with
[Sparkle](https://sparkle-project.org): Mudroom > Check for Updates, or
let it check once a day (it asks the second time you open it). Nothing is
installed until you click Install, and Mudroom only installs an update that
is signed with its own key. The `mudroom` command inside the app updates
with it. Mudroom 0.5.0 and older don't have the updater yet, so update
those once by hand: `brew upgrade --cask mudroom`, or run the install script
again.

**Command line.** `mudroom update` checks for a new release and updates
the way Mudroom was installed:

| Installed with | `mudroom update` |
|---|---|
| Homebrew | runs `brew upgrade --cask mudroom` |
| The install script or the zip | opens Mudroom.app's updater |
| A Windows release zip | downloads the new zip, checks its SHA-256 against the release, and swaps the files in |
| Scoop, winget | prints `scoop update mudroom` or `winget upgrade --id KernelHunter.Mudroom --exact` to run (neither can replace `mudroom.exe` while it runs) |
| Built from source | tells you to `git pull` and rebuild |

It asks before changing anything; `--yes` skips the question and `--check`
only checks. In a terminal, Mudroom also prints one line after a command
when a newer release is out, at most once a day:

```text
Mudroom 0.6.0 is available (you have 0.5.0). Run `mudroom update` to get it.
```

<details>
<summary><b>What the update check sends, and how to turn it off</b></summary>

<br>

The CLI makes one request, once a day (an hour later if GitHub couldn't be
reached): `GET
https://api.github.com/repos/Kernel-Hunter/mudroom/releases/latest`, over
HTTPS, with no cookies or credentials. GitHub sees your IP address and a
`User-Agent: mudroom/<version>` header, which its API requires. Nothing
else is sent: no ID, no system details, nothing about your projects or
sessions. The answer is cached in Mudroom's data folder
(`update-check.json`). The check runs on your machine only, never in the
sandbox, and never during `run`, `start` or `agent`, in JSON output, under
CI, or when standard output or standard error isn't a terminal. A slow or
failed check never delays a command by more than a second and never
changes its result.

The Mac app reads its feed, `https://kernel-hunter.github.io/mudroom/appcast.xml`,
once a day if you said yes to automatic checks. Sparkle sends the app's
name and version in its User-Agent and no system profile. The feed and
each update are signed with Mudroom's EdDSA key; an update or feed that
doesn't match the key is refused.

To turn the checks off:

- the CLI: `mudroom update --auto-check off` (saved in Mudroom's
`settings.json`), or `MUDROOM_NO_UPDATE_CHECK=1` in your environment;
- the app: Mudroom > Settings > Check for updates automatically. The
`mudroom` command inside the app follows this setting too.

`mudroom update` itself always checks, since you asked it to.

</details>

## Quick start

In the app:
Expand Down Expand Up @@ -1493,6 +1558,19 @@ macOS, Linux and Windows.

## FAQ

<details>
<summary><b>Does Mudroom connect to anything on its own?</b></summary>

<br>

Only to check for updates: the CLI asks GitHub for the latest release at
most once a day, and the Mac app reads its update feed once a day if you
allow it. Neither sends anything about you or your projects. See [What the
update check sends, and how to turn it off](#updating). Everything else
Mudroom connects to is what you or the agent ask for.

</details>

<details>
<summary><b>Does the agent ever touch my real project folder?</b></summary>

Expand Down Expand Up @@ -1608,6 +1686,7 @@ swift test # diff, hunks, apply, undo, allowlist, proxy, snapsho
scripts/make-demo.sh # demo sessions in build/demo (no VM)
scripts/screenshots.sh # regenerates docs/screenshots from the demo
scripts/release.sh 0.4.0 # dist/Mudroom-0.4.0.zip and its SHA-256
scripts/appcast.sh 0.4.0 # adds a published release to the app's update feed
scripts/windows-package.ps1 .build/release/mudroom.exe 0.4.0 x86_64 # on Windows: dist/mudroom-0.4.0-windows-x86_64.zip with its DLLs
mudroom network check # verifies isolation in a real sandbox (any backend)
```
Expand All @@ -1630,6 +1709,26 @@ The proxy tests run it against a loopback test server. The app target is
platforms). `MudroomCore` has no UI code; the app and the CLI both sit on
top of it.

### Releasing

1. Set the version in `Sources/mudroom/Version.swift`, commit, and push a
tag: `git tag v0.6.0 && git push origin v0.6.0`. The release workflow
builds `Mudroom-0.6.0.zip` and the Windows zips, with a `.sha256` for
each, and attaches them to the GitHub release.
2. `scripts/appcast.sh 0.6.0`: downloads the Mac zip, checks it against
its `.sha256`, signs it with Sparkle's `sign_update` (the EdDSA key in the
login Keychain), adds it to `docs/appcast.xml` with the release notes and
signs the feed. Commit `docs/appcast.xml` and push it to main; GitHub
Pages serves it to the app.
3. `scripts/update-cask.sh 0.6.0 --remote`, then copy the cask to the
Kernel-Hunter/homebrew-tap repo.
4. `scripts/update-windows-manifests.sh 0.6.0`, then copy the Scoop manifest
to Kernel-Hunter/scoop-bucket and the winget folder to a winget-pkgs fork.
5. In the README, set `$v = '0.6.0'` in the Windows zip install lines.

The CLI's update notice reads GitHub's latest release, so it shows up as
soon as the release is published; the app's comes with step 2.

## Contributing

Bug reports, corrections to the comparison tables and pull requests are
Expand Down
6 changes: 6 additions & 0 deletions Sources/MudroomApp/MudroomApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct MudroomApp: App {
.commands {
CommandGroup(replacing: .appInfo) {
Button("About Mudroom") { AppDelegate.showAbout() }
CheckForUpdatesButton(updater: AppUpdater.shared)
Button("Setup…") { app.openSetup() }
}
CommandGroup(replacing: .newItem) {
Expand Down Expand Up @@ -65,6 +66,10 @@ struct MudroomApp: App {
}
.defaultSize(width: 720, height: 860)
.windowResizability(.contentMinSize)

Settings {
UpdateSettingsView(updater: AppUpdater.shared)
}
}
}

Expand All @@ -88,6 +93,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
NSApp.setActivationPolicy(.regular)
NSApp.activate()
AppUpdater.shared.listenForCLI()

let defaults = UserDefaults.standard
switch defaults.string(forKey: "MudroomAppearance") {
Expand Down
100 changes: 100 additions & 0 deletions Sources/MudroomApp/Updater.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import AppKit
import Combine
import Sparkle
import SwiftUI

/// Sparkle, set up from Info.plist: the feed (SUFeedURL), the key that
/// signs every update and the feed itself (SUPublicEDKey), no system
/// profile, and installs only when the user clicks Install. Sparkle asks
/// on the second launch whether to check automatically.
@MainActor
final class AppUpdater: ObservableObject {
static let shared = AppUpdater()

private let controller: SPUStandardUpdaterController
/// False for builds without a feed (`swift run`) and for screenshots.
let isAvailable: Bool
@Published private(set) var canCheck = false
private var lastRequest = Date.distantPast

private init() {
controller = SPUStandardUpdaterController(startingUpdater: false, updaterDelegate: nil, userDriverDelegate: nil)
isAvailable = Bundle.main.object(forInfoDictionaryKey: "SUFeedURL") != nil && !AppDelegate.isSnapshot
guard isAvailable else { return }
controller.startUpdater()
controller.updater.publisher(for: \.canCheckForUpdates).assign(to: &$canCheck)
}

var automaticallyChecks: Bool {
get { isAvailable && controller.updater.automaticallyChecksForUpdates }
set {
objectWillChange.send()
controller.updater.automaticallyChecksForUpdates = newValue
}
}

func checkForUpdates() {
guard isAvailable else { return }
controller.checkForUpdates(nil)
}

/// `mudroom update` opens the app with --check-for-updates, and posts
/// this notification for a copy that is already running. Either way the
/// user still sees the update and clicks Install. Any local program can
/// post it, so it only opens the check, at most every 30 seconds, and
/// doesn't pull the app in front of what the user is typing into.
func listenForCLI() {
guard isAvailable else { return }
if CommandLine.arguments.contains("--check-for-updates") {
lastRequest = Date()
checkForUpdates()
}
let name = Notification.Name((Bundle.main.bundleIdentifier ?? "io.github.kernel-hunter.mudroom") + ".checkForUpdates")
DistributedNotificationCenter.default().addObserver(forName: name, object: nil, queue: .main) { _ in
MainActor.assumeIsolated {
let updater = AppUpdater.shared
guard Date().timeIntervalSince(updater.lastRequest) > 30 else { return }
updater.lastRequest = Date()
updater.checkForUpdates()
}
}
}
}

struct CheckForUpdatesButton: View {
@ObservedObject var updater: AppUpdater

var body: some View {
Button("Check for Updates…") { updater.checkForUpdates() }
.disabled(!updater.canCheck)
}
}

struct UpdateSettingsView: View {
@ObservedObject var updater: AppUpdater

var body: some View {
Form {
Section {
Toggle("Check for updates automatically", isOn: Binding(
get: { updater.automaticallyChecks },
set: { updater.automaticallyChecks = $0 }))
.disabled(!updater.isAvailable)
Text("Once a day Mudroom reads its update feed from kernel-hunter.github.io. Nothing about your Mac or your projects is sent. An update is installed only when you click Install, and only if it is signed with Mudroom's key. The mudroom command in Terminal follows this setting.")
.font(.callout)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
}
Section {
HStack {
Text("Version \(Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "?")")
Spacer()
CheckForUpdatesButton(updater: updater)
}
}
}
.formStyle(.grouped)
.frame(width: 460)
.fixedSize()
}
}
Loading
Loading