# Client extension points

<p class="generated-note">Generated from <a href="https://github.com/altasystem-ai/alta/blob/main/docs/standards/client-extension-points.md"><code>docs/standards/client-extension-points.md</code></a> · <code>npm run docs:gen</code></p>

Code: [`client/app/registry.ts`](https://github.com/altasystem-ai/alta/blob/main/client/app/registry.ts), [`client/app/bus.ts`](https://github.com/altasystem-ai/alta/blob/main/client/app/bus.ts), [`client/app/app.ts`](https://github.com/altasystem-ai/alta/blob/main/client/app/app.ts). Tests: [`tests/registry.test.ts`](https://github.com/altasystem-ai/alta/blob/main/tests/registry.test.ts).
Example: [`client/features/_example/index.ts`](https://github.com/altasystem-ai/alta/blob/main/client/features/_example/index.ts) (a tab, a step kind, a layer, a quest source; dev only).

Status: **alpha**. This format can still change before its 1.0; a change follows the versioning rules of the project and is announced in the changelog.

## Features

A feature is a folder `client/features/<name>/index.ts` that exports `feature: { id, init(app) }`. Every shipped
folder is loaded at boot (`import.meta.glob`); folders starting with `_` load only in development and are left out
of the production build. A feature that throws at init is reported and left out. A feature never edits the core:
it registers.

`App { S, bus, T(key, vars?), L(text), api: { call(path, init?) }, save, ui, world }`:
- `save`: `persist()`, `tick(key, on)`, `answer(key, value)`, `track(uid, on)`, `completeQuest(uid)` (turns in a
  repeatable), `markSeen(key)`, `seen(key)`.
- `ui`: `el(tag, cls?, txt?)`, `button(label, cls, fn, disabled?)`, `toast(msg)`, `openWindow(tab, arg?)`,
  `openPanel(type, arg?)`, `refresh()`.
- `world`: `walkTo(id)`, `positionOf(id)`, `cam`.

## Registry

```ts
registerWindowTab(t: { id, order, key?, icon, label(), slot?, render(body, arg?), badge?() })
registerPanel(type: string, render: (box: HTMLElement, arg: unknown) => void)
registerEntityAction(fn: (e: Entity) => { label, primary?, run() } | null)
registerStepKind(kind: string, render: (ctx: { view, step, locked, refresh() }) => HTMLElement | null)
registerQuestSource(id: string, fn: (ctx: { world, save, now, server }) => Branch | null)
registerQuestDecorator(fn: (v: QuestView, where: "card" | "tracker" | "detail", node: HTMLElement) => void)
registerJournalSection(s: { id, order, title(), match(v: QuestView), header?(box) })
registerWorldLayer(l: { id, z: "below" | "above", draw(d, cam, layout), pick?(wx, wy) → { tip, click() } | null })
registerPartyBadge(fn: (role: AgentRole) => { text, cls } | null)
registerBootStep(order: number, fn: () => Promise<void>)
registerPoll(everyMs: number /* ≥ 1000 */, fn: () => Promise<boolean /* changed */>)
registerShot(kind: string, play: (shot, stage: HTMLElement, app) => Promise<void>)
registerKey(key: string, fn: () => void)
registerUniverse(u: Universe)
```

Rules: an id is registered once; the core's tabs (`quests`, `character`, `skills`, `openclaw`), panels and keys
(`CORE_KEYS`) cannot be taken. A quest source returns a branch whose id starts with `_` (reserved for generated
branches); a source that throws, or returns another id, is left out with a warning. Its branch is merged into the
game and played by the core like any other.

## Bus

`bus.on(name, fn) → off`, `bus.emit(name, payload)`; a failing listener breaks nothing. Events: `state`, `world`,
`universe {id}`, `lang {lang}`, `save`, `quest:done {view, xp}`, `quest:reopened {view}`, `level:up {level}`,
`mission:sent {id, agent, key?}`, `mission:back {id, ok}`, `item:installed {id}`, `guide:start`, `guide:end`.
