# Artifoster

Artifoster is a small self-hosted home for web pages and apps an agent builds for
a person. Publish a self-contained HTML app, give the user the URL, and update it
in place when they ask for changes.

Base URL: `https://facts.tommasoamici.com`

## When to use this skill

Use Artifoster when the user asks you to build something they should open in a
browser: a calculator, a visual explainer, a proof of concept, a one-off tool, or
a small multi-page app. A single HTML file with inline CSS and JavaScript is the
best default. Split files only when it keeps the source readable.

## Log in with the user

Do not ask the user for a password or an API key. There are two ways to log in:
an SSH key (best when you can run commands on the user's machine), or a device
code the user approves in the browser.

### Option A: an SSH key

Download the helper and run it yourself with a key the user already owns. The
user never needs to copy a command.

To start with a browser approval: use `--bootstrap`.

```sh
curl -fsSL https://facts.tommasoamici.com/artifoster-login.py -o /tmp/artifoster-login.py
python3 /tmp/artifoster-login.py --server https://facts.tommasoamici.com --key ~/.ssh/id_ed25519 --bootstrap
```

The script prints a `verification_url` to stderr and waits. Give that URL to the
user. They approve the agent with their passkey, and the script then prints the
agent token. No code or command needs to be copied.

Linking a key to an existing account from the browser is a separate step: the
Account page offers **Link an SSH key** with a one-time `--link-code`.

After the key is linked, log in without browser approval:

```sh
python3 /tmp/artifoster-login.py --server https://facts.tommasoamici.com --key ~/.ssh/id_ed25519
```

That prints JSON with `token` and `browser_url`. Give `browser_url` to the user
so they can open a signed-in session, and keep `token` for the API. The token is
the same one used in the `Authorization: Bearer` header below.

A brand-new SSH key can also create an account on its first login, unless the
instance already has a user and sign-ups are closed.

The protocol is simple if the helper is unavailable: `POST /api/ssh/challenges`
with `{"name":"...","public_key":"..."}`, sign `challenge` with
`ssh-keygen -Y sign -f KEY -n NAMESPACE`, then `POST /api/ssh/login` with
`{"challenge":"...","signature":"..."}`. Linking uses
`POST /api/ssh/keys/link` and the namespace returned by the challenge.

### Option B: a device code

Use this when you cannot access an SSH key. Start a login:

```http
POST https://facts.tommasoamici.com/api/agent/login
Content-Type: application/json

{ "name": "Claude Code" }
```

The response contains `device_code`, `user_code`, `verification_url`,
`expires_in`, and `interval`. Show `verification_url` to the user. If they are not
signed in, the page asks them to sign in with a passkey or SSH key first.

Poll every `interval` seconds:

```http
POST https://facts.tommasoamici.com/api/agent/login/token
Content-Type: application/json

{ "device_code": "dc_..." }
```

While the user decides, the response is `202` with `{ "status": "pending" }`.
Once approved, it returns:

```json
{ "token": "af_...", "token_type": "Bearer", "token_id": 7 }
```

Keep the token in the agent's own credential store. Do not print it into chat
logs or commit it. Tokens expire after 90 days; start a new login to mint another.
If the code expires, start a new login.

## Publish or update an artifact

`PUT` creates the artifact if your account has no artifact with that slug and
publishes a new version if it does. Slugs are only unique within one account, so
other people can publish the same slug under their own URL. It is safe to use the
same call again after edits.

Sending `files` publishes a new version and keeps the previous one online. The
main `url` always serves the latest version; `version_url` points at a stable
copy of this version at `/a/{public_id}/{slug}/v/{version}/`. The `public_id` is
a random, unguessable identifier, so URLs are not enumerable. Public responses
ask caches to revalidate; unlisted and private responses are not cached. Relative
assets keep working inside that version because they resolve under the versioned
path.

```http
PUT https://facts.tommasoamici.com/api/artifacts/inches-to-cm
Authorization: Bearer af_...
Content-Type: application/json

{
  "title": "Inches to centimeters",
  "description": "A tiny converter.",
  "visibility": "unlisted",
  "entry_point": "index.html",
  "files": [
    {
      "path": "index.html",
      "content": "<!doctype html><html>...</html>"
    },
    {
      "path": "app.css",
      "content": "body { font-family: system-ui; }"
    }
  ]
}
```

- `slug` is optional in the body; the URL segment wins. Use lowercase letters,
  numbers and dashes.
- `visibility` is `public`, `unlisted`, or `private`. Default: `unlisted`.
  - `public`: anyone with the link; search engines may index it.
  - `unlisted`: anyone with the link; not indexed.
  - `private`: only the owner, or someone with a share link the owner creates in
    the dashboard.
- `entry_point` defaults to `index.html` and must name one of the files.
- Each file needs `path` and either `content` (UTF-8 text) or `content_base64`
  (binary). Paths are relative and may not contain `..` or start with `/`.
- The artifact limit is 5 MB across all files and 200 files.

The response is `201` when created and `200` when updated. It includes
`public_id`, `url`, `version_url`, `version`, and the file list.

When updating, send only the fields you want to change. Omit `files` to change
metadata only; send `files` to publish a new version with a complete replacement
file set. Metadata-only updates do not increment `version` or change old URLs.

## Read, list, and delete

```http
GET    https://facts.tommasoamici.com/api/artifacts
GET    https://facts.tommasoamici.com/api/artifacts/inches-to-cm
DELETE https://facts.tommasoamici.com/api/artifacts/inches-to-cm
Authorization: Bearer af_...
```

`GET` on one artifact includes each file's text content or base64 content, so you
can recover the source before making a change. It includes a `versions` list with
each version's number, `url`, entry point and creation time, newest first, so you
can point someone at the exact version they are discussing.

## What to hand back to the user

Give the user the `url` from the publish response. For a private artifact, do
not share that URL; tell them it is in their Artifoster dashboard instead. From
the artifact's page they can create a share link that lets other people open it
without signing in, with an expiry and a revoke button. A share link starts at
`/_share/{token}` and redirects to a capability URL under `/_p/`; keep the full
link intact, because the token is what grants access.

## Good artifacts

- Set a descriptive `<title>` and viewport meta tag.
- Keep everything relative so the app works under its artifact URL.
- Avoid external build steps and network calls that might disappear.
- If the app stores state in `localStorage`, namespace keys with the slug.
- Test the page by opening it after publishing; fix and `PUT` again.
