Skip to content

Plugins: accept a file as base64 (#1727) - #1730

Closed
michielbdejong wants to merge 2 commits into
claude/plugin-accepts-filefrom
claude/accepts-binary
Closed

michielbdejong wants to merge 2 commits into
claude/plugin-accepts-filefrom
claude/accepts-binary

Conversation

@michielbdejong

Copy link
Copy Markdown
Contributor

Closes #1727. Stacked on #1691 (claude/plugin-accepts-file).

What a plugin receives

An accepts entry takes an optional as:

"accepts": [{ "extensions": [".willow"], "as": "base64", "maxBytes": 1000000 }]

input.upload (ctx.upload in run) carries the file in a field named after the declared encoding:

as ctx.upload
"text", or left out { name, mediaType, size, text }, UTF-8 with a Windows-1252 fallback (unchanged)
"base64" { name, mediaType, size, base64 }, the exact bytes, standard padded base64, no charset detection

size is the file's byte size in both cases. The sandbox has atob, so atob(ctx.upload.base64) returns a binary string with one character per byte.

Changes

  • Manifest (server/src/plugins/manifest.rs, browser/lib/src/plugin-manifest.ts): as is optional and is kept exactly as declared. If it's left out, it stays out of the serialized form. If it's an explicit "text" (what Plugins: let a plugin accept a file and declare its destination (#1653) #1691 required), it stays in. Existing release ids don't change either way. Any other value, including "Base64" or 64, fails in both validators with accepts entries must be read \as` text or base64`.
  • Server (check_upload in plugin_run.rs):
    • The upload must carry exactly one of text or base64.
    • Some accepts entry must declare that encoding.
    • maxBytes is checked against the raw size (for base64, the decoded length, not the length of the string). Invalid base64 is refused.
  • Browser: @tomic/lib gets acceptFor and readUpload, which build input.upload. FileImport.tsx uses them in place of its own decode. The UI doesn't change.
  • Docs: accepts has been added to the manifest v2 field list in docs/src/plugins/creating-plugins.md, and the DeclaredAccept / Accept doc comments describe the wire format.

Tests

New fixtures only; no existing fixture file was edited. One existing case was renamed in index.json: "v2 accepts only text" is now "v2 accepts an unknown as".

  • testdata/plugin-manifest/:
    • v2-accepts-base64.json is accepted and serialized with as.
    • v2-accepts-default-text.json has no as and is serialized without one.
    • v2-accepts-as-upper-case.json and v2-accepts-as-not-string.json are rejected.
  • release.rs accepts_without_as_keeps_the_release_id: the default-text fixture and Plugins: let a plugin accept a file and declare its destination (#1653) #1691's explicit-"text" fixture give the same release id before and after parsing.
  • js_runtime.rs a_base64_upload_reaches_the_plugin_byte_for_byte: bytes 0–255 go through the real sandbox, the plugin decodes them with atob, and every byte comes back.
  • plugin_run.rs:
    • The raw size is what's limited: 256 bytes (344 base64 characters) pass maxBytes: 256, and 257 bytes fail.
    • The encoding must be one that was declared.
    • Invalid base64 is refused, and so is an upload with both fields.
    • MT940 text mode is unchanged.
  • plugin-upload.test.ts:
    • Bytes 0–255 round-trip through base64.
    • A 100 KB file larger than the chunk size keeps every byte.
    • MT940 in UTF-8 and in Windows-1252 decodes to the same text, whether as is text or left out.
    • acceptFor picks the right entry.

Checks run:

  • cargo test -p atomic-server --lib -- plugins:: handlers::plugin_run
  • cargo clippy -p atomic-server --all-targets (clean)
  • browser/lib vitest: 967 passed
  • data-browser typecheck

🤖 Generated with Claude Code

An `accepts` entry takes an optional `as: "text" | "base64"`, text by
default. With base64 the host hands over the file's exact bytes as
`input.upload.base64`, with no charset detection; text mode still
arrives as `input.upload.text`, so a plugin can tell them apart.

- `as` is kept as declared: left out, it stays out of the serialized
  manifest, and an explicit "text" stays in, so no release id moves.
- Both validators accept text or base64 and reject anything else with
  the same message, checked against new shared fixtures.
- The server checks the upload is in a declared encoding and bounds it
  by its raw size: the decoded length for base64, not the string's.
- The data browser picks the matching `accepts` entry and reads the
  file with `readUpload` from @tomic/lib.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michielbdejong michielbdejong added enhancement New feature or request plugin Should probably be an Atomic Plugin labels Sep 24, 2026
michielbdejong pushed a commit that referenced this pull request Sep 24, 2026
Conflicts, both sides kept:
- routes/IntegrationStore.tsx: the drive-apps count in nothingToDiscover
  next to #1742's gated catalog (marked releases and their refusals).
- locales/en.po: the CatalogApps/FileImport/InstallationConnections
  entries next to #1742's PublicEndpoints entries; no duplicate msgids.
- browser/lib/src/index.ts: #1730's plugin-upload exports next to
  #1742's checkGate, parsePluginRoutesStatus and requiresGate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pre-commit format check was skipped when this branch was committed
with --no-verify.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michielbdejong

Copy link
Copy Markdown
Contributor Author

Merge-risk triage (2026-09-28). This is a read-only review of this PR's own diff. The rule it applies: nothing that works today may break for existing users or clients, and new behaviour is added alongside the old. The stack is being rebased onto develop as one chain before merging, so line references are against the current stacked base.

Verdict: SAFE

Additive. as is optional and defaults to text, an explicit "as":"text" still validates, and the release id stays the same when as is left out (accepts_without_as_keeps_the_release_id). The upload size check is now per encoding and uses decoded bytes.

Note: #1774 needs this PR's acceptFor/readUpload after the rebase.

🤖 Generated with Claude Code

@michielbdejong

Copy link
Copy Markdown
Contributor Author

Closing as part of the plugin-host stack cleanup (Q-101): not needed by atomic-plugins now. See the inventory at #1726 (comment). The branch is kept, and pin candidates are unaffected. Closed by Claude (VPS coordinator) on behalf of Michiel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request plugin Should probably be an Atomic Plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant