Skip to content

Refactor repository wizard to defer provider creation until secrets saved#10

Merged
BillJr99 merged 1 commit into
mainfrom
claude/admiring-newton-FuK5K-wizard-secrets-first
May 25, 2026
Merged

Refactor repository wizard to defer provider creation until secrets saved#10
BillJr99 merged 1 commit into
mainfrom
claude/admiring-newton-FuK5K-wizard-secrets-first

Conversation

@BillJr99
Copy link
Copy Markdown
Owner

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 .env in place after secrets are saved, improving the user experience for repository providers that require environment variables.

Key Changes

  • Introduced wzRepoCtx state 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, if wzRepoCtx exists, 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

  • The result object from _wzRepoBuildAndIntrospect() includes ok, buildErr, failed_command, workdir, env_keys, tools, and introErr fields for comprehensive state tracking.
  • Placeholder tools are inserted when no tools are introspected, allowing the provider to be created even if the build fails, with a note to re-introspect after fixing the build.
  • The wizard properly resets wzRepoCtx to null after finalization to prevent state leakage between wizard invocations.
  • Tests verify the presence of new helper functions and the use of PUT for idempotent operations.

https://claude.ai/code/session_01R2Vi6NE4wGxwv6rZ2HEXji

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.
@BillJr99 BillJr99 merged commit ab1b371 into main May 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants