Skip to content

feat: auto-detect profileArn from Kiro Agent IDE local storage - #239

Open
Yashwant00CR7 wants to merge 5 commits into
jwadow:mainfrom
Yashwant00CR7:feature/auto-detect-profile-arn
Open

feat: auto-detect profileArn from Kiro Agent IDE local storage#239
Yashwant00CR7 wants to merge 5 commits into
jwadow:mainfrom
Yashwant00CR7:feature/auto-detect-profile-arn

Conversation

@Yashwant00CR7

Copy link
Copy Markdown

Feat: Auto-detect profileArn from Kiro Agent IDE local storage

Summary

This pull request introduces an automatic resolution mechanism for the profileArn parameter by reading the local settings/profile storage file (profile.json) generated by the Kiro Agent IDE (OpenCode / Kiro Desktop). This resolves the profileArn is required for this request completions error (HTTP 400) out-of-the-box for Kiro Agent IDE users, without requiring manual environment variable configurations or SQLite database syncing.

Context & Root Cause

The Kiro completion endpoints (runtime.kiro.dev) now strictly require the presence of a valid profileArn in the request payload for all authentication types (including personal Builder ID / AWS SSO accounts).

Previously, PR #186 bypassed this validation for Builder ID accounts by omitting the profileArn field from the request payload. However, due to recent upstream API updates, omitting it now results in a validation exception:

{"__type":"com.amazon.kiro.runtimeservice#ValidationException","message":"profileArn is required for this request."}

Because the standard AWS SSO token cache file (kiro-auth-token.json) does not store the profileArn, the gateway could not retrieve it automatically.

Fortunately, the Kiro Agent IDE saves the active session's profile configuration—including the correct profileArn—inside profile.json in its global storage path.

Proposed Changes

1. Utilities (kiro/utils.py)

  • Implemented detect_kiro_agent_profile_arn() to locate the platform-specific Kiro global storage directory:
    • Windows: %APPDATA%\Kiro\User\globalStorage\kiro.kiroagent
    • macOS: ~/Library/Application Support/Kiro/User/globalStorage/kiro.kiroagent
    • Linux: ~/.config/Kiro/User/globalStorage/kiro.kiroagent
  • Reads and parses profile.json (both directly and recursively inside kiro.kiroagent to accommodate subfolders) to extract the profile ARN.

2. Authentication (kiro/auth.py)

  • Integrated detect_kiro_agent_profile_arn() as a fallback inside the KiroAuthManager.profile_arn property.
  • When PROFILE_ARN is not set in .env and is not present in the active SQLite database credentials, the manager dynamically resolves and caches the profileArn from the IDE's storage.

3. Tests (tests/unit/test_auth_manager.py)

  • Added test_profile_arn_fallback_auto_detection to verify the fallback logic correctly reads the file.
  • Added test_profile_arn_returns_none_if_no_detection to ensure the property defaults to None gracefully if the file is missing or invalid.

Verification & Testing

  • Ran all unit and integration tests successfully (pytest --ignore=tests/unit/test_routes_anthropic_shim.py):
    ============================ 1716 passed in 24.97s ============================
    

@cla-bot

cla-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

Thanks for the PR! 🎉

Before merge, we need a one-time CLA confirmation.
It confirms that you have the right to contribute this code and allow the project to use it.

Full CLA text:
https://github.com/jwadow/kiro-gateway/blob/main/CLA.md

Please reply once with:

I have read the CLA and I accept its terms

You need to write once, all further messages from me can be ignored.

@cla-bot

cla-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

Thanks for the PR! 🎉

Before merge, we need a one-time CLA confirmation.
It confirms that you have the right to contribute this code and allow the project to use it.

Full CLA text:
https://github.com/jwadow/kiro-gateway/blob/main/CLA.md

Please reply once with:

I have read the CLA and I accept its terms

You need to write once, all further messages from me can be ignored.

@cla-bot

cla-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown

Thanks for the PR! 🎉

Before merge, we need a one-time CLA confirmation.
It confirms that you have the right to contribute this code and allow the project to use it.

Full CLA text:
https://github.com/jwadow/kiro-gateway/blob/main/CLA.md

Please reply once with:

I have read the CLA and I accept its terms

You need to write once, all further messages from me can be ignored.

@Yashwant00CR7

Copy link
Copy Markdown
Author

I have read the CLA and I accept its terms

@cla-bot

cla-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

Thanks for the PR! 🎉

Before merge, we need a one-time CLA confirmation.
It confirms that you have the right to contribute this code and allow the project to use it.

Full CLA text:
https://github.com/jwadow/kiro-gateway/blob/main/CLA.md

Please reply once with:

I have read the CLA and I accept its terms

You need to write once, all further messages from me can be ignored.

@cla-bot

cla-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

Thanks for the PR! 🎉

Before merge, we need a one-time CLA confirmation.
It confirms that you have the right to contribute this code and allow the project to use it.

Full CLA text:
https://github.com/jwadow/kiro-gateway/blob/main/CLA.md

Please reply once with:

I have read the CLA and I accept its terms

You need to write once, all further messages from me can be ignored.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant