files/2) is one set of requests that every client uses: the web app, the phone layout, the PWA, Desktop, iOS, Android and Gizzi Code. The contract is in contracts/files-drive/ in the platform repo: SPEC.md says how it behaves, schema/*.json holds the message shapes, and fixtures/ holds examples. The older Files API covers cloud file storage and attachments and is a different system.
The protocol ships dark behind the per-account flag files_drive. A caller without it gets feature_disabled.
The routes the runtime (allternit-api) answers today, with what this release does not do yet, are listed in the Files drive runtime API.
Principles
- Routes take IDs, not paths. The one exception is adding a user folder as a root.
- Browsing never wakes or bills a computer. Only the wake-consent call wakes one.
- A write carries
base_rev. A stale write becomes a conflict copy, never an overwrite. - Every read says where it came from, in a
Freshnessobject. - Files in Inbox and shared folders are untrusted data.
Runtime routes
The computer that owns the files serves these under/api/v1/files/v2.
From a terminal,
gizzi files and the TUI /files command speak this API, and gizzi files mount shows a computer’s drive as a FUSE or WebDAV folder on Linux. See Files drive in the terminal.
The relay maps any path containing /files to the runtime:files capability, so no new capability is needed.
Roots
A root is a named folder with a policy: read, write, shareable, agent_process, protected, offline, replica, versions andtrash_days. The default roots are allternit_home (~/Allternit), inbox, shared, agent_output, downloads, meetings, scans, memory_drive, code and models, plus any user_added root. path_hint is shown to the owner only and is never sent to guests.
POST /roots takes local_path. The runtime resolves symlinks, requires the folder to be inside the home folder, and refuses the secrets deny-list with scope_violation. A root added over the relay starts with shareable: false and agent_process: false.
A symlink that leads outside its root is not followed. A protected root answers protected_root_locked until the client sends a device unlock proof in x-allternit-unlock.
Items and revisions
An item ID (it_ plus an opaque string) comes from the index on the owning computer and survives rename and move. Never parse it.
A revision is "<meta_version>-<blake3 content hash>", or "<meta_version>-dir" for a folder. It is the HTTP ETag.
Conflicts
Small writes, upload commits, moves, deletes and version restores carrybase_rev. When it is stale:
The conflict copy is named
<stem> (conflict <device name> <YYYY-MM-DD HHmm>).<ext>, for example Lease (conflict iPhone 2026-11-15 1042).pdf. If that name exists, 2, 3 and so on is added before the closing parenthesis. A create with no base_rev whose name exists lands as <stem> (2).<ext> with keep_both, or returns already_exists with fail. Move, delete, trash and version restore with a stale base_rev always return rev_mismatch.
Writes queued on the device
A client never wakes a computer to save a file unless the user agreed (or the wake setting isauto). A write made while the computer is asleep or unreachable waits on the device and is sent the next time the computer answers. It keeps the base_rev it was made against, so the rules above apply when it lands: if the file changed meanwhile it becomes a conflict copy, and if the file is gone keep_both creates it again. The codes that mean “wait” are wake_consent_required, wake_denied, asleep, waking and offline (including a network failure).
Rename, move and delete are not queued: a stale
base_rev has no keep-both form for them.
Chunked upload
A file of 4 MiB or less can use the small write. Larger files, and any file that must resume, use an upload session.Chunker
Clients must pass the shared vectors in
contracts/files-drive/vectors/chunker-v1.json. The schema rejects a chunk bigger than 4 MiB. The relay caps a request body at 5 MiB, and a 4 MiB chunk leaves room for the envelope.
Flow
- Chunk the file and compute each chunk hash and the whole-file hash.
POST /chunks/have-needwith the hashes. The response lists what the computer still needs.POST /uploadswith the target (a new file underparent_id, oritem_idatbase_rev), the size, the hash and the first chunk refs.PUT /uploads/:session_id/chunks/:hashfor each needed chunk. For very large files,POST /uploads/:session_id/chunksappends more refs.POST /uploads/:session_id/commit. The runtime checks every chunk hash and the whole-file hash.
expires_at. GET /uploads/:session_id returns what is still needed, so a client resumes by sending only that. DELETE /uploads/:session_id cancels. Chunks are stored once per computer and shared between revisions.
Commit and put errors: chunk_hash_mismatch (bytes do not match their hash), chunk_missing (a needed chunk was never sent), manifest_invalid (a bad manifest, or a whole-file hash that does not match).
Write and upload-create requests can send utc_offset_minutes so the conflict name uses the editing device’s local time.
Change feed
Each root has a monotonic change cursor, formattedc1. plus an opaque string. Compare cursors only by asking the server.
- Poll:
GET /roots/:root_id/changes?cursor=&limit=&wait_s=.wait_sis at most 25 and holds the request open until something changes. - Subscribe: open the WebSocket and send a
SubscribeMessagewith a cursor per root. The server sendschanges,reset,stateandheartbeatframes. - If the cursor is too old, the index was rebuilt or the root was removed, the answer is
reset_required: true(poll) or aresetframe. List from scratch.410 cursor_expiredis for a cursor that cannot be parsed or that names another root; treat it like a reset.
state: asleep and closes.
Wake consent
For/api/v1/files/v2/*, cloud-api does not call wake_for_device and does not touch the activity timer. Legacy /api/v1/files/* keeps its current wake behaviour until its callers move to v2.
While a computer sleeps:
roots,list,stat,changesand name search are answered from the asleep snapshot, withserved_by: snapshotandcomputer_state: asleep.content,manifest,chunks, uploads, writes and content search returnwake_consent_required(409) with aWakeHint(setting,consent_path), unless the request carries a valid wake ticket.
The consent call
WakeConsentRequest with a WakeReason. The computer’s wake setting decides the result:
The response is
{ticket, expires_at, computer_state: waking|awake, estimated_wake_s}. Send the ticket in x-allternit-wake-ticket on later requests. A ticket lives 120 seconds, wakes its computer at most once, and can be sent on any number of requests to that one computer until it expires. The consent call records one activity touch, so the idle sweep does not put the computer back to sleep right after the wake. A transfer that outlasts the idle window asks for a new ticket.
Get and set the setting with GET and PUT /api/v1/computer-files/:computer_id/wake-settings.
The snapshot
The runtime writes file names, sizes and revisions, never contents, to the user’s own R2 bucket. It writes only while awake: on a sleep notice, and at most every 5 minutes while changes are pending. Names are plain text in v2 (names_encrypted: false). Protected roots are left out, and path_hint and local paths are never included.
Transports and where a read comes from
GET /api/v1/computer-files/:computer_id/endpoints returns transport candidates sorted by priority, lowest first.
Cloud computers are relay only. A client picks the first source that works: loopback, mesh, relay (awake only), a current replica on another device, the snapshot (metadata only), then the device’s own cache.
Relay
A client posts aRelayRequest to POST /api/v1/runtime-devices/:computer_id/proxy with path set to /api/v1/files/v2/.... The request body is {method, path, headers, body, body_encoding}. cloud-api accepts body_encoding and the older bodyEncoding. The relay streams the runtime’s raw response back.
The relay passes these request headers through to the runtime:
The relay caps a request body at 5 MiB, measured as the decoded size. Live change-feed sockets use the existing socket-ticket flow.
The computer ID is the cloud-api
computer_id.
Sharing routes
Guests send
Authorization: Files-Guest followed by a capability token. See the sharing guide.
The guest page at ai.allternit.com/s/ followed by the link token calls summary first, then redeem with the passcode when passcode_required comes back. It sends Authorization: Files-Guest on the v2 routes and redeems again about a minute before the token lapses (tokens last one hour), so a long visit does not ask for the passcode twice. Error codes it handles: passcode_required, passcode_invalid, rate_limited, share_expired, share_revoked, not_found, guest_wake_not_allowed. The owner’s share dialog creates a share with role, optional expires_at, passcode, invite_emails and guest_wake. The “let an agent process files” switch is not part of the share. It updates the root policy field agent_process.
Capability tokens
Wake tickets and guest tokens share one format: a prefix, the claims as base64url JSON, and an Ed25519 signature, joined by dots. The prefix isawt1 for a wake ticket and fgt1 for a guest token. cloud-api signs them. Runtimes fetch public keys from GET /api/v1/computer-files/token-keys and verify offline.
Two checks apply to a guest. The gateway checks the token and whether the share is revoked. The runtime then checks scope (computer, root, item, role) on every request. Roles are view_download, upload_only, edit and comment. An upload_only guest cannot list. A passcode is checked at redeem (passcode_required, passcode_invalid). A guest never wakes the owner’s computer unless the share has guest_wake: true.
Principals
agent_process is separate from share roles, and transfer is separate from execute.
Events
Versions and trash
Each root keeps versions by count and age.keep_days counts from the time a version was replaced, and 0 means no limit. Delete moves to trash unless permanent is set. trash_days: 0 deletes at once. A write whose base_rev names a file that is now gone creates it with keep_both, and returns not_found with fail or replace.
The web Files tab lists versions per file and trash per root, and restores either. A restore into a taken name returns the item under a new name. There is no route yet to download an old version or to empty the trash.
Search and intelligence
The runtime indexes the text of files on the computer that owns them. The index lives inintel.sqlite beside the engine database and never leaves the computer.
Search modes
POST /search takes mode:
name: the file name contains the query. Always available.full_text: words inside files and names, ranked by relevance (SQLite FTS5, bm25). Words match any-of, best match first. Put the query in double quotes to match a phrase. Each hit carries asnippetof the matching text.semantic: files closest in meaning to the query, using the local embedding endpoint (ALLTERNIT_EMBED_URL, by default the loopback model on port 7719). With no model reachable the route answers501 unsupported, and no vectors are made. The hash fallback the memory index uses is not used here, because it carries no meaning.
index_state is building until the background worker has caught up with the files, then ready. Searches only return files in roots the caller may read. A caller that is an agent sees only roots whose policy allows agent_process. A guest gets no hits from these routes; guests search inside their share through the sharing gateway. Snippets are file content and are never returned to a guest. A protected root needs the unlock header, as everywhere else.
What is indexed, and when
- What is read. Text files (UTF-8, no NUL bytes in the first 8 KiB, up to 2 MiB), PDFs (up to 20 MiB, the first 50 pages, 5 seconds of extraction) and the text of Word
.docxfiles. Text is capped at 2 MiB per file. A PDF that is encrypted, broken or over a cap is skipped. Spreadsheets, slides and audio are not read yet. Images get a thumbnail and no text. - Only while the computer is awake (D12). Indexing, embeddings and previews run on one background thread inside the runtime process. They never wake a computer, never reset its idle timer, and use no company compute. The embedding call goes to the endpoint on the computer.
- CPU budget. One thread at low priority (niced on Linux), held to a duty cycle of 25% of one core by default: after each file it rests three times as long as the file took. At most 8 files per pass. When a pass finds nothing the wait before the next doubles from 30 seconds up to 5 minutes. Set
ALLTERNIT_FILES_INTEL_CPU_PERCENT(1 to 100),ALLTERNIT_FILES_INTEL_BATCH(1 to 200) orALLTERNIT_FILES_INTEL=offto change it. This keeps a 2 CPU, 4 GB cloud computer usable for the user’s own work. - Protected roots are skipped. The Memory Drive and any root with
protected: trueare not indexed. The owner can opt a root in withPUT /intel/roots/{root_id}and{"index": true}, which needs the device unlock and does not work over a relay. Opting out removes what was indexed.
Routes
Items returned anywhere carry
tags, provenance (shown by clients as an AI-generated label when ai_generated is true) and has_thumbnail when they exist. Summaries and transcripts are never made on their own: only an explicit action or a folder rule the owner created runs them.
Errors
Every error body isErrorBody: {error, message, code} plus optional retry_after_s, computer_state, wake, current and missing_chunks. error and code both hold the error code.
Try it without a runtime
node tools/files-stub/server.mjs in the platform repo serves this contract from memory on http://127.0.0.1:47820, with switches for asleep, waking, conflict, slow, guest and error cases.