refactor(enable): extract the storage-backend gate to clear maintidx · Entire

refactor(enable): extract the storage-backend gate to clear maintidx

fba1ab8→main·

peyton-alt·9h ago·1 file·+44 added/-35

runEnableInteractive crossed the maintainability threshold after the review-driven gate additions; behavior unchanged.

Co-Authored-By: Claude Fable 5 noreply@anthropic.com

Changes

1

1238 unmodified lines

1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1242
1243
1244
1245
1274
1275
1276
1277
1246
1247
1248
1249
105 unmodified lines

1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400

1238 unmodified lines

opts.applyStrategyOptions(settings)

// Checkpoint storage backend. An explicit --checkpoint-backend always
    // wins. Otherwise a first interactive setup asks, with git-refs
    // pre-selected as the recommendation (one Enter for most users);
    // non-interactive/--yes first runs take the recommendation silently,
    // and a cancelled prompt takes it with an explicit note (unless the
    // command context itself was cancelled — then enable stops).
    // Either way the choice is written explicitly into the new
    // settings file, and the config-less runtime fallback stays git-branch
    // so existing repos are untouched. The prompt is skipped while
    // ENTIRE_CHECKPOINTS_PRIMARY is active (firstRunCheckpointBackendDefault
    // returns ""): the env fully replaces settings, so an answer could not
    // take effect and would only write diverging config.
    if opts.CheckpointBackend == "" && firstRun && !opts.Yes &&
        firstRunCheckpointBackendDefault() != "" && interactive.CanPromptInteractively() {
        chosen, err := promptCheckpointBackend(ctx, w)
        if err != nil {
            return err
        }
        if ctx.Err() != nil {
            // A cancelled command context (SIGINT/SIGTERM) surfaces as a
            // form cancellation, but the user asked to stop: setup must not
            // adopt a default and keep mutating the repo.
            return fmt.Errorf("checkpoint storage selection: %w", ctx.Err())
        }
        if chosen == "" {
            // Cancelled prompt: the recommendation is adopted, but never
            // silently — every other cancelled setup prompt skips its
            // action, so persisting a choice here must be disclosed.
            fmt.Fprintln(w, "Using the recommended git-refs checkpoint storage.")
        }
        opts.CheckpointBackend = chosen // "" (cancelled) falls through to the recommendation
    }
    backend, err := resolveFirstRunCheckpointBackend(ctx, w, opts, firstRun)
    if err != nil {
        return err
    }
    if opts.CheckpointBackend == "" && firstRun {
        opts.CheckpointBackend = firstRunCheckpointBackendDefault()
    }
    if err := applyCheckpointBackendFlag(settings, opts.CheckpointBackend); err != nil {
    if err := applyCheckpointBackendFlag(settings, backend); err != nil {
        return err
    }

105 unmodified lines

fmt.Fprintln(w, "\nTo add more agents, run `entire agent add <name>`.")
}

// resolveFirstRunCheckpointBackend decides the checkpoint storage backend
// the setup flow writes. An explicit --checkpoint-backend always wins.
// Otherwise a first interactive setup asks, with git-refs pre-selected as
// the recommendation (one Enter for most users); non-interactive/--yes
// first runs take the recommendation silently, and a cancelled prompt takes
// it with an explicit note (unless the command context itself was cancelled
// — then enable stops). Either way the choice is written explicitly into
// the new settings file, and the config-less runtime fallback stays
// git-branch so existing repos are untouched. The prompt is skipped while
// ENTIRE_CHECKPOINTS_PRIMARY is active (firstRunCheckpointBackendDefault
// returns ""): the env fully replaces settings, so an answer could not
// take effect and would only write diverging config.
func resolveFirstRunCheckpointBackend(ctx context.Context, w io.Writer, opts EnableOptions, firstRun bool) (string, error) {
    backend := opts.CheckpointBackend
    if backend == "" && firstRun && !opts.Yes &&
        firstRunCheckpointBackendDefault() != "" && interactive.CanPromptInteractively() {
        chosen, err := promptCheckpointBackend(ctx, w)
        if err != nil {
            return "", err
        }
        if ctx.Err() != nil {
            // A cancelled command context (SIGINT/SIGTERM) surfaces as a
            // form cancellation, but the user asked to stop: setup must not
            // adopt a default and keep mutating the repo.
            return "", fmt.Errorf("checkpoint storage selection: %w", ctx.Err())
        }
        if chosen == "" {
            // Cancelled prompt: the recommendation is adopted, but never
            // silently — every other cancelled setup prompt skips its
            // action, so persisting a choice here must be disclosed.
            fmt.Fprintln(w, "Using the recommended git-refs checkpoint storage.")
        }
        backend = chosen // "" (cancelled) falls through to the recommendation
    }
    if backend == "" && firstRun {
        backend = firstRunCheckpointBackendDefault()
    }
    return backend, nil
}

// firstRunCheckpointBackendDefault is the backend written on first-time
// setups when --checkpoint-backend wasn't passed: the git-refs store (a
// storage-topology question is unanswerable during first-time setup). Empty —