Skip to content

feat(settings): scaffold default settings.json on first run#203

Open
kuishou68 wants to merge 1 commit into
lessweb:mainfrom
kuishou68:fix/scaffold-default-settings
Open

feat(settings): scaffold default settings.json on first run#203
kuishou68 wants to merge 1 commit into
lessweb:mainfrom
kuishou68:fix/scaffold-default-settings

Conversation

@kuishou68

Copy link
Copy Markdown

Problem

Closes #202.

A fresh install has no ~/.deepcode/settings.json, so the first task fails with:

API key not found. Please configure ~/.deepcode/settings.json or ./.deepcode/settings.json.

The message says "configure" the file, but it does not exist — the user has to create it from scratch and guess the schema. Settings are only ever read on startup; nothing scaffolds the file on first run.

Change

  • packages/core/src/settings.ts
    • buildDefaultSettings() — returns the template (env.API_KEY = "", BASE_URL = DEFAULT_BASE_URL, MODEL = DEFAULT_MODEL).
    • ensureUserSettingsFile() — writes that template to the user settings path when missing; returns { path, created }. Never overwrites an existing file.
  • packages/core/src/index.ts — export both helpers from the public API.
  • packages/cli/src/cli.tsx — call ensureUserSettingsFile() on startup (after the TTY check, before the TUI renders). When a file is newly created, print where it is and remind the user to set API_KEY. Failures are caught and reported without blocking startup.

After this change the first run leaves the user with a ready-to-edit config file; they only paste their key instead of authoring the file by hand.

Tests

Added to packages/core/src/tests/settings-and-notify.test.ts (run against a temp HOME):

  • creates the template when the settings file is missing (and the contents match buildDefaultSettings()),
  • never overwrites an existing settings file.

Verification

  • npm run typecheck — passes
  • npm run lint / prettier --check — clean on changed files
  • npm run test --workspace @vegamo/deepcode-core — 248 passing, 0 failing (incl. the 2 new tests)

Notes

  • Backwards compatible: existing users with a populated settings.json are untouched (the file is only written when absent).
  • The scaffolded API_KEY is empty, so the existing "API key not found" guard still applies until the user fills it in — now they have an obvious file to edit.

A fresh install has no ~/.deepcode/settings.json, so the first task fails
with "API key not found" and the user must create the file by hand while
guessing the schema.

Add ensureUserSettingsFile(), which writes a template settings file with an
empty API_KEY and default BASE_URL/MODEL when none exists, and never
overwrites an existing file. The CLI calls it on startup (after the TTY
check) and tells the user where to set their key.

Covered by unit tests for both the create and the never-overwrite paths.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fresh install has no settings.json: first run fails with "API key not found" and forces manual file creation

1 participant