From 1d31eb34c6d2feb9edff744adaed98fbcb4e20f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Wed, 17 Jun 2026 21:57:29 -0600 Subject: [PATCH 1/3] Add OpenCode shell plugin --- plugins/opencode/api_key.go | 31 +++++++++++++++++++++++ plugins/opencode/api_key_test.go | 43 ++++++++++++++++++++++++++++++++ plugins/opencode/opencode.go | 25 +++++++++++++++++++ plugins/opencode/plugin.go | 22 ++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 plugins/opencode/api_key.go create mode 100644 plugins/opencode/api_key_test.go create mode 100644 plugins/opencode/opencode.go create mode 100644 plugins/opencode/plugin.go diff --git a/plugins/opencode/api_key.go b/plugins/opencode/api_key.go new file mode 100644 index 00000000..52dd28c0 --- /dev/null +++ b/plugins/opencode/api_key.go @@ -0,0 +1,31 @@ +package opencode + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/importer" + "github.com/1Password/shell-plugins/sdk/provision" + "github.com/1Password/shell-plugins/sdk/schema" + "github.com/1Password/shell-plugins/sdk/schema/credname" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +func APIKey() schema.CredentialType { + return schema.CredentialType{ + Name: credname.APIKey, + DocsURL: sdk.URL("https://opencode.ai/docs/"), + ManagementURL: sdk.URL("https://opencode.ai/auth"), + Fields: []schema.CredentialField{ + { + Name: fieldname.APIKey, + MarkdownDescription: "API Key used to authenticate to opencode.", + Secret: true, + }, + }, + DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping), + Importer: importer.TryEnvVarPair(defaultEnvVarMapping), + } +} + +var defaultEnvVarMapping = map[string]sdk.FieldName{ + "OPENCODE_API_KEY": fieldname.APIKey, +} diff --git a/plugins/opencode/api_key_test.go b/plugins/opencode/api_key_test.go new file mode 100644 index 00000000..94e292f3 --- /dev/null +++ b/plugins/opencode/api_key_test.go @@ -0,0 +1,43 @@ +package opencode + +import ( + "testing" + + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/plugintest" + "github.com/1Password/shell-plugins/sdk/schema/fieldname" +) + +const exampleAPIKey = "sk-0123456789abcdefghijEXAMPLE" + +func TestAPIKeyProvisioner(t *testing.T) { + plugintest.TestProvisioner(t, APIKey().DefaultProvisioner, map[string]plugintest.ProvisionCase{ + "default": { + ItemFields: map[sdk.FieldName]string{ + fieldname.APIKey: exampleAPIKey, + }, + ExpectedOutput: sdk.ProvisionOutput{ + Environment: map[string]string{ + "OPENCODE_API_KEY": exampleAPIKey, + }, + }, + }, + }) +} + +func TestAPIKeyImporter(t *testing.T) { + plugintest.TestImporter(t, APIKey().Importer, map[string]plugintest.ImportCase{ + "environment": { + Environment: map[string]string{ + "OPENCODE_API_KEY": exampleAPIKey, + }, + ExpectedCandidates: []sdk.ImportCandidate{ + { + Fields: map[sdk.FieldName]string{ + fieldname.APIKey: exampleAPIKey, + }, + }, + }, + }, + }) +} diff --git a/plugins/opencode/opencode.go b/plugins/opencode/opencode.go new file mode 100644 index 00000000..c6460ac8 --- /dev/null +++ b/plugins/opencode/opencode.go @@ -0,0 +1,25 @@ +package opencode + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/needsauth" + "github.com/1Password/shell-plugins/sdk/schema" + "github.com/1Password/shell-plugins/sdk/schema/credname" +) + +func OpencodeCLI() schema.Executable { + return schema.Executable{ + Name: "opencode CLI", + Runs: []string{"opencode"}, + DocsURL: sdk.URL("https://opencode.ai/docs/"), + NeedsAuth: needsauth.IfAll( + needsauth.NotForHelpOrVersion(), + needsauth.NotWithoutArgs(), + ), + Uses: []schema.CredentialUsage{ + { + Name: credname.APIKey, + }, + }, + } +} diff --git a/plugins/opencode/plugin.go b/plugins/opencode/plugin.go new file mode 100644 index 00000000..2419d650 --- /dev/null +++ b/plugins/opencode/plugin.go @@ -0,0 +1,22 @@ +package opencode + +import ( + "github.com/1Password/shell-plugins/sdk" + "github.com/1Password/shell-plugins/sdk/schema" +) + +func New() schema.Plugin { + return schema.Plugin{ + Name: "opencode", + Platform: schema.PlatformInfo{ + Name: "opencode", + Homepage: sdk.URL("https://opencode.ai"), + }, + Credentials: []schema.CredentialType{ + APIKey(), + }, + Executables: []schema.Executable{ + OpencodeCLI(), + }, + } +} From 596756c1cc62ead7c2f2f50fdcd291ff2454d015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Wed, 17 Jun 2026 22:06:26 -0600 Subject: [PATCH 2/3] Fix comments --- plugins/opencode/api_key.go | 2 +- plugins/opencode/opencode.go | 2 +- plugins/opencode/plugin.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/opencode/api_key.go b/plugins/opencode/api_key.go index 52dd28c0..85024296 100644 --- a/plugins/opencode/api_key.go +++ b/plugins/opencode/api_key.go @@ -17,7 +17,7 @@ func APIKey() schema.CredentialType { Fields: []schema.CredentialField{ { Name: fieldname.APIKey, - MarkdownDescription: "API Key used to authenticate to opencode.", + MarkdownDescription: "API Key used to authenticate to OpenCode.", Secret: true, }, }, diff --git a/plugins/opencode/opencode.go b/plugins/opencode/opencode.go index c6460ac8..b9cc33f5 100644 --- a/plugins/opencode/opencode.go +++ b/plugins/opencode/opencode.go @@ -9,7 +9,7 @@ import ( func OpencodeCLI() schema.Executable { return schema.Executable{ - Name: "opencode CLI", + Name: "OpenCode CLI", Runs: []string{"opencode"}, DocsURL: sdk.URL("https://opencode.ai/docs/"), NeedsAuth: needsauth.IfAll( diff --git a/plugins/opencode/plugin.go b/plugins/opencode/plugin.go index 2419d650..51429bc1 100644 --- a/plugins/opencode/plugin.go +++ b/plugins/opencode/plugin.go @@ -9,7 +9,7 @@ func New() schema.Plugin { return schema.Plugin{ Name: "opencode", Platform: schema.PlatformInfo{ - Name: "opencode", + Name: "OpenCode", Homepage: sdk.URL("https://opencode.ai"), }, Credentials: []schema.CredentialType{ From c0eaafdb6cf1b685d657382804574d4afe8731c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Fri, 19 Jun 2026 16:47:27 -0600 Subject: [PATCH 3/3] Fix comments --- plugins/opencode/api_key.go | 4 ++-- plugins/opencode/opencode.go | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/opencode/api_key.go b/plugins/opencode/api_key.go index 85024296..64865edd 100644 --- a/plugins/opencode/api_key.go +++ b/plugins/opencode/api_key.go @@ -12,12 +12,12 @@ import ( func APIKey() schema.CredentialType { return schema.CredentialType{ Name: credname.APIKey, - DocsURL: sdk.URL("https://opencode.ai/docs/"), + DocsURL: sdk.URL("https://opencode.ai/docs/providers/"), ManagementURL: sdk.URL("https://opencode.ai/auth"), Fields: []schema.CredentialField{ { Name: fieldname.APIKey, - MarkdownDescription: "API Key used to authenticate to OpenCode.", + MarkdownDescription: "OpenCode Zen API key from https://opencode.ai/auth used to authenticate to OpenCode. `OPENCODE_API_KEY` covers only the OpenCode Zen gateway, not BYOK keys such as `ANTHROPIC_API_KEY`.", Secret: true, }, }, diff --git a/plugins/opencode/opencode.go b/plugins/opencode/opencode.go index b9cc33f5..cf2309cb 100644 --- a/plugins/opencode/opencode.go +++ b/plugins/opencode/opencode.go @@ -15,6 +15,7 @@ func OpencodeCLI() schema.Executable { NeedsAuth: needsauth.IfAll( needsauth.NotForHelpOrVersion(), needsauth.NotWithoutArgs(), + needsauth.NotWhenContainsArgs("auth"), ), Uses: []schema.CredentialUsage{ {