0016 · Attachments for agents with inject, in the same decision as the item
- Status: accepted
- Date: 2026-11-02
Context
ADR 0014 §9.3 left attachments out of the agents' scope. In the real milestone A test this showed up twice:
- The case that motivates
injectin the design (§7) is Apple's.p8: a file that a tool only accepts on disk. An agent withinjectcouldn't write it, neither withinject_filenor with the[files]ofklav.toml. - The "what it saw" report marked the
APNsitem withSECRET: yeseven thoughinject_filehad failed. The server recorded an allowedinject(it handed over the details), but those details had no value at all: the item's only secret is the attachment, and the server never handed it over.
Through its grant, the agent already has everything needed to decrypt an attachment: the project key opens the item key, and that one opens the attachment's (spec §10). What was missing is the server handing it over behind the same policy barrier as the details.
Decision
1. A single request and a single decision
POST /v1/agent/access accepts include_attachments: true, only with inject. If the policy allows it, the response carries, besides the item, all its completed, non-deleted attachments: metadata with the wrapped key and the ciphertext.
- It is the same decision: with
ask, one approval (or one lease) covers the item and its attachments. A second download route would have needed another check, and with "approve once" the approval would already be spent on the first request. - The server doesn't know which field the agent asked for (the details are encrypted), so it hands over all the item's attachments. The runtime asks for
include_attachmentsonly if the item has any. - Limit: 16 MiB of ciphertext in total per request (
MAX_AGENT_ATTACHMENTS_BYTES). Above that,400, before evaluating the policy: it leaves no event in the audit log because nothing is handed over. Typical keys and.p8files weigh a few KiB. search_itemsandget_itemshow how many attachments an item has (attachments), so the agent knows it can ask for them. The field name goes in the encrypted details: the agent knows it from the person or from the reference it is given.- So that the runtime knows whether an item has attachments,
GET /v1/agent/itemslists the attachment metadata of each project (without content). It isn't new information: the agent can already decrypt those items' keys.
2. No new cryptography
The runtime (klav-sdk) decrypts with the usual hierarchy and only with klav-core: the grant's project key opens the item key (unwrap_item_key), that opens the attachment's (unwrap_attachment_key, with the full AttachmentContext in the AAD) and STREAM opens the content (decrypt_attachment_bytes). It checks that each attachment belongs to the requested item and has the declared size. An attachment that doesn't open is an error, never a half-written file.
3. Where an attachment can go
Only to a file, never into the LLM's context:
- MCP
inject_filewithref(andklav agent inject -r,injectin@klav/sdk): writes the bytes as they are into a new 0600 file. [files]ofklav.tomlinrun_with_secrets(andklav agent run): they are written before the command and deleted when it ends.- Into an environment variable, only if it is UTF-8 with no null bytes; otherwise, an error.
- Into a template, never (as in the person's
klav inject). For templates the runtime doesn't even ask for the attachments. revealandfilldon't hand over attachments.
If a command prints the content of a text attachment, the output shows it as [redacted by klav], the same as variables.
4. The audit log says what was handed over
The agent.access event carries attachments, the list of attachments handed over, only when the result is allow. The field is optional and omitted when empty, so earlier events have the same hash and klav log verify doesn't change. The server reads the content before recording the decision: if it can't read it, no event is left saying it was handed over.
5. A "what it saw" report that doesn't exaggerate
SECRET is computed on the person's device, which can read the item:
yesif any attachment was handed over (yes (file)in the table,attachmentsin--json);yesif the details were handed over (fill,inject,totp,revealallowed) and the item has any secret field with a value, or notes;yesif the device can't open the item (deleted or not synced): when in doubt, it is marked;nootherwise, such as an item whose only secret is an attachment that was never handed over.
The content that counts is the item's current content: if the person later deleted its secret fields, an earlier access shows no even though it handed over values at the time. This is accepted: the report is for deciding what to change now, and a value that is no longer in the item has to be changed at the source anyway.
In addition, the runtime checks before asking for anything what can fail in advance: that the target file doesn't exist (without overwrite) and that its directory exists, also for each [files] entry. That way a common failure doesn't leave in the audit log an access that served no purpose.
Consequences
- Additive changes in
klav-proto:AccessRequest.include_attachments,AccessGranted.attachments(AgentAttachment),AgentProjectItems.attachmentsandAuditEvent.attachments. No migration. - Injecting a text field from an item with attachments also downloads its attachments, and the report counts them as handed over. It is conservative and capped at 16 MiB. Separating fields and attachments would require the server to know which field each attachment belongs to, which today is encrypted.
- Residual risk: the report is still based on what the server handed over. A compromised runtime that received the details has whatever they contain; what this ADR changes is that an item with no text values is no longer marked as if it had them.
- Replaces the last sentence of 0014 §9.3 ("Attachments aren't available to agents yet").