From ec7e1ba69c7fb337cc03bf5abb979e77b559367a Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Wed, 11 Nov 2026 18:27:03 -0500 Subject: [PATCH] docs: describe chat attachments and upload admission Document local file uploads, structured history cards, draft recovery, input identity, retention, and partial writes against the current wiki. Preserve contributor rules for storage paths and attachment metadata. --- docs/http-api-design.md | 11 ++++---- docs/http-sessions.md | 56 ++++++++++++++++++++++++++++---------- robot-docs/artifacts.md | 4 ++- robot-docs/contributing.md | 14 ++++++++++ robot-docs/files.md | 5 ++++ robot-docs/kernel-state.md | 17 ++++++++++++ robot-docs/sessions.md | 15 ++++++++++ robot-docs/web.md | 46 +++++++++++++++++++++++++++++++ 8 files changed, 147 insertions(+), 21 deletions(-) diff --git a/docs/http-api-design.md b/docs/http-api-design.md index 6f73a766c..d76aeb16b 100644 --- a/docs/http-api-design.md +++ b/docs/http-api-design.md @@ -151,11 +151,12 @@ replace the complete array. Writable fields are listed for each resource. rules. Ordinary JSON request bodies have a 64 KiB limit. Input admission has a -72,200,000-byte limit, room for ten encoded images. JSON responses and SSE data -frames have a 1 MiB limit. The limits on each OpenAPI operation apply as well. -HTTP body framing accepts valid fixed-length and chunked requests, enforcing the -same byte limit while reading. Ambiguous framing, unsupported content encoding, -and incomplete bodies fail without executing the operation. +100,200,000-byte limit, room for ten encoded images and 20 MiB of decoded +generic files. JSON responses and SSE data frames have a 1 MiB limit. The limits +on each OpenAPI operation apply as well. HTTP body framing accepts valid +fixed-length and chunked requests, enforcing the same byte limit while reading. +Ambiguous framing, unsupported content encoding, and incomplete bodies fail +without executing the operation. zstd is the one content coding. A JSON or text response of at least 1 KiB is compressed when `Accept-Encoding` admits `zstd`, and so is a session or diff --git a/docs/http-sessions.md b/docs/http-sessions.md index 5b7777e60..2b00df5c0 100644 --- a/docs/http-sessions.md +++ b/docs/http-sessions.md @@ -250,18 +250,41 @@ attachment token and preserve ordered text and resource-link blocks. Message, continuation, skill, and command inputs share durable admission. Only a catalog command declared for input delivery can use that variant. Field -inventories and image limits belong to OpenAPI. - -A message requires nonblank text or an image. Images accept PNG, JPEG, GIF, and -WebP, subject to decoding, dimension, and selected-provider bounds. The model -receives the text, then the images in upload order. The CLI marks where each was -attached with `[Image #N]` in the text, numbered from 1 in upload order. Pastes -are marked the same way, `[Paste #N, …]` for the Nth paste. The model receives a -paste under 100 lines and 32 KiB in place of its marker. A longer one is saved -to `$ALBEDO_HOME/pastes//-.md` and its marker names that -file. History shows the text as sent, markers intact. The daemon preserves -original upload metadata and the full durable payload. Provider-specific fitting -stays daemon-owned and appears in durable history. +inventories, image limits, and file limits belong to OpenAPI. + +A message requires nonblank text, an image, or a file. Images accept PNG, JPEG, +GIF, and WebP, subject to decoding, dimension, and selected-provider bounds. The +model receives the text, then the images in upload order. The CLI marks where +each was attached with `[Image #N]` in the text, numbered from 1 in upload +order. Pastes are marked the same way, `[Paste #N, …]` for the Nth paste. The +model receives a paste under 100 lines and 32 KiB in place of its marker. A +longer one is saved to `$ALBEDO_HOME/pastes//-.md` and its +marker names that file. History shows the text as sent, markers intact. The +daemon preserves original upload metadata and the full durable payload. +Provider-specific fitting stays daemon-owned and appears in durable history. + +A message can also carry generic `files`, each a name and base64 data. A message +with only files needs no text. Files require a local workspace, because the +daemon saves them on its own host. A remote workspace rejects them with +`attachment_workspace_unsupported`, and its images keep working. +[`uploads.check`](../src/albedo/daemon/uploads.gleam) checks the workspace, each +name, decoding, and the decoded total before preparation saves any paste or +file. [`uploads.expand`](../src/albedo/daemon/uploads.gleam) then saves each +file under `$ALBEDO_HOME/pastes//`. The saved name combines the input +ID and a content hash, with a short alphanumeric extension retained when +present. The uploaded filename is never a path component. The model's text gains +a system note with each quoted filename and saved path. History keeps the text +as sent. The user entry's `files` lists each file's name and decoded size in +upload order, without the path or bytes. Entries recorded without files omit the +field. Do not infer attachments from text that looks like a file label. + +Checking before writing is not a transaction. Saves happen during preparation, +before admission. The session actor checks the workspace again when it admits +the input, so a workspace that became remote in between still rejects it. A +write failure or that later rejection can leave saved files behind until the +[age-based sweep](../robot-docs/kernel-state.md#saved-pastes-and-uploads) +removes them. A `files` entry in history does not mean the saved bytes still +exist. Command inputs prepare a user turn. They do not invoke arbitrary management handlers. Their preparation produces content, runs outside the session actor, @@ -272,9 +295,12 @@ effects exposes its own domain operation instead. The first accepted PUT returns `202` with `Input`. An identical PUT returns the retained admission decision and current delivery state, using the original admission status. Changed intent under the same ID returns `409 input_conflict`. -Echo-only `client_id` does not change identity. Lookup happens before current -workspace, skill, provider, and queue validation. Defaults and skill content -resolve once. Rejected decisions are durable, including `429 queue_full`. +Echo-only `client_id` does not change identity. File names and data are part of +intent, and a message without files keeps its earlier intent. To change +attachments after a failure, send them under a new input ID. Lookup happens +before current workspace, skill, provider, and queue validation. Defaults and +skill content resolve once. Rejected decisions are durable, including +`429 queue_full`. `GET /sessions/{session_id}/inputs/{input_id}` returns the known decision even after session deletion. The input resource separates its admission decision, diff --git a/robot-docs/artifacts.md b/robot-docs/artifacts.md index 30de59501..ec7e0fb4f 100644 --- a/robot-docs/artifacts.md +++ b/robot-docs/artifacts.md @@ -50,7 +50,9 @@ user. `artifacts.url` requires a running albedo web process and returns a URL for a version or the latest version. See the [Python binding](../priv/python/albedo_plugins/artifacts.py). Artifacts differ from workspace [files](files.md): saving one uploads content into the artifact -store. +store. Files attached to a chat message are not artifacts. They are saved beside +pastes and expire by age. See +[saved pastes and uploads](kernel-state.md#saved-pastes-and-uploads). ## Related pages diff --git a/robot-docs/contributing.md b/robot-docs/contributing.md index 74848a148..8f46ec92d 100644 --- a/robot-docs/contributing.md +++ b/robot-docs/contributing.md @@ -145,6 +145,20 @@ before retrying. A missing answer does not establish that the operation did nothing. Keep operation identity across retries where the [admission contract](operations.md) requires it. +## Handle uploaded files + +Treat client-side attachment checks as convenience. The daemon validates names, +encoding, counts, and sizes again and decides admission. Build storage paths +from daemon-owned identity, such as the session, input ID, and content hash. Do +not use the uploaded filename as a path component. + +Record attachment metadata in the submission that owns the message. Do not infer +that a message had an attachment from text that looks like a label. Do not +resend changed attachments under an old input ID. A transcript can outlive the +saved bytes, so do not promise that a file named in history is still readable. +See [saved pastes and uploads](kernel-state.md#saved-pastes-and-uploads) and the +[web client's attachment rules](web.md#chat-attachments). + ## Test the observable change Use the shared real-daemon harness for externally visible behavior. Do not copy diff --git a/robot-docs/files.md b/robot-docs/files.md index c0e8d5435..1f1112dae 100644 --- a/robot-docs/files.md +++ b/robot-docs/files.md @@ -5,6 +5,11 @@ bounded reads, exact edits, directory listings, and searches in the kernel's environment. Relative paths resolve in that environment's working directory. See [workspaces](workspaces.md). +A file attached to a chat message reaches the model as a saved path under the +daemon home. The model can read that absolute path with `files.read` or other +kernel code. Attaching adds no plugin API and no sandbox. See +[saved pastes and uploads](kernel-state.md#saved-pastes-and-uploads). + ## Read `files.read(path, start_line=1, end_line=None, limit=None, max_chars=16000)` diff --git a/robot-docs/kernel-state.md b/robot-docs/kernel-state.md index f47eac811..3127bb435 100644 --- a/robot-docs/kernel-state.md +++ b/robot-docs/kernel-state.md @@ -65,9 +65,26 @@ for IDs absent from the known-session list, with a file modification time at least one day old. This policy is distinct from session activity retention. Successful state-file deletion also removes its jobs sidecar. +## Saved pastes and uploads + +Long pastes and uploaded chat files live under `$ALBEDO_HOME/pastes//`. +[`maintenance.prune_pastes`](../src/albedo/daemon/maintenance.gleam) runs during +the same expiry sweep and uses the same `ALBEDO_STATE_EXPIRY_SECONDS` retention. +[`albedo_pastes.prune`](../src/albedo/daemon/albedo_pastes.erl) deletes each +regular file whose modification time is older than the retention, then removes +empty session folders. + +This policy uses file age, not session activity. An active conversation does not +keep an old upload. A transcript can still name a file that has been deleted, so +retained history does not mean the bytes are available. Deleting a session does +not itself delete these files. They remain until the age-based sweep removes +them. + ## Related pages - [All topics](README.md) - [Change guidance](contributing.md) - [The detached kernel](kernel.md) - [Compaction](compaction.md) +- [Session attachment](sessions.md) +- [Web client](web.md) diff --git a/robot-docs/sessions.md b/robot-docs/sessions.md index 0fa64e8a4..5226dc74b 100644 --- a/robot-docs/sessions.md +++ b/robot-docs/sessions.md @@ -20,6 +20,21 @@ ACP cancellation has an additional attachment authorization check at the actor transition. See [ACP](acp.md) and [`acp_session.authorize_cancellation`](../src/albedo/daemon/acp_session.gleam). +## Attached files + +[`http_sessions.input`](../src/albedo/daemon/http_sessions.gleam) checks the +input's durable intent before preparation and admits it with +`session.admit_durable` afterward. Preparation expands pastes and attached files +before admission. [`uploads.gleam`](../src/albedo/daemon/uploads.gleam) +validates the files, saves them for a local workspace, and adds their paths to +the model's text only. The session actor checks the workspace again when it +admits the input. The display text stays as submitted. The submission keeps each +file's name and decoded size as history metadata, without the path or bytes. See +[input admission](../docs/http-sessions.md#input-admission-and-outcomes) for +retries and errors, and +[saved pastes and uploads](kernel-state.md#saved-pastes-and-uploads) for +retention. + ## Observation and streams A `Cursor` contains a generation and sequence. `session.read` returns a page of diff --git a/robot-docs/web.md b/robot-docs/web.md index f6c2826bd..314220c95 100644 --- a/robot-docs/web.md +++ b/robot-docs/web.md @@ -26,6 +26,52 @@ client also renders artifacts, which have a separate `/frame/` path in sandbox headers and forwards artifact requests separately from authenticated `/api` requests. See [artifacts](artifacts.md) for their execution boundary. +## Chat attachments + +The chat composer attaches images and other files from its picker, from paste, +and from a drop anywhere on the chat. [`main.ts`](../web/src/main.ts) stops a +file drop outside a chat from navigating the page. Images appear as tiles in the +editor. Other files appear as removable cards with a name and size. +[`Composer.svelte`](../web/src/lib/chat/Composer.svelte) and +[`Chat.svelte`](../web/src/lib/chat/Chat.svelte) own this presentation. + +[`attachments.ts`](../web/src/lib/chat/attachments.ts) reads files and checks +the browser limits in `attachmentProblem`: ten images, ten other files, and 20 +MiB of decoded bytes for both kinds together. These limits keep a send inside +what the daemon accepts. They are not authorization. The daemon checks its own +bounds and can still reject a send. See +[input admission](../docs/http-sessions.md#input-admission-and-outcomes). + +[`Draft`](../web/src/lib/chat/drafts.ts) owns the attachments of an unsent +message, by session, so they survive a board switch. It reads files one at a +time and reports the result even if the composer unmounted meanwhile. +`Draft.reading` and `Draft.problem` block Send while a read is pending or the +selection is over a limit. The send handler checks again before it clears the +draft. Do not clear a draft before that check, and do not drop files to fit a +limit. Let the user remove or split them. Moving a draft into a canvas note +moves its prose. Image tiles and file cards stay in the chat. + +Attachment bytes live only in memory. The draft text is saved to `localStorage` +without its `[Image #n]` markers, and a page reload loses its images and files. +Other text is kept as typed. Literal text that looks like a file label, such as +`[File #1: notes.txt]`, stays in the draft and the message. + +Generic files require a local workspace, because the daemon saves them on its +own host and gives the model their path. For a remote-workspace session, the +composer accepts images and refuses other files. The daemon rejects them too. + +[`Transcript`](../web/src/lib/transcript.svelte.ts) keeps a pending send's +payloads in memory. A reload drops that copy, including a failed send that was +waiting for retry. Retry resends the same input ID with the same text and +attachments. When a stop cancels queued sends, `Transcript.take` returns them +and `Draft.restore` appends their text and attachments to the draft. A restored +selection can exceed the limits, so Send stays blocked until the user removes +some. A committed message shows file cards only from the history entry's `files` +metadata, never from its text. Images use the entry's image references. Saved +bytes can expire while the history remains. See +[saved pastes and uploads](kernel-state.md#saved-pastes-and-uploads) and the +[uploaded-file rules](contributing.md#handle-uploaded-files). + ## Settings [`Settings.svelte`](../web/src/lib/Settings.svelte) owns the settings interface. -- knotmirror 0.0.1