# `core/platform/platform.ts`

<p class="generated-note">Generated from the exports of <a href="https://github.com/altasystem-ai/alta/blob/main/core/platform/platform.ts"><code>core/platform/platform.ts</code></a> · <code>npm run docs:gen</code></p>

Compatibility by operating system (PLAN-V2 §2.6): one type and one decision function for steps, quests, store items and server executors. A value is either the same for every system or given per system (PerOS); a thing says which systems it supports (Support); the server describes the machine it runs on (Host).

**Standards that cite this file**: [Platform support (per OS, local or hosted)](https://docs.altasystem.ai/reference/advanced/specs/platform)

## Exports

### `OS` 
```ts
type OS = "macos" | "linux" | "windows";
```

### `OSES` 
```ts
const OSES: readonly OS[]
```

### `Arch` 
```ts
type Arch = "arm64" | "x64";
```

### `ARCHES` 
```ts
const ARCHES: readonly Arch[]
```

### `Platform` 
```ts
interface Platform { os: OS; arch?: Arch[]; min?: string /* minimal OS version, dotted */ }
```

### `PerOS` 
One value for every system, or one value per system.

```ts
type PerOS<T> = T | Partial<Record<OS, T>>;
```

### `Need` 
```ts
type Need = "gui" | "audio" | "gpu" | "keychain" | "sudo" | "terminal" | "local-device";
```

### `NEEDS` 
```ts
const NEEDS: readonly Need[]
```

### `LOCAL_ONLY_NEEDS` 
Needs a hosted world can never offer: a thing that has one of them cannot be "ok" when hosted.

```ts
const LOCAL_ONLY_NEEDS: readonly Need[]
```

### `Support` 
```ts
interface Support {
  /** Not empty; a single element means "only on this system", and is shown as such. */
  platforms: Platform[];
  /** Default: "ok" when linux is listed and needs is empty, else "no". */
  hosted?: "ok" | "limited" | "no";
  needs?: Need[];
  notes?: Partial<Record<OS, Text>>;
}
```

### `Host` 
The machine the game server runs on, as /api/game describes it.

```ts
interface Host {
  os: OS; arch: Arch; version?: string; mode: "local" | "hosted"; has: Need[];
  /** Hosted only: the trial ("free") or a kept world ("paid"). Absent: unknown. */
  tier?: "free" | "paid";
  /** The marketing axis this world was opened from (a closed list, checked by core/axes once it exists). */
  axis?: string;
  /** Hosted: the experiment arm drawn by the control plane (WORLD_ARM), "control" by default. */
  arm?: string;
  /** Hosted: the store item of a store landing (WORLD_ITEM): the world opens on that item. */
  item?: string;
  /** What the server measured of the machine (core/platform/resources.ts): cores, memory, free disk, GPU. Absent: unknown. */
  machine?: Measured;
}
```

### `HostCond` 
Where a beat, a tour stop, a step or a choice applies (ONBOARDING-V2 §4.3). Absent = everywhere.
`hosted-free` holds only when the tier is known to be "free", `hosted-paid` only when it is "paid": an unknown tier
shows neither the trial's text nor the kept world's.

```ts
type HostCond = "local" | "hosted" | "hosted-free" | "hosted-paid";
```

### `HOST_CONDS` 
```ts
const HOST_CONDS: readonly HostCond[]
```

### `isHostCond` 
```ts
const isHostCond = (x: unknown): x is HostCond => …
```

### `onHost` 
Does this condition hold on this host? No host described = local (the 0.1 default host).

```ts
function onHost(c: HostCond | undefined | null, h: Host | undefined | null): boolean
```

### `RefHostId` 
The reference hosts, shared by the client (?host=), the validators and the tests.

```ts
type RefHostId = "local" | "hosted-free" | "hosted-paid";
```

### `REF_HOST_IDS` 
```ts
const REF_HOST_IDS: readonly RefHostId[]
```

### `REF_HOSTS` 
```ts
const REF_HOSTS: Readonly<Record<RefHostId, Host>>
```

### `refHost` 
`?host=` values of the demo and the tests: "hosted" is the free tier.

```ts
function refHost(id: string | null | undefined): Host | undefined
```

### `Unsupported` 
```ts
type Unsupported = { ok: false; reason: "os" | "arch" | "version" | "hosted" | "needs"; detail: string };
```

### `Supported` 
```ts
type Supported = { ok: true } | Unsupported;
```

### `compareVersions` 
Compares dotted versions: negative when a &lt; b. Missing parts count as 0; non-numeric parts as 0.

```ts
function compareVersions(a: string, b: string): number
```

### `hostedLevel` 
The hosted level of a support, with its default.

```ts
function hostedLevel(s: Support): "ok" | "limited" | "no"
```

### `supports` 
Can this thing run on this host? No support declared means "everywhere" (0.1 behaviour).

```ts
function supports(s: Support | undefined | null, h: Host): Supported
```

### `isPerOSTable` 
True when a PerOS value is written as a table by system (and not as one value for all).

```ts
function isPerOSTable(v: unknown): v is Partial<Record<OS, unknown>>
```

### `pick` 
The value for this system: the single value, or the one of its row. Generalises command() of 0.1.

```ts
function pick<T>(v: PerOS<T> | null | undefined, os: OS): T | null
```

### `checkSupport` 
Problems of a support declaration (empty = valid). `perOS` lists the PerOS values of the same thing (install,
verify, scripts…): written as a table, each must cover exactly the declared systems.

```ts
function checkSupport(s: unknown, perOS: Record<string, unknown> = {}): string[]
```

### `hostOf` 
The host of a Node process (used by the server and by tests).

```ts
function hostOf(platform: string, arch: string, mode: "local" | "hosted", has: Need[], version?: string): Host
```
