# `core/platform/resources.ts`

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

What a step, a choice or an executor needs of the machine, written like Kubernetes resources (docs/standards/ resources.md): `{ cpu: 4, memory: "16Gi", disk: "20Gi", gpu: true, arch: ["arm64"] }`, any subset. The server measures the machine read only (Host.machine, server/lib/mode.mjs); `missing()` says what falls short, and `shortText()` says it to the player in one line ("Needs 16 GB of memory (this machine: 8 GB)"). A resource the server did not measure is never refused on a guess.

**Standards that cite this file**: [Resources: what a step, a choice or an executor needs of the machine](https://docs.altasystem.ai/reference/advanced/specs/resources)

## Exports

### `Resources` 
Declared needs. cpu: cores (a number, "4" or "500m"); memory and disk: bytes or a quantity ("16Gi", "512Mi", "20G").

```ts
interface Resources {
  cpu?: number | string;
  memory?: number | string;
  /** Free disk space on the volume of the player's home. */
  disk?: number | string;
  /** A GPU the models can use (Apple Silicon's unified memory counts). */
  gpu?: boolean;
  /** The processor families it runs on. */
  arch?: Arch[];
}
```

### `RESOURCE_KEYS` 
```ts
const RESOURCE_KEYS = ["cpu", "memory", "disk", "gpu", "arch"] as const
```

### `ResourceKey` 
```ts
type ResourceKey = (typeof RESOURCE_KEYS)[number];
```

### `Measured` 
What the server measured (Host.machine): cores, total memory and free disk in bytes, a usable GPU.

```ts
interface Measured { cpu?: number; memory?: number; disk?: number; gpu?: boolean }
```

### `parseBytes` 
A quantity in bytes ("16Gi", "20G", "512Mi", 1073741824), or null when malformed.

```ts
function parseBytes(q: unknown): number | null
```

### `parseCpu` 
Cores (4, "4", "2.5", "500m" = half a core), or null when malformed.

```ts
function parseCpu(q: unknown): number | null
```

### `checkResources` 
The problems of a declared block, each "resources.&lt;key&gt;: …" (rule ids resources.*), empty when valid.

```ts
function checkResources(r: unknown): string[]
```

### `Short` 
One resource that falls short: what is needed, what the machine has (bytes, cores, or the arch).

```ts
interface Short { key: ResourceKey; need: number | boolean | Arch[]; have: number | boolean | Arch }
```

### `MachineSide` 
The machine a check is made against: its arch and its measures.

```ts
interface MachineSide { arch?: Arch; machine?: Measured }
```

### `missing` 
What falls short on this machine, in the order cpu, memory, disk, gpu, arch. Unmeasured: never short.

```ts
function missing(r: Resources | null | undefined, h: MachineSide | null | undefined): Short[]
```

### `mergeResources` 
The larger of two blocks, key by key (a step and its executor).

```ts
function mergeResources(a: Resources | null | undefined, b: Resources | null | undefined): Resources | undefined
```

### `shortText` 
The one-line reason, in English and French: "Needs 16 GB of memory (this machine: 8 GB)." Null when nothing is short.

```ts
function shortText(short: Short[]): Text
```

### `SMALLEST_MACHINE` 
The smallest machine the validators try a choice step on: one core, 1 GB of memory, no free disk, no GPU.

```ts
const SMALLEST_MACHINE: Measured
```
