Skip to content

fix(kiro): use CLI wire contract without profiles - #694

Merged
lidge-jun merged 2 commits into
lidge-jun:devfrom
byongshintv:fix/kiro-cli-auth-compat
Jul 29, 2026
Merged

fix(kiro): use CLI wire contract without profiles#694
lidge-jun merged 2 commits into
lidge-jun:devfrom
byongshintv:fix/kiro-cli-auth-compat

Conversation

@byongshintv

@byongshintv byongshintv commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Use Kiro's CLI-shaped request contract for Builder ID credentials and Kiro API keys, which have no profile ARN.
  • Preserve the existing IDE-shaped contract for enterprise credentials with a profile ARN.
  • Add the CLI origin, environment state, agent continuation fields, CLI user agents, and the API_KEY token type only where required.
  • Keep the current conversation validation, bounded completion, stream parsing, and replay-safety behavior unchanged.

This fixes profile-less Builder ID requests being routed through the IDE contract, where the service expects a profile ARN. The request shape is based on an observed Kiro CLI request.

Verification

  • bun test tests/kiro-images.test.ts tests/kiro-stream.test.ts tests/kiro-adapter.test.ts tests/kiro-review-regressions.test.ts tests/kiro-retry.test.ts tests/kiro-oauth.test.ts (225 passed)
  • bun run typecheck
  • bun run privacy:scan
  • bun run test (5,900 passed, 1 Windows-only test skipped, 0 failed)
  • Live Builder ID smoke test against the Kiro runtime: HTTP 200 using the CLI wire contract with no profile ARN. No token or response body was logged.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. No user-facing configuration changes are required.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. Bearer tokens remain confined to the Authorization header; profile ARNs are preserved only for enterprise IDE requests; tokentype: API_KEY is added only for ksk_ credentials.

Summary by CodeRabbit

  • New Features
    • Added support for Kiro CLI request mode, including CLI-specific headers, user-agent, and authentication behavior (including API key token type handling).
    • CLI requests now include CLI-origin message metadata and conversation state details in the request payload.
  • Bug Fixes
    • Refined request formatting to correctly distinguish CLI vs IDE/OAuth header expectations (including accept and agent-mode fields).
    • Updated conversation history metadata so CLI-originated messages are labeled consistently.

Co-authored-by: OpenAI Codex <codex@openai.com>
@github-actions github-actions Bot added the bug Something isn't working label Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5994f66f-5f5f-45cf-93fa-e1a20cf62708

📥 Commits

Reviewing files that changed from the base of the PR and between 28996a4 and 9b5b827.

📒 Files selected for processing (2)
  • src/adapters/kiro.ts
  • tests/kiro-adapter.test.ts

📝 Walkthrough

Walkthrough

Kiro adapter requests now distinguish CLI and IDE callers. CLI requests receive dedicated headers and conversation metadata, while IDE requests retain their existing origin and profile behavior. Tests cover CLI, API-key, OAuth, and conversation-history contracts.

Changes

Kiro CLI and IDE wire contracts

Layer / File(s) Summary
CLI payload contract
src/adapters/kiro.ts
Adds wire-client typing and CLI-specific payload fields, including KIRO_CLI origin, agentContinuationId, and agentTaskType.
Caller-specific request construction
src/adapters/kiro.ts
Selects CLI or IDE request shaping from API-key and profile context, builds corresponding headers, forwards wireClient, and includes it in diagnostics.
Wire-contract test coverage
tests/kiro-adapter.test.ts
Verifies CLI headers and payloads, API-key token semantics, OAuth metadata headers, and CLI conversation-history origins.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant KiroClient
  participant createKiroAdapter
  participant buildKiroPayload
  participant KiroAPI
  KiroClient->>createKiroAdapter: build request
  createKiroAdapter->>createKiroAdapter: select CLI or IDE wireClient
  createKiroAdapter->>buildKiroPayload: buildKiroPayload(..., wireClient)
  buildKiroPayload-->>createKiroAdapter: caller-specific conversation payload
  createKiroAdapter->>KiroAPI: send headers and payload
Loading

Possibly related PRs

Suggested reviewers: lidge-jun, ingwannu, wibias

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: Kiro now uses the CLI wire contract when no profile is present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 28996a4cfb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/adapters/kiro.ts Outdated
"x-amz-target": AMZ_TARGET,
"user-agent": kiroCliUserAgent(true),
"x-amz-user-agent": kiroCliUserAgent(false),
"x-amzn-codewhisperer-optout": "false",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve the CodeWhisperer privacy opt-out

For every profile-less Builder ID or Kiro API-key request, this branch changes the previously sent x-amzn-codewhisperer-optout value from true to false. This silently reports that the user has not opted out of CodeWhisperer data collection even though ocx exposes no setting or consent flow for that reversal; keep the header at true unless an explicit user preference enables participation.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9b5b827. CLI-shaped requests now preserve x-amzn-codewhisperer-optout: true. Verified with the focused Kiro suite and a live profile-less Builder ID request (HTTP 200).

Comment thread src/adapters/kiro.ts Outdated
if (wireClient === "cli") {
currentUim.userInputMessageContext = {
...(currentUim.userInputMessageContext ?? {}),
envState: { operatingSystem: kiroCliPlatform(), currentWorkingDirectory: process.cwd() },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not report the proxy process as the client environment

When the persistent proxy starts from project A and later serves a request from project B—or runs as a background service or for a remote client—process.cwd() and process.platform describe the proxy process, not the requesting Codex client's workspace and OS. The CLI-shaped payload therefore gives Kiro stale or incorrect environment state, which can make generated tool paths and shell commands target the wrong project while also disclosing an unrelated local path; propagate trusted per-request client metadata or use neutral values instead.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9b5b827. The adapter no longer sends proxy-process envState; no client workspace or OS is fabricated or disclosed. A live profile-less Builder ID request without envState returned HTTP 200.

Comment thread src/adapters/kiro.ts Outdated
const profileArn = resolveKiroProfileArn(parsed._kiroAuthContext);
// Builder ID and Kiro API keys have no profile ARN and are accepted only on Kiro's CLI
// request path. Enterprise profiles retain the existing IDE-shaped request.
const wireClient: KiroWireClient = profileArn ? "ide" : "cli";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Force Kiro API keys onto the CLI contract

When a custom Kiro API-key provider is used while KIRO_PROFILE_ARN is set or the local Kiro CLI database contains a profile ARN, resolveKiroProfileArn() returns that unrelated profile and this condition selects the IDE contract solely because it is nonempty. The resulting ksk_ request includes the profile ARN and omits the tokentype: API_KEY header, so authentication is sent using the exact contract this change says API keys cannot use; determine API-key status first and ignore profile metadata for those credentials.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9b5b827. ksk_ detection now precedes wire-client selection, forces CLI mode, and clears resolved profile metadata. The regression test supplies an unrelated profile ARN and asserts that neither the header nor payload contains it while tokentype: API_KEY remains present.

Co-authored-by: OpenAI Codex <codex@openai.com>
@lidge-jun
lidge-jun merged commit b898824 into lidge-jun:dev Jul 29, 2026
4 checks passed
lidge-jun added a commit that referenced this pull request Jul 29, 2026
…ion hardening, Windows scheduler fixes

Promotes dev to main for the v2.7.43 quick-fix release:
- fix(gui): renew loopback dashboard sessions silently instead of prompting
- PR #705 + follow-up: Claude effort restoration boundary hardening
- PRs #694/#698/#699 and Windows scheduler compare/denial fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants