Files
plugins/packages/kiro/README.md
T
yetone ceda580080 kiro 0.1.18: an image over Kiro's 5 MiB Base64 limit is shrunk on the request, or replaced by a note (#428)
imwaco (#428): in Codex -> magpie -> Kiro, view_image returned a PNG of
4,171,428 bytes, 5,561,904 as Base64, and Kiro answered
  messages.130.content.2.image.source.base64: image exceeds 5 MB maximum:
  5561904 bytes > 5242880 bytes (IMAGE_SIZE_EXCEEDED)
on that turn and on every later one, text-only ones too, as the image
stays in history. The limit is on the Base64 string: 5561904 is that
image's Base64 length, not its file size, so the largest file that fits is
3,932,160 bytes. kiro-cli's own gate is 10 MB of raw file
(MAX_IMAGE_SIZE, aws/amazon-q-developer-cli chat/consts.rs), the gap
kirodotdev/Kiro#11497 describes.

buildKiro's conversation is now built as an object (kiroRequest) and,
after the latest-image selection, kiroBody fits every image left in it,
user images and tool images in history alike, on the plugin's own copy:
- an image at or under 5,242,880 Base64 characters is sent byte for byte;
- one over it is decoded with Bun.Image (Bun 1.4's built-in libspng /
  libjpeg-turbo / libwebp, no new dependency; magpie's host and OpenCode
  2.0.25 both run Bun 1.4.2) and tried, in order: its own kind with the
  long edge at most 2000 px, then WebP (keeps alpha) or JPEG for a JPEG,
  q80, then 0.7x smaller at q75 down to 256 px, until it fits;
- bounds: 50M pixels (a header claiming more is refused before decoding),
  64 MB of Base64 looked at, 30 s per image; one image is worked once per
  sha256 (in-flight shared, 4 kept);
- one that can't be read, has too many pixels, can't be brought under, or
  a host without Bun.Image: the image is left out and a one-line note
  takes its place in that message's text, so the turn still goes.
History, entry count, tool pairing and image order are unchanged.

Run:
- HOME=$(mktemp -d) bun test packages/kiro: 67 pass (image-size.test.mjs
  new, 10 tests); the same under OpenCode 2.0.25's Bun (BUN_BE_BUN=1
  opencode test packages/kiro): 67 pass. bun scripts/check.mjs kiro: ok.
- Fixtures are built in the test: a 1389x1000 noise PNG padded to exactly
  4,171,428 bytes (5,561,904 Base64), PNGs at 3,932,159 / 3,932,160 /
  3,932,161 bytes (Base64 5,242,880 with "=", 5,242,880, 5,242,884), a
  20000x20000 header bomb and 4 MB of junk.
- Full HOME=$(mktemp -d) bun test at 18268848: 2851 pass, 1 fail:
  layerfs "item 3: an import over the file limit" timed out at its 30 s
  bar (46 s) writing 20,001 files at load ~40; it fails alone too at this
  load, and the kiro change doesn't reach layerfs.
Broken by hand: kiroBody without fitImages: 7 of 10 fail; no cache: the
once-per-image test fails; `<` for `<=` at the limit: the boundary test
fails.
Not tried: a real Kiro account (none in a sandbox; no live sign-in read);
an animated GIF over the limit (Bun decodes its first frame only).
2026-10-27 17:27:57 +08:00

135 lines
6.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# @magpie-community/opencode-kiro-auth
Signs in to a [Kiro](https://kiro.dev) subscription (Free, Pro, Pro+,
Power) and makes its requests, in OpenCode and in magpie. Provider id:
`kiro`.
## Signing in
- **Kiro (Google, GitHub, AWS Builder ID, IAM Identity Center)**: the Kiro
IDE's own sign-in.
- Kiro's page (`app.kiro.dev/signin`) sends the browser back to one of
the ports the IDE listens on (3128, 4649, 6588, 8008, 9091, 49153,
50153–53153) on `127.0.0.1`. While the IDE is signing in, those ports
may be busy.
- Google and GitHub come back with a code. Kiro's auth service trades it
for tokens.
- Builder ID and Identity Center come back with an AWS sign-in URL and
region. The plugin registers a client with AWS's OIDC service, sends
the browser to AWS, and trades the code AWS returns.
- The account is named by the email Kiro has for it (`Get-Usage-Limits`)
and the way it was signed in to: `email (Google)`, `email (GitHub)`,
`email (Builder ID)`, `email (IAM Identity Center)`, `email
(Internal)`. Its plan is read from the same call, and its usage names
it the same way.
- Kiro keeps a Google, a GitHub, a Builder ID and an Identity Center
sign-in of one email as different accounts. The sign-in carries a `uid`
(`google`, `github`, `builderid`, `enterprise`), so magpie keeps each one
beside the others, and a sign-in again the same way replaces only its
own account. An account signed in before 0.1.13 is given its `uid`,
and one named by its bare email before 0.1.14 its name, on its first
request, model listing, usage read or renewal. Until then, a sign-in
again the same way goes beside it rather than replacing it: magpie
matches a sign-in by its name, and the plugin can't see the other
accounts to match it by `uid`.
- A company's own identity provider (`external_idp`) is not supported
here. Sign in with `kiro-cli login` and use the next method instead.
- **Kiro CLI's or Kiro IDE's sign-in**: uses the account kiro-cli is signed
in to, or else the Kiro IDE's. Nothing is copied. It is read each time
from where they keep it:
- kiro-cli: its SQLite database's `auth_kv` table.
- macOS: `~/Library/Application Support/kiro-cli/data.sqlite3`
- Linux: `~/.local/share/kiro-cli/data.sqlite3`
- Windows: `%APPDATA%\kiro-cli\data.sqlite3`
- The IDE: `~/.aws/sso/cache/kiro-auth-token.json`.
kiro-cli refreshes its own token first (`kiro-cli debug refresh-auth-token`).
A token the plugin refreshes itself is written back, so kiro-cli and the
IDE go on with it.
- **Kiro API key (`ksk_…`)**: sent with `tokentype: API_KEY`, as kiro-cli
sends it. `GetProfile` is asked in us-east-1, then eu-central-1, for the
region the key's profile is in; a key it finds none for is used in
us-east-1, as kiro-cli uses it. Its models are listed with the control
plane's `ListAvailableModels` and its credits with `GetUsageLimits`, and
no profile is named in its calls, as kiro-cli names none.
A browser sign-in is kept where OpenCode keeps sign-ins (`auth.json`; in
magpie, `plugin-auth.json`) as an `oauth` entry. The entry holds the
tokens, the profile ARN, the region and, for AWS, the registered client.
Refreshing such a sign-in:
- magpie renews the token 10 minutes before it expires, through the
plugin's `auth.refresh`, once for the account and before its requests,
models and usage need it. magpie saves the new token. A failed renewal,
even one Kiro refused, doesn't mark the account: it is tried again.
- OpenCode doesn't call that hook: there the token is refreshed 2 minutes
before it expires, before a request, and saved.
- Either way, a token Kiro turns down (a 403) is refreshed and the request
tried once more.
- Only one refresh runs at a time, magpie's renewal included, and a token
refreshed but not yet saved is used rather than spending the old refresh
token again.
- kiro-cli's and the IDE's sign-ins aren't renewed by magpie: they are
refreshed before a request, as above, and written back.
Tokens are refreshed through:
- Google/GitHub: through `prod.<region>.auth.desktop.kiro.dev/refreshToken`.
- Builder ID/Identity Center: through AWS's `oidc.<region>.amazonaws.com/token`.
## Requests
Kiro has no API OpenCode speaks. The models are declared on Anthropic's
Messages (`@ai-sdk/anthropic`), and the plugin's `fetch` handles each
request:
- It sends the request to `runtime.<region>.kiro.dev/generateAssistantResponse`,
the API kiro-cli uses, with kiro-cli's headers. The region is the one the
profile ARN names.
- It turns the request into a Kiro conversation:
- The system prompt goes at the head of the first message.
- Tool calls and results are paired: an unanswered call gets an error
result, and a result longer than 250,000 characters is cut.
- Tool ids Kiro wouldn't take are rewritten. A tool name over 64
characters (an MCP plugin's, in Claude Code) is sent shortened with a
hash and its calls come back under the full name.
- A tool's images (a screenshot, Codex's view_image) go with the
message that answers the call, as Kiro's tool results hold text alone.
- Only the latest images are sent.
- An image Kiro would turn away for size (over 5 MiB as Base64, which is
3.75 MiB of file) is made smaller on the request being sent: its long
edge brought to 2000 pixels, then WebP or JPEG, smaller each try. One
that can't be read or brought under is replaced by a short note, so the
conversation goes on (#428). Smaller images are sent as they are.
- Tools the history used but the request doesn't offer are declared.
- It turns the AWS event stream Kiro answers with back into Messages'
events (streamed) or one message. The reply includes text, thinking,
tool calls and usage. When Kiro reports only how full the context is,
input tokens are estimated from that.
- Thinking (Claude models and Auto) is asked for the way kiro-cli asks, in
the prompt, with a budget: low 10k, medium 20k, high 30k, xhigh and max
50k (as magpie's built-in Kiro: #120). The
`<thinking>` block of the reply comes back as thinking.
- Kiro's failures keep their meaning:
- input too long → 400
- no capacity → 503
- usage limit → 429
- throttling → "rate limited"
## Models
The `config` hook declares `auto` (Kiro picks the model). Once signed in,
the `provider.models` hook replaces it with the account's own list from
`List-Available-Models`, with the default first. Each model carries its
context window, output limit and whether it takes images. Claude models
and Auto have the thinking variants.
## Not included
- Usage and quota (credits, the monthly window).
- Switching between several accounts. OpenCode keeps one sign-in per
provider.
- Signing in with a company's own identity provider in the browser (use
kiro-cli's sign-in).
- magpie's web-search stand-in for Kiro.