Repository navigation
fix(setup): fix the agent sandbox and give the agent more facts (6/6) #899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
atornsii
wants to merge
12
commits into
atorns/agent-5-opencode-handler
from
atorns/agent-6-run-fixes
+385
−51
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5b8bd44
fix(setup): make the agent sandbox work with uv and git
atornsii 9378e4a
feat(setup): give the agent the project, environment, and provider keys
atornsii 0abfee0
Merge remote-tracking branch 'origin/atorns/agent-5-opencode-handler'…
atornsii 8a56521
Merge remote-tracking branch 'origin/atorns/agent-5-opencode-handler'…
atornsii 78ed988
fix(setup): give the fallback prompt the new facts and skip blank dot…
atornsii 1ac85d2
Merge remote-tracking branch 'origin/atorns/agent-5-opencode-handler'…
atornsii d1cf8e9
fix(setup): always give OpenCode a TMPDIR
atornsii 80bf2bd
Merge remote-tracking branch 'origin/atorns/agent-5-opencode-handler'…
atornsii 9030cfe
Merge remote-tracking branch 'origin/atorns/agent-5-opencode-handler'…
atornsii 0b01d03
Merge remote-tracking branch 'origin/atorns/agent-5-opencode-handler'…
atornsii 3ef4e62
fix(setup): allow metadata reads on parents under the closed temporar…
atornsii e68aa99
Merge remote-tracking branch 'origin/atorns/agent-5-opencode-handler'…
atornsii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package agent | ||
|
|
||
| import ( | ||
| "bufio" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| ) | ||
|
|
||
| // providerKeyNames are the environment variables that hold the API keys of | ||
| // the model providers that LaunchDarkly AI SDKs support. | ||
| var providerKeyNames = []string{ | ||
| "ANTHROPIC_API_KEY", | ||
| "OPENAI_API_KEY", | ||
| "AZURE_OPENAI_API_KEY", | ||
| "GEMINI_API_KEY", | ||
| "GOOGLE_API_KEY", | ||
| "MISTRAL_API_KEY", | ||
| "COHERE_API_KEY", | ||
| "GROQ_API_KEY", | ||
| "AWS_ACCESS_KEY_ID", | ||
| "AWS_PROFILE", | ||
| } | ||
|
|
||
| // ProviderKeys returns the names of the provider keys that are set, in the | ||
| // environment or in the project's .env file. It never returns a value. The | ||
| // agent uses the answer to decide whether it can run the app, so it never | ||
| // has to ask for a key or print the environment. | ||
| func ProviderKeys(dir string, environ []string) []string { | ||
| set := map[string]bool{} | ||
| for _, kv := range environ { | ||
| if name, value, ok := strings.Cut(kv, "="); ok && strings.TrimSpace(value) != "" { | ||
| set[name] = true | ||
| } | ||
| } | ||
| for name := range dotEnvNames(filepath.Join(dir, ".env")) { | ||
| set[name] = true | ||
| } | ||
| var found []string | ||
| for _, name := range providerKeyNames { | ||
| if set[name] { | ||
| found = append(found, name) | ||
| } | ||
| } | ||
| return found | ||
| } | ||
|
|
||
| // dotEnvNames returns the names in a .env file that have a value. | ||
| func dotEnvNames(path string) map[string]bool { | ||
| names := map[string]bool{} | ||
| f, err := os.Open(path) | ||
| if err != nil { | ||
| return names | ||
| } | ||
| defer f.Close() | ||
| scanner := bufio.NewScanner(f) | ||
| for scanner.Scan() { | ||
| line := strings.TrimSpace(scanner.Text()) | ||
| line = strings.TrimPrefix(line, "export ") | ||
| if line == "" || strings.HasPrefix(line, "#") { | ||
| continue | ||
| } | ||
| name, value, ok := strings.Cut(line, "=") | ||
| value = strings.TrimSpace(strings.Trim(strings.TrimSpace(value), `"'`)) | ||
| if ok && value != "" { | ||
| names[strings.TrimSpace(name)] = true | ||
| } | ||
| } | ||
| return names | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package agent | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestProviderKeys_NamesFromTheEnvironmentAndDotEnv(t *testing.T) { | ||
| dir := t.TempDir() | ||
| require.NoError(t, os.WriteFile(filepath.Join(dir, ".env"), | ||
| []byte("# keys\nexport OPENAI_API_KEY=\"sk-123\"\nGEMINI_API_KEY=\nLAUNCHDARKLY_SDK_KEY=sdk-1\n"), 0o600)) | ||
|
|
||
| keys := ProviderKeys(dir, []string{"ANTHROPIC_API_KEY=sk-ant", "MISTRAL_API_KEY=", "PATH=/bin"}) | ||
|
|
||
| assert.Equal(t, []string{"ANTHROPIC_API_KEY", "OPENAI_API_KEY"}, keys, "empty values do not count") | ||
| } | ||
|
|
||
| func TestBuildFacts_HasProjectEnvironmentAndKeyNames(t *testing.T) { | ||
| facts := BuildFacts(Task{ | ||
| SDKID: "python-server-sdk", ProjectKey: "experimentation", EnvironmentKey: "production", | ||
| ProviderKeys: []string{"ANTHROPIC_API_KEY"}, | ||
| }) | ||
|
|
||
| assert.Contains(t, facts, "- LaunchDarkly project: experimentation") | ||
| assert.Contains(t, facts, "- LaunchDarkly environment: production") | ||
| assert.Contains(t, facts, "- Model provider keys that are set: ANTHROPIC_API_KEY (names only)") | ||
| assert.Contains(t, facts, "Do not look for keys") | ||
| assert.Contains(t, BuildFacts(Task{}), "- Model provider keys that are set: none") | ||
| } | ||
|
|
||
| func TestProviderKeys_BlankQuotedValueIsNotSet(t *testing.T) { | ||
| dir := t.TempDir() | ||
| require.NoError(t, os.WriteFile(filepath.Join(dir, ".env"), []byte("OPENAI_API_KEY=\" \"\nANTHROPIC_API_KEY=' x '\n"), 0o600)) | ||
| assert.Equal(t, []string{"ANTHROPIC_API_KEY"}, ProviderKeys(dir, nil)) | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.