feat: inject short-lived scoped CLI credentials into agent sessions#4752
Open
supernandor wants to merge 2 commits into
Open
feat: inject short-lived scoped CLI credentials into agent sessions#4752supernandor wants to merge 2 commits into
supernandor wants to merge 2 commits into
Conversation
When creating an agent session, generate a 1-hour scoped JWT token locked to the user's org. On the first message of each session (or after token refresh), inject a CLI setup block that writes ~/.superplane.yaml with the token, org ID, and API URL. This lets the agent's bash tool run SuperPlane CLI commands authenticated as the user, scoped to their org, without exposing long-lived tokens. Changes: - Migration: add api_token + api_token_expires_at to agent_sessions - Service: generate scoped token on session create, auto-refresh on resume - Stream: buildPrompt injects CLI config on first message - Tests: buildPrompt with/without token, updated existing tests
|
👋 Commands for maintainers:
|
Instead of calling GetSession separately (which races with ListEvents), detect session.status_idle and session.status_failed from the events list itself. Since events are ordered, the idle event always comes AFTER all agent.message events, guaranteeing the full response is captured before we close the stream. Also removes GetSession from the poll loop entirely — one fewer API call per poll cycle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Gives the managed agent CLI access to the SuperPlane API by injecting a short-lived scoped JWT token into the Anthropic session.
How it works
agent)~/.superplane.yamlwith the tokensuperplaneCLI commands authenticate with the scoped tokenWhat the agent sees (first message only)
Security
Changes
db/migrations/20260512210222_*api_token+api_token_expires_atcolumnspkg/agents/service.gopkg/agents/store.gopkg/agents/stream.gobuildPromptinjects CLI configpkg/agents/stream_test.goTests
TestBuildPrompt_WithToken_FirstMessage— verifies CLI setup injectedTestBuildPrompt_WithoutToken— verifies no setup when no token