-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(cli): make -y flag properly support non-interactive mode in create #21208
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
base: main
Are you sure you want to change the base?
Conversation
|
@ThomasK33 I wrote a guide for PRs which should create less AI-like descriptions. However, it seems like claude code doesn't always listen. Any ideas why? https://github.com/coder/coder/blob/main/.claude/docs/PR_STYLE_GUIDE.md Perhaps these should be skills |
9d5bb50 to
34b73d4
Compare
|
I instructed CC to create the PR near the compaction window limit, around 150k tokens. As a result, its recall may no longer be optimal, since all documents have been placed at the front, and tool calls occurred in between. If we want to optimize for Claude Code, we might consider introducing a sub-agent dedicated to strictly following rules within a much cleaner and more streamlined context window, instead of letting the main session handle the PR description. |
The -y flag was documented as 'Bypass prompts' but only bypassed the final 'Confirm create?' prompt. All other interactive prompts (preset selection, parameter input, template selection, workspace name) would still appear, breaking CI/CD and non-interactive usage. Changes: - Add isNonInteractive(inv) helper in create.go - Workspace name: error if not provided with -y - Template selection: auto-select if exactly 1 template exists, error if multiple - Preset selection: skip presets entirely (default to none) with -y - Parameters: use default values automatically, error if required param has no default - External auth: error immediately if required auth not authenticated - Update SkipPromptOption() description to accurately describe behavior - Regenerate golden files for updated flag description The -y flag now enables true non-interactive mode for `coder create`.
34b73d4 to
7e2b111
Compare
@bpmct, rerean it on a fresh context, and the PR description is now more aligned with what's in that doc. |
| // isNonInteractive checks if the command is running in non-interactive mode | ||
| // (i.e., the --yes/-y flag was provided). | ||
| func isNonInteractive(inv *serpent.Invocation) bool { | ||
| if inv.ParsedFlags().Lookup("yes") != nil { |
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.
not sure if that’s a pattern or not, but can we not do a double look up of string “yes”, there’s gotta be a better way to handle this
deansheather
left a comment
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.
Originally I was going to suggest leaving the erroring up to cliui.Select and co., but it's probably better to deal with it in the command handler like you've done so we get better error messages.
Looks good.
|
|
||
| // isNonInteractive checks if the command is running in non-interactive mode | ||
| // (i.e., the --yes/-y flag was provided). | ||
| func isNonInteractive(inv *serpent.Invocation) bool { |
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.
This should probably go into the cliui package beside the SkipPromptOption function
Previously, the
-yflag only bypassed the final "Confirm create?" prompt while still showing interactive prompts for preset selection, parameter input, and template selection. This broke CI/CD and automation workflows that expected-yto enable true non-interactive mode.Now when
-yis passed: workspace name must be an argument, templates auto-select if only one exists (error if multiple), presets default to "none", parameters use their defaults (error if required without default), and external auth must be pre-authenticated.-y--template--parameterImplementation Plan
Plan: Fix
-yFlag to Properly Support Non-Interactive Mode incoder createProblem
The
-yflag claims to "Bypass prompts" but only bypasses the final "Confirm create?" prompt. All other interactive prompts (preset selection, parameter input, template selection, workspace name) still appear, breaking non-interactive/CI environments.Requirements
-yis passed, never prompt the user-y, default to "none" (skip presets)Files to Modify
cli/create.go- Main create command logiccli/parameterresolver.go- Parameter resolution with input promptscli/cliui/externalauth.go- External auth handlingcli/cliui/prompt.go- Update flag description (minor)Implementation Plan
1. Add Helper to Check Non-Interactive Mode
In
cli/create.go, add a helper function to check if we're in non-interactive mode:2. Handle Workspace Name (cli/create.go:77-95)
Current: Prompts if workspace name not provided as argument.
Change: If
-yand no workspace name, return an error:3. Handle Template Selection (cli/create.go:124-178)
Current: Prompts with template selection if
--templatenot provided.Change: If
-yand no template specified, return an error:4. Handle Preset Selection (cli/create.go:293-304)
Current: If presets exist and no
--presetflag, prompts for selection.Change: If
-yand no preset specified, default to "none" (skip presets):5. Handle Parameter Input (cli/parameterresolver.go)
Current:
resolveWithInputprompts for any unresolved parameters.Change: Pass non-interactive flag to resolver and handle appropriately.
5a. Add field to ParameterResolver struct:
5b. Modify
resolveWithInputto respect non-interactive mode:5c. Update caller in
cli/create.goto pass non-interactive flag:6. Update Flag Description
In
cli/cliui/prompt.go, update the description to be accurate:7. Handle External Auth (cli/create.go:571)
Current: Waits/polls for browser-based authentication if external auth is required.
Change: In non-interactive mode, fail immediately if any required external auth is not already authenticated:
Modify
cliui.ExternalAuthincli/cliui/externalauth.goto accept a non-interactive flag and fail immediately if required auth is missing:Edge Cases
Ephemeral Parameters: These are build-time options. In non-interactive mode with
--prompt-ephemeral-parameters, we should probably fail if ephemeral parameters exist but weren't provided via--ephemeral-parameterflags.Multi-select Parameters (list(string)): These have defaults that are JSON arrays. The default handling should work, but verify the default value is properly applied.
Testing
Test
coder create workspace -t template -ywith a template that has:Test error messages are clear and actionable
Test that interactive mode (without
-y) still works as beforeSummary of Changes
-y--template--parameter🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com