Skip to content

fix(cli): prevent welcome() from re-triggering setup when global config exists#2859

Closed
Bernardxu123 wants to merge 1 commit into
esengine:main-v2from
Bernardxu123:fix/welcome-retrigger-setup
Closed

fix(cli): prevent welcome() from re-triggering setup when global config exists#2859
Bernardxu123 wants to merge 1 commit into
esengine:main-v2from
Bernardxu123:fix/welcome-retrigger-setup

Conversation

@Bernardxu123
Copy link
Copy Markdown
Collaborator

Problem

When running reasonix without arguments from a directory that lacks reasonix.toml, the setup wizard is re-triggered even though a valid global config (~/.config/reasonix/config.toml) exists and loads successfully.

Root Cause

In welcome() (internal/cli/cli.go), the setup trigger condition was:

if src == "" && isInteractive() {   // src = config.SourcePath()
    interactiveSetup("reasonix.toml")  // ← triggers setup wizard
}

SourcePath() checks for reasonix.toml in cwd first, then falls back to the global user config. When the user runs reasonix from a different directory (e.g., after cd), ``SourcePath()returns""` because there's no cwd-local file — even though `config.Load()` would succeed from the global path.

The chat entry path also unnecessarily required src != "":

if src != "" && cfgErr == nil && isInteractive() {  // ← blocks chat when src is empty
    return chatREPL(nil)
}

Fix

  1. Move config.Load() before the setup-trigger check
  2. Change trigger condition from src == "" to src == "" && cfgErr != nil — wizard only runs when no config loads from ANY source
  3. Remove redundant src != "" guard on chat entry — cfgErr == nil is sufficient
// Before: always triggered setup when no cwd-local file
if src == "" && isInteractive() {

// After: only triggers setup when config.Load() also fails
if src == "" && cfgErr != nil && isInteractive() {

Testing

  • go build ./... — compiles successfully
  • go test ./internal/config/ — all tests pass
  • go test ./internal/cli/ — 5 pre-existing i18n test failures unrelated to this change

Closes #2856

…ig exists

When running `reasonix` without arguments from a directory that lacks
`reasonix.toml`, the old code treated it as a first-run scenario and
re-triggered the setup wizard, even though a valid global config
(`~/.config/reasonix/config.toml`) was loaded successfully.

Fix by moving `config.Load()` before the setup-trigger check, and
changing the trigger condition from `src == ""` to `src == "" &&
cfgErr != nil`. This ensures the wizard only runs when no config can
be loaded from ANY source (neither cwd-local nor user-global).

Also remove the redundant `src != ""` guard on the chat entry path
(`cfgErr == nil` is sufficient — if config loads, we can chat).

Closes esengine#2856
@esengine
Copy link
Copy Markdown
Owner

esengine commented Jun 3, 2026

Good catch and a clean diagnosis — welcome() keying the setup trigger on SourcePath() == "" (no cwd-local file) instead of on whether config.Load() actually succeeds was exactly the bug. Your fix (load early, gate on cfgErr != nil, drop the redundant src != "" on the chat path) is the right shape.

The branch had drifted into a conflict with main-v2 (the interactiveSetup signature changed since you opened this), so I reapplied your change verbatim onto current main-v2 in #2906 with your authorship preserved. It'll land there.

Closing in favour of #2906 — thanks for the contribution!

@esengine esengine closed this Jun 3, 2026
@Bernardxu123 Bernardxu123 deleted the fix/welcome-retrigger-setup branch June 3, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:reasonix 无参数运行会在某些情况下重新触发设置向导

2 participants