Files
archie/internal/tools/sendfile
sam 0b2398f026 feat(telegram): send local files as uploads, not fetchable URLs
The agent could produce a file -- a transcript, a log dump, a screenshot --
and had no way to hand it over. Asked to send one it offered a "download"
link; nothing arrived and it had no signal that anything had failed. The
defect was not that it lied: success and silent non-delivery were
indistinguishable to it.

Three places made a local file undeliverable, and each is fixed here:

  - liveReply.Media skipped any attachment with an empty URL, so a local
    file was dropped before it ever reached a sender.
  - telegramMediaSender built every attachment as models.InputFileString,
    which tells Telegram to FETCH the string as a URL. A host path is not
    fetchable, so the send did nothing while reporting success. It now
    chooses by what the attachment carries: URL -> fetch, Path -> upload
    via models.InputFileUpload over an open file.
  - Nothing let the agent ask for a send at all. New send_file tool
    (internal/tools/sendfile) validates the file and returns a
    MultimodalResult naming it; the turn's channel delivers it.

Meaning changes, called out because the names did not:

  - MediaAttachment gains Path, the alternative to URL. Exactly one is
    meaningful for an outbound send.
  - tools.MultimodalResult.URLs used to mean remote-hosted media only; it
    now means media this result wants delivered, which may be local. JSON
    name unchanged so existing producers keep working.
  - errNoURL is now errNoSource: having neither source, not having no URL,
    is what makes an attachment undeliverable.

Failures are visible at every layer, which is the actual fix. send_file
errors on an absent, irregular, unreadable, oversized or confinement-
refused path, so the model sees it and can report it. The sender checks
Telegram's ceilings (10 MB photos, 50 MB otherwise) before the request and
reports the real size rather than leaving a 400 nobody reads. A delivery
that still fails now appends "could not send <name>" to the reply instead
of an empty link, which read as a delivered file.

Exposing a public URL for local files was explicitly rejected: it trades a
missing feature for a hosting and access-control problem.

send_file resolves paths through builtin.ResolveReadable -- the read tool's
own policy, exported rather than reimplemented -- so sending cannot reach
what reading cannot, whatever [chat] unrestricted_filesystem is set to.
2026-08-25 01:43:15 +10:00
..