# alta.index/0.1: the chart repository index

<p class="generated-note">Generated from <a href="https://github.com/alta-system-os/alta-os/blob/main/docs/standards/alta-index-0.1.md"><code>docs/standards/alta-index-0.1.md</code></a> · <code>npm run docs:gen</code></p>

Code: [`core/charts/index-format.ts`](https://docs.os.altasystem.ai/reference/advanced/core-api/charts-index-format) (types, `checkIndex`, `installable`, `searchIndex`, `catalogOf`),
[`core/charts/repos.ts`](https://docs.os.altasystem.ai/reference/advanced/core-api/charts-repos) (`alta.repos/0.1`, `checkRepos`, `checkRepoUrl`), `tools/cli/src/{repos,search,pull,net,index-build}.ts`
(the commands), [`server/lib/market.mjs`](https://github.com/alta-system-os/alta-os/blob/main/server/lib/market.mjs) and [`server/routes/market.mjs`](https://github.com/alta-system-os/alta-os/blob/main/server/routes/market.mjs) (what the machine's server lists). Tests:
[`tests/index-format.test.ts`](https://github.com/alta-system-os/alta-os/blob/main/tests/index-format.test.ts), [`tests/cli-repos.test.ts`](https://github.com/alta-system-os/alta-os/blob/main/tests/cli-repos.test.ts), [`tests/market-api.test.ts`](https://github.com/alta-system-os/alta-os/blob/main/tests/market-api.test.ts). Fixture and template:
[`examples/charts-repo/`](https://github.com/alta-system-os/alta-os/tree/main/examples/charts-repo).

A **repository** is a place charts come from that is not this machine. Its **index** (`index.json`) lists, per chart,
every version with its digest, where its archive is, where its source is, what it needs outside the machine and
whether a review let it through. A machine keeps a list of the repositories its owner added, fetches their indexes
only when asked (`alta repo update`), searches them offline (`alta search`) and downloads one chart only when asked
(`alta pull`). Installing stays what it is: the machine's server, its plan cards and the owner's yes
([alta-chart-0.1](alta-chart-0.1) §15).

It follows Helm's chart repository (`index.yaml`: every version of every chart, with its digest and its URLs) and
Artifact Hub's repository metadata (who publishes, where to report), in JSON, with what an agent package needs to be
judged before install: locality, services, capabilities, an audit status.

## 1. Relation to `alta.catalog/0.2`

The index does **not** replace the catalog. The catalog stays the single-version view a machine installs from
(one entry per chart). `catalogOf(index, pins?)` (pure) derives a catalog from an index: for each chart, the pinned
version if one is given, else the newest **installable** version (section 4); charts with no installable version are
left out. Paid versions keep their amount and currency (from `pricing`); an official repository's charts get
`origin: "alta"`, the others `origin: "community"` with their source.

## 2. Format

```
Index {
  schema: "alta.index/0.1"
  generatedAt: ISO date
  repo: { id: ^[a-z][a-z0-9-]{1,31}$, title: Text, url: https URL, tier: "official" | "community",
          report: https URL }                      where a problem with a chart is reported
  publishers: { "<publisher id>": { name, url?, tier: "official" | "verified" | "community",
                keys?: [ { id, alg: "ed25519", public: base64, revoked?: ISO date } ] } }
  charts: { "<chart id>": {
    publisher: "<publisher id>"
    kind, title: Text, summary: Text, categories?, keywords?, icon?: https URL, homepage?: https URL
    deprecated?: boolean, replacedBy?: "<chart id>", aliases?: ["<old id>"]
    versions: [ {                                  newest first, semver order
      version, created: ISO date
      digest: sha256 hex                           the chart tree digest (alta.tree/1), the same as `alta package`
      archive?: { url: https URL, sha256, size }   the deterministic archive of `alta package --public`
      source: { git, commit, ref?, path? }         as a chart's source, plus the folder in the repository
      license, price: "free" | "paid"
      pricing?: { model: "one-time" | "subscription", amount: number, currency: ISO 4217, interval?: "month" | "year" }
      locality?: "local" | "local-first" | "cloud"
      localityRange?: { best, worst }              over every value choice
      localityCheck: "declared" | "linted" | "tested"
      services: [ { id, name, hosts, phase, required, account } ]
      capabilities: string[]
      risk?: "low" | "medium" | "high"             computed from the chart by `alta repo index` (riskOf), never declared
      support: Support                             copied from the chart (platform.md)
      resources?, requires?                        copied from the chart
      audit: { status: "pass" | "review" | "warn" | "malicious" | "pending" | "error", at: ISO date, by: string }
      attestations?: [ { type: "publish" | "review" | "provenance", url: https URL, keyid?: string } ]
      changes?: Text
      withdrawn?: { at: ISO date, reason: Text }
    } ]
  } }
}
```

`Text` is `{ en, fr }`, as in a chart. `locality`, `services` and `localityRange` describe what a chart needs outside
the machine (the `locality` and `external` fields of [alta-chart-0.1](alta-chart-0.1)); the index **copies** them
from the chart and says how far they were checked in `localityCheck`:

| `localityCheck` | Means |
|---|---|
| `declared` | copied from what the author wrote |
| `linted` | recomputed by the index builder from the chart's closed lists (the locality floor) |
| `tested` | the chart was installed against the fakes with the network off and its `ready` proofs held |

`alta repo index` writes `linted`: it recomputes the level from what the chart names (its locality floor and the
services that apply to its default values) and lists the less local of that and the declared level (a chart that
passes `alta lint` never declares more local than its floor), and it computes `localityRange` over every choice of
values. A data chart (quest pack, universe, cosmetic) is `local`, `linted`, by construction. A chart without
`locality` is "not declared" (`localityCheck: declared`, no `locality`): it is shown that way and never matches a
locality filter.

## 3. Rules (`checkIndex`)

`checkIndex` returns plain problem strings, like `checkCatalog`. `alta lint` reads an `index.json` (and a machine's
`repos.json`, `alta.repos/0.1`) like any content file: each problem gets its rule (`index.schema`, `index.repo`,
`index.publisher`, `index.version`, `index.digest`, `index.locality`, `index.audit`…, and `repos.*`), its field and its
fix on the errors page. The JSON schemas are `alta.index.schema.json` and `alta.repos.schema.json`.

- `schema` is `alta.index/0.1`; `generatedAt` an ISO date; `repo` complete, its `url` and `report` https.
- Chart ids follow the chart id pattern and each appears once; publisher ids `^[a-z0-9][a-z0-9-]{1,38}$`; every chart
  names a listed publisher; `replacedBy` and `aliases` are chart ids.
- Versions are semver, unique, in **descending** semver order; `digest` is 64 hex; `archive.sha256` 64 hex and
  `archive.size` a positive integer; `source.commit` a full 40-hex commit.
- Every URL is https and carries no user name or password. (A test machine accepts `http://127.0.0.1` when
  `ALTA_TEST_HTTP=1` is set; nothing else.)
- `price: "paid"` or any `pricing` is refused in an index whose `repo.tier` is `community`: paid charts are not open
  yet. A paid version has a `pricing`; a free one has none.
- A version after the first of a chart needs `changes`.
- The tier of a chart is the tier of its publisher; a publisher of tier `official` only in a repository of tier
  `official`.
- Closed values: `kind` (the chart kinds), `locality`, `localityCheck`, `risk`, `audit.status`, `pricing.model`,
  `pricing.interval`, `attestations[].type`, `services[].phase`, `services[].account`.
- A key of a `publishers` entry is `alg: "ed25519"` with a base64 public key.

## 4. Installable

`installable(chart, version)` (pure) says whether a version may be pulled and installed, and if not, the sentence that
says why:

| Case | Refused with |
|---|---|
| `withdrawn` | `withdrawn by the repository on <date>: <reason>` |
| `audit.status` is `pending` | "its review is not finished: nothing is installable while a review is pending" |
| `audit.status` is `error` | "its review failed to run: it stays blocked until a review passes" |
| `audit.status` is `malicious` | "the review found it harmful: it is blocked" |
| the chart is `deprecated` without `replacedBy` | "deprecated by its publisher, with nothing to replace it" |

`pass`, `review` and `warn` are installable; `review` and `warn` are shown next to the version. A pending review blocks
install: the hole of installing while a scan is still running is closed by construction.

## 5. Search (`searchIndex`)

`searchIndex(index, { words?, locality?, kind?, tier?, free?, fits? })` (pure) returns one hit per chart, with its
newest version, the newest installable version, and the reason when none is installable. Filters:

- `words`: every word is found in the id, the title, the summary (English or French) or the keywords;
- `locality`: `local` matches a chart whose newest version says `local`, or whose `localityRange.best` is `local`
  (shown as "local possible"); `local-first` matches `local-first` (or a range whose best is `local-first`); `cloud`
  matches `cloud`. A chart that does not declare it matches no locality filter;
- `kind`, `tier` (the publisher's), `free` (price `free`), `fits` (a `Host`: `supports` of [platform](platform)).

## 6. Signature

A remote index is served with a detached signature `index.json.sig` next to it: a DSSE envelope whose in-toto subject
is `index.json` with the sha256 of the index's bytes, signed with Ed25519 by the repository's key
([alta-attestation-0.1](alta-attestation-0.1) §5). `alta repo sign <index.json> --key <private key file>` writes it.
`alta repo update` checks it against the public key given to `alta repo add --key` before anything is cached: a bad,
missing or foreign signature is refused and the previous cache is kept. A repository added without `--key` has
nothing to check a signature with, so its index is refused, unless it was added with `--insecure-unsigned` (printed at
every use; then the signature is stored and said "present, not checked"). `alta repo update` says "verified" only
after the check held.

## 7. Machine files

The base folder is the home folder; `ALTA_HOME` replaces it (tests), then `WORLD_HOME`.

| File | Schema | Written by |
|---|---|---|
| `~/.config/alta/repos.json`, mode 0600 | `alta.repos/0.1`: `{ schema, repos: [ { name, url, added, key?: { alg: "ed25519", public }, unsigned?: true } ] }` | `alta repo add`, `alta repo remove` |
| `~/.cache/alta/repos/<name>/index.json` (+ `index.json.sig`, `meta.json`: date, ETag, signature state) | `alta.index/0.1` | `alta repo update` |
| `~/.local/share/alta/charts/<repo>/<id>/` | a chart folder, its digest checked | `alta pull` |

A repository name is `^[a-z][a-z0-9-]{1,31}$`, and not one of the names of the local folders (`modules`, `agents`,
`engine`, `local`, `world-charts`). `alta repo remove` moves the cache folder to `~/.local/share/archive/<date>/`: nothing is deleted.
The machine's server reads the pulled folders after the folders of this repository and of `WORLD_CHARTS`, so a pulled
chart is offered by `alta install` like any other, with the same admission checks.

## 8. Network

The only network code of `alta` is `tools/cli/src/net.ts`, used by `alta repo update` and `alta pull` and by the
commands that talk to the machine's own server. A remote GET:

- https only (http only for `127.0.0.1` with `ALTA_TEST_HTTP=1`), no user name or password in an address;
- no redirect to another host (at most 3 redirects, same host and scheme);
- at most 8 MB for an index and 20 MB for a chart archive (the chart size limit), a timeout of 30 s;
- `If-None-Match` with the stored ETag;
- the only identifying header is `User-Agent: alta-cli/<version>`; nothing about the person or the machine.

No telemetry: no install counts, no update check. A machine talks to a repository only when its owner types
`alta repo update` or `alta pull`.

## 9. Pull

`alta pull <id>[@<version>] [--repo <name>]`:

1. finds the chart in the cached indexes (two repositories with the same id: `--repo` is required);
2. picks the version given, or the newest installable one; a version that is not installable is refused with its
   sentence (section 4);
3. downloads the archive (no git clone in this version), checks its sha256 against `archive.sha256`;
4. unpacks it into a temporary folder (every path must be plain and relative), recomputes the tree digest and
   compares it with `digest`;
5. lints the folder (`checkChart`, the same as `alta lint`) and checks its id and version match the index;
6. moves it to `~/.local/share/alta/charts/<repo>/<id>/`; a folder already there goes to the archive first.

Any failure leaves nothing behind.

## 10. A charts repository

The layout a charts repository follows (template: [`examples/charts-repo/`](https://github.com/alta-system-os/alta-os/tree/main/examples/charts-repo)):

```
repo.json                          { id, title, url, tier, report, git? }: the index's repo block
charts/<chart id>/                 a chart kept in the repository itself (small charts, official ones)
sources/<chart id>.json            or a pointer: { git, commit, ref?, path?, sha256 } to the author's repository
publishers/<publisher id>.json     { id, name, url?, tier, github: "<login>", keys: [...] }
moderation.json                    review results and withdrawals: { "<id>@<version>": { audit?, withdrawn? } }
index.json, index.json.sig         generated on the main branch by CI only; a change that touches them is refused
```

`alta repo index <folder> [--out <file>] [--archives <url>] [--checkouts <dir>] [--commit <sha>] [--previous <index>]`
builds `index.json` from such a folder:

- a chart of `charts/<id>/` gets its source from `repo.json`'s `git` and `--commit`; a pointer of `sources/<id>.json`
  is read from `--checkouts <dir>/<id>/` (the content at that commit, cloned by the CI beforehand) and its tree digest
  must equal the pointer's `sha256`;
- `--archives <base url>` writes the deterministic archive of each chart next to the index and records its URL,
  sha256 and size;
- the chart's publisher is its `publisher.id` if it has one, else its `author`;
- `locality` and `localityRange` are recomputed from the chart (`localityCheck: linted`, section 2), the services of
  `external` are copied, `risk` is computed (never read from `moderation.json`);
- `audit` is `{ "status": "pending" }` unless `moderation.json` says otherwise, so nothing is installable until a
  review step says so;
- `--previous` keeps the older versions of an earlier index.

## 11. What it is not

- Not a package manager for code: archives hold chart folders (data), nothing in them is run.
- Not a store front: price and payment are described elsewhere; a community repository cannot list a paid chart.
- Not a trust boundary by itself: the boundary stays the closed lists, the permissions floor and the consent step.
