A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
fix onboarding login and model selector flow (#445)
ktd02d98da8a30
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.mdindex 1e0fb2f701..9286d3a85c 100644--- a/packages/coding-agent/CHANGELOG.md+++ b/packages/coding-agent/CHANGELOG.md@@ -6,6 +6,7 @@- Changed shell commands to use discoverable agent, schedule, package, model, session, update, doctor, and full-shutdown verbs without exposing the background daemon hierarchy ([ENG-4538](https://linear.app/primeintellect/issue/ENG-4538/standardize-bash-command-conventions-and-improve-command-discovery)).- Fixed unsupported Node versions crashing before startup by requiring Node 22.8.0 or newer and showing upgrade guidance before loading the CLI ([ENG-4260](https://linear.app/primeintellect/issue/ENG-4260/incorrect-node-version-breaks-first-launch)).- Added `@` file-path autocomplete to new-agent and reply prompts in the Agents View.+- Fixed first-launch Prime login and kept onboarding visible between team and model selection ([ENG-4658](https://linear.app/primeintellect/issue/ENG-4658/fix-onboarding-login-enter-key-and-model-selector-flicker)).- Fixed active heartbeat sessions appearing under Needs Input or Completed instead of a dedicated Heartbeats section ([ENG-4654](https://linear.app/primeintellect/issue/ENG-4654/categorize-heartbeat-sessions-as-working)).- Fixed stashed prompts being lost when leaving and reopening a session from the Agents View ([ENG-4659](https://linear.app/primeintellect/issue/ENG-4659/stashed-prompts-should-persist)).- Added a combined heartbeat indicator and manager for pausing, resuming, or stopping user and agent heartbeats ([ENG-4536](https://linear.app/primeintellect/issue/ENG-4536/add-heartbeat-observability-and-management-ui)).diff --git a/packages/coding-agent/src/modes/agents-view/agents-view-mode.ts b/packages/coding-agent/src/modes/agents-view/agents-view-mode.tsindex 120fe40d2a..bd748a576a 100644--- a/packages/coding-agent/src/modes/agents-view/agents-view-mode.ts+++ b/packages/coding-agent/src/modes/agents-view/agents-view-mode.ts@@ -1108,21 +1108,13 @@ class AgentsViewMode implements Component, Focusable {hide();resolve();};- const restore = () => {- if (settled) return;- hidden = false;- handle?.setHidden(false);- handle?.focus();- this.ui.requestRender();- };const authenticate = (provider: AuthSelectorProvider, tab: "providers" | "mcp-connections") => {if (settled) return;- handle?.setHidden(true);void authFlows.loginProvider(provider).then(async (authResult) => {if (settled) return;- restore();+ handle?.focus();menu.refreshAuthentication();if (authResult.status !== "success" || tab === "mcp-connections") return;@@ -1131,7 +1123,7 @@ class AgentsViewMode implements Component, Focusable {menu.setActiveTab("models");}).catch((error) => {- restore();+ handle?.focus();this.setStatusMessage(error instanceof Error ? error.message : String(error), { tone: "error" });});};diff --git a/packages/coding-agent/src/modes/interactive/components/prime-onboarding-splash.ts b/packages/coding-agent/src/modes/interactive/components/prime-onboarding-splash.tsindex 6d2d8601c5..5cc7dfe945 100644--- a/packages/coding-agent/src/modes/interactive/components/prime-onboarding-splash.ts+++ b/packages/coding-agent/src/modes/interactive/components/prime-onboarding-splash.ts@@ -51,6 +51,7 @@ interface QuietZone {export class PrimeOnboardingSplashComponent implements Component {private frame = 0;private animationInterval?: ReturnType<typeof setInterval>;+ private progressMessage?: string;constructor(private readonly onSelect: () => void,@@ -77,6 +78,12 @@ export class PrimeOnboardingSplashComponent implements Component {this.animationInterval = undefined;}+ showProgress(message: string): void {+ this.progressMessage = message;+ this.dispose();+ this.options.requestRender?.();+ }+render(width: number): string[] {const safeWidth = Math.max(1, width);const panelLines = this.renderPanel(safeWidth);@@ -91,6 +98,9 @@ export class PrimeOnboardingSplashComponent implements Component {}handleInput(keyData: string): void {+ if (this.progressMessage) {+ return;+ }const kb = getKeybindings();if (kb.matches(keyData, "tui.select.confirm")) {this.onSelect();@@ -102,6 +112,9 @@ export class PrimeOnboardingSplashComponent implements Component {}private formatContinueHint(): PanelTextLine {+ if (this.progressMessage) {+ return [{ text: this.progressMessage, tone: "muted" }];+ }const actionLabel = this.options.continueActionLabel ?? "login with Prime Intellect";return [{ text: "Press ", tone: "muted" },diff --git a/packages/coding-agent/src/modes/interactive/interactive-mode.ts b/packages/coding-agent/src/modes/interactive/interactive-mode.tsindex 10569ff8d0..a96068bf54 100644--- a/packages/coding-agent/src/modes/interactive/interactive-mode.ts+++ b/packages/coding-agent/src/modes/interactive/interactive-mode.ts@@ -464,6 +464,11 @@ type GoalAnnouncementSnapshot = {type ModelFallbackWarningAction = "show" | "suppress";+interface OnboardingSplashHandle {+ showProgress(message: string): void;+ dismiss(): void;+}+const THINKING_LEVEL_DESCRIPTIONS: Record<ThinkingLevel, string> = {off: "No reasoning",minimal: "Very brief reasoning",@@ -1505,15 +1510,23 @@ export class InteractiveMode {return true;}+ private async showOnboardingModelSelection(splash: OnboardingSplashHandle): Promise<void> {+ try {+ await this.showConfigurationMenu("models");+ } finally {+ splash.dismiss();+ }+ }+private async runOnboardingFlow(showPrimeCliSplash = this.shouldRunPrimeCliOnboardingSplash()): Promise<void> {this.modelRegistry.refresh();if (showPrimeCliSplash) {- const shouldContinue = await this.showOnboardingModelSelectionSplash();- if (!shouldContinue) {+ const splash = await this.showOnboardingSplash("choose a model");+ if (!splash) {return;}- await this.showConfigurationMenu("models");+ await this.showOnboardingModelSelection(splash);return;}@@ -1523,7 +1536,21 @@ export class InteractiveMode {return;}- await this.showConfigurationMenu("providers");+ const splash = await this.showOnboardingSplash();+ if (!splash) {+ return;+ }++ splash.showProgress("Signing in to Prime Intellect...");+ const authResult = await this.createAuthFlows().runPrimeInferenceLogin();+ if (authResult.status !== "success") {+ splash.dismiss();+ return;+ }++ splash.showProgress("Preparing models...");+ await this.prepareForModelSelectionAfterLogin(authResult);+ await this.showOnboardingModelSelection(splash);}private getMarkdownThemeWithSettings(): MarkdownTheme {@@ -7194,13 +7221,6 @@ export class InteractiveMode {hide();resolve();};- const restore = () => {- if (settled) return;- hidden = false;- handle?.setHidden(false);- handle?.focus();- this.ui.requestRender();- };const refreshModels = (force: boolean) => {const refreshPromise = this.getModelSelectorRefreshPromise({ force });if (!refreshPromise) return;@@ -7214,12 +7234,11 @@ export class InteractiveMode {};const authenticate = (provider: AuthSelectorProvider, tab: "providers" | "mcp-connections") => {if (settled) return;- handle?.setHidden(true);void authFlows.loginProvider(provider).then(async (authResult) => {if (settled) return;- restore();+ handle?.focus();menu.refreshAuthentication();if (authResult.status !== "success") return;@@ -7240,7 +7259,7 @@ export class InteractiveMode {refreshModels(true);}).catch((error) => {- restore();+ handle?.focus();this.showError(error instanceof Error ? error.message : String(error));});};@@ -7656,36 +7675,44 @@ export class InteractiveMode {}}- private showOnboardingModelSelectionSplash(): Promise<boolean> {+ private showOnboardingSplash(continueActionLabel?: string): Promise<OnboardingSplashHandle | undefined> {return new Promise((resolve) => {let settled = false;+ let dismissed = false;let handle: OverlayHandle | undefined;let selector: PrimeOnboardingSplashComponent | undefined;- const settle = (result: boolean) => {+ const settle = (result: OnboardingSplashHandle | undefined) => {if (settled) {return;}settled = true;resolve(result);};- const close = () => {+ const dismiss = () => {+ if (dismissed) {+ return;+ }+ dismissed = true;selector?.dispose();handle?.hide();this.ui.requestRender();};selector = new PrimeOnboardingSplashComponent(() => {- close();- settle(true);+ selector?.dispose();+ settle({+ showProgress: (message) => selector?.showProgress(message),+ dismiss,+ });},() => {- close();- settle(false);+ dismiss();+ settle(undefined);},{getRows: () => this.ui.terminal.rows,requestRender: () => this.ui.requestRender(),- continueActionLabel: "choose a model",+ ...(continueActionLabel ? { continueActionLabel } : {}),},);handle = this.ui.showOverlay(selector, {diff --git a/packages/coding-agent/test/interactive-mode-status.test.ts b/packages/coding-agent/test/interactive-mode-status.test.tsindex b067b98204..76ce244ef9 100644--- a/packages/coding-agent/test/interactive-mode-status.test.ts+++ b/packages/coding-agent/test/interactive-mode-status.test.ts@@ -1833,6 +1833,10 @@ describe("InteractiveMode model selection persistence", () => {});describe("InteractiveMode Prime CLI onboarding", () => {+ type OnboardingSplashHandle = {+ showProgress(message: string): void;+ dismiss(): void;+ };type OnboardingHarness = {shouldRunOnboarding(): boolean;markOnboardingShown(): void;@@ -1870,7 +1874,8 @@ describe("InteractiveMode Prime CLI onboarding", () => {maybeWarnAboutAnthropicSubscriptionAuth?: (model?: AgentConnectionModel) => void;checkDaxnutsEasterEgg?: (model: { provider: string; id: string }) => void;findExactModelMatch?: (searchTerm: string) => Promise<AgentConnectionModel | undefined>;- showOnboardingModelSelectionSplash?: () => Promise<boolean>;+ showOnboardingSplash?: (continueActionLabel?: string) => Promise<OnboardingSplashHandle | undefined>;+ createAuthFlows?: () => { runPrimeInferenceLogin(): Promise<AuthenticationResult> };showConfigurationMenu?: (tab: "providers" | "models" | "mcp-connections") => Promise<void>;getModelCandidates?: () => Promise<AgentConnectionModel[]>;};@@ -2010,7 +2015,7 @@ describe("InteractiveMode Prime CLI onboarding", () => {test("cancelled Prime CLI splash exits onboarding before opening configuration", async () => {const fakeThis = createPrimeCliHarness(false);- fakeThis.showOnboardingModelSelectionSplash = vi.fn(async () => false);+ fakeThis.showOnboardingSplash = vi.fn(async () => undefined);fakeThis.showConfigurationMenu = vi.fn(async () => {});await expect(runOnboardingFlow.call(fakeThis)).resolves.toBeUndefined();@@ -2020,12 +2025,21 @@ describe("InteractiveMode Prime CLI onboarding", () => {test("opens the Models tab after the Prime CLI splash", async () => {const fakeThis = createPrimeCliHarness(false);- fakeThis.showOnboardingModelSelectionSplash = vi.fn(async () => true);- fakeThis.showConfigurationMenu = vi.fn(async () => {});+ const configuration = createDeferred<void>();+ const dismiss = vi.fn();+ fakeThis.showOnboardingSplash = vi.fn(async () => ({ showProgress: vi.fn(), dismiss }));+ fakeThis.showConfigurationMenu = vi.fn(() => configuration.promise);- await expect(runOnboardingFlow.call(fakeThis)).resolves.toBeUndefined();+ const onboarding = runOnboardingFlow.call(fakeThis);+ await flushAsyncWork();expect(fakeThis.showConfigurationMenu).toHaveBeenCalledWith("models");+ expect(dismiss).not.toHaveBeenCalled();++ configuration.resolve();+ await expect(onboarding).resolves.toBeUndefined();++ expect(dismiss).toHaveBeenCalledTimes(1);});test("opens the Models tab when models are already available", async () => {@@ -2040,15 +2054,40 @@ describe("InteractiveMode Prime CLI onboarding", () => {expect(fakeThis.showConfigurationMenu).toHaveBeenCalledWith("models");});- test("opens the Providers tab when no models are available", async () => {+ test("opens Prime login before the Models tab when no models are available", async () => {const fakeThis = createPrimeCliHarness(false);fakeThis.connectionState = createConnectionState({ model: undefined });fakeThis.getModelCandidates = vi.fn(async () => []);- fakeThis.showConfigurationMenu = vi.fn(async () => {});+ const showProgress = vi.fn();+ const dismiss = vi.fn();+ fakeThis.showOnboardingSplash = vi.fn(async () => ({ showProgress, dismiss }));+ fakeThis.createAuthFlows = vi.fn(() => ({+ runPrimeInferenceLogin: vi.fn(async () => ({+ status: "success" as const,+ providerId: PRIME_INFERENCE_PROVIDER_ID,+ providerName: "Prime Inference",+ authType: "api_key" as const,+ kind: "provider" as const,+ })),+ }));+ fakeThis.prepareForModelSelectionAfterLogin = vi.fn(async () => true);+ const configuration = createDeferred<void>();+ fakeThis.showConfigurationMenu = vi.fn(() => configuration.promise);- await expect(runOnboardingFlow.call(fakeThis, false)).resolves.toBeUndefined();+ const onboarding = runOnboardingFlow.call(fakeThis, false);+ await flushAsyncWork();++ expect(fakeThis.showOnboardingSplash).toHaveBeenCalledWith();+ expect(showProgress).toHaveBeenNthCalledWith(1, "Signing in to Prime Intellect...");+ expect(showProgress).toHaveBeenNthCalledWith(2, "Preparing models...");+ expect(fakeThis.prepareForModelSelectionAfterLogin).toHaveBeenCalledTimes(1);+ expect(fakeThis.showConfigurationMenu).toHaveBeenCalledWith("models");+ expect(dismiss).not.toHaveBeenCalled();++ configuration.resolve();+ await expect(onboarding).resolves.toBeUndefined();- expect(fakeThis.showConfigurationMenu).toHaveBeenCalledWith("providers");+ expect(dismiss).toHaveBeenCalledTimes(1);});});diff --git a/packages/coding-agent/test/prime-onboarding-splash.test.ts b/packages/coding-agent/test/prime-onboarding-splash.test.tsindex 33999b9375..9d19129176 100644--- a/packages/coding-agent/test/prime-onboarding-splash.test.ts+++ b/packages/coding-agent/test/prime-onboarding-splash.test.ts@@ -91,6 +91,22 @@ describe("PrimeOnboardingSplashComponent", () => {expect(output).not.toContain("Press Enter to login with Prime Intellect");});+ it("shows progress and ignores input while onboarding advances", () => {+ const onSelect = vi.fn();+ const onCancel = vi.fn();+ const component = new PrimeOnboardingSplashComponent(onSelect, onCancel, { getRows: () => 36 });++ component.showProgress("Preparing models...");+ component.handleInput("\r");+ component.handleInput("\x1b");++ const output = stripAnsi(component.render(100).join("\n"));+ expect(output).toContain("Preparing models...");+ expect(output).not.toContain("Press Enter");+ expect(onSelect).not.toHaveBeenCalled();+ expect(onCancel).not.toHaveBeenCalled();+ });+it("animates the splash at an interactive cadence", () => {vi.useFakeTimers();let renderRequests = 0;diff --git a/packages/coding-agent/test/suite/regressions/4658-onboarding-transitions.test.ts b/packages/coding-agent/test/suite/regressions/4658-onboarding-transitions.test.tsnew file mode 100644index 0000000000..1a1ce0f440--- /dev/null+++ b/packages/coding-agent/test/suite/regressions/4658-onboarding-transitions.test.ts@@ -0,0 +1,179 @@+import { type Component, type OverlayHandle, setKeybindings, type TUI } from "@earendil-works/pi-tui";+import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";+import { KeybindingsManager } from "../../../src/core/keybindings.js";+import type { ModelRegistry } from "../../../src/core/model-registry.js";+import type { AgentConnectionModel } from "../../../src/modes/agent-connection/types.js";+import type { AuthenticationResult } from "../../../src/modes/interactive/auth-flows.js";+import type { ConfigurationMenuComponent } from "../../../src/modes/interactive/components/configuration-menu.js";+import { InteractiveMode } from "../../../src/modes/interactive/interactive-mode.js";+import { initTheme } from "../../../src/modes/interactive/theme/theme.js";+import { createHarness, type Harness } from "../harness.js";++interface OnboardingSplashHandle {+ showProgress(message: string): void;+ dismiss(): void;+}++interface InteractiveOnboardingHarness {+ runOnboardingFlow(showPrimeCliSplash?: boolean): Promise<void>;+ uiServices: {+ modelRegistry: ModelRegistry;+ };+ getModelCandidates(): Promise<AgentConnectionModel[]>;+ showOnboardingSplash(continueActionLabel?: string): Promise<OnboardingSplashHandle | undefined>;+ createAuthFlows(): {+ runPrimeInferenceLogin(): Promise<AuthenticationResult>;+ };+ prepareForModelSelectionAfterLogin(authResult: AuthenticationResult): Promise<boolean>;+ showConfigurationMenu(tab: "providers" | "models" | "mcp-connections"): Promise<void>;+}++interface ConfigurationHarness {+ showConfigurationMenu(tab: "providers" | "models" | "mcp-connections"): Promise<void>;+ ui: TUI;+ uiServices: {+ modelRegistry: ModelRegistry;+ settingsManager: Harness["settingsManager"];+ };+ getCachedModelCandidates(): AgentConnectionModel[];+ getScopedModelState(): [];+ getCurrentModel(): AgentConnectionModel;+ getModelSelectorRefreshPromise(): undefined;+ createAuthFlows(): {+ getLoginProviderOptions(): Array<{ id: string; name: string; authType: "api_key" }>;+ loginProvider(): Promise<AuthenticationResult>;+ };+ showFullPaneOverlay(component: Component, width: number): OverlayHandle;+ showError(message: string): void;+ showStatus(message: string): void;+}++function deferred<T>(): { promise: Promise<T>; resolve(value: T): void } {+ let resolvePromise: (value: T) => void = () => {};+ const promise = new Promise<T>((resolve) => {+ resolvePromise = resolve;+ });+ return { promise, resolve: resolvePromise };+}++describe("ENG-4658 onboarding transitions", () => {+ const harnesses: Harness[] = [];++ beforeEach(() => {+ initTheme("dark");+ setKeybindings(new KeybindingsManager());+ });++ afterEach(() => {+ for (const harness of harnesses.splice(0)) {+ harness.cleanup();+ }+ });++ test("keeps the splash mounted until first-launch model selection closes", async () => {+ const harness = await createHarness({ provider: "prime-inference", withConfiguredAuth: false });+ harnesses.push(harness);+ const order: string[] = [];+ const configuration = deferred<void>();+ const splash: OnboardingSplashHandle = {+ showProgress: (message) => order.push(`progress:${message}`),+ dismiss: () => order.push("dismiss"),+ };+ const fakeThis = Object.create(InteractiveMode.prototype) as InteractiveOnboardingHarness;+ fakeThis.uiServices = { modelRegistry: harness.session.modelRegistry };+ fakeThis.getModelCandidates = vi.fn(async () => []);+ fakeThis.showOnboardingSplash = vi.fn(async () => splash);+ fakeThis.createAuthFlows = vi.fn(() => ({+ runPrimeInferenceLogin: async (): Promise<AuthenticationResult> => {+ order.push("login");+ return {+ status: "success",+ providerId: "prime-inference",+ providerName: "Prime Inference",+ authType: "api_key",+ kind: "provider",+ };+ },+ }));+ fakeThis.prepareForModelSelectionAfterLogin = vi.fn(async () => {+ order.push("prepare");+ return true;+ });+ fakeThis.showConfigurationMenu = vi.fn((tab) => {+ order.push(`configuration:${tab}`);+ return configuration.promise;+ });++ const onboarding = fakeThis.runOnboardingFlow(false);+ await vi.waitFor(() => expect(fakeThis.showConfigurationMenu).toHaveBeenCalledWith("models"));++ expect(order).not.toContain("dismiss");+ configuration.resolve();+ await onboarding;++ expect(fakeThis.showOnboardingSplash).toHaveBeenCalledWith();+ expect(order).toEqual([+ "progress:Signing in to Prime Intellect...",+ "login",+ "progress:Preparing models...",+ "prepare",+ "configuration:models",+ "dismiss",+ ]);+ });++ test("keeps the configuration overlay mounted while provider authentication is pending", async () => {+ const harness = await createHarness();+ harnesses.push(harness);+ const login = deferred<AuthenticationResult>();+ const setHidden = vi.fn();+ const hide = vi.fn();+ const focus = vi.fn();+ let menu: ConfigurationMenuComponent | undefined;+ const overlayHandle: OverlayHandle = {+ hide,+ setHidden,+ isHidden: () => false,+ focus,+ unfocus: vi.fn(),+ isFocused: () => true,+ };+ const model = harness.getModel() as AgentConnectionModel;+ const fakeThis = Object.create(InteractiveMode.prototype) as ConfigurationHarness;+ fakeThis.ui = {+ terminal: { rows: 24 },+ requestRender: vi.fn(),+ } as unknown as TUI;+ fakeThis.uiServices = {+ modelRegistry: harness.session.modelRegistry,+ settingsManager: harness.settingsManager,+ };+ fakeThis.getCachedModelCandidates = () => [model];+ fakeThis.getScopedModelState = () => [];+ fakeThis.getCurrentModel = () => model;+ fakeThis.getModelSelectorRefreshPromise = () => undefined;+ fakeThis.createAuthFlows = () => ({+ getLoginProviderOptions: () => [{ id: model.provider, name: model.provider, authType: "api_key" }],+ loginProvider: () => login.promise,+ });+ fakeThis.showFullPaneOverlay = (component) => {+ menu = component as ConfigurationMenuComponent;+ return overlayHandle;+ };+ fakeThis.showError = vi.fn();+ fakeThis.showStatus = vi.fn();++ const configuration = fakeThis.showConfigurationMenu("providers");+ expect(menu).toBeDefined();+ menu?.handleInput("\r");++ expect(setHidden).not.toHaveBeenCalled();+ expect(hide).not.toHaveBeenCalled();++ login.resolve({ status: "cancelled" });+ await vi.waitFor(() => expect(focus).toHaveBeenCalled());+ menu?.handleInput("\x1b");+ await expect(configuration).resolves.toBeUndefined();+ expect(hide).toHaveBeenCalledOnce();+ });+});