# Work from a shared world

Start from the team's history, keep it fresh, and know what you are holding.

This page is executed as written by `packages/cli/src/journeys/tutorials.test.ts`; the recording
is made from the same run.

![The page, recorded](../media/work-from-a-shared-world/work-from-a-shared-world.gif)

## The shared world, for this page

The world from [share a world](./share-a-world.md), on this machine, with one issue in it.

```json file=package.json
{ "name": "acme-web", "private": true, "type": "module", "dependencies": { "@octokit/rest": "^21" } }
```

```js file=file-issue.mjs
import { Octokit } from '@octokit/rest';
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
const { data: issue } = await octokit.issues.create({ owner: 'acme', repo: 'web', title: process.argv[2] ?? 'Launch checklist' });
console.log(`filed #${issue.number}`);
```

```bash
npm install
npm install -g @volter/world
npm install -D @volter/twin-github
mkdir ../team && cd ../team && volter world init --bare acme/team --twins github
volter world serve --port 4300 &
cd ../acme-web
volter world init
volter world clone http://127.0.0.1:4300/acme/team --token "$(cat ../team/.volter/token)"
volter world up
```

```text
cloned  http://127.0.0.1:4300/acme/team  0 changes
```

## Clone

`clone` records the shared world as origin, remembers the token in your config directory
(`~/.config/volter/credentials.json`, owner-only, keyed by the URL), and sets your base to the
shared world's current position. Your world's history is the team's from here on.

```bash
volter world origin
```

```text
origin  http://127.0.0.1:4300/acme/team
```

## Pull

Someone else pushes. `pull` brings it in and moves your base; your own entries stay on top.

```bash
cd ../team && volter world run -- node ../acme-web/file-issue.mjs "From the shared world" && cd ../acme-web
volter world pull
volter world log
```

```text
pulled  origin  1 change
github   issue.create   acme/web#1
```

Pull before a push, and pull whenever you want the world to look like the team's does now.

## Branch over the shared history

A branch starts at your current position, which is now the team's history. Work on it, compare,
and come back.

```bash
volter world branch spike
volter world run -- node file-issue.mjs "Spike"
volter world diff
volter world checkout main
volter world diff
```

```text
filed #2
1 change since branch spike
0 changes since origin
```

## What you are holding

If the shared world's twins have a root at the vendor, the history you cloned is real records from
a real account, in plain text on your disk. Treat it that way: do not commit it, do not paste it
into a bug report, and `volter world reset` or `volter world down --purge` when the session that
needed it ends. [Data and keys](../concepts/data-and-keys.md) says exactly what lands where.

## Back to the default data

A world with an origin can still reset. The branch returns to the default data; the origin stays
recorded, and the next `pull` brings the team's history back.

```bash
volter world reset
volter world origin
volter world down
kill %1
```

```text
origin  http://127.0.0.1:4300/acme/team
```

<!-- playback:BEGIN — GENERATED by `bun scripts/docs-media.ts`; do not edit between markers -->

## Playback

Each command above, as the recording shows it.

<details><summary><code>npm install</code></summary>

![step 1](../media/work-from-a-shared-world/step-01.png)

</details>
<details><summary><code>npm install -g @volter/world</code></summary>

![step 2](../media/work-from-a-shared-world/step-02.png)

</details>
<details><summary><code>npm install -D @volter/twin-github</code></summary>

![step 3](../media/work-from-a-shared-world/step-03.png)

</details>
<details><summary><code>mkdir ../team &amp;&amp; cd ../team &amp;&amp; volter world init --bare acme/team --twins github</code></summary>

![step 4](../media/work-from-a-shared-world/step-04.png)

</details>
<details><summary><code>volter world serve --port 4300 &amp;</code></summary>

![step 5](../media/work-from-a-shared-world/step-05.png)

</details>
<details><summary><code>cd ../acme-web</code></summary>

![step 6](../media/work-from-a-shared-world/step-06.png)

</details>
<details><summary><code>volter world init</code></summary>

![step 7](../media/work-from-a-shared-world/step-07.png)

</details>
<details><summary><code>volter world clone http://127.0.0.1:4300/acme/team --token "$(cat ../team/.volter/token)"</code></summary>

![step 8](../media/work-from-a-shared-world/step-08.png)

</details>
<details><summary><code>volter world up</code></summary>

![step 9](../media/work-from-a-shared-world/step-09.png)

</details>
<details><summary><code>volter world origin</code></summary>

![step 10](../media/work-from-a-shared-world/step-10.png)

</details>
<details><summary><code>cd ../team &amp;&amp; volter world run -- node ../acme-web/file-issue.mjs "From the shared world" &amp;&amp; cd ../acme-web</code></summary>

![step 11](../media/work-from-a-shared-world/step-11.png)

</details>
<details><summary><code>volter world pull</code></summary>

![step 12](../media/work-from-a-shared-world/step-12.png)

</details>
<details><summary><code>volter world log</code></summary>

![step 13](../media/work-from-a-shared-world/step-13.png)

</details>
<details><summary><code>volter world branch spike</code></summary>

![step 14](../media/work-from-a-shared-world/step-14.png)

</details>
<details><summary><code>volter world run -- node file-issue.mjs "Spike"</code></summary>

![step 15](../media/work-from-a-shared-world/step-15.png)

</details>
<details><summary><code>volter world diff</code></summary>

![step 16](../media/work-from-a-shared-world/step-16.png)

</details>
<details><summary><code>volter world checkout main</code></summary>

![step 17](../media/work-from-a-shared-world/step-17.png)

</details>
<details><summary><code>volter world diff</code></summary>

![step 18](../media/work-from-a-shared-world/step-18.png)

</details>
<details><summary><code>volter world reset</code></summary>

![step 19](../media/work-from-a-shared-world/step-19.png)

</details>
<details><summary><code>volter world origin</code></summary>

![step 20](../media/work-from-a-shared-world/step-20.png)

</details>
<details><summary><code>volter world down</code></summary>

![step 21](../media/work-from-a-shared-world/step-21.png)

</details>
<details><summary><code>kill %1</code></summary>

![step 22](../media/work-from-a-shared-world/step-22.png)

</details>

<!-- playback:END -->
