Skip to content

Open source AI coding agent. Designed for large projects and real world tasks.

Update all commands to use unified auth verification

Dane Schneider17192ace3d4e
diff --git a/app/cli/cmd/build.go b/app/cli/cmd/build.go
index 18c899ce..862bcb80 100644
--- a/app/cli/cmd/build.go
+++ b/app/cli/cmd/build.go
@@ -41,15 +41,10 @@ func build(cmd *cobra.Command, args []string) {
mustSetPlanExecFlags(cmd, false)
- var apiKeys map[string]string
- if !auth.Current.IntegratedModelsMode {
- apiKeys = lib.MustVerifyAuthVars()
- }
-
didBuild, err := plan_exec.Build(plan_exec.ExecParams{
CurrentPlanId: lib.CurrentPlanId,
CurrentBranch: lib.CurrentBranch,
- AuthVars: apiKeys,
+ AuthVars: lib.MustVerifyAuthVars(auth.Current.IntegratedModelsMode),
CheckOutdatedContext: func(maybeContexts []*shared.Context, projectPaths *types.ProjectPaths) (bool, bool, error) {
auto := autoConfirm || tellAutoApply || tellAutoContext
return lib.CheckOutdatedContextWithOutput(auto, auto, maybeContexts, projectPaths)
diff --git a/app/cli/cmd/chat.go b/app/cli/cmd/chat.go
index 7ab113c1..7081e1bf 100644
--- a/app/cli/cmd/chat.go
+++ b/app/cli/cmd/chat.go
@@ -41,11 +41,6 @@ func doChat(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
mustSetPlanExecFlags(cmd, false)
- var apiKeys map[string]string
- if !auth.Current.IntegratedModelsMode {
- apiKeys = lib.MustVerifyAuthVars()
- }
-
prompt := getTellPrompt(args)
if prompt == "" {
@@ -56,7 +51,7 @@ func doChat(cmd *cobra.Command, args []string) {
plan_exec.TellPlan(plan_exec.ExecParams{
CurrentPlanId: lib.CurrentPlanId,
CurrentBranch: lib.CurrentBranch,
- AuthVars: apiKeys,
+ AuthVars: lib.MustVerifyAuthVars(auth.Current.IntegratedModelsMode),
CheckOutdatedContext: func(maybeContexts []*shared.Context, projectPaths *types.ProjectPaths) (bool, bool, error) {
auto := autoConfirm || tellAutoApply || tellAutoContext
return lib.CheckOutdatedContextWithOutput(auto, auto, maybeContexts, projectPaths)
diff --git a/app/cli/cmd/continue.go b/app/cli/cmd/continue.go
index 69ab695e..a9d2beb7 100644
--- a/app/cli/cmd/continue.go
+++ b/app/cli/cmd/continue.go
@@ -38,11 +38,6 @@ func doContinue(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
mustSetPlanExecFlags(cmd, false)
- var apiKeys map[string]string
- if !auth.Current.IntegratedModelsMode {
- apiKeys = lib.MustVerifyAuthVars()
- }
-
tellFlags := types.TellFlags{
TellBg: tellBg,
TellStop: tellStop,
@@ -59,7 +54,7 @@ func doContinue(cmd *cobra.Command, args []string) {
plan_exec.TellPlan(plan_exec.ExecParams{
CurrentPlanId: lib.CurrentPlanId,
CurrentBranch: lib.CurrentBranch,
- AuthVars: apiKeys,
+ AuthVars: lib.MustVerifyAuthVars(auth.Current.IntegratedModelsMode),
CheckOutdatedContext: func(maybeContexts []*shared.Context, projectPaths *types.ProjectPaths) (bool, bool, error) {
auto := autoConfirm || tellAutoApply || tellAutoContext
diff --git a/app/cli/cmd/debug.go b/app/cli/cmd/debug.go
index 1bc3e06c..c88138ff 100644
--- a/app/cli/cmd/debug.go
+++ b/app/cli/cmd/debug.go
@@ -66,11 +66,6 @@ func doDebug(cmd *cobra.Command, args []string) {
}
}
- var apiKeys map[string]string
- if !auth.Current.IntegratedModelsMode {
- apiKeys = lib.MustVerifyAuthVars()
- }
-
// Get current working directory
cwd, err := os.Getwd()
if err != nil {
@@ -248,7 +243,7 @@ func doDebug(cmd *cobra.Command, args []string) {
plan_exec.TellPlan(plan_exec.ExecParams{
CurrentPlanId: lib.CurrentPlanId,
CurrentBranch: lib.CurrentBranch,
- AuthVars: apiKeys,
+ AuthVars: lib.MustVerifyAuthVars(auth.Current.IntegratedModelsMode),
CheckOutdatedContext: func(maybeContexts []*shared.Context, projectPaths *types.ProjectPaths) (bool, bool, error) {
return lib.CheckOutdatedContextWithOutput(true, true, maybeContexts, projectPaths)
},
diff --git a/app/cli/cmd/repl.go b/app/cli/cmd/repl.go
index aeee55df..8520db3d 100644
--- a/app/cli/cmd/repl.go
+++ b/app/cli/cmd/repl.go
@@ -145,9 +145,7 @@ func runRepl(cmd *cobra.Command, args []string) {
setReplConfig()
- if !auth.Current.IntegratedModelsMode {
- lib.MustVerifyAuthVars()
- }
+ lib.MustVerifyAuthVars(auth.Current.IntegratedModelsMode)
projectPaths, err = fs.GetProjectPaths(fs.Cwd)
if err != nil {
diff --git a/app/cli/cmd/tell.go b/app/cli/cmd/tell.go
index 4e1e06d1..034eb1c0 100644
--- a/app/cli/cmd/tell.go
+++ b/app/cli/cmd/tell.go
@@ -43,11 +43,6 @@ func doTell(cmd *cobra.Command, args []string) {
lib.MustResolveProject()
mustSetPlanExecFlags(cmd, false)
- var authVars map[string]string
- if !auth.Current.IntegratedModelsMode {
- authVars = lib.MustVerifyAuthVars()
- }
-
if isImplementationOfChat && len(args) > 0 {
term.OutputErrorAndExit("Error: --from-chat cannot be used with a prompt")
}
@@ -77,7 +72,7 @@ func doTell(cmd *cobra.Command, args []string) {
plan_exec.TellPlan(plan_exec.ExecParams{
CurrentPlanId: lib.CurrentPlanId,
CurrentBranch: lib.CurrentBranch,
- AuthVars: authVars,
+ AuthVars: lib.MustVerifyAuthVars(auth.Current.IntegratedModelsMode),
CheckOutdatedContext: func(maybeContexts []*shared.Context, projectPaths *types.ProjectPaths) (bool, bool, error) {
auto := autoConfirm || tellAutoApply || tellAutoContext
return lib.CheckOutdatedContextWithOutput(auto, auto, maybeContexts, projectPaths)
diff --git a/app/cli/lib/apply.go b/app/cli/lib/apply.go
index 8c262e80..067da509 100644
--- a/app/cli/lib/apply.go
+++ b/app/cli/lib/apply.go
@@ -574,24 +574,14 @@ func execApplyScript(
}
func apiApplyPlan(planId, branch string) (string, error) {
- var apiKeys map[string]string
- if !auth.Current.IntegratedModelsMode {
- apiKeys = MustVerifyAuthVarsSilent()
- }
+ authVars := MustVerifyAuthVarsSilent(auth.Current.IntegratedModelsMode)
var commitSummary string
- openAIBase := os.Getenv("OPENAI_API_BASE")
- if openAIBase == "" {
- openAIBase = os.Getenv("OPENAI_ENDPOINT")
- }
-
log.Println("Applying plan with API call")
commitSummary, apiErr := api.Client.ApplyPlan(planId, branch, shared.ApplyPlanRequest{
- ApiKeys: apiKeys,
- OpenAIBase: openAIBase,
- OpenAIOrgId: os.Getenv("OPENAI_ORG_ID"),
+ AuthVars: authVars,
})
if apiErr != nil {
diff --git a/app/cli/lib/context_load.go b/app/cli/lib/context_load.go
index a3f789e8..178d8529 100644
--- a/app/cli/lib/context_load.go
+++ b/app/cli/lib/context_load.go
@@ -49,20 +49,18 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {
onErr(fmt.Errorf("failed to stat stdin: %v", err))
}
- var apiKeys map[string]string
+ var authVars map[string]string
var openAIBase string
- if !auth.Current.IntegratedModelsMode {
- if params.Note != "" || fileInfo.Mode()&os.ModeNamedPipe != 0 {
- apiKeys = MustVerifyAuthVarsSilent()
- }
+ if params.Note != "" || fileInfo.Mode()&os.ModeNamedPipe != 0 {
+ authVars = MustVerifyAuthVarsSilent(auth.Current.IntegratedModelsMode)
}
if params.Note != "" {
loadContextReq = append(loadContextReq, &shared.LoadContextParams{
ContextType: shared.ContextNoteType,
Body: params.Note,
- ApiKeys: apiKeys,
+ ApiKeys: authVars,
OpenAIBase: openAIBase,
OpenAIOrgId: os.Getenv("OPENAI_ORG_ID"),
SessionId: params.SessionId,
@@ -81,7 +79,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {
loadContextReq = append(loadContextReq, &shared.LoadContextParams{
ContextType: shared.ContextPipedDataType,
Body: string(pipedData),
- ApiKeys: apiKeys,
+ ApiKeys: authVars,
OpenAIBase: openAIBase,
OpenAIOrgId: os.Getenv("OPENAI_ORG_ID"),
SessionId: params.SessionId,
diff --git a/app/cli/main.go b/app/cli/main.go
index 692638c6..2a6a3cf0 100644
--- a/app/cli/main.go
+++ b/app/cli/main.go
@@ -33,14 +33,11 @@ func init() {
plan_exec.SetPromptSyncModelsIfNeeded(lib.PromptSyncModelsIfNeeded)
lib.SetBuildPlanInlineFn(func(autoConfirm bool, maybeContexts []*shared.Context) (bool, error) {
- var apiKeys map[string]string
- if !auth.Current.IntegratedModelsMode {
- apiKeys = lib.MustVerifyAuthVars()
- }
+ authVars := lib.MustVerifyAuthVars(auth.Current.IntegratedModelsMode)
return plan_exec.Build(plan_exec.ExecParams{
CurrentPlanId: lib.CurrentPlanId,
CurrentBranch: lib.CurrentBranch,
- AuthVars: apiKeys,
+ AuthVars: authVars,
CheckOutdatedContext: func(maybeContexts []*shared.Context, projectPaths *types.ProjectPaths) (bool, bool, error) {
return lib.CheckOutdatedContextWithOutput(true, autoConfirm, maybeContexts, projectPaths)
},
diff --git a/app/cli/plan_exec/apply_exec.go b/app/cli/plan_exec/apply_exec.go
index 80b82259..941c41f3 100644
--- a/app/cli/plan_exec/apply_exec.go
+++ b/app/cli/plan_exec/apply_exec.go
@@ -120,10 +120,8 @@ func getOnApplyExecFail(applyFlags types.ApplyFlags, tellFlags types.TellFlags,
lib.Rollback(toRollback, true)
}
- var apiKeys map[string]string
- if !auth.Current.IntegratedModelsMode {
- apiKeys = lib.MustVerifyAuthVarsSilent()
- }
+ authVars := lib.MustVerifyAuthVarsSilent(auth.Current.IntegratedModelsMode)
+
prompt := fmt.Sprintf("Execution failed with exit status %d. Output:\n\n%s\n\n--\n\n",
status, output)
@@ -144,7 +142,7 @@ func getOnApplyExecFail(applyFlags types.ApplyFlags, tellFlags types.TellFlags,
TellPlan(ExecParams{
CurrentPlanId: lib.CurrentPlanId,
CurrentBranch: lib.CurrentBranch,
- AuthVars: apiKeys,
+ AuthVars: authVars,
CheckOutdatedContext: func(maybeContexts []*shared.Context, projectPaths *types.ProjectPaths) (bool, bool, error) {
return lib.CheckOutdatedContextWithOutput(true, true, maybeContexts, projectPaths)
},