# Batch Upload
<!--
ref: @protocol/batch-upload
tags: [upload, corpus, import, batch, files]
triggers: [upload a directory, bulk upload, import a corpus, batch upload, migrate docs into protocol.supply]
version: 2
updated_at: 2026-09-26T08:53:05.327Z
files: [batch_upload.py]
-->

Put a directory of documents into a repo **as is, immediately**: one entry per markdown file, other files attached, nothing on the write path waiting on an LLM, and re-runs that update instead of duplicating.

**Why this is a recipe and not an endpoint.** You already control exactly what you post. A server-side importer would have to guess your layout, and historically it also added an LLM extraction pass per document that nobody asked for. A walker you can read, run and change is cheaper and more honest: the mapping below is the whole contract.

## The mapping

| On disk | In the repo | Why |
|---|---|---|
| directory `guides/deep-dive/` | `path: guides/deep-dive` | The address is `(repo, path, slug)`. The directory tree already *is* your namespace, so reusing it means nothing has to be renamed to fit. |
| file `deploy.md` | `slug: deploy` | Filenames are the names people already use for these documents. |
| `ref:`, `path:` or `slug:` already in a file's frontmatter | kept; the walker only fills in what's missing | The author's declared address wins. Overriding it would silently move a document the author placed on purpose. |
| `diagram.png` next to `diagram.md` | a support file on `diagram` | A figure belongs with the text that cites it. |
| any other non-markdown file | a support file on the directory's `index` entry (created if the directory has no `index.md`) | Every file needs an owning entry; the directory's index is the least surprising one. |

Segments are lowercased and kebab-cased (`Deep Dive` → `deep-dive`), so a path is always a valid address.

## Authored protocols vs raw corpus

- **Authored protocols** (the default): each file goes through `POST /entry/publish`, which reads the frontmatter and upserts on `(repo, path, slug)`.
- **Raw corpus** (`--raw`): source material you want searchable but not presented as authored guidance — transcripts, exports, notes. These are stored as `type: raw`, which is never sent for review. Publish cannot set that type (frontmatter `type:` is a classification that lands in metadata), so raw entries go through `POST /entry` the first time and `PUT /entry/{id}` after.

## No LLM on the way in

Every write is sent with `?scrub=none&review=false`:

- `scrub=none` skips the pass that fills in a missing summary, tags and triggers. Your text goes up exactly as written.
- `review=false` skips the quality review. The review is asynchronous anyway (a write never waits for it), but on a corpus of thousands it is thousands of LLM calls you may not want. Pass `--review` to queue it; the result lands on each entry later as `reviewStatus` / `reviewResult`.

Refinement is an add-on you can run afterwards, or never. Nothing downstream may assume it ran.

## Re-runs are safe

- A publish is an upsert on `(repo, path, slug)`, and an unchanged body mints no new version.
- A raw `PUT` with an unchanged body mints no version either.
- A file `PUT` replaces by name, and bumps the entry only when the bytes changed.

So the walker is also the sync: edit files, run it again, and only what changed moves.

## Read the warnings

`POST /entry/publish` returns a `warnings` array whenever the address it wrote differs from what the document's own lines imply. The walker prints every one and exits non-zero. The one that matters most:

> Created a new entry at @repo/slug. The slug "slug" already exists at another path…

That is a **fork**, not an update. The usual cause is a file that moved directories, or a `path:` line someone deleted. The original entry is untouched. Decide which address is right, republish there, and delete the stray.

## Run it

The walker is attached to this entry as `batch_upload.py` (Python 3, no dependencies beyond `curly`):

```bash
curly protocol "@protocol/batch-upload_/batch_upload.py" > batch_upload.py
python3 batch_upload.py ./corpus --repo myteam --dry-run   # print the plan, send nothing
python3 batch_upload.py ./corpus --repo myteam             # authored protocols
python3 batch_upload.py ./transcripts --repo myteam --raw  # raw corpus
```

Every request goes through `curly protocol`, so your token stays in curly's config — never in argv, an environment dump, or shell history. Always start with `--dry-run`: it prints every address before anything is written.

## Adapting it

The mapping is the part worth keeping; the script is disposable. If your layout differs — one directory per entry, a front-matter convention of your own, a different home for attachments — change the mapping deliberately, keep the address explicit (`path:` + `slug:`), and keep reading the warnings.

---

*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*

*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*