# Publishing source to GitHub

1. **dev** Every commit, by `git commit` in the main checkout or a worktree Development instance, port 18200
2. `scripts/publishing/publish-github.sh -m`, about once a day
3. **main** One squashed commit per sync, its own history GitHub; pushing it starts no workflow
4. `scripts/publishing/publish-github.sh --tag vX.Y.Z`, now and then
5. **Release** Built, signed and notarized by the Release workflow Stable App, port 18100, updates to it in-app

GitHub carries `main` and nothing else. Its history never merges with `dev`, and nothing pulls GitHub's `main` back. The stable App on this machine is the published Release, the same build every user gets.

## Branches

| Line | Role |
| --- | --- |
| `dev` | Takes every commit, from the main checkout or a worktree. The [development instance](https://fzkuji.github.io/OpenProgram/docs/reference/design/distribution/dev-instance.html) (`/Applications/OpenProgram Dev.app`, port 18200, `~/.openprogram-dev`) runs it, updated after commits by `openprogram dev deploy` or `scripts/local-instances/refresh-dev-instance.sh` |
| `main` | The line GitHub carries, with its own history. Only `scripts/publishing/publish-github.sh` adds to it: one commit per sync, holding a `dev` tree on top of the previous `main` commit |

A worktree branch is merged into `dev` and deleted, or deleted when abandoned. One worth keeping goes under `refs/archive/`, which no command lists as a branch and nothing pushes.

## Daily sync, occasional release

| Step | What happens |
| --- | --- |
| Sync (`publish-github.sh -m "summary"`) | About once a day, when `dev` has new commits. GitHub gets the day's source; no workflow runs |
| Release (`publish-github.sh -m "summary" --tag vX.Y.Z`) | When a version is ready. The sync goes up, then the tag, which starts the Release workflow |

Pushing `main` starts nothing, so a daily sync costs no Actions time:

| Workflow | Starts on |
| --- | --- |
| `release.yml` | A pushed `v*` tag, or by hand with `tag`; `rehearse` builds and checks everything without publishing |
| `ci.yml`, `docs-pages.yml`, `contributors-readme.yml`, `linux-release-smoke.yml`, `windows-install-smoke.yml` | Only by hand (`workflow_dispatch`) |

## The stable App on this machine

`/Applications/OpenProgram.app` (port 18100, data in `~/.openprogram`) is the official Release: installed once from its DMG, then updated only by the App's own [updater](https://fzkuji.github.io/OpenProgram/docs/reference/design/distribution/automatic-updates.html), which downloads the next Release in the background, shows **New** and swaps it in on **Restart to update**.

Nothing on this machine builds or installs it, so what the owner runs as stable is exactly what users download.

## Syncing

```
scripts/publishing/publish-github.sh -m "Sidebar run status, Launchpad, Agent cards" --dry-run
scripts/publishing/publish-github.sh -m "Sidebar run status, Launchpad, Agent cards"
python scripts/release/release-version.py set 1.3.0
scripts/publishing/publish-github.sh -m "Office editor" --tag v1.3.0 --office-archive /path/to/OfficeAssets-….zip --dry-run
scripts/publishing/publish-github.sh -m "Office editor" --tag v1.3.0 --office-archive /path/to/OfficeAssets-….zip
```

| Flag | Effect |
| --- | --- |
| `-m "summary"` | What the sync brings; required when the source differs from `main` |
| `--source <ref>` | Squash another commit on `dev`; default `dev` |
| `--dry-run` | Show the message and checks, change nothing |
| `--no-push` | Stop after step 7 |
| `--tag vX.Y.Z` | Step 9; cannot be combined with `--no-push` |
| `--office-archive <file>` | With `--tag`: the local copy of the [Office archive](#office-archive), checked against its pin and put on the tag's draft release when GitHub has none |

1. Install the guards into the shared `.git/hooks`, so every worktree has them.
2. Refuse a source not on `dev`. When `main` already holds the source's tree there is nothing to sync; go to step 8.
3. Refuse a source whose tree, or a summary, names a [retired account](#retired-accounts), listing each `path:line`. This runs on every call, dry runs included.
4. Scan added lines for live-looking credentials (GitHub tokens, Anthropic API keys, AWS access keys, private key blocks) and refuse on a hit. AWS's documented example key and one-line PEM strings in tests do not count.
5. Refuse if `scripts.docs_site.check --all` fails on the source commit, read from a temporary checkout of it.
6. Write the message: the summary, the number of local commits since the previous sync, and a `Local-Source:` trailer.
7. Create the commit with `git commit-tree`: the source's tree, the previous `main` as only parent (none for the first sync), author and committer the [publishing identity](#publishing-identity). Move `main` and record the source in `refs/publish/last`, where the next sync starts counting.
8. Push `main` after checking GitHub's `main` is an earlier point of local `main`, so the push only fast-forwards. Refuse when any commit being uploaded has another author or committer, or its message names a retired account.
9. Tag the pushed commit and push the tag. Before anything moves, a tag run refuses:
   
   - a tag that already exists;
   - a source where any [version place](#version-places) says another version, naming each one;
   - a source without `.github/release-notes/vX.Y.Z.md` starting with `# OpenProgram X.Y.Z Release Notes`;
   - a given `--office-archive` that is not the pinned [Office archive](#office-archive);
   - a real run when neither the newest release nor the tag's draft has the archive (asked with `gh`) and no file was given. With a file, it seeds the draft instead.
   
   `--dry-run` runs these checks offline, skipping only the question to GitHub, says whether a local archive was given and matches, and shows the tag.

### Version places

A release's version is written in six places. `python scripts/release/release-version.py set X.Y.Z` writes all of them, or none when one cannot be found; `check vX.Y.Z` names each that differs, and is what step 9 runs on the source commit.

| Place | What stops a release that missed it |
| --- | --- |
| `pyproject.toml`, `apps/desktop/package.json` | `verify-release-version.py --tag` in every build job |
| `scripts/release/install-release.sh` and `.ps1` default version | The same check |
| `uv.lock`, its `openprogram` entry | `uv run --locked` and `uv sync --locked` in the wheel, runtime and Windows contract steps |
| `package-lock.json`, its `apps/desktop` entry | Nothing in the build; kept with the others so the tree never names two versions |

**Other refusals**

| Condition | Result |
| --- | --- |
| `refs/publish/last` is not an ancestor of the source | Refused; nothing changes |
| No `origin` remote | The version stays on local `main` |
| GitHub's `main` is not part of local `main` | Push refused |

## Publishing identity

The repository is `Fzkuji/OpenProgram`, the project's first repository: `main` carries its history up to 0.9.8 and then squashed commits from 1.0.0 on.

Each sync commit is signed `FuzzyKuji`, `9404270+FuzzyKuji@users.noreply.github.com`, the account that uploads it, so no commit on GitHub carries the owner account's address; the script sets it whatever identity the checkout commits with and refuses to upload a sync holding any other. Only the part of `main` GitHub does not have yet is checked, since the earlier history has many authors.

The upload itself goes through the collaborator account `FuzzyKuji`, whichever `gh` account is active: the script takes that account's token from `gh` and has git ask `gh` for credentials, so the owner account's token never reaches GitHub. Without a `FuzzyKuji` login it refuses before anything moves.

Versions 1.0.0 to 1.3.0 were built in `FuzzyKuji/OpenProgram`, where their installers stay, and their release notes link there. From 1.4.0 on, releases are built in `Fzkuji/OpenProgram`:

- Download links, the installer scripts and the App's update check read releases from it, as source links do.
- An App of 1.3.0 or earlier checks the repository it was built in, so 1.4.0 or later is installed over it by hand once.
- Author lines in `pyproject.toml`, `apps/desktop/package.json` and the README licence line keep the name the 1.x versions shipped with.

## Retired accounts

The project once published under a GitHub account it no longer has. Nothing published names it: no author, link, example, fixture or note.

| Where | Check |
| --- | --- |
| `scripts/publishing/retired_accounts.py` | Holds each login, address and id only as the SHA-256 of its lowercase form, so the guard names none. Text is compared token by token; tokens are also split at `/ @ + . _ -` and percent-encoding (also double), HTML entities and `\u`/`\x` escapes are decoded, so a login inside a URL, an address or a file name is found |
| `tests/unit/config/test_no_retired_accounts.py` | Fails when any tracked text file, or a tracked path, names one |
| `scripts/publishing/publish-github.sh` | Scans the source commit's tree, read from the object store rather than the checkout, the summary and the part of `main` being uploaded |
| `scripts/publishing/update_readme_contributors.py` | Never lists a retired login in the README contributor block |

`.github/release-notes/` holds notes for those versions only, and the 1.0.0 notes link to no earlier version.

## The website

The landing page and the documentation are published by the docs-pages workflow as the GitHub Pages site of `Fzkuji/OpenProgram` itself, at `https://fzkuji.github.io/OpenProgram/`, documentation under `docs/`. A separate site repository under another account went down with that account, so the site lives with the code. The address is one setting: `SITE_URL` in `openprogram/operations/project_site.py`.

| Point | Decision |
| --- | --- |
| Not `openprogram.io` | GitHub will not attach the domain to the site repository: a retired Pages site still claims it. The domain answers GitHub's 404 on every path, so nothing links it any more |
| Derived in code | Canonical and language links, the sitemap, Markdown copies, `llms.txt`, `robots.txt`, social-card URLs, the IndexNow host and key, the update source and its host. Files in `docs/_static_root` write `{{SITE_URL}}`; the build writes `CNAME` only for a custom domain |
| Mount path | Links the build writes start with `OPENPROGRAM_DOCS_BASE`: `/docs/` in the worker, `project_site.DOCS_PATH` in the workflow. They stay root-absolute because the site script keeps the sidebar across page changes and matches it by path. Files that sit at the site root, such as `favicon.ico`, are linked through the parent of that path, so they resolve below the address's path too |
| Relative | Links written between documentation pages, including the newest-download links to `../latest.html?<name>`, and every link on the landing page. `latest.js` reads only GitHub and the page's own query |
| Written out | READMEs, release notes, install scripts, the landing page's canonical and social URLs, the desktop App's update source. `tests/unit/config/test_site_address.py` fails on any tracked file naming another site address, and on an absolute link between documentation pages |
| Read at run time | `install`, `install.ps1` and `install.cmd` at the site root; `update-source.json`, optional and read only when GitHub fails |

## What a release builds

The Release workflow runs on the pushed tag. Every platform leg is independent.

A tag never moves, so a release can be rehearsed first. Publish `main` without `--tag`, then run `gh workflow run release.yml -f tag=vX.Y.Z -f rehearse=true`: every leg builds from `main`, the same checks run and nothing is published.

`gh workflow run windows-install-smoke.yml -f tag=vX.Y.Z -f run_id=<rehearsal run>` installs that run's Windows files on a Windows runner. When both pass, `scripts/publishing/publish-github.sh --source refs/publish/last --tag vX.Y.Z` tags the same commit; without `--source`, commits made on `dev` in between would go up as a new, unrehearsed sync.

| Point | Behaviour |
| --- | --- |
| Failed leg | Its files are left out; the publish job uploads what succeeded |
| Thin App without update files | The Windows or Linux App leg marks an error before building when its platform's update files were not built, then still builds and checks the App so the same run shows every other problem; publish leaves that App out and names why |
| Windows checks | App leg: the platform contract tests in `scripts/release/windows-contracts.txt`, then the installer installs, launches to a healthy worker, makes one tool call and uninstalls keeping the data. A failed contract does not stop the build and the install check; a step before the upload keeps that App out. Runtime leg: the installed command makes one tool call. A failure leaves out only that package. A failed Windows leg keeps its logs as a `diagnostics-windows-*` artifact, never published |
| `release-manifest.json` | Lists only what exists |
| Release notes | Gain a "Not in this release" section naming what is missing and why |
| Planned package missing | After the release is public, the publish job fails and names each one, so the run cannot look complete |
| Publishing refused | Only when the wheel or the [Office archive](#office-archive) is missing, or no macOS or Linux command-line runtime was built |

Certificates decide the form of a package, never whether it exists.

| Package | With credentials | Without |
| --- | --- | --- |
| macOS App | Developer ID signed and notarized, `OpenProgram-X.Y.Z-mac-<arch>.dmg` | Ad-hoc signature, `-unsigned` in the name |
| Windows App | Authenticode signed, `OpenProgram-X.Y.Z-win-<arch>.exe` | `-unsigned.exe` |
| Linux App | AppImage and deb need none; built on Ubuntu 22.04, x86_64 and arm64 | The same |

| Case | Result |
| --- | --- |
| `OPENPROGRAM_UPDATE_SIGNING_KEY` absent or not listed in `RELEASE_PUBLIC_KEYS` | Windows and Linux Apps are left out and named in the notes: a thin-layout App with no trusted update signing key could never update |
| AppImage build fails | The deb still ships |
| One copy per file | Each App is uploaded once, under its versioned name; newest-download links go through `latest.html` on the docs site ([why](https://fzkuji.github.io/OpenProgram/docs/reference/design/distribution/installation-packaging.html#one-copy-per-file)) |

Repository variables adjust the legs. None is needed for a normal release.

| Variable | Default | Effect |
| --- | --- | --- |
| `OPENPROGRAM_RELEASE_DESKTOP_MAC`, `_WINDOWS`, `_LINUX` | On; `false` switches off | That platform's App |
| `OPENPROGRAM_RELEASE_WINDOWS_RUNTIME` | On; `false` switches off | The Windows command-line runtime |
| `OPENPROGRAM_RELEASE_WINDOWS_ARM64` | Off; `true` switches on | Windows on Arm, App and runtime |
| `OPENPROGRAM_RELEASE_MAC_THIN` | Off; `true` switches on | The thin macOS App, once signing and the update key exist |
| `OPENPROGRAM_RELEASE_CLI_SEEDS` | Off; `true` switches on | `-seed-` assets for the command-line installers, once the key exists |

macOS stays on the full App, and command-line installs on the complete runtime, until those two switches are turned on: Apps and command lines from v1.0.0 need the existing DMG names, runtime archives and `release-manifest.json`, and a seed install needs a released network fetcher.

## The Office archive

The optional Office editor installs from one zip, about 699 MiB, whose name, size and SHA-256 are pinned in `openprogram/programs/applications/office_editor/install.py`; the download limit for `office.assets` in `safe_http.py` is the same size. Every release from 1.3.0 uploads it once; 1.0.0 to 1.2.0 carry none.

| Point | Behaviour |
| --- | --- |
| Where the App looks | Its own version's release, then `releases/latest/download/`, which serves a build that has no release of its own while the pin is unchanged. Both copies are held to the pinned size and SHA-256 |
| Why not only the newest release | A fixed name on the newest release breaks every installed version the day a release changes the pack; a copy in each release keeps each version installable for as long as its release exists |
| No release has it | The install answers `office_release_missing`: a version before 1.3.0 is told to update to 1.3.0 or newer, any other to update to the newest version. A retry is not offered as the fix |
| Where a release gets it | It cannot be rebuilt in CI: the licensed fonts and the pinned editor build are the owner's inputs ([Office README](https://github.com/Fzkuji/OpenProgram/blob/main/scripts/release/office/README.md)). The `office` job downloads the newest published release's copy, or else the one on the tag's draft release, and checks its bytes |
| First release to carry it | `publish-github.sh --tag vX.Y.Z --office-archive /path/to/OfficeAssets-….zip` checks the file and, before anything moves, puts it on the tag's draft release (`office-archive.py seed`). Every later release carries the previous one's copy with no upload by hand |
| Neither copy exists | The `office` job fails with the file name, size, SHA-256 and the seed command. Every build waits for it, so nothing is built or published |
| After publishing | The check on the public latest release also requires exactly one copy of the archive |
| A new pack | Needs a new file name, never new bytes under an old one, because installed versions pin the bytes behind each name. `office-archive.py pack` names it `OfficeAssets-<editor>-<patch>-<pack>.zip`, the last part from the pack's own manifest digest, so different bytes always get a different name |

### Rebuilding the archive

On the owner's machine, from a `dev` checkout. The `pack` step makes the same zip from the same prepared pack. An installed copy is a prepared pack: when `~/.openprogram/cache/office/<source>-<patch>/versions/<manifest>` validates against the pins in `office_editor/assets.py`, copy it out and go straight to the `pack` step; nothing is built or downloaded.

1. Gather the inputs the [Office README](https://github.com/Fzkuji/OpenProgram/blob/main/scripts/release/office/README.md) names: a git checkout of `agentbridges-ai/onlyoffice-browser` at `d15d12b6945be4d8b0f3aa1806120e740d2950ee` (package 0.3.34); the licensed font input and the font pack made from it with `font-generation.mjs` and Document Server 9.3.0's generator, whose manifest digest must equal `OFFICE_FONT_MANIFEST_DIGEST` in `office_editor/assets.py`; npm registry access for `npm ci`.
2. Set `OFFICE_LOCK_SHA256` in `office_editor/assets.py` to the SHA-256 of `scripts/release/office/package-lock.json`, the reviewed lock `prepare.py` builds with; the pack's last validation refuses any other lock.
3. `python scripts/release/office/prepare.py --source … --font-pack … --font-input … --output /path/to/prepared-office`
4. `python scripts/release/office-archive.py pack /path/to/prepared-office /path/to/out` writes the zip and pins its name, size and SHA-256 in `install.py` and the download limit in `safe_http.py`.
5. Run the affected tests, commit on `dev` and deploy.
6. `scripts/publishing/publish-github.sh -m "…" --tag vX.Y.Z --office-archive /path/to/out/OfficeAssets-….zip --dry-run`, then the same without `--dry-run`.

## The guards

| Hook | Refuses | Allows |
| --- | --- | --- |
| `scripts/git-hooks/pre-push` | A push to `refs/heads/main` without `OPENPROGRAM_GITHUB_PUBLISH=1` (set by the script) or not sending local `main`; a push of any other branch, which would upload the working history; a tag not pushed by the script or not naming local `main`, because a pushed tag starts the Release workflow | Deleting a remote branch or tag |
| `scripts/git-hooks/pre-commit` | A commit while `main` is checked out; a commit whose staged docs fail `scripts.docs_site.check` | Every other branch |

The machine's global hooks (`core.hooksPath`) delegate both to the repository's `.git/hooks`, which is why the script installs them there.

## Rules for sessions

- **Commit**: to `dev` as often as the work needs; deploy as in [Deploying to the development instance](https://fzkuji.github.io/OpenProgram/docs/reference/design/distribution/dev-instance.html#deploying-to-the-development-instance)
- **Sync**: about once a day when `dev` has new commits, without `--tag`
- **Release**: when a version is ready, with `--tag vX.Y.Z`; not after every feature
- **Never**: commit on `main`
- **Never**: `git push` `main` by hand
- **Never**: merge `main` into `dev`
- **Never**: push another branch to GitHub
- **Never**: open a pull request from a local branch: it would list every local commit

## Implementation status

| Status | Items |
| --- | --- |
| Implemented | `scripts/publishing/publish-github.sh` with dry run, `--no-push`, `--tag`, credential scan, retired-account scan, publishing-identity check and `refs/publish/last`; both guards; every workflow except Release started only by hand; the rules in `AGENTS.md`; the Release workflow's independent legs; the Office archive in every release and the App's download from its own release |
| Switch-over | The stable App on this machine is still a local build. It becomes the official Release when the next release is installed from its DMG; installing an older release over data written by newer local builds is avoided, so the switch waits for that release. |
| Not yet run | A complete Release run. The one run so far, for v1.1.0, published the macOS and Linux Apps and every command-line runtime; the Windows installer was built and left out, because the Windows update files failed. The 1.2.0 rehearsal ran once: the publish job's check named the three Apps that did not pass (both macOS legs at signing, Windows at its App smoke). The Windows install smoke workflow has not run |
| Waiting for 1.3.0 | No release carries the Office archive yet. The pinned file, `OfficeAssets-d15d12b-dc31dd9d-24d2d8e1.zip`, is [packed](#rebuilding-the-office-archive) from the installed pack and kept on the owner's machine at `~/OpenProgram-release/office/`; 1.3.0 is tagged with `--office-archive` pointing at it |
