diff --git a/README.md b/README.md index 4ce920e..f2bddc4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![CI](https://github.com/SingularityCoLabs/parallax/actions/workflows/ci.yml/badge.svg)](https://github.com/SingularityCoLabs/parallax/actions/workflows/ci.yml) [![Release](https://github.com/SingularityCoLabs/parallax/actions/workflows/publish.yml/badge.svg)](https://github.com/SingularityCoLabs/parallax/actions/workflows/publish.yml) -[![npm](https://img.shields.io/npm/v/%40singularitycolabs%2Fparallax?label=npm%20next)](https://www.npmjs.com/package/@singularitycolabs/parallax) +[![npm](https://img.shields.io/npm/v/%40singularitycolabs%2Fparallax?label=npm%20latest)](https://www.npmjs.com/package/@singularitycolabs/parallax) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) A secure, extensible **agent runtime** with a CLI as its first interface. The model @@ -145,7 +145,7 @@ the history carries over to the new model: > /models list models for the current provider (with price/context) > /provider openai switch provider (uses its default model) > /model anthropic/claude-sonnet-4-6 switch provider + model in one step -> /model open the interactive model picker +> /model (or /m) choose a provider, then choose its model > /tools list the available agent tools > /theme light switch the color theme (toggles with no arg) > /mode plan set permission mode (or /plan, /workspace, /read-only, /bypass) diff --git a/docs/releasing.md b/docs/releasing.md index 38d1b14..e6667c6 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -3,10 +3,15 @@ Parallax uses two release paths in [`publish.yml`](../.github/workflows/publish.yml): -| Branch | Trigger | npm dist-tag | Purpose | -| ------------- | ------------------------ | ------------ | --------------------- | -| `main` | Successful main CI run | `next` | Public beta releases | -| `development` | Manual workflow dispatch | `dev` | Development snapshots | +| Branch | Trigger | npm dist-tag | Purpose | +| ------------- | ------------------------ | ------------ | ----------------------- | +| `main` | Successful main CI run | `latest` | Public pre-1.0 releases | +| `development` | Manual workflow dispatch | `dev` | Development snapshots | + +While Parallax is pre-1.0, the newest public build is intentionally published as +`latest`, including beta versions. The legacy `next` tag is not advanced by the +current workflow; use the plain package name or `@latest` when installing and +verifying a release. Daily work belongs on `development`. Promote tested work to `main` with a pull request. Do not create npm versions, Git tags, or GitHub Releases for normal beta @@ -47,8 +52,8 @@ After choosing the version, the workflow: 3. Creates a generated `chore(release): v [skip ci]` commit when the manifest version changed. 4. Atomically pushes the release commit and matching `v` tag. -5. Publishes prereleases to npm `next`, or stable versions to npm `latest`, with - provenance through trusted publishing. +5. Publishes the selected pre-1.0 release to npm `latest`, with provenance + through trusted publishing. 6. Creates the matching GitHub Release and generated release notes. The atomic Git push prevents npm publication if another main update races with @@ -90,9 +95,9 @@ Verify the completed release: ```bash npm dist-tag ls @singularitycolabs/parallax -npm view @singularitycolabs/parallax@next version gitHead +npm view @singularitycolabs/parallax@latest version gitHead gh release list --repo SingularityCoLabs/parallax --limit 5 -npx --yes @singularitycolabs/parallax@next --version +npx --yes @singularitycolabs/parallax@latest --version ``` ## Starting a new release line @@ -116,7 +121,8 @@ main merges automatically advance to `0.2.0-beta.1`, `0.2.0-beta.2`, and so on. To publish a stable release, deliberately set an unpublished stable version such as `0.2.0` on `development`, verify it, and promote it through the same pull -request flow. Stable releases use npm `latest` and create a normal GitHub Release. +request flow. Stable releases continue using npm `latest` and create a normal +GitHub Release instead of a prerelease. ## Manually publishing `development` diff --git a/src/cli/replCommands.ts b/src/cli/replCommands.ts index e25db62..6e5c318 100644 --- a/src/cli/replCommands.ts +++ b/src/cli/replCommands.ts @@ -39,6 +39,7 @@ export function parseCommand(line: string): ReplCommand { return { kind: 'models', ...(arg !== undefined ? { arg } : {}) }; case 'provider': return { kind: 'provider', ...(arg !== undefined ? { arg } : {}) }; + case 'm': case 'model': return { kind: 'model', ...(arg !== undefined ? { arg } : {}) }; default: @@ -120,7 +121,7 @@ export function formatModels(providerId: string, currentModel?: string): string export function formatHelp(): string { return [ 'commands:', - ' /model [id] switch model, or open the picker (e.g. /model claude-sonnet-4-6)', + ' /model | /m [id] switch model; bare command opens the provider/model picker in the TUI', ' /model / switch provider + model (e.g. /model openai/gpt-4o)', ' /provider switch provider, using its default model', ' /models [provider] list models for the current (or named) provider', diff --git a/src/cli/tui/App.tsx b/src/cli/tui/App.tsx index 47b40d8..0b27abf 100644 --- a/src/cli/tui/App.tsx +++ b/src/cli/tui/App.tsx @@ -8,6 +8,7 @@ import { readUpdateCache, refreshUpdateInfo, resolveApiKey, + sanitizeApiKey, saveCredential, saveLocalConfig, upgradeCommand, @@ -96,6 +97,10 @@ export function App(props: AppProps): React.ReactElement { const [dialogOpen, setDialogOpen] = useState(false); const [dialogProviders, setDialogProviders] = useState([]); const [dialogInitialProvider, setDialogInitialProvider] = useState(undefined); + const [dialogInitialModel, setDialogInitialModel] = useState(undefined); + const [dialogInitialStep, setDialogInitialStep] = useState<'provider' | 'model' | undefined>( + undefined, + ); const [sessionKeys, setSessionKeys] = useState>({}); // "Update available" banner data: read the local cache immediately, then do a // best-effort network refresh. Both are non-blocking and never throw. @@ -119,23 +124,36 @@ export function App(props: AppProps): React.ReactElement { const info = getProvider(id); if (!info) return false; if (info.wire === 'fake') return true; // the fake provider needs no key - return Boolean(sessionKeys[id] ?? resolveApiKey(id)); + return Boolean(sanitizeApiKey(sessionKeys[id] ?? resolveApiKey(id))); }, [sessionKeys], ); /** - * Open the `/model` overlay, snapshotting the catalog so it can't shift. A - * `fake`/empty provider is treated as "no preset" so the dialog opens on the - * provider list rather than jumping into the offline stub's model step. + * Open the `/model` overlay, snapshotting the catalog so it can't shift. The + * bare command starts at the provider list with the active provider selected; + * recovery from a direct switch can still jump to that provider/model/key. A + * `fake`/empty provider is treated as "no preset" so it never shortcuts into + * the offline stub's model step. */ - const openDialog = useCallback((initialProvider?: string) => { - setDialogProviders(listProviders()); - setDialogInitialProvider( - initialProvider && initialProvider !== 'fake' ? initialProvider : undefined, - ); - setDialogOpen(true); - }, []); + const openDialog = useCallback( + ( + initial: { + provider?: string; + model?: string; + step?: 'provider' | 'model'; + } = {}, + ) => { + setDialogProviders(listProviders()); + setDialogInitialProvider( + initial.provider && initial.provider !== 'fake' ? initial.provider : undefined, + ); + setDialogInitialModel(initial.model); + setDialogInitialStep(initial.step); + setDialogOpen(true); + }, + [], + ); const pushSystem = useCallback((text: string) => { setSystemLines((prev) => [...prev.slice(-40), ...text.split('\n')]); @@ -200,7 +218,10 @@ export function App(props: AppProps): React.ReactElement { // No key on this path — offer the dialog to enter one, preset to the // provider the user asked for. pushSystem(`${sel.provider} needs an API key. Opening /model to configure it…`); - openDialog(sel.provider); + openDialog({ + provider: sel.provider, + ...(sel.model !== undefined ? { model: sel.model } : {}), + }); return; } pushSystem(`Could not switch: ${err instanceof Error ? err.message : String(err)}`); @@ -247,8 +268,9 @@ export function App(props: AppProps): React.ReactElement { return; case 'model': { if (!command.arg) { - // Bare `/model` opens the interactive picker (OpenCode-style). - openDialog(provider); + // Bare `/model` and `/m` expose the complete provider → model path, + // with the current provider highlighted rather than skipped. + openDialog({ provider, model, step: 'provider' }); return; } await switchTo(parseModelSelector(command.arg, provider)); @@ -345,7 +367,7 @@ export function App(props: AppProps): React.ReactElement { // No usable model yet — send them to the picker instead of a dead turn. if (needsSetup) { pushSystem('Choose a model first — opening /model.'); - openDialog(provider); + openDialog({ provider }); return; } await submitTurn(line); @@ -358,7 +380,7 @@ export function App(props: AppProps): React.ReactElement { useEffect(() => { if (needsSetup && introDone && !autoOpened && !dialogOpen) { setAutoOpened(true); - openDialog(provider); + openDialog({ provider }); } }, [needsSetup, introDone, autoOpened, dialogOpen, openDialog, provider]); @@ -465,6 +487,8 @@ export function App(props: AppProps): React.ReactElement { theme={theme} providers={dialogProviders} {...(dialogInitialProvider ? { initialProviderId: dialogInitialProvider } : {})} + {...(dialogInitialModel ? { initialModelId: dialogInitialModel } : {})} + {...(dialogInitialStep ? { initialStep: dialogInitialStep } : {})} hasKey={hasKey} onSubmit={onDialogSubmit} onCancel={() => setDialogOpen(false)} diff --git a/src/cli/tui/components/ApprovalPrompt.tsx b/src/cli/tui/components/ApprovalPrompt.tsx index 6493205..0ebf1d9 100644 --- a/src/cli/tui/components/ApprovalPrompt.tsx +++ b/src/cli/tui/components/ApprovalPrompt.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { Box, Text } from 'ink'; -import SelectInput from 'ink-select-input'; +import SelectInput, { type IndicatorProps, type ItemProps } from 'ink-select-input'; import type { ApprovalDecision } from '../../../protocol/index.ts'; import { DiffView } from './DiffView.tsx'; import { type Theme } from '../theme.ts'; @@ -32,6 +32,17 @@ export function ApprovalPrompt({ theme: Theme; onDecision: (decision: ApprovalDecision) => void; }): React.ReactElement { + const ThemedIndicator = ({ isSelected = false }: IndicatorProps): React.ReactElement => ( + + {isSelected ? '❯' : ' '} + + ); + const ThemedItem = ({ isSelected = false, label }: ItemProps): React.ReactElement => ( + + {label} + + ); + return ( } - onDecision(item.value)} /> + onDecision(item.value)} + /> ); diff --git a/src/cli/tui/components/ModelDialog.tsx b/src/cli/tui/components/ModelDialog.tsx index c53df86..47ad235 100644 --- a/src/cli/tui/components/ModelDialog.tsx +++ b/src/cli/tui/components/ModelDialog.tsx @@ -34,6 +34,10 @@ export interface ModelDialogProps { providers: ProviderInfo[]; /** Preselect this provider (the desired one when launching unconfigured). */ initialProviderId?: string; + /** Preserve a directly requested model while collecting a missing API key. */ + initialModelId?: string; + /** Start on the provider list without discarding the active-provider highlight. */ + initialStep?: 'provider' | 'model'; /** Whether a key already resolves for a provider (env / creds / session). */ hasKey: (providerId: string) => boolean; onSubmit: (selection: ModelSelection) => void; @@ -80,21 +84,41 @@ export function ModelDialog({ theme, providers, initialProviderId, + initialModelId, + initialStep, hasKey, onSubmit, onCancel, }: ModelDialogProps): React.ReactElement { - // Preselecting a provider jumps past the provider list: to the model step if - // it already has a key, or straight to key entry if it doesn't. Otherwise we - // start at the provider list. + // A preset can either be highlighted on the provider step (bare `/model`) or + // jump to model/key recovery (a direct switch that discovered a missing key). const preset = initialProviderId ? providers.find((p) => p.id === initialProviderId && p.supported) : undefined; const presetNeedsKey = preset !== undefined && !hasKey(preset.id); + const beginAtProvider = initialStep === 'provider' || preset === undefined; + const presetIndex = preset ? providers.findIndex((p) => p.id === preset.id) : 0; + const presetModel = initialModelId ?? preset?.defaultModel ?? ''; + const presetModelIndex = preset?.models.indexOf(presetModel) ?? -1; + const presetCustomIndex = + preset?.models.filter((model) => matches(model, presetModel)).length ?? 0; + const beginAtModel = !beginAtProvider && !presetNeedsKey; - const [step, setStep] = useState(preset ? (presetNeedsKey ? 'key' : 'model') : 'provider'); - const [filter, setFilter] = useState(''); - const [selected, setSelected] = useState(0); + const [step, setStep] = useState( + beginAtProvider ? 'provider' : presetNeedsKey ? 'key' : 'model', + ); + const [filter, setFilter] = useState( + beginAtModel && presetModel !== '' && presetModelIndex < 0 ? presetModel : '', + ); + const [selected, setSelected] = useState( + beginAtProvider + ? Math.max(0, presetIndex) + : beginAtModel + ? presetModelIndex >= 0 + ? presetModelIndex + : presetCustomIndex + : 0, + ); const [providerId, setProviderId] = useState(preset?.id ?? ''); const [keyText, setKeyText] = useState(''); // Default ON: a key entered here is saved to the 0600 credentials store so the @@ -103,9 +127,7 @@ export function ModelDialog({ const [hint, setHint] = useState(''); // The model chosen while we detour through the key step (its default when we // jumped straight to key entry for a preset provider). - const [pendingModel, setPendingModel] = useState( - presetNeedsKey ? (preset?.defaultModel ?? '') : '', - ); + const [pendingModel, setPendingModel] = useState(presetModel); const provider = useMemo( () => providers.find((p) => p.id === providerId), @@ -125,9 +147,14 @@ export function ModelDialog({ // non-matching filter becomes an explicit "use what I typed" row. const allowCustomModel = filter.trim() !== '' && !modelRows.some((m) => m === filter.trim()); - const resetList = (): void => { - setFilter(''); - setSelected(0); + const focusModel = (p: ProviderInfo | undefined, preferredModel?: string): void => { + const candidate = preferredModel ?? p?.defaultModel ?? ''; + const index = p?.models.indexOf(candidate) ?? -1; + const customIndex = p?.models.filter((model) => matches(model, candidate)).length ?? 0; + // An arbitrary/custom model is represented by the synthetic filtered row. + setFilter(candidate !== '' && index < 0 ? candidate : ''); + setSelected(index >= 0 ? index : customIndex); + setPendingModel(candidate); setHint(''); }; @@ -138,7 +165,7 @@ export function ModelDialog({ } setProviderId(p.id); setStep('model'); - resetList(); + focusModel(p, p.id === preset?.id ? presetModel : p.defaultModel); }; const chooseModel = (model: string): void => { @@ -168,12 +195,19 @@ export function ModelDialog({ if (step === 'provider') return onCancel(); if (step === 'model') { setStep('provider'); - resetList(); + setFilter(''); + setSelected( + Math.max( + 0, + providers.findIndex((p) => p.id === providerId), + ), + ); + setHint(''); return; } setStep('model'); // from key step setKeyText(''); - resetList(); + focusModel(provider, pendingModel); return; } diff --git a/src/cli/tui/slashCommands.ts b/src/cli/tui/slashCommands.ts index 7767a60..a5ee7b8 100644 --- a/src/cli/tui/slashCommands.ts +++ b/src/cli/tui/slashCommands.ts @@ -7,6 +7,8 @@ export interface SlashCommand { name: string; + /** Short names accepted by the parser but kept out of the main menu. */ + aliases?: readonly string[]; /** One-line help shown in the autocomplete menu. */ summary: string; /** Whether it takes an argument (shown as a hint). */ @@ -16,7 +18,12 @@ export interface SlashCommand { /** The commands the TUI offers, in menu order. */ export const SLASH_COMMANDS: SlashCommand[] = [ { name: 'help', summary: 'Show commands and shortcuts' }, - { name: 'model', summary: 'Switch model (or provider/model)', arg: '[prov/]id' }, + { + name: 'model', + aliases: ['m'], + summary: 'Choose a provider and model', + arg: '[[provider/]model]', + }, { name: 'models', summary: 'List models for a provider', arg: '[provider]' }, { name: 'provider', summary: 'Switch provider (uses its default model)', arg: 'id' }, { name: 'providers', summary: 'List providers and key status' }, @@ -49,5 +56,15 @@ export function slashCommands(): SlashCommand[] { export function completionsFor(input: string): SlashCommand[] { if (!input.startsWith('/') || input.includes(' ')) return []; const prefix = input.slice(1).toLowerCase(); - return slashCommands().filter((c) => c.name.startsWith(prefix)); + const commands = slashCommands(); + + // An exact alias is an intentional shortcut, not an ambiguous prefix. This + // makes `/m` deterministically resolve to `/model` instead of also offering + // `/models` and `/mode`; longer prefixes still use normal autocomplete. + const exactAlias = commands.find((c) => c.aliases?.includes(prefix)); + if (exactAlias) return [exactAlias]; + + return commands.filter( + (c) => c.name.startsWith(prefix) || c.aliases?.some((alias) => alias.startsWith(prefix)), + ); } diff --git a/src/cli/tui/theme.ts b/src/cli/tui/theme.ts index a549558..31a9de9 100644 --- a/src/cli/tui/theme.ts +++ b/src/cli/tui/theme.ts @@ -1,9 +1,9 @@ /** - * TUI color palette. Parallax's identity is a **red** accent (brand marks, - * borders, bullets, prompt), **purple** for the selected/highlighted row in - * menus, and **blue** for links, the permission/approval color, and the mode - * indicator. Primary body text stays high-contrast (near-white on dark, - * near-black on light) for readability — only secondary text is tinted. + * TUI color palette. Parallax's identity is the exact **#DC0000** brand red for + * marks, borders, bullets, and the prompt. Blue handles interactive selection, + * links, and permissions; orange handles warnings and other attention states. + * Primary body text stays high-contrast (near-white on dark, near-black on + * light) for readability — only secondary text is tinted. * * Values are truecolor `rgb(...)` strings that Ink passes through to the * terminal; on terminals without truecolor Ink degrades gracefully. These are @@ -14,7 +14,7 @@ export interface Theme { accent: string; /** Lighter accent for secondary emphasis / intro pulse. */ accentDim: string; - /** Highlighted/selected row in menus & completions. Purple. */ + /** Highlighted/selected row in menus & completions. Blue. */ selection: string; /** Permission/approval, links, and the mode indicator. Blue. */ permission: string; @@ -30,34 +30,39 @@ export interface Theme { diffRemoved: string; } -/** Dark theme (default) — red accent, purple selection, blue links. */ +/** Exact brand primary requested for both terminal themes (#DC0000). */ +export const BRAND_PRIMARY = 'rgb(220,0,0)'; + +/** Dark theme (default) — brand red, blue interactions, orange attention. */ export const darkTheme: Theme = { - accent: 'rgb(235,75,75)', // brand red - accentDim: 'rgb(250,130,130)', - selection: 'rgb(180,140,255)', // purple — selected row - permission: 'rgb(95,155,255)', // blue — approvals, links, mode - text: 'rgb(232,232,232)', - subtle: 'rgb(140,150,170)', // blue-tinted gray for secondary text - success: 'rgb(70,180,110)', - error: 'rgb(255,105,125)', // pink-red, distinct from the accent red - warning: 'rgb(225,175,70)', - diffAdded: 'rgb(80,180,110)', - diffRemoved: 'rgb(255,105,125)', + accent: BRAND_PRIMARY, + // A brighter red is available for secondary emphasis and intro motion while + // the exact requested red remains the canonical brand accent. + accentDim: 'rgb(255,77,77)', + selection: 'rgb(78,161,255)', + permission: 'rgb(56,189,248)', + text: 'rgb(242,244,248)', + subtle: 'rgb(154,167,186)', + success: 'rgb(60,203,127)', + error: 'rgb(255,92,122)', + warning: 'rgb(255,159,28)', + diffAdded: 'rgb(60,203,127)', + diffRemoved: 'rgb(255,92,122)', }; -/** Light theme — deeper red/purple/blue for contrast on a light background. */ +/** Light theme — exact brand red with darker blue/orange semantic colors. */ export const lightTheme: Theme = { - accent: 'rgb(200,40,40)', // brand red - accentDim: 'rgb(170,55,55)', - selection: 'rgb(120,70,200)', // purple — selected row - permission: 'rgb(40,90,210)', // blue — approvals, links, mode - text: 'rgb(28,28,28)', - subtle: 'rgb(95,105,120)', - success: 'rgb(38,120,60)', - error: 'rgb(190,40,70)', - warning: 'rgb(150,110,20)', - diffAdded: 'rgb(38,120,60)', - diffRemoved: 'rgb(190,40,70)', + accent: BRAND_PRIMARY, + accentDim: 'rgb(167,0,0)', + selection: 'rgb(0,95,204)', + permission: 'rgb(0,122,159)', + text: 'rgb(25,28,32)', + subtle: 'rgb(94,105,120)', + success: 'rgb(19,122,67)', + error: 'rgb(180,35,62)', + warning: 'rgb(180,83,9)', + diffAdded: 'rgb(19,122,67)', + diffRemoved: 'rgb(180,35,62)', }; export type ThemeName = 'dark' | 'light'; diff --git a/src/config/updateCheck.ts b/src/config/updateCheck.ts index 8daa28f..e48b39d 100644 --- a/src/config/updateCheck.ts +++ b/src/config/updateCheck.ts @@ -27,7 +27,7 @@ const FETCH_TIMEOUT_MS = 3_000; export interface UpdateInfo { current: string; latest: string; - /** `latest` for a stable release, `next` for a prerelease-channel newest. */ + /** npm dist-tag that currently points at the selected newer version. */ channel: 'latest' | 'next'; checkedAt: number; } @@ -146,8 +146,9 @@ export async function refreshUpdateInfo(): Promise { }); if (!res.ok) return undefined; const tags = distTagsSchema.parse(await res.json()); - // Prefer a newer stable `latest`; fall back to the prerelease `next` channel - // when the running build is itself a prerelease (e.g. a `-beta` user). + // Compare both supported public channels and choose the semver-newest one. + // Pre-1.0 releases currently advance `latest`; `next` remains understood for + // future prerelease-channel use and for older registry state. const candidates: Array<{ v: string; channel: 'latest' | 'next' }> = []; if (tags.latest) candidates.push({ v: tags.latest, channel: 'latest' }); if (tags.next) candidates.push({ v: tags.next, channel: 'next' }); diff --git a/tests/repl-commands.test.ts b/tests/repl-commands.test.ts index 6d2c457..b22d26a 100644 --- a/tests/repl-commands.test.ts +++ b/tests/repl-commands.test.ts @@ -43,6 +43,11 @@ describe('parseCommand', () => { kind: 'model', arg: 'claude-opus-4-8', }); + expect(parseCommand('/m')).toEqual({ kind: 'model' }); + expect(parseCommand('/m openai/gpt-4o')).toEqual({ + kind: 'model', + arg: 'openai/gpt-4o', + }); }); it('is case-insensitive on the command name and trims the arg', () => { @@ -115,7 +120,7 @@ describe('formatters', () => { it('help lists the core commands', () => { const help = formatHelp(); - for (const cmd of ['/model', '/provider', '/models', '/providers', '/help']) { + for (const cmd of ['/model', '/m', '/provider', '/models', '/providers', '/help']) { expect(help).toContain(cmd); } }); diff --git a/tests/slash-commands.test.ts b/tests/slash-commands.test.ts index f0cb068..1e5fb9b 100644 --- a/tests/slash-commands.test.ts +++ b/tests/slash-commands.test.ts @@ -30,6 +30,11 @@ describe('slash-command catalog', () => { expect(forB).toContain('bypass'); }); + it('resolves the exact /m alias only to the provider/model picker', () => { + expect(completionsFor('/m').map((c) => c.name)).toEqual(['model']); + expect(slashCommands().find((c) => c.name === 'model')?.aliases).toContain('m'); + }); + it('offers all commands for a bare slash, and none once a space is typed', () => { expect(completionsFor('/').length).toBe(slashCommands().length); expect(completionsFor('/model ')).toEqual([]); // typing an argument, not a name diff --git a/tests/theme.test.ts b/tests/theme.test.ts index f70474b..12bc69e 100644 --- a/tests/theme.test.ts +++ b/tests/theme.test.ts @@ -1,8 +1,24 @@ import { describe, it, expect } from 'vitest'; -import { darkTheme, lightTheme, getTheme, glyphs } from '../src/cli/tui/theme.ts'; +import { BRAND_PRIMARY, darkTheme, lightTheme, getTheme, glyphs } from '../src/cli/tui/theme.ts'; describe('theme', () => { - it('exposes the red/blue/purple identity roles on both themes', () => { + it('uses the exact #DC0000 primary with blue interaction and orange warning roles', () => { + expect(BRAND_PRIMARY).toBe('rgb(220,0,0)'); + expect(darkTheme).toMatchObject({ + accent: BRAND_PRIMARY, + selection: 'rgb(78,161,255)', + permission: 'rgb(56,189,248)', + warning: 'rgb(255,159,28)', + }); + expect(lightTheme).toMatchObject({ + accent: BRAND_PRIMARY, + selection: 'rgb(0,95,204)', + permission: 'rgb(0,122,159)', + warning: 'rgb(180,83,9)', + }); + }); + + it('exposes every semantic color role on both themes', () => { for (const theme of [darkTheme, lightTheme]) { // Every semantic role the components reference must be a defined color. for (const key of [ @@ -15,13 +31,16 @@ describe('theme', () => { 'success', 'error', 'warning', + 'diffAdded', + 'diffRemoved', ] as const) { expect(theme[key]).toMatch(/^rgb\(\d+,\d+,\d+\)$/); } - // selection (purple) is distinct from accent (red) and permission (blue). + // Interaction and attention colors stay distinct from the brand primary. expect(theme.selection).not.toBe(theme.accent); - expect(theme.selection).not.toBe(theme.permission); expect(theme.accent).not.toBe(theme.permission); + expect(theme.warning).not.toBe(theme.accent); + expect(theme.warning).not.toBe(theme.selection); } }); diff --git a/tests/tui-app.test.tsx b/tests/tui-app.test.tsx index 8ab4dd4..0b7da8a 100644 --- a/tests/tui-app.test.tsx +++ b/tests/tui-app.test.tsx @@ -58,15 +58,20 @@ function overrideConfig(over: { provider?: string; model?: string }): Config { function renderApp( agent: Agent, sessionId: string, - opts: { animateIntro?: boolean; needsSetup?: boolean } = {}, + opts: { + animateIntro?: boolean; + needsSetup?: boolean; + initialProvider?: string; + initialModel?: string; + } = {}, ) { return render( => new Promise((r) => setTimeout(r, ms)); // Keystrokes for ink-testing-library's mock stdin. const ENTER = '\r'; +const UP = '\u001B[A'; const DOWN = ''; // down-arrow escape sequence const ESC = ''; @@ -93,7 +99,7 @@ beforeEach(() => { // Isolate credential/key resolution so `hasKey` is deterministic regardless of // the developer's shell or `~/.parallax`. tmpHome = mkdtempSync(join(tmpdir(), 'parallax-tui-')); - for (const key of ['PARALLAX_HOME', 'PARALLAX_API_KEY', 'ANTHROPIC_API_KEY']) { + for (const key of ['PARALLAX_HOME', 'PARALLAX_API_KEY', 'ANTHROPIC_API_KEY', 'OPENAI_API_KEY']) { savedEnv[key] = process.env[key]; delete process.env[key]; } @@ -203,6 +209,49 @@ describe('TUI App render', () => { unmount(); }); + it('/m opens provider-first, highlights the active provider, then selects its model', async () => { + const agent = makeAgent([[modelText('hi')]]); + const session = await agent.facade.createSession({ + cwd: '/demo/project', + permissionMode: 'workspace', + }); + const { lastFrame, stdin, unmount } = renderApp(agent, session.id, { + initialProvider: 'openai', + initialModel: 'gpt-4.1', + }); + await tick(); + + // The trailing space bypasses autocomplete and exercises `/m` as a real + // parsed alias. The current provider is highlighted, but not skipped. + stdin.write('/m '); + await tick(); + stdin.write(ENTER); + await tick(); + expect(lastFrame() ?? '').toContain('Configure model'); + expect(lastFrame() ?? '').toContain('select a provider'); + expect(lastFrame() ?? '').toContain('❯ ✗ OpenAI'); + + // Entering the current provider preserves and highlights its active model. + stdin.write(ENTER); + await tick(); + expect(lastFrame() ?? '').toContain('OpenAI · select a model'); + expect(lastFrame() ?? '').toContain('❯ gpt-4.1'); + + // Back returns to the same provider instead of resetting to the first row. + stdin.write(ESC); + await tick(); + expect(lastFrame() ?? '').toContain('❯ ✗ OpenAI'); + + // Move from OpenAI to Anthropic and confirm: the second step is its model + // list, proving the command exposes the complete provider → model path. + stdin.write(UP); + await tick(); + stdin.write(ENTER); + await tick(); + expect(lastFrame() ?? '').toContain('Anthropic (Claude) · select a model'); + unmount(); + }); + it('switches to bypass mode via /bypass and shows the loud footer', async () => { const agent = makeAgent([[modelText('hi')]]); const session = await agent.facade.createSession({ @@ -297,4 +346,40 @@ describe('TUI model configuration', () => { expect(frame).not.toContain('/model to configure'); unmount(); }); + + it('preserves a directly requested model while collecting its missing key', async () => { + // A whitespace-only env value must be treated exactly like a missing key by + // both provider construction and the dialog's routing logic. + process.env.OPENAI_API_KEY = ' \n\t '; + const agent = makeAgent([[modelText('hi')]]); + const session = await agent.facade.createSession({ + cwd: '/demo/project', + permissionMode: 'workspace', + }); + const { lastFrame, stdin, unmount } = renderApp(agent, session.id); + await tick(); + + stdin.write('/model openai/gpt-4.1'); + await tick(); + stdin.write(ENTER); + await tick(120); + expect(lastFrame() ?? '').toContain('OpenAI · enter API key'); + + // Going back restores the requested model, not row zero; selecting it again + // returns to key entry with the same pending selection. + stdin.write(ESC); + await tick(); + expect(lastFrame() ?? '').toContain('OpenAI · select a model'); + expect(lastFrame() ?? '').toContain('❯ gpt-4.1'); + stdin.write(ENTER); + await tick(); + expect(lastFrame() ?? '').toContain('OpenAI · enter API key'); + + stdin.write('sk-test-openai'); + await tick(); + stdin.write(ENTER); + await tick(120); + expect(lastFrame() ?? '').toContain('openai:gpt-4.1'); + unmount(); + }); });