-
Notifications
You must be signed in to change notification settings - Fork 0
feat(init): Allow agent init without implicit app selection #244
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
Changes from all commits
13a59bf
0b6092f
d69f33f
230a35b
0d2c02d
0046c6d
e2e2a21
a6c44d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "clerk": patch | ||
| --- | ||
|
|
||
| Allow `clerk init` to run in agent mode without requiring `--app`. For keyless-capable frameworks, agent init now uses keyless setup when no real Clerk app target is provided; explicit `--app` or an existing linked profile still uses the authenticated app-linking flow, including the normal login fallback when needed. Agent init no longer creates, auto-selects, or auto-links a Clerk application when no app target is provided. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,14 +56,15 @@ type InitOptions = { | |
|
|
||
| export async function init(options: InitOptions = {}) { | ||
| const cwd = process.cwd(); | ||
| const agent = isAgent(); | ||
|
|
||
| const frameworkOverride = options.framework | ||
| ? (lookupFramework(options.framework) ?? undefined) | ||
| : undefined; | ||
|
|
||
| // In agent mode, implicitly enable --yes to skip all confirmation prompts. | ||
| const overrides: BootstrapOverrides = { | ||
| skipConfirm: options.yes || isAgent(), | ||
| skipConfirm: options.yes || agent, | ||
| pmOverride: options.pm, | ||
| nameOverride: options.name, | ||
| }; | ||
|
|
@@ -85,12 +86,21 @@ export async function init(options: InitOptions = {}) { | |
| await enrichProjectContext(ctx); | ||
|
|
||
| const authed = await isAuthenticated(); | ||
| const keyless = resolveKeylessMode(bootstrap, ctx, authed); | ||
| const linkedProfile = agent && !options.app ? await resolveProfile(ctx.cwd) : undefined; | ||
| const hasRealAppTarget = Boolean(options.app || linkedProfile); | ||
| const keyless = resolveKeylessMode({ | ||
| agent, | ||
| bootstrap, | ||
| ctx, | ||
| authed, | ||
| hasRealAppTarget, | ||
| }); | ||
| ctx.keyless = keyless; | ||
|
|
||
| const skipAuth = !keyless && bootstrap != null && overrides.skipConfirm && !authed; | ||
| const manualSetup = | ||
| !keyless && (agent ? !hasRealAppTarget : bootstrap != null && overrides.skipConfirm && !authed); | ||
|
|
||
| if (!keyless && !skipAuth) { | ||
| if (!keyless && !manualSetup) { | ||
| bar(); | ||
| await authenticateAndLink(ctx.cwd, options.app); | ||
| } | ||
|
|
@@ -104,12 +114,15 @@ export async function init(options: InitOptions = {}) { | |
|
|
||
| if (alreadySetUp) { | ||
| log.success("\nClerk is already set up in this project."); | ||
| if (agent && manualSetup) { | ||
| printBootstrapManualSetupInfo(ctx.framework.name); | ||
| } | ||
| outro("Done"); | ||
| return; | ||
| } | ||
|
|
||
| bar(); | ||
| if (skipAuth) { | ||
| if (manualSetup) { | ||
| printBootstrapManualSetupInfo(ctx.framework.name); | ||
| } else if (!keyless) { | ||
| await pull({ file: ctx.envFile, cwd: ctx.cwd }); | ||
|
|
@@ -205,28 +218,35 @@ function printBootstrapNextSteps( | |
| function printBootstrapManualSetupInfo(frameworkName: string): void { | ||
| const lines = [ | ||
| `\n ${frameworkName} requires API keys — set them up manually:`, | ||
| " clerk auth login", | ||
| " clerk link", | ||
| " clerk init --app <app_id>", | ||
| " clerk env pull", | ||
| ]; | ||
| log.info(lines.map(dim).join("\n")); | ||
| } | ||
|
|
||
| // --- Keyless --- | ||
|
|
||
| function resolveKeylessMode( | ||
| bootstrap: BootstrapResult | null, | ||
| ctx: ProjectContext, | ||
| authed: boolean, | ||
| ): boolean { | ||
| // Auto-keyless is scoped to bootstrap (new-project) flows only. For existing | ||
| // projects, fall through to the authenticated flow so `clerk init` still | ||
| // runs `authenticateAndLink` and pulls real keys — even when signed out the | ||
| // user gets a login prompt rather than being silently dropped into keyless | ||
| // (which would skip `env pull` and could overwrite permissive middleware). | ||
| if (!bootstrap) return false; | ||
|
|
||
| function resolveKeylessMode({ | ||
| agent, | ||
| bootstrap, | ||
| ctx, | ||
| authed, | ||
| hasRealAppTarget, | ||
| }: { | ||
| agent: boolean; | ||
| bootstrap: BootstrapResult | null; | ||
| ctx: ProjectContext; | ||
| authed: boolean; | ||
| hasRealAppTarget: boolean; | ||
| }): boolean { | ||
| if (ctx.framework.supportsKeyless) { | ||
| if (agent) return !hasRealAppTarget; | ||
|
|
||
| // Auto-keyless is scoped to bootstrap (new-project) flows only in human | ||
| // mode. Existing projects keep the authenticated flow so real keys can be | ||
| // pulled unless an agent explicitly chooses keyless by omitting an app. | ||
| if (!bootstrap) return false; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactoring
The new integration test Suggested fix: short-circuit on the non-keyless framework before the function does anything else, and let the caller own user-facing copy: function resolveKeylessMode({...}): boolean {
if (!ctx.framework.supportsKeyless) return false;
if (agent) return !hasRealAppTarget;
if (!bootstrap) return false;
return !authed;
}If the bootstrap-of-non-keyless framework hint is still wanted, emit it at the bootstrap call site (e.g., next to |
||
|
|
||
| // Authenticated (OAuth token or CLERK_PLATFORM_API_KEY) — use the | ||
| // authenticated flow so real keys get pulled into .env. Otherwise fall | ||
| // back to keyless: the app runs on auto-generated dev keys and the user | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be honest i'm not sure this is what we want, but its what we were doing before. i find the fact that
clerk initdoesn't require auth for bootstrapping and does require auth in existing projects a bit odd