Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __tests__/ui/screens/InstallPluginsScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ describe('InstallPluginsScreen', () => {

await waitFor(() => {
const frame = sut.lastFrame()!;
const codexPos = frame.indexOf('Codex');
const cursorPos = frame.indexOf('Cursor');
const codexPos = frame.lastIndexOf('Codex');
const cursorPos = frame.lastIndexOf('Cursor');
expect(codexPos).toBeGreaterThan(-1);
expect(cursorPos).toBeGreaterThan(-1);
expect(codexPos).toBeLessThan(cursorPos);
Expand Down
30 changes: 11 additions & 19 deletions src/ui/tui/screens/install-plugins/InstallPluginsScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { getIntegrations } from '@integrations/index.js';
import { ScreenId } from '@lib/session.js';
import { track } from '@lib/telemetry.js';
import type { IdeId } from '@shared-kernel/types.js';

import { MainLayout } from '../../components/MainLayout.js';
import { TaskList } from '../../components/TaskList.js';
import { useAutoAdvance } from '../../hooks/useAutoAdvance.js';
Expand All @@ -8,18 +10,15 @@ import { useNavigation } from '../../hooks/useNavigation.js';
import { buildWizardTasks } from '../../lib/wizard-tasks.js';
import { $session, store } from '../../store.js';
import { usePluginInstall } from './usePluginInstall.js';
import { track } from '@lib/telemetry.js';
import {
pluginsAlreadyInstalled,
pluginInstalled,
pluginExitedAfterError,
} from './log-messages.js';
import * as te from './telemetry-events.js';
import { type IdeSelectValue, type DetectedSelectValue, type ErrorAction } from './actions.js';
import { type ErrorAction } from './actions.js';
import { BottomPrompt, MainContent } from './components/index.js';

const ALL_INTEGRATIONS = getIntegrations();

export function InstallPluginsScreen() {
const navigate = useNavigation(ScreenId.InstallPlugins);
const log = useLogger(ScreenId.InstallPlugins);
Expand All @@ -35,24 +34,18 @@ export function InstallPluginsScreen() {
},
});

function handleIdeSelect(value: IdeSelectValue) {
track(te.pluginIdeSelected(value));
selectIde(value);
}

const preferredIndex = ALL_INTEGRATIONS.map((i) => i.id).find((id) => detected.includes(id));

function handleDetectedSelect(value: DetectedSelectValue) {
if (value === 'continue') {
if (!preferredIndex) return;
function handleIdeSelect(value: IdeId) {
if (detected.includes(value)) {
store.setIde(value);

store.setIde(preferredIndex);
log(pluginsAlreadyInstalled(detected));
track(te.pluginsAlreadyDetected());
navigate.to('next');
return;
}
handleIdeSelect(value);

track(te.pluginIdeSelected(value));
selectIde(value);
}

function handleError(value: ErrorAction) {
Expand Down Expand Up @@ -83,8 +76,7 @@ export function InstallPluginsScreen() {
<BottomPrompt
phase={phase}
detected={detected}
onIdeSelect={handleIdeSelect}
onDetectedSelect={handleDetectedSelect}
onSelect={handleIdeSelect}
onError={handleError}
/>
}
Expand Down
4 changes: 0 additions & 4 deletions src/ui/tui/screens/install-plugins/actions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { IdeId } from '@shared-kernel/types.js';
import type { PromptOption } from '../../components/PromptPanel.js';

export type IdeSelectValue = IdeId;

export type DetectedSelectValue = IdeSelectValue | 'continue';

export const IDE_SELECT_OPTIONS: PromptOption<IdeId>[] = [
{ label: 'Claude Code', value: 'claude' },
{ label: 'Cursor', value: 'cursor' },
Expand Down
54 changes: 19 additions & 35 deletions src/ui/tui/screens/install-plugins/components/BottomPrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,23 @@ import type { IdeId } from '@shared-kernel/types.js';
import { getIntegrations } from '@integrations/index.js';
import { PromptPanel } from '../../../components/PromptPanel.js';
import type { PluginPhase } from '../usePluginInstall.js';
import {
IDE_SELECT_OPTIONS,
ERROR_OPTIONS,
type IdeSelectValue,
type DetectedSelectValue,
type ErrorAction,
} from '../actions.js';
import { ERROR_OPTIONS, type ErrorAction } from '../actions.js';
import { DefaultPrompt } from './DefaultPrompt.js';

const ALL_INTEGRATIONS = getIntegrations();

type BottomPromptProps = {
phase: PluginPhase;
detected: IdeId[];
onIdeSelect: (value: IdeSelectValue) => void;
onDetectedSelect: (value: DetectedSelectValue) => void;
onSelect: (value: IdeId) => void;
onError: (value: ErrorAction) => void;
};

export function BottomPrompt({
phase,
detected,
onIdeSelect,
onDetectedSelect,
onError,
}: BottomPromptProps) {
export function BottomPrompt({ phase, detected, onSelect, onError }: BottomPromptProps) {
switch (phase) {
case 'choose-ide':
return (
<PromptPanel
mode="select"
status="Which CLI agent would you like to use?"
options={IDE_SELECT_OPTIONS}
onSelect={onIdeSelect}
/>
);
return <DefaultPrompt onSelect={onSelect} />;

case 'error':
return (
<PromptPanel
Expand All @@ -46,32 +28,34 @@ export function BottomPrompt({
onSelect={onError}
/>
);

case 'already-installed': {
const detectedSet = new Set(detected);
const preferred = ALL_INTEGRATIONS.find((i) => detectedSet.has(i.id));
const otherOptions = ALL_INTEGRATIONS.filter((i) => i.id !== preferred?.id)

if (!preferred) {
return <DefaultPrompt onSelect={onSelect} />;
}

const rest = ALL_INTEGRATIONS.filter((i) => i.id !== preferred.id)
.toSorted((a, b) => Number(detectedSet.has(b.id)) - Number(detectedSet.has(a.id)))
.map((i) => ({
label: i.name,
value: i.id,
}));
.map((i) => ({ label: i.name, value: i.id }));

return (
<PromptPanel
mode="select"
status={`Confidence plugin detected for ${preferred?.name}. Continue with it?`}
options={[
{ label: `Continue with ${preferred?.name}`, value: 'continue' },
...otherOptions,
]}
onSelect={onDetectedSelect}
status={`Confidence plugin detected for ${preferred.name}. Continue with it?`}
options={[{ label: `Continue with ${preferred.name}`, value: preferred.id }, ...rest]}
onSelect={onSelect}
/>
);
}

case 'detecting':
case 'installing':
case 'installed':
return null;

default: {
const _exhaustive: never = phase satisfies never;
throw new Error(`Unhandled phase: ${_exhaustive}`);
Expand Down
18 changes: 18 additions & 0 deletions src/ui/tui/screens/install-plugins/components/DefaultPrompt.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { PromptPanel } from '@ui/tui/components/index.js';
import type { IdeId } from '@shared-kernel/types.js';
import { IDE_SELECT_OPTIONS } from '../actions.js';

type DefaultPromptProps = {
onSelect: (value: IdeId) => void;
};

export function DefaultPrompt({ onSelect }: DefaultPromptProps) {
return (
<PromptPanel
mode="select"
status="Which CLI agent would you like to use?"
options={IDE_SELECT_OPTIONS}
onSelect={onSelect}
/>
);
}