# Upgrade

| Installed as | Update | Go back |
| --- | --- | --- |
| macOS App | A new version downloads by itself and **New** appears beside the OpenProgram name at the top left. Click it, then **Restart to update**. To look sooner: **Settings → Versions and updates → Application → Check now**. An App outside a folder it can write gets **Download and open installer** instead: save the DMG, quit with Command-Q, drag it onto the copy in Applications and choose **Replace**. | Download that version's DMG from [GitHub Releases](https://github.com/Fzkuji/OpenProgram/releases) and replace the App the same way. |
| Windows or Linux App | Same buttons; the new version installs in place. When a release needs a newer App: Windows and AppImage: it downloads by itself; click **New**, then **Restart to update**. deb: `sudo apt install ./OpenProgram-X.Y.Z-linux-amd64.deb` | **Settings → Versions and updates → Go back**. [If the App can't start](#app-recovery). |
| Terminal or server, every system | `openprogram upgrade`, then `openprogram worker restart` | [Install the older version](https://fzkuji.github.io/OpenProgram/docs/install/install.html#exact-version) with its exact number, then `openprogram worker restart` |
| Source checkout | [`openprogram dev deploy`](https://fzkuji.github.io/OpenProgram/docs/install/development-checkout.html) for the development instance, or [`openprogram upgrade`](https://fzkuji.github.io/OpenProgram/docs/server/upgrading.html). Restarts by itself. | [Undo a change](https://fzkuji.github.io/OpenProgram/docs/install/conversational-self-update.html#undoing-a-change) |

Stable installations move only between published versions and never follow `origin/main`. State under `~/.openprogram` is left unchanged. If the terminal command itself is broken, reinstall the latest version:

```
curl -fsSL https://fzkuji.github.io/OpenProgram/install | sh
irm https://fzkuji.github.io/OpenProgram/install.ps1 | iex
```

**What the App updater does**

- macOS: picks the complete DMG for the architecture, downloads it to the location you choose, verifies byte count and SHA-256, and opens it. The shell and complete product runtime are replaced together. Unsigned packages: [Open Anyway](https://fzkuji.github.io/OpenProgram/docs/install/install.html#macos).
- Windows, Linux: run `openprogram upgrade` in the version store and take the App file only when the release needs a newer shell.
- Windows App file: verifies release metadata, file length and SHA-256. A signed App also requires a valid Authenticode signature from the same publisher; only an App built unsigned accepts an unsigned installer.
- Downloads go through the system proxy and resume after a dropped connection. When GitHub's API refuses or does not answer, the App finds the release through GitHub's web pages.

**When an App that manages versions can't start**

A thin-shell App keeps its code as numbered versions under `~/.openprogram/runtime` (`%USERPROFILE%\.openprogram\runtime` on Windows). First start unpacks the bundled code behind a progress page, about a minute.

| Opens the recovery page | How |
| --- | --- |
| Automatic | The running version has not answered for two minutes and is not mid-switch |
| macOS | **OpenProgram > Go back to a previous version**, under About |
| Windows, Linux | Same item, bottom of the **File** menu |
| macOS, Windows | Hold Shift while opening the App |
| Linux deb | The launcher's **Go back to a previous version** action, or `openprogram-desktop --recovery` |
| Linux AppImage | `./OpenProgram-X.Y.Z-linux-x86_64.AppImage --recovery` |

- Lists the versions kept on the computer, as Settings does. Pick one and the App restarts with it. Conversations and files are not touched.
- Shows the log path, `recovery.log` in the same folder. With an empty code folder it offers to restore the bundled code; it never overwrites existing code.
- Apps with a built-in runtime have neither page nor menu item: every macOS App published so far and the development App.

## CLI and server release

| Goal | Command |
| --- | --- |
| Is a new stable release available? | `openprogram upgrade --check` |
| Install or go back to one version | [Exact-version installer command](https://fzkuji.github.io/OpenProgram/docs/install/install.html#exact-version) |

1. **Download** runtime archive from the release tag
2. **Verify** checksum and manifest in staging
3. **Cold-start** worker, before the version is live
   
   Any stage before Activate fails: previous version stays selected, unpublished staging runtime removed
4. **Activate** macOS, Linux: current symlink Windows: launchers

macOS and Linux serialize upgrades. Version directories are kept, which is what makes rollback the same command. A running worker is not restarted.

**Windows launcher replacement**

- One `openprogram.cmd` launcher is prepared before activation and replaced atomically. The previous one stays as `openprogram.previous.cmd`. Older `openprogram.ps1` launchers are removed, because the default script policy would refuse them.
- A validated runtime is retained for retry even when launcher activation fails.

**Releases that carry a seed**

- When a release publishes `OpenProgram-<version>-seed-<platform>-<arch>.tar.gz`, `install.sh` and `install.ps1` put it in the version store a thin App uses, `<state>/runtime`; `openprogram` runs the version `current` names.
- `openprogram versions list` shows what is kept.
- Without that asset, the plain runtime above is installed.
- An interrupted install starts over on the next run. A run on an existing version store updates it through `openprogram upgrade` and reports what that did.

## Official updates on a version-store installation

Takes a release as signed files and carries your own commits over. The Windows and Linux Apps update this way. The macOS App and plain terminal installs use the routes above.

```
openprogram upgrade --check
openprogram upgrade
openprogram upgrade --from <directory>     # files already on this computer
```

| Release file | Contents |
| --- | --- |
| `version-<platform>.tar.zst` | Sealed version for one platform, e.g. `macos-arm64` |
| `repo.bundle` | Official source line up to this release |
| `base-<platform>.tar.zst` | Python and third-party packages. Downloaded only when this computer does not have that base |
| `toolchain-<platform>.tar.zst` | The Web build's `node_modules`. Downloaded only when you have commits of your own to build |
| `SHA256SUMS` | Hash of each file above |
| `update-manifest.json` `update-manifest.json.sig` | Release contents and their Ed25519 signature |

Signature, checksums and every file this platform needs are checked first. An unsigned or altered release changes nothing.

| Case | Outcome |
| --- | --- |
| No commits of your own | The prebuilt version is unpacked and tried |
| Your commits | Applied on the release oldest first, then built and tried |
| Commit conflicts | It is saved; the others carry on |
| Release already contains it | Skipped |
| Build or trial fails | Your newest commit is saved and the rest retried, ending at the unmodified release. After 5 retries the remaining commits are saved together and the unmodified release is tried. |
| Unmodified release fails | Nothing changes: current version, your commits kept |
| Needs a newer signed shell, or another Python minor version than the launcher | Waits for the shell update: nothing unpacked, official line does not move |

The result lists replayed and saved commits. Saved ones are `git format-patch` files at `<state>/runtime/unreplayable/<release>/<commit>.patch`, ready to apply as a new change.

## Other routes

| Route | Covers |
| --- | --- |
| [Update from chat](https://fzkuji.github.io/OpenProgram/docs/install/conversational-self-update.html) | `self_update`, from a conversation |
| [Recover a chat update](https://fzkuji.github.io/OpenProgram/docs/install/conversational-self-update.html#recovering-a-conversational-self-update) | App stuck in maintenance, or cannot start |
| [Undo a change](https://fzkuji.github.io/OpenProgram/docs/install/conversational-self-update.html#undoing-a-change) | Back to a version, or revert one commit |
| [What an update restarts](https://fzkuji.github.io/OpenProgram/docs/install/conversational-self-update.html#what-an-update-restarts) | Changed paths, rebuild and restart |
| [Development checkout](https://fzkuji.github.io/OpenProgram/docs/install/development-checkout.html) | `openprogram dev deploy` to the development instance; macOS signing |
