Skip to content

feat(cli): standalone first-run API-key onboarding in the TUI - #1177

Merged
Astro-Han merged 7 commits into
mainfrom
feat/cli-onboarding-apikey
Jul 17, 2026
Merged

Astro-Han merged 7 commits into
mainfrom
feat/cli-onboarding-apikey

Conversation

@Astro-Han

Copy link
Copy Markdown
Contributor

Summary

Addresses #1098 (phase 1: API-key onboarding). The standalone CLI used to abort on a fresh install with NO_REAL_CONNECTION:missing_default_connection and tell the user to configure a connection in Maka Desktop — so it could never stand on its own. This adds an in-TUI onboarding path:

  • First-run: maka with no connection now runs the wizard automatically, then retries context creation and launches the normal TUI.
  • /setup: a slash command to add another API-key connection from an already-running TUI.

The wizard lists the API-key-capable providers from the catalog, collects provider + key, and persists a default connection through the host-agnostic store layer. There is no parallel persistence path — setupApiKeyConnection reuses connectionStore + credentialStore + fetchProviderModels that the runtime already uses, so the new connection is immediately usable.

The first-run wizard runs over a stub MakaSessionDriver (chat/runtime methods are unreachable; the editor only collects provider + key via the onboarding intercept, and the TUI never touches driver.runtime), hands control back to cli.ts on success, which retries createMakaCliRuntimeContext and launches the normal TUI.

Verification

  • npm run build clean.
  • packages/cli test suite: 136 pass, 0 fail, including new tests for the provider picker, the key-submission interception → setupApiKeyConnection, and first-run auto-opening the picker without /setup.
  • Manual: fresh workspace (no connection) → maka auto-opens the picker → enter API key → normal TUI launches and is chat-ready; a subsequent /model lists the provider's models.

Phase 2 (intentionally not in this PR)

  • Base URL prompt in the wizard — the plumbing (setupApiKeyConnection + effectiveBaseUrl) already supports a custom base URL, but the wizard does not yet ask for it.
  • OAuth providers — the loop is currently locked behind Electron subscription services.
  • In-wizard model selection.

End-to-end vertical slice for #1098: a TUI wizard that adds an API-key
connection without leaving the CLI.

- /setup lists API-key providers (listApiKeyOnboardableProviders); after
  picking one, the wizard collects the API key in the editor and persists
  the connection + secret via setupApiKeyConnection, then makes it default.
- setupApiKeyConnection: gate on api-key providers and a non-empty key,
  create the connection, store the secret, probe models non-blocking.
- MakaOnboardingSurface: the TUI collects provider + key; the host
  (runtime-bootstrap) owns the stores and runs the real setup, mirroring
  the skills surface pattern.
- FakeTerminal end-to-end tests cover the picker and the key→setup path;
  two slash-autocomplete tests updated for the new /setup command.

Out of scope (next slice): first-run auto-trigger — createMakaCliRuntimeContext
throws before the TUI starts when no connection exists, so /setup today adds a
connection once the CLI can launch; OAuth subscription loop, baseUrl prompt,
and in-wizard model selection are also deferred.
Fresh installs hit NO_REAL_CONNECTION:missing_default_connection and exited
with a "configure in Maka Desktop" message, so the standalone CLI could never
bootstrap itself — the very gap #1098 exists to close.

- cli.ts catches missing_default_connection, runs the in-TUI onboarding wizard
  (runFirstRunOnboarding) over a stub session driver, then retries
  createMakaCliRuntimeContext and launches the normal TUI.
- runMakaPiTui firstRun mode auto-opens the provider picker on launch and
  closes the TUI (onConfigured + beginClose) once a connection is configured,
  handing control back to the host for the retry.
- createFirstRunSessionDriver: a stub MakaSessionDriver whose chat/runtime
  methods are unreachable (the wizard only collects provider + key via the
  onboarding intercept); driver.runtime is unused by the TUI.

A connection configured via first-run or /setup is usable on the next launch
without Maka Desktop.
listApiKeyOnboardableProviders listed every API-key provider, including
openai-compatible and cloudflare-workers-ai, whose catalog baseUrl is empty.
Phase 1 collects only an API key, so picking one saved a connection whose
defaultModel was empty (openai-compatible) -> the post-wizard context retry
threw missing_model, which is neither caught nor re-offers the wizard, wedging
the install permanently (hand-edit llm-connections.json or install Desktop).

Exclude requiresBaseUrl providers until the phase-2 base-URL prompt lands.

PR #1177 review (Codex + Kimi K3) finding A.
- Remove the unused onConfigured MakaPiTuiInput field: cli.ts's first-run
  path already detects success via the configured closure, so the callback
  was speculative dead API.
- createFirstRunSessionDriver no longer carries runtime/cwd/slug/model (none
  are MakaSessionDriver members) and drops the as-unknown-as cast; the object
  now directly satisfies the interface.

PR #1177 review (Codex + Kimi K3) findings F, G.
The wizard reported unconditional success even when the model probe failed
(wrong key, offline), and re-onboarding the same provider threw "slug already
exists" — so a typo'd key at first-run left a broken default with no in-CLI
recovery. The mid-session /setup notice also promised immediate usability the
frozen modelChoices could not deliver.

- setupApiKeyConnection upserts by slug: an existing connection keeps its
  endpoint/model and only the key is rotated; a newly-created one is rolled
  back (remove) when the secret write fails, so no orphan becomes default.
- MakaOnboardingSurface.setup now resolves with { testError } when the
  connection was saved but the probe failed; the wizard surfaces it and
  re-arms the key prompt so the user retries in place.
- Extract createApiKeyOnboardingSurface so cli.ts (first-run) and
  runtime-bootstrap (in-session) share one write path and one slug policy.
- The in-session success notice no longer claims /model works immediately;
  the new connection takes effect on the next maka launch.
- cli.ts detects a configured first-run via connectionStore.getDefault()
  instead of a speculative callback.

PR #1177 review (Codex + Kimi K3) findings B, D, H.
…apture

The first-run wizard shared the normal editor submit path, so two defects
leaked: Esc on the provider picker dropped into a driver-less editor where any
submit ran the stub driver's preparePrompt (an errored turn), and a slash
command typed while the key prompt was armed was swallowed as the API key.

- First-run mode now refuses agent turns: an unarmed submit re-opens the
  picker, and cancelling the picker closes the TUI (the host sees no configured
  connection) instead of entering a session-less editor.
- A slash command typed while the key prompt is armed is routed as a command,
  not stored as the secret.

PR #1177 review (Codex + Kimi K3) finding C.
…rors

- The editor's key-submission intercept called input.onboarding?.setup().then():
  the ?. guarded the call but not .then, so a host without an onboarding surface
  threw TypeError on submit. Guard explicitly and report "onboarding unavailable".
- cli.ts retried createMakaCliRuntimeContext outside any try/catch after the
  wizard, so a still-unready connection (e.g. missing_model) crashed with a raw
  stack. Wrap the retry in the same classified guidance path as the first attempt.

PR #1177 review (Codex + Kimi K3) findings E, J.
@Astro-Han
Astro-Han merged commit f3b742d into main Jul 17, 2026
3 checks passed
@Astro-Han
Astro-Han deleted the feat/cli-onboarding-apikey branch July 24, 2026 09:04
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.

1 participant