# `core/charts/needs.ts`

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

Needs of alta.chart/0.1 (docs/standards/alta-chart-0.1.md, "Needs"): a chart says it needs "a mind" or "a channel" instead of naming Claude or Telegram. The player binds each kind once to a provider (their onboarding choices) and every chart reuses that binding unless it says otherwise. Agents, parts and proofs name the need ("need:mind"); the engine binds. Providers are a closed table here (like the sign-in tools): their services, sign-ins, proofs and repairs come from their row, never from a chart. Pure: no disk, no network.

**Standards that cite this file**: [alta.chart/0.1: the Agent Chart](https://docs.altasystem.ai/reference/advanced/specs/alta-chart-0.1)

## Exports

### `NEED_KINDS` 
```ts
const NEED_KINDS = ["mind", "channel"] as const
```

### `NeedKind` 
```ts
type NeedKind = (typeof NEED_KINDS)[number];
```

### `NEED_FEATURES` 
What a provider of each kind may offer (closed): a need asks for some with `features`.

```ts
const NEED_FEATURES: Readonly<Record<NeedKind, readonly string[]>>
```

### `NEED_ID` 
```ts
const NEED_ID = /^[a-z][a-z0-9-]{0,31}$/
```

### `NEED_KEYS` 
```ts
const NEED_KEYS = ["$comment", "kind", "why", "accept", "model", "features", "prefer", "reuse", "optional"] as const
```

### `Need` 
A need as written: `{}` or `true` is broad (any provider of its kind, the player's own choice).

```ts
interface Need {
  kind?: NeedKind;
  why?: Text;
  accept?: string[];
  model?: string;
  features?: string[];
  prefer?: string[];
  reuse?: "owner" | "ask";
  optional?: boolean;
}
```

### `NeedDecl` 
```ts
type NeedDecl = Need | true;
```

### `NeedOf` 
A need with its kind known and its defaults filled.

```ts
interface NeedOf extends Need { id: string; kind: NeedKind; why: Text; reuse: "owner" | "ask"; optional: boolean }
```

### `NEED_WHY` 
The sentence the consent screen shows when a need has no `why`.

```ts
const NEED_WHY: Readonly<Record<NeedKind, Text>>
```

### `NEED_DATA` 
What leaves the machine through a provider of each kind (external.services `data`).

```ts
const NEED_DATA: Readonly<Record<NeedKind, "prompts" | "messages">>
```

### `ProviderSignin` 
```ts
interface ProviderSignin { id: string; use: "signin.cli" | "channel.connect" | "channel.pair-approve"; args: Record<string, string>; proof: Check; why: Text; requires?: string[] }
```

### `Provider` 
```ts
interface Provider {
  id: string;
  kind: NeedKind;
  label: Text;
  features: readonly string[];
  /** Runs on the machine (or in the game itself): nothing leaves it. */
  local: boolean;
  /** The engine's word for it (`alta-step --model` / `--channel`, the answers `default_model` and `channel`). */
  word: string;
  /** Mind: the providers of a "provider/model" id it serves (a pinned `model`). */
  models?: readonly string[];
  /** Not local: the online service, generated in `external.services` when it is bound. */
  service?: { name: string; hosts: readonly string[]; account: "none" | "free" | "paid"; homepage?: string };
  /** What connects it, in order (each a generated sign-in step). Empty: nothing to connect. */
  signins: readonly ProviderSignin[];
  /** The read-only proof that it still works (cheap): the `need` proof becomes this one. Absent: always met. */
  proof?: Check;
  /** The repairs of that proof, from the closed list of repair kinds. */
  repairs: readonly { id: string; kind: string; args: Record<string, string> }[];
  resources?: Resources;
  /** Can it be bound in a hosted world? Default yes. */
  hosted?: boolean;
  /** How the consent step names the binding: "will think with <this>", "will write to you <this>". */
  phrase: Text;
}
```

### `PROVIDERS` 
The closed table of providers. Order is the engine's recommendation order.

```ts
const PROVIDERS: readonly Provider[]
```

### `PROVIDER_IDS` 
```ts
const PROVIDER_IDS: readonly string[]
```

### `provider` 
```ts
const provider = (id: unknown) => …
```

### `providersOf` 
```ts
const providersOf = (kind: NeedKind) => …
```

### `needKindOf` 
The kind of a need: its `kind`, else its id (`mind`), else the prefix of its id (`mind-deep`).

```ts
function needKindOf(id: string, decl: unknown): NeedKind | undefined
```

### `inferredKind` 
The kind its id alone says, or undefined.

```ts
function inferredKind(id: string): NeedKind | undefined
```

### `needsOf` 
The needs of a chart, kinds known and defaults filled (a need of unknown kind is left out: lint reports it).

```ts
function needsOf(c: { needs?: unknown }): Record<string, NeedOf>
```

### `needRefOf` 
"need:&lt;id&gt;" → id, or undefined.

```ts
const needRefOf = (v: unknown): string | undefined => …
```

### `isNeedRef` 
```ts
const isNeedRef = (v: unknown) => …
```

### `mindOfModel` 
The provider of a "provider/model" id, among the minds.

```ts
const mindOfModel = (model: unknown) => …
```

### `candidates` 
The providers a need may take, from what it says alone (kind, accept, model, features): no machine, no player.

```ts
function candidates(n: Pick<NeedOf, "kind" | "accept" | "model" | "features">): Provider[]
```

### `World` 
What the player has: their default per kind (onboarding answers), the providers already connected, the preset.

```ts
interface World {
  /** Their default provider per kind ("my install"). */
  owner?: Partial<Record<NeedKind, string>>;
  /** Providers already connected on this machine (their sign-in holds). */
  connected?: readonly string[];
  /** The preset "100% local": only providers that keep everything on the machine. */
  localOnly?: boolean;
  /** The player's own pick per need ("change", or the preset "customise"). */
  picked?: Readonly<Record<string, string>>;
}
```

### `BindStatus` 
```ts
type BindStatus = "bound" | "connect" | "choose" | "unmet" | "skip";
```

### `Binding` 
```ts
interface Binding {
  need: string; kind: NeedKind;
  status: BindStatus;
  /** The provider: bound, to connect, or preselected when the player is asked. */
  provider?: string;
  /** Every provider the player may pick, recommended first. */
  candidates: string[];
  /** The rule of `bind` that decided (0: the player's own pick). */
  rule: 0 | 2 | 3 | 4 | 5 | 6;
  optional: boolean;
  /** Why no provider fits (rule 2). */
  reason?: Text;
}
```

### `ownerFromAnswers` 
The engine's answers → the player's default per kind: `default_model` ("provider/model" or a word), `channel`.

```ts
function ownerFromAnswers(a: Record<string, unknown> | null | undefined): Partial<Record<NeedKind, string>>
```

### `fitting` 
Rule 1 for one need: the candidates that also fit this machine and the player's preset, recommended first.

```ts
function fitting(n: NeedOf, host?: Host, localOnly = false): Provider[]
```

### `bind` 
Binds every need of a chart (pure). The first rule that applies:
1. candidates: right kind, inside `accept`, with the `features`, the pinned `model`, that this machine can carry
   and, with "100% local", local only; 2. none: unmet, with the reason (the chart is greyed, never hidden);
3. one candidate (pinned): bound when connected, else a connection; 4. `reuse` owner and the player's default is
a candidate: bound, no question; 5. another candidate already connected: proposed, preselected, one question;
6. nothing connected: a choice, recommended first by `prefer` then by the engine, then the connection.
The player's own pick (`world.picked`) comes before 3 when it is a candidate.

```ts
function bind(chart: { needs?: unknown }, world: World = {}, machine?: Host): Record<string, Binding>
```

### `bindingValues` 
The provider each need goes with (bound, to connect, or preselected), as the `chosen` map keys "need:&lt;id&gt;".

```ts
function bindingValues(b: Record<string, Binding>): Record<string, string>
```

### `bindingWords` 
The words of one binding on the consent step: "will think with your Claude subscription".

```ts
function bindingWords(b: Binding): Text
```

### `bindingLines` 
One line per need for the consent step: "This chart will think with your Claude subscription · change".

```ts
function bindingLines(title: Text, b: Record<string, Binding>): { en: string[]; fr: string[] }
```

### `needService` 
The online service a bound provider adds (external.services shape), or undefined for a local one.

```ts
function needService(needId: string, p: Provider, optional = false)
```
