# `alta package`

> alta package: lints, then writes a deterministic archive; prints its sha256 and the tree digest (source.sha256).

Lints, then writes a deterministic archive; prints its sha256 and the tree digest (source.sha256).

*Les descriptions et les sorties sont en anglais, comme la CLI.*

## Usage

```text
alta package <dir> [--out <file.alta.tar>] [--public] [--json]
```

## Arguments

| Nom | | Description |
|---|---|---|
| `dir` | **requis** | The folder to package. |

## Options

| Nom | Type | Défaut | Description |
|---|---|---|---|
| `--out` | *string* | *Défaut: `<dir>.alta.tar`* | Where to write the archive. |
| `--public` | *flag* |  | The archive is for a public repository: refused unless the chart says "privacy": "shareable". |
| `--json` | *flag* |  | Print the result (alta.pack/1) as JSON. |

## Codes de sortie

| Nom | Description |
|---|---|
| `0` | ok |
| `1` | problèmes trouvés |
| `2` | mauvais usage |
| `3` | pas dans cette version |

## Exemples

*Package a chart*

```sh [Terminal]
alta package my-agent
```

```text [Sortie]
packaged 4 files into my-agent.alta.tar (6656 bytes)
  archive sha256: 26afc25c319001ec0bcce3f52f27c89d7710acfeb6055e2f0217120e4f901b4b
  tree digest (the source.sha256 of a chart): 5868a4d8874b1e4ac8b42810aac8e877074190f3efd288e96183e68a2263f322
  source block (the commit and the address come from `alta publish`):
    {
      "git": "https://<your repository>",
      "commit": "<full commit of the push>",
      "sha256": "5868a4d8874b1e4ac8b42810aac8e877074190f3efd288e96183e68a2263f322"
    }
```

*For a public repository (a shareable chart only)*

```sh [Terminal]
alta package my-agent --public
```

```text [Sortie · exit 1]
not packaged: this chart is personal (privacy: "personal"); set "privacy": "shareable" in chart.json to package it for a public repository — see https://docs.altasystem.ai/charts/guides/share
```

**JSON:**

*JSON, to fill a chart's source*

```sh [Terminal]
alta package my-agent --json
```

```json [Sortie]
{
  "schema": "alta.pack/1",
  "archive": "my-agent.alta.tar",
  "bytes": 6656,
  "sha256": "26afc25c319001ec0bcce3f52f27c89d7710acfeb6055e2f0217120e4f901b4b",
  "tree": "5868a4d8874b1e4ac8b42810aac8e877074190f3efd288e96183e68a2263f322",
  "files": [
    {
      "path": "README.md",
      "size": 138,
      "sha256": "cf99df079af0717642e94ab0ea0b15a5cc9a9102a7444872a474710908a52626"
    },
    {
      "path": "agents/helper/AGENTS.md",
      "size": 94,
      "sha256": "ebdf78bbcf13f0569cc20475efc124aedb5f409558b9b8b2e4ad501d497d2250"
    },
    {
      "path": "agents/helper/SOUL.md",
      "size": 132,
      "sha256": "e076ab815e8e39ea266f295a0282c7861558c3eb529764e4a6cede59e1b3e6f1"
    },
    {
      "path": "chart.json",
      "size": 2042,
      "sha256": "e0cfa7213726bd1801d853df6769cf30800df221982ce581b5678bb23841d57f"
    }
  ],
  "source": {
    "git": "https://<your repository>",
    "commit": "<full commit of the push>",
    "sha256": "5868a4d8874b1e4ac8b42810aac8e877074190f3efd288e96183e68a2263f322"
  }
}
```

**TypeScript SDK:**

*La même chose en TypeScript, avec `pack` de `@altasystem/sdk` ; lance-le avec `node example.mjs`.*

```js [example.mjs]
// Pack files into a deterministic archive: the same files always give the same digests.
import { pack, treeDigest } from "@altasystem/sdk";

const files = [
  { path: "chart.json", bytes: new TextEncoder().encode('{ "schema": "alta.chart/0.1" }\n') },
  { path: "README.md", bytes: new TextEncoder().encode("# My chart\n") },
];

const packed = pack(files);
console.log(packed.files.map(f => f.path).join(", "));
console.log("tree:", packed.tree === treeDigest(files));
console.log("same archive twice:", pack(files).sha256 === packed.sha256);
```

```text [Sortie]
README.md, chart.json
tree: true
same archive twice: true
```

## Voir aussi

- [Publier un chart](https://docs.altasystem.ai/fr/marketplace/publish)
- [Calculer l'empreinte d'un chart](https://docs.altasystem.ai/fr/recipes/chart-digest)
- [`pack` (SDK)](https://docs.altasystem.ai/fr/reference/sdk/pack)
