Skip to content
Open
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ server, workers, web app and CLI.

You need:

- An x86-64 Ubuntu 24.04 server with SSH access and administrator privileges.
- An x86-64 or ARM64 Ubuntu 24.04 server with SSH access and administrator
privileges.
- A Tailscale account for private access to the factory.
- Permission to create a GitHub App and install it on your repositories.
- A supported coding account, such as Codex or Claude Code.
- On your computer: Python 3.10+, Git, authenticated GitHub CLI (`gh`), and
[uv](https://docs.astral.sh/uv/getting-started/installation/).

Your server and coding provider may have costs. GitHub Pro is not required.
Mac hosting is not supported by this installer yet.
macOS is not a supported host; on Apple Silicon, run Forge in an ARM64 Ubuntu VM.

Install the CLI on your computer, then start setup:

Expand Down
21 changes: 20 additions & 1 deletion docs/cli-fresh-host.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ GitHub-confirmed merge allows the final repository handover.

## Prerequisites

- A dedicated x86-64 Ubuntu 24.04 VM with AppArmor, systemd and `/usr/bin/python3`.
- A dedicated x86-64 or ARM64 Ubuntu 24.04 VM with AppArmor, systemd and
`/usr/bin/python3`. See [Apple Silicon (ARM64) VM](#apple-silicon-arm64-vm).
- SSH access from your computer as root or an account with noninteractive sudo.
Configure its SSH key through your VM provider. Forge handles remote commands
and file transfers through the CLI.
Expand All @@ -19,6 +20,24 @@ GitHub-confirmed merge allows the final repository handover.
selected repositories. GitHub Pro is not required. Forge respects existing
repository rules and reports any merge blockers.

### Apple Silicon (ARM64) VM

A Mac with Apple Silicon can host Forge in a Linux VM:

- Use [UTM](https://mac.getutm.app/) or [Lima](https://lima-vm.io/) with Apple
Virtualization (not QEMU emulation). Install Ubuntu 24.04 Server for arm64.
- On a 64 GB M1, give the VM 10 vCPUs, 40–48 GB of memory and a 250 GB disk.
- To keep the Mac running with the lid closed, run
`sudo pmset -a disablesleep 1` and `sudo pmset -a autorestart 1`. Start the
VM at login (a UTM or Lima login item) so it returns after a power cut.
- Install Tailscale inside the VM, not only on the Mac, and join it with a tag,
for example `sudo tailscale up --advertise-tags=tag:forge`. The tag must be
listed under `tagOwners` in your tailnet policy.

Prepared releases are amd64-only, so ARM64 hosts build the operator UI and worker
images on the host. The first install and each update take longer.
Claude Code, Codex and Grok all have native ARM64 builds.

## Install the CLI and start

```sh
Expand Down
10 changes: 6 additions & 4 deletions docs/harness-adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ Each module contains:
and cannot be weakened by repository configuration.

The build installer supports two pinned distributions: an npm package at an exact
version (`package`, `binary`), or a single Linux binary (`distribution: "binary"`,
`url`, `sha256`) downloaded at build time from `https://x.ai/cli/` and verified
against its manifest checksum before it is placed in the image. Never run an
unpinned remote installer in a worker.
version (`package`, `binary`), or a Linux binary per architecture
(`distribution: "binary"`, `binaries.x86_64` and `binaries.aarch64`, each with
`url` and `sha256`) downloaded at build time from `https://x.ai/cli/` and verified
against its manifest checksum before it is placed in the image. A build on an
architecture the manifest does not list fails with a message naming the harness.
Never run an unpinned remote installer in a worker.

`run` receives a supervisor-owned assignment, the prepared checkout, and only that
execution's credential environment. It invokes the harness with native isolation,
Expand Down
2 changes: 1 addition & 1 deletion docs/prepared-releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ it cannot fetch private releases using your personal credentials.
Maintainers can deliberately build all assets from a source checkout by setting
`FORGE_BUILD_FROM_SOURCE=1` for the host-side setup/update command. This remains
an explicit development choice, not a fallback for missing release assets.
Other platforms currently require this path.
ARM64 Linux hosts take this path automatically, because prepared releases are amd64-only.

To prepare release files on a clean Linux amd64 checkout with Docker, sudo and
AppArmor available:
Expand Down
12 changes: 10 additions & 2 deletions forge/harnesses/grok/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
"name": "Grok Build",
"version": "1.0.34",
"distribution": "binary",
"url": "https://x.ai/cli/grok-1.0.34-linux-x86_64",
"sha256": "be5905e107d2b8b5f3c142d21ecfe4c8fd32a913d2fd551b788707930c4dc80d",
"binaries": {
"x86_64": {
"url": "https://x.ai/cli/grok-1.0.34-linux-x86_64",
"sha256": "be5905e107d2b8b5f3c142d21ecfe4c8fd32a913d2fd551b788707930c4dc80d"
},
"aarch64": {
"url": "https://x.ai/cli/grok-1.0.34-linux-aarch64",
"sha256": "39ab87666877d64ef3a40aa60fbe0c3b6a6acd7001b78fe60e2c76bb6cfc4a94"
}
},
"command": "grok",
"login": [
"login",
Expand Down
24 changes: 19 additions & 5 deletions forge/harnesses/install.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Build-time only. Manifests and executable code are reviewed with the image.
// Two pinned distributions: an npm package at an exact version, or a single
// binary at an exact https URL verified against its manifest sha256.
// binary per architecture at an exact https URL verified against its sha256.
const fs = require('node:fs');
const path = require('node:path');
const crypto = require('node:crypto');
Expand All @@ -11,7 +11,12 @@ function validate(m) {
if (m.contract_version !== 1 || !/^\d+\.\d+\.\d+$/.test(m.version) || !/^[a-z][a-z0-9_-]*$/.test(m.id)) throw Error('Invalid harness manifest');
if (!/^[a-z][a-z0-9_-]*$/.test(m.command)) throw Error('Invalid harness command name');
if (m.distribution === 'binary') {
if (!/^https:\/\/x\.ai\/cli\/[A-Za-z0-9._-]+$/.test(m.url) || !/^[a-f0-9]{64}$/.test(m.sha256)) throw Error('Binary harness needs a pinned https://x.ai/cli/ URL and sha256');
if (!m.binaries || !Object.keys(m.binaries).length) throw Error('Binary harness needs per-architecture binaries');
for (const [arch, b] of Object.entries(m.binaries)) {
if (!['x86_64', 'aarch64'].includes(arch) || !/^https:\/\/x\.ai\/cli\/[A-Za-z0-9._-]+$/.test(b.url) || !/^[a-f0-9]{64}$/.test(b.sha256)) {
throw Error('Binary harness needs a pinned https://x.ai/cli/ URL and sha256 per architecture');
}
}
} else if (typeof m.package !== 'string' || typeof m.binary !== 'string') {
throw Error('npm harness needs package and binary');
}
Expand All @@ -22,12 +27,20 @@ function target(m) {
: path.join('/usr/local/lib/node_modules', m.package, m.binary);
}

function binary(m, arch = process.arch) {
const name = {x64: 'x86_64', arm64: 'aarch64'}[arch] || arch;
const selected = m.binaries[name];
if (!selected) throw Error(m.name + ' ' + m.version + ' has no ' + name + ' Linux build; it is unavailable on this host.');
return selected;
}

async function fetchBinary(m) {
const response = await fetch(m.url, {redirect: 'follow'});
const {url, sha256} = binary(m);
const response = await fetch(url, {redirect: 'follow'});
if (!response.ok) throw Error('Download failed for ' + m.id + ': ' + response.status);
const data = Buffer.from(await response.arrayBuffer());
const digest = crypto.createHash('sha256').update(data).digest('hex');
if (digest !== m.sha256) throw Error('Checksum mismatch for ' + m.id + ' (' + digest + ')');
if (digest !== sha256) throw Error('Checksum mismatch for ' + m.id + ' (' + digest + ')');
const file = target(m);
fs.mkdirSync(path.dirname(file), {recursive: true});
fs.writeFileSync(file, data, {mode: 0o755});
Expand Down Expand Up @@ -56,4 +69,5 @@ async function main() {
}
}

main().catch(error => { console.error(error.message); process.exit(1); });
module.exports = {validate, binary};
if (require.main === module) main().catch(error => { console.error(error.message); process.exit(1); });
3 changes: 2 additions & 1 deletion forge/release_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ class ArtifactError(ValueError):


def source_build():
"""Prepared assets are amd64-only, so ARM64 Linux hosts always build on the host."""
value = os.environ.get('FORGE_BUILD_FROM_SOURCE', '')
if value not in ('', '0', '1'):
raise ArtifactError('FORGE_BUILD_FROM_SOURCE must be 0 or 1.')
return value == '1'
return value == '1' or (platform.system() == 'Linux' and platform.machine() in ('aarch64', 'arm64'))


def require(value, message):
Expand Down
8 changes: 5 additions & 3 deletions forge_client/_install_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def facts():
need(sys.platform == 'linux' and os.geteuid() == 0, 'administrator_required')
release = dict(line.split('=', 1) for line in Path('/etc/os-release').read_text().splitlines() if '=' in line)
need(release.get('ID', '').strip('"') == 'ubuntu' and release.get('VERSION_ID', '').strip('"') == '24.04', 'unsupported_os')
need(platform.machine() == 'x86_64', 'unsupported_architecture')
need(platform.machine() in ('x86_64', 'aarch64', 'arm64'), 'unsupported_architecture')
enabled = Path('/sys/module/apparmor/parameters/enabled')
need(enabled.exists() and enabled.read_text().strip() == 'Y', 'apparmor_required')
need(Path('/run/systemd/system').is_dir(), 'systemd_required')
Expand Down Expand Up @@ -217,9 +217,11 @@ def dispatch(request, payload):
need(data['payload'] == payload_digest or request['upgrade_installer'], 'installer_changed')
with locked('work'):
if release_access is not None:
from forge_release_helpers import stage, ArtifactError
from forge_release_helpers import stage, source_build, ArtifactError
try:
stage(release_access, cache_root=STATE / 'prepared')
# ARM64 hosts build from source; prepared assets are amd64-only.
if not source_build():
stage(release_access, cache_root=STATE / 'prepared')
except ArtifactError:
raise InstallError('prepared_release_unavailable') from None
if not source_present(data):
Expand Down
2 changes: 1 addition & 1 deletion forge_client/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'account_handoff_unconfirmed': 'A different login is now connected. Inspect it before replacing provider credentials.',
'administrator_required': 'Use root or an SSH account with noninteractive sudo for this VM.',
'unsupported_os': 'Fresh installation currently supports Ubuntu 24.04. Select a supported VM.',
'unsupported_architecture': 'Fresh installation requires an x86-64 (amd64) Ubuntu 24.04 server. ARM64 servers are not supported; select an x86-64 VM.',
'unsupported_architecture': 'Fresh installation requires an x86-64 (amd64) or ARM64 (aarch64) Ubuntu 24.04 server. Select a supported VM.',
'apparmor_required': 'Use a VM with AppArmor enabled in its kernel.',
'systemd_required': 'Use a VM running systemd.',
'existing_installation': 'This host already has a forge account or installation. Use the existing-server commands or select a fresh VM.',
Expand Down
4 changes: 2 additions & 2 deletions forge_client/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
try:
if release_access is not None:
if request.get("apply") is not True or not isinstance(release_access,dict) or release_access.get("revision")!=request.get("source_revision"): raise MigrationError("invalid_release_access")
from forge.release_artifacts import stage,ArtifactError
try: stage(release_access)
from forge.release_artifacts import stage,source_build,ArtifactError
try: source_build() or stage(release_access)
except ArtifactError: raise MigrationError("prepared_release_unavailable") from None
release_access=None
prepared=None
Expand Down
14 changes: 7 additions & 7 deletions tests/test_fresh_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,13 @@ def setUp(self):
context = patch('forge_client._install_host.' + target, **options)
context.start(); self.addCleanup(context.stop)

def test_x86_64_ubuntu_facts_match_supported_contract(self):
with patch.object(remote.platform, 'machine', return_value='x86_64'):
self.assertEqual(remote.facts(), FACTS)
def test_x86_64_and_arm64_ubuntu_facts_match_supported_contract(self):
for architecture in ('x86_64', 'aarch64', 'arm64'):
with self.subTest(architecture=architecture), patch.object(remote.platform, 'machine', return_value=architecture):
self.assertEqual(remote.facts(), FACTS)

def test_arm64_is_refused_before_planning_or_host_mutations(self):
for architecture in ('aarch64', 'arm64', 'i686'):
def test_other_architectures_are_refused_before_planning_or_host_mutations(self):
for architecture in ('i686', 'armv7l', 'riscv64'):
for action in ('plan', 'apply', 'resume'):
with self.subTest(architecture=architecture, action=action), \
patch.object(remote.platform, 'machine', return_value=architecture), \
Expand All @@ -282,8 +283,7 @@ def test_cli_preserves_architecture_error_and_explains_supported_host(self):
with self.assertRaises(SetupError) as caught:
host.rpc('payload', {})
self.assertEqual(caught.exception.code, 'unsupported_architecture')
self.assertIn('x86-64 (amd64) Ubuntu 24.04', str(caught.exception))
self.assertIn('ARM64 servers are not supported', str(caught.exception))
self.assertIn('x86-64 (amd64) or ARM64 (aarch64) Ubuntu 24.04', str(caught.exception))


class RemoteInstallerTests(unittest.TestCase):
Expand Down
21 changes: 19 additions & 2 deletions tests/test_harnesses.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import hashlib
import io
import json
import shutil
import subprocess
import threading
import time
Expand Down Expand Up @@ -181,14 +182,30 @@ def test_grok_probe_reports_fixed_failure_reasons(self):
def test_binary_harness_manifest_is_pinned_and_verifiable(self):
item = manifests()['grok']
self.assertEqual(item['distribution'], 'binary')
self.assertRegex(item['url'], r'^https://x\.ai/cli/grok-' + item['version'].replace('.', r'\.') + r'-linux-x86_64$')
self.assertRegex(item['sha256'], r'^[a-f0-9]{64}$')
self.assertEqual(set(item['binaries']), {'x86_64', 'aarch64'})
for arch, binary in item['binaries'].items():
self.assertRegex(binary['url'], r'^https://x\.ai/cli/grok-' + item['version'].replace('.', r'\.') + '-linux-' + arch + '$')
self.assertRegex(binary['sha256'], r'^[a-f0-9]{64}$')
self.assertEqual(item['auth_file'], '.grok/auth.json')
self.assertEqual(item['login'], ['login', '--device-auth'])
self.assertEqual(set(item['managed_files'].values()), {'/etc/grok/requirements.toml', '/etc/grok/managed_config.toml'})
for name in item['managed_files']:
self.assertTrue((Path('forge/harnesses/grok') / name).is_file(), name)

@unittest.skipUnless(shutil.which('node'), 'The build installer requires Node.js')
def test_binary_harness_selects_the_build_architecture(self):
script = (
"const {validate, binary} = require('./forge/harnesses/install.cjs');"
"const m = JSON.parse(require('fs').readFileSync('forge/harnesses/grok/manifest.json', 'utf8'));"
"validate(m);"
"const only = {...m, binaries: {x86_64: m.binaries.x86_64}};"
"let missing; try { binary(only, 'arm64'); } catch (error) { missing = error.message; }"
"console.log(JSON.stringify({x64: binary(m, 'x64').url, arm64: binary(m, 'arm64').url, missing}));")
result = json.loads(subprocess.run(['node', '-e', script], capture_output=True, text=True, timeout=10, check=True).stdout)
self.assertTrue(result['x64'].endswith('-linux-x86_64'))
self.assertTrue(result['arm64'].endswith('-linux-aarch64'))
self.assertEqual(result['missing'], 'Grok Build 1.0.34 has no aarch64 Linux build; it is unavailable on this host.')

def test_setup_probe_failure_messages_name_the_cause(self):
from forge.setup_service import probe_failure_message
self.assertIn('setup login claude', probe_failure_message({'result': {'reason': 'provider_login_expired'}}, 'claude'))
Expand Down
13 changes: 13 additions & 0 deletions tests/test_release_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ def test_source_fallback_is_explicit_and_skips_downloads(self):
with patch.dict('os.environ', {'FORGE_BUILD_FROM_SOURCE': 'yes'}):
with self.assertRaises(artifacts.ArtifactError): artifacts.source_build()

def test_arm64_linux_always_builds_from_source(self):
for system, machine, expected in [('Linux', 'aarch64', True), ('Linux', 'arm64', True),
('Linux', 'x86_64', False), ('Darwin', 'arm64', False)]:
with self.subTest(system=system, machine=machine), patch.dict('os.environ', {'FORGE_BUILD_FROM_SOURCE': ''}), \
patch.object(artifacts.platform, 'system', return_value=system), \
patch.object(artifacts.platform, 'machine', return_value=machine), \
patch.object(artifacts, 'prepared') as prepared, \
patch.object(host_update, 'artifact_inputs', return_value=INPUTS), \
patch.object(host_update, 'source_revision', return_value=REVISION):
self.assertEqual(artifacts.source_build(), expected)
self.assertEqual(host_update.prepared_release() is None, expected)
self.assertEqual(prepared.called, not expected)

def test_missing_manifest_does_not_build_from_source(self):
with patch.object(artifacts.urllib.request, 'urlopen', side_effect=artifacts.urllib.error.URLError('release not published')):
with self.assertRaisesRegex(artifacts.ArtifactError, 'Wait for its Prepared release workflow'):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_release_transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ def private(path, create=False):
for path in state.iterdir():
if path.is_file(): self.assertNotIn(b'secret=ephemeral', path.read_bytes())

def test_arm64_host_builds_from_source_without_staging_prepared_assets(self):
with tempfile.TemporaryDirectory() as directory:
state = Path(directory).resolve() / 'state'
request = dict(version=1, action='apply', intent=INTENT, source=PACK,
upgrade_installer=False, release_access=deepcopy(ACCESS))
def private(path, create=False):
if create: path.mkdir(mode=0o700, exist_ok=True)
with patch.object(remote, 'STATE', state), patch.object(remote, 'facts', return_value=FACTS), \
patch.object(remote, 'check_new_host'), patch.object(remote, 'running', return_value=False), \
patch.object(remote, 'private_directory', side_effect=private), patch.object(remote, 'run'), \
patch.dict(sys.modules, {'forge_release_helpers': release_artifacts}), \
patch.object(release_artifacts.platform, 'system', return_value='Linux'), \
patch.object(release_artifacts.platform, 'machine', return_value='aarch64'), \
patch.object(release_artifacts, 'stage') as stage:
remote.dispatch(request, 'worker code')
stage.assert_not_called()
self.assertFalse((state / 'prepared').exists())

def test_fresh_revision_mismatch_rejected_before_any_stage(self):
request = dict(version=1, action='apply', intent=INTENT, source=PACK,
upgrade_installer=False, release_access={**ACCESS, 'revision': 'b'*40})
Expand Down
Loading