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
17 changes: 0 additions & 17 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@
"@types/bun": "latest",
"@types/lodash-es": "^4.17.12",
"@types/react": "18",
"@types/react-dom": "18",
"ink-testing-library": "^4.0.0",
"react-devtools-core": "^7.0.1",
"typescript": "^6.0.3"
},
"dependencies": {
"@commander-js/extra-typings": "^14.0.0",
"chalk": "^5.6.2",
"figures": "^6.1.0",
"ink": "5",
"ink-text-input": "^6.0.0",
"lodash-es": "^4.18.1",
"react": "18",
"react-dom": "18",
"zod": "^4.3.6"
}
}
32 changes: 6 additions & 26 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,35 @@
import { memoize } from 'lodash-es'
import type { ReactElement } from 'react'
import type { AppState } from './state/AppState.js'
import type { Action } from './state/actions.js'

export interface CommandCtx {
interface CommandCtx {
state: AppState
dispatch: React.Dispatch<Action>
}

interface CommandBase {
export interface LocalCommand {
name: string
description: string
aliases?: string[]
}

export interface PromptCommand extends CommandBase {
type: 'prompt'
getPrompt: (args: string[]) => string
}

export interface LocalCommand extends CommandBase {
type: 'local'
call: (args: string[], ctx: CommandCtx) => Promise<string | void>
}

export interface LocalJSXCommand extends CommandBase {
type: 'local-jsx'
render: (args: string[], ctx: CommandCtx) => ReactElement
}

export type Command = PromptCommand | LocalCommand | LocalJSXCommand

// Memoized command registry — lazy loads modules
const loadCommands = memoize(async (): Promise<Command[]> => {
const [themeMod, filterMod, configMod] = await Promise.all([
import('./commands/theme/index.js'),
import('./commands/filter/index.js'),
const loadCommands = memoize(async (): Promise<LocalCommand[]> => {
const [configMod] = await Promise.all([
import('./commands/config/index.js'),
])
return [
themeMod.default,
filterMod.default,
configMod.default,
]
})

export async function findCommand(name: string): Promise<Command | undefined> {
export async function findCommand(name: string): Promise<LocalCommand | undefined> {
const commands = await loadCommands()
return commands.find(c => c.name === name || c.aliases?.includes(name))
}

export async function getAllCommands(): Promise<Command[]> {
export async function getAllCommands(): Promise<LocalCommand[]> {
return loadCommands()
}
13 changes: 10 additions & 3 deletions src/commands/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import type { LocalCommand } from '../../commands.js'
import { setConfigValue } from '../../services/config.js'

const THEMES = new Set(['dark', 'light', 'plexicus'])

const configCommand: LocalCommand = {
name: 'config',
type: 'local',
description: 'Manage configuration (/config set <key> <value>)',
call: async (args, _ctx) => {
description: 'Manage configuration (:config set <key> <value>)',
call: async (args, ctx) => {
const [subcommand, key, ...valueParts] = args
if (subcommand !== 'set' || !key || valueParts.length === 0) {
return 'Usage: /config set <key> <value>'
return 'Usage: :config set <key> <value>'
}
const value = valueParts.join(' ')
await setConfigValue(key, value)
// Persisting the theme without also applying it live would leave the running
// session showing the old theme until restart, looking like the command no-op'd.
if (key === 'theme' && THEMES.has(value)) {
ctx.dispatch({ type: 'ui/setTheme', payload: value as 'dark' | 'light' | 'plexicus' })
}
return `Config updated: ${key} = ${value}`
},
}
Expand Down
3 changes: 2 additions & 1 deletion src/commands/configSet.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { setConfigValue } from '../services/config.js'
import { friendlyError } from '../utils/errors.js'

export default async function ConfigSetCommand(key: string, value: string): Promise<void> {
try {
await setConfigValue(key, value)
const isSensitive = key === 'token'
console.log(`✓ Set ${key} = ${isSensitive ? '***' : value}`)
} catch (err) {
console.error(`✗ Failed to set ${key}: ${err instanceof Error ? err.message : String(err)}`)
console.error(`✗ Failed to set ${key}: ${friendlyError(err, 'Unknown error')}`)
process.exit(1)
}
}
55 changes: 0 additions & 55 deletions src/commands/filter/index.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/commands/login.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/commands/repos.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/commands/theme/index.ts

This file was deleted.

25 changes: 11 additions & 14 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { FirstRunWizard } from './FirstRunWizard.js'
import { findCommand } from '../commands.js'
import { useWebSocket } from '../hooks/useWebSocket.js'
import { filterCommands } from '../utils/replCommands.js'
import { friendlyError } from '../utils/errors.js'
import { createApiClient } from '../services/apiClient.js'
import type { Config } from '../services/config.js'

interface AppProps {
Expand Down Expand Up @@ -53,7 +55,6 @@ function AppShell(props: AppProps) {
const { exit } = useApp()
const [replInput, setReplInput] = useState('')
const [replOutput, setReplOutput] = useState<string | null>(null)
const [showHelp, setShowHelp] = useState(false)
const commandHistory = useRef<string[]>([])
const historyIndex = useRef(-1)
const replInputRef = useRef('')
Expand Down Expand Up @@ -89,16 +90,16 @@ function AppShell(props: AppProps) {
const ac = accent(state.theme)

useInput((input, key) => {
if (showHelp) {
setShowHelp(false)
if (state.inputMode === 'help') {
dispatch({ type: 'help/close' })
return
}

if (state.inputMode === 'filter') return
if (state.inputMode === 'scm') return

if (input === '?' && state.inputMode === 'navigation') {
setShowHelp(true)
dispatch({ type: 'help/open' })
return
}

Expand Down Expand Up @@ -253,26 +254,22 @@ function AppShell(props: AppProps) {
return
}
try {
const { loadConfig } = await import('../services/config.js')
const { PlexicusApi } = await import('../services/plexicusApi.js')
const config = await loadConfig()
const api = new PlexicusApi({ baseUrl: config.serverUrl, token: stateRef.current.token ?? config.token })
const api = await createApiClient(stateRef.current.token)
const repo = stateRef.current.repos.find(r => r.id === repoId)
await api.requestScan(repoId)
dispatch({
type: 'status/open',
payload: { type: 'repo', id: repoId, name: repo?.nickname ?? repoId, status: 'pending', progress: 0, logs: [] },
})
} catch (err) {
setReplOutput(err instanceof Error ? err.message : 'Scan request failed')
setReplOutput(friendlyError(err, 'Scan request failed'))
}
dispatch({ type: 'ui/setInputMode', payload: 'navigation' })
return
}

if (cmdName === '?' || cmdName === 'help') {
dispatch({ type: 'ui/setInputMode', payload: 'navigation' })
setShowHelp(true)
dispatch({ type: 'help/open' })
return
}

Expand All @@ -288,11 +285,11 @@ function AppShell(props: AppProps) {
setReplOutput(`Unknown command: ${cmdName} — type :help for available commands`)
dispatch({ type: 'ui/setInputMode', payload: 'navigation' })
} catch (err) {
setReplOutput(err instanceof Error ? err.message : 'Command failed')
setReplOutput(friendlyError(err, 'Command failed'))
dispatch({ type: 'ui/setInputMode', payload: 'navigation' })
}
},
[dispatch, setShowHelp],
[dispatch],
)

const { sort_by: _sb, sort_dir: _sd, ...filterRest } = state.findingsFilter
Expand Down Expand Up @@ -396,7 +393,7 @@ function AppShell(props: AppProps) {
)}
</Box>

{showHelp && <KeybindingsHelp onDismiss={() => setShowHelp(false)} accentColor={ac} />}
{state.inputMode === 'help' && <KeybindingsHelp accentColor={ac} />}
</Box>
)
}
Expand Down
Loading
Loading