review: use RunWithContext for backend prompt; clarify validator doc · Entire

review: use RunWithContext for backend prompt; clarify validator doc

48a4502→main·

Soph·1w ago·3 files·+19 added/-14 removed

Address PR #1661 bot review: - promptCheckpointBackend now runs via RunWithContext(ctx) and routes failures through handleFormCancellation, matching the setup-family convention (setup_import.go). Ctrl+C / cancelled context now abort cleanly and keep the default backend instead of surfacing a generic wrapped error. - Clarify ValidatePrimaryBackend doc: unknown types error with the registered type list; non-git-backed types are rejected separately.

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

Sessions

01KWY2JSNNA4DW1RSNA6599P8RView transcript

[?
Enable Checkpoint Backend Selection FlagClaude Code·Opus 4.8[1m]·1 step](/content/gh/entireio/cli/session/11ba6f88-6d84-431a-936c-a96e4a64ed9b#timeline-01KWY2JSNNA4DW1RSNA6599P8R/index.html)

Changes

3

93 unmodified lines

94
95
96
97
98
99
100
101
102
97
98
99
100
101
102
103
104
105
106

93 unmodified lines

}

// ValidatePrimaryBackend reports an error unless typ names a registered backend
// that may serve as the primary. Only git-backed backends qualify: a
// non-git-backed or unknown type is rejected with a descriptive message that
// names the valid types. This is the single source of the "primary must be
// git-backed" rule — buildPrimary delegates here, and selection surfaces (entire
// enable / configure --checkpoint-backend) call it to reject a bad backend
// before writing it to settings, rather than failing later in Open.
// that may serve as the primary. An unknown type is rejected with an error
// listing the registered backend types; a registered but non-git-backed type is
// rejected separately, since only git-backed backends may be the primary. This
// is the single source of the "primary must be git-backed" rule — buildPrimary
// delegates here, and selection surfaces (entire enable / configure
// --checkpoint-backend) call it to reject a bad backend before writing it to
// settings, rather than failing later in Open.
func ValidatePrimaryBackend(typ string) error {
    b, err := lookupBackend(typ)
    if err != nil {

Mcmd/entire/cli/checkpoint/registry.go+7/-6


109 unmodified lines

110
111
112
113
114
115
116
113
114
115
116
117
118
119
120
121
122
123
7 unmodified lines

131
132
133
130
131
134
135
136
137
138

109 unmodified lines

// promptCheckpointBackend asks the user to choose a checkpoint storage backend
// during first-time interactive setup. The default is the git-branch backend;
// the git-refs backend is offered as the selectable alternative. It returns the
// canonical backend type, or "" when the user kept the default so the caller can
// skip writing a redundant config block. Callers must gate this on an
// interactive terminal.
func promptCheckpointBackend() (string, error) {
// canonical backend type, or "" when the user kept the default (or cancelled) so
// the caller can skip writing a redundant config block. Callers must gate this
// on an interactive terminal.
//
// Cancellation (Ctrl+C or a cancelled ctx) is treated like keeping the default:
// it prints a "cancelled" line and returns ("", nil) so enable continues with
// the default backend, matching the optional-prompt behavior elsewhere in setup.
func promptCheckpointBackend(ctx context.Context, w io.Writer) (string, error) {
    choice := checkpoint.BackendTypeGitBranch
    form := NewAccessibleForm(
        huh.NewGroup(
7 unmodified lines

Value(&choice),
        ),
    )
    if err := form.Run(); err != nil {
        return "", fmt.Errorf("checkpoint backend selection: %w", err)
    if err := form.RunWithContext(ctx); err != nil {
        return "", handleFormCancellation(w, "Checkpoint backend selection", err)
    }
    if choice == checkpoint.BackendTypeGitBranch {
        return "", nil

Mcmd/entire/cli/checkpoint_backend.go+10/-6


1178 unmodified lines

1179
1180
1181
1182
1182
1183
1184
1185
1186
1186
1187
1188
1189

1178 unmodified lines

// Otherwise, on the first interactive setup, offer a choice (default: branch).
    // Non-interactive or --yes first runs keep the default git-branch backend.
    if opts.CheckpointBackend == "" && firstRun && !opts.Yes && interactive.CanPromptInteractively() {
        chosen, err := promptCheckpointBackend()
        chosen, err := promptCheckpointBackend(ctx, w)
        if err != nil {
            return err
        }
        opts.CheckpointBackend = chosen // "" keeps the default backend
        opts.CheckpointBackend = chosen // "" keeps the default (or cancelled) backend
    }
    if err := applyCheckpointBackendFlag(settings, opts.CheckpointBackend); err != nil {
        return err
}