# alta.game/0.2: quests, types and cycles

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

Code: [`core/quests/standard.ts`](https://docs.altasystem.ai/reference/advanced/core-api/quests-standard). Tests: [`tests/quest-cycles.test.ts`](https://github.com/altasystem-ai/alta/blob/main/tests/quest-cycles.test.ts), `tests/quests.test.ts`. The current version is
[alta.game/0.3](alta-game-0.3), which reads 0.2 files as they are and adds inputs, secrets, `human` and `provenBy`.

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.

## Shape

`Game { schema, langs, branches[] }` → `Branch { id, acts[], skills[], quests[], item?, generated?, support? }` →
`QuestDef` → `Step`. A 0.1 file is read as is: `upgradeGame(g)` returns a 0.2 game, and [`content/branches.json`](https://github.com/altasystem-ai/alta/blob/main/content/branches.json)
evaluates the same in 0.1 and 0.2 (tested). Fragments `alta.quests/0.2` (`content/quests/*.json`, store items) add
quests to an existing branch: `mergeFragments(game, fragments)`, `checkFragment(f, game)`.

`QuestDef` adds to 0.1: `type` (absent = `campaign`), `reset` (daily), `repeat` (repeatable), `origin`
(repair, personal), `target` (entity id), `expires`, `support`.

`Step.kind`: `manual | choice | check | action | command | link | mission`, or a kind drawn by a client feature
(`registerStepKind`; the validator checks the format `^[a-z][a-z0-9-]{1,31}$`; unknown at run time, it renders as
`action`). New step fields: `arch`, `mission`, `run` (an executor of the closed list, `PerOS<RunSpec>`),
`cmd` and `open` as `PerOS<string>`.

Host on steps and choices (ONBOARDING-V2 §4.5): `Step.host` (`HostCond`, see [platform](platform)) hides a step
outside that host, like `os` does outside its system. A choice is a `Choice { id, label, host?, off?, resources?,
hint?, recommended? }`: `host` shows it only there; `off: { host, why }` shows it there greyed, with its reason, and it
cannot be picked; `resources` shows it greyed the same way where the machine has less, with a line that names what is
missing (see [resources](resources): a resource not measured is never refused, and `off` comes first when both
hold). A step may declare `resources` too: it then says what is missing instead of its "Do it"; `hint` is the one-line promise under the label and `recommended` the "Recommended" tag (neither
changes the evaluation). `choicesFor(step, host)` gives the choices of a host, each with its `off` reason.

## Types and cycles

| Type | Period key | XP | Rule |
|---|---|---|---|
| campaign | none (`uid/step`) | steps and reward | done once; a proof that falls back (or a choice taken back) makes it `reopened`, XP kept; done again, it keeps the XP it was recorded with |
| instant | none | 10 to 30 | once |
| daily | `uid@2026-12-05/step` or `uid@w2026-11-30/step` | its reward, ≤ 60 per branch per day | `reset: { every: "day"\|"week", at: "HH:MM" (04:00), weekday? }`, local time, no streak |
| repeatable | `uid@r<n>/step` | its reward, ≤ 30 | turned in (`turnIn`), `repeat: { cooldownS?, max? }`; `cooldown` status between rounds |
| repair | `uid/step` | 40 | one incident per entity (`Save.incidents`); a relapse within 24 h is the same incident |
| system | `uid/step` | 20 | generated from probes |
| personal | `uid/step` | 5, ≤ 25 per day | from the owner's tasks |

The clock is injected: `Context.now` (ms) and `Context.tzOffsetMin` (local minus UTC). `periodOf(reset, now, tz)`
gives `{ key, endsAt }`.

## Evaluation and history

- `evaluate(ctx)` is a pure reading: views with `status` (`locked | open | active | done | cooldown | unavailable`),
  `type`, `period`, `resetsAt`, `count`, `reopened`, `ready`, `unavailable { reason, detail }`, plus xp and level.
- `record(ctx, ev, { campaign? })` returns `{ save, gained[] }`: writes `Save.log` for what was accomplished (the
  only XP source of non-campaign quests). `turnIn(ctx, view)` closes a repeatable round. Both are pure.
- `Save` v2: `ticked`, `answers`, `log`, `incidents`, `tasks`, `seen` (`upgradeSave`; server: `cleanSave` v2).
- Checks resolved by the core from what the client holds (`CORE_CHECKS`): `answer`, `entity { id, state[] }`,
  `world { kind, state[], min?, max? }`, `mission`, `seen { key }` (a scene watched or skipped: `Save.seen`;
  `"trailer"` is the trailer of any world), and `item { id }` when `ctx.items` is given. Checks the server runs
  include `signin { mind: claude | codex }` (the player is signed in to that tool) and `model { mind: claude | codex |
  local }` (OpenClaw thinks with that mind): see [runs, routes, checks](runs-routes-checks). They are never
  declarable by hand. `serverChecks(game)` is what the server runs.
- `unavailable`: a quest whose `support` (or its branch's) does not match `ctx.host` (see [platform](platform)).
  An unavailable quest of an `optional` act does not block the chain. A quest that has required steps for this
  system but none for this host mode is unavailable with the reason `host` (no `support` needed): this is how the
  local door (`core.get`, `core.install`, `core.launch`, every step `host: "local"`) and the hosted door
  (`core.arrive`) exclude each other in act 0, which is optional. The journal does not list a campaign quest
  unavailable for the reason `host`. `unavailableOn(quest, branch, host)` gives the same answer for one host.

## Generated quests (lot Q2)

Pure functions in [`core/quests/sources/`](https://github.com/altasystem-ai/alta/tree/main/core/quests/sources) build the generated branches; the client registers them as quest sources
([`client/features/generated`](https://github.com/altasystem-ai/alta/tree/main/client/features/generated)), and the core plays them like any other branch.

| Branch | Born from | Uid | Proof | Leaves |
|---|---|---|---|---|
| `_repair` | an entity of kind `module`, `automation`, `agent`, `account`, `device`, `interface` in `error` or `degraded` (`incomplete` opens none in v1) | `_repair.<slug of the entity id>` | `entity { id, state: ["running", "ok"] }`; optional steps `look` (manual) and `send` (mission, brief prefilled with the real name and the map's notes) | entity gone: removed without xp; healed: done, shown 24 h |
| `_system` | a server probe with `ok: false` (`gateway`, `openclaw`, `map`) | `_system.<probe id>` | `probe { id }`, answered by the server | probe gone: removed; passes: done, shown 24 h |
| `_personal` | a task typed in the game (`Save.tasks`), or a box of the owner's Markdown file (read only) | `_personal.<task id>` | typed: a manual step `done`; file: `task { id }`, answered by the server | task gone: removed |

Incidents are keyed by the origin's `ref`: the entity id, or `probe:<id>`. A task of the file already ticked the
first time the game sees it gives nothing (the client marks `Save.seen["task:<id>"]` for tasks seen open).
A generated quest that leaves the game keeps the xp it won: `evaluate()` adds the `log` xp of generated uids
(`_…`) that have no view any more, and the personal cap of the day counts them too.

## Validator

`checkGame(g)` refuses: unknown type; daily without `reset`; bad `at`; `repeat` outside repeatable; repair or
personal without `origin`; `run` naming an executor outside the closed list or one that does not accept the step's
OS; `run.args` outside the executor's declared arguments; a `signin`, `model` or `seen` check without its `mind` or `key`;
a `PerOS` table with an unknown OS; bad `support`; duplicate uids; unknown `requires`. Generated branch ids
(`_repair`, `_system`, `_personal`, and any id starting with `_` from a client source) are reserved.

It also refuses an unknown `host` on a step or a choice; an `off` without `why` in English and French, or with an
unknown `host`; a malformed `resources` (rules `resources.*`); a choice step visible on a reference host (or, when one
of its choices has `resources`, on a reference host as the smallest machine) where no choice can be picked; a
`recommended` choice that is greyed (`off` or `resources`) there, or more than one `recommended` choice shown on the
same reference host (one "Recommended" per choice); and any `host` or `resources` on a step, or `host`, `off` or
`resources` on a choice, in a game that declares `alta.game/0.1`.
