Refactor repository wizard to defer provider creation until secrets saved#10
Merged
Merged
Conversation
Previously when a repo build failed because .env values weren't set yet, the wizard would still POST /api/tools (creating the provider with a placeholder), then try to show the Secrets step. If the user clicked Next a second time the POST returned 409 and the user got stuck with no path to fill in secrets. New flow: when /api/clone-and-build returns env_keys (regardless of build success), the wizard stashes everything in wzRepoCtx and jumps straight to the Secrets step *without* creating the provider. After the user fills in values and saves them to .env, the wizard re-runs clone-and-build (server now writes <workdir>/.env from os.environ before the build commands run) and re-introspects, then finalises by PUT-ing the provider — idempotent, so retries can't 409. If the retry still fails, the provider is saved anyway with whatever tools were discovered (or a placeholder), so the user can fix things in the editor instead of being stuck on the wizard.
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
Refactored the repository wizard flow to separate build/introspection from provider creation, enabling retry logic when environment secrets are populated. This allows the build to be re-run with
.envin place after secrets are saved, improving the user experience for repository providers that require environment variables.Key Changes
Introduced
wzRepoCtxstate variable: Carries repository wizard context (name, command, repo details, build results) across wizard steps instead of immediately creating the provider.Extracted
_wzRepoBuildAndIntrospect()helper: Consolidates clone, build, and introspection logic into a reusable function that returns a structured result object with build status, workdir, env_keys, tools, and error details.Extracted
_wzRepoFinalize()helper: Handles the actual provider creation/update, converting introspected tools into the provider schema and using idempotent PUT instead of POST to safely retry without 409 conflicts.Deferred provider creation: The repository step now saves context instead of immediately creating the provider. Provider creation is deferred until after the Secrets step, allowing the build to be retried with environment variables in place.
Added retry logic in
wzGoSecrets(): After secrets are saved, ifwzRepoCtxexists, the build and introspection are retried with the new environment. The provider is then finalized regardless of retry success, allowing users to manually fix issues in the editor.Improved error handling: Build failures, introspection failures, and retry failures are now surfaced as toasts with actionable messages, and the wizard gracefully handles partial success states.
Changed API call from POST to PUT: Provider creation now uses PUT
/api/tools/{name}for idempotency, making the wizard safe to retry without collision errors.Notable Implementation Details
_wzRepoBuildAndIntrospect()includesok,buildErr,failed_command,workdir,env_keys,tools, andintroErrfields for comprehensive state tracking.wzRepoCtxto null after finalization to prevent state leakage between wizard invocations.https://claude.ai/code/session_01R2Vi6NE4wGxwv6rZ2HEXji