| description | Use Bun instead of Node.js, npm, pnpm, or vite. |
|---|---|
| globs | *.ts, *.tsx, *.html, *.css, *.js, *.jsx, package.json |
| alwaysApply | false |
Default to using Bun instead of Node.js.
- Use
bun <file>instead ofnode <file>orts-node <file> - Use
bun testinstead ofjestorvitest - Use
bun build <file.html|file.ts|file.css>instead ofwebpackoresbuild - Use
bun installinstead ofnpm installoryarn installorpnpm install - Use
bun run <script>instead ofnpm run <script>oryarn run <script>orpnpm run <script> - Use
bunx <package> <command>instead ofnpx <package> <command> - Bun automatically loads .env, so don't use dotenv.
Bun.serve()supports WebSockets, HTTPS, and routes. Don't useexpress.bun:sqlitefor SQLite. Don't usebetter-sqlite3.Bun.redisfor Redis. Don't useioredis.Bun.sqlfor Postgres. Don't usepgorpostgres.js.WebSocketis built-in. Don't usews.- Prefer
Bun.fileovernode:fs's readFile/writeFile - Bun.$
lsinstead of execa.
Use bun test to run tests.
import { test, expect } from "bun:test";
test("hello world", () => {
expect(1).toBe(1);
});Use HTML imports with Bun.serve(). Don't use vite. HTML imports fully support React, CSS, Tailwind.
Server:
import index from "./index.html"
Bun.serve({
routes: {
"/": index,
"/api/users/:id": {
GET: (req) => {
return new Response(JSON.stringify({ id: req.params.id }));
},
},
},
// optional websocket support
websocket: {
open: (ws) => {
ws.send("Hello, world!");
},
message: (ws, message) => {
ws.send(message);
},
close: (ws) => {
// handle close
}
},
development: {
hmr: true,
console: true,
}
})HTML files can import .tsx, .jsx or .js files directly and Bun's bundler will transpile & bundle automatically. <link> tags can point to stylesheets and Bun's CSS bundler will bundle.
<html>
<body>
<h1>Hello, world!</h1>
<script type="module" src="./frontend.tsx"></script>
</body>
</html>With the following frontend.tsx:
import React from "react";
import { createRoot } from "react-dom/client";
// import .css files directly and it works
import './index.css';
const root = createRoot(document.body);
export default function Frontend() {
return <h1>Hello, world!</h1>;
}
root.render(<Frontend />);Then, run index.ts
bun --hot ./index.tsFor more information, read the Bun API docs in node_modules/bun-types/docs/**.mdx.
# Development (mock API — real API not yet live)
MOCK_PLEXICUS=1 bun run src/main.tsx --token test
# CLI subcommands
bun run src/main.tsx config set llm.provider claude
bun run src/main.tsx config set llm.api_key <key>
bun run src/main.tsx config set llm.base_url <url>
bun run src/main.tsx login
bun run src/main.tsx repos
# Type check
bun run typecheck # tsc --noEmit
# Build binary
bun build src/main.tsx --outfile dist/plexicus --target bunCommander entrypoint with 4 subcommands: default (TUI), login, repos, config set. Each lazily imports its module. Token resolution: --token flag → PLEXICUS_TOKEN env → ~/.config/plexicus/config.json.
plexicus login (no flags) attempts a browser-based auth flow when webUrl is configured and canOpenBrowser() is true. Flow: bind local Bun.serve on 127.0.0.1:9100–9199 → open {webUrl}/auth/cli?port=PORT&state=NONCE in browser → frontend page POSTs to POST /auth/cli/exchange with the user's web JWT → backend mints a CLI - YYYY-MM-DD API token → frontend redirects browser to http://127.0.0.1:PORT?token=...&email=...&state=NONCE → TUI verifies state nonce, saves token, exits.
plexicus login --headless skips the browser flow and falls back to the LoginForm (email/password). Falls back automatically when SSH_TTY is set, DISPLAY/WAYLAND_DISPLAY absent (Linux), or webUrl not configured. Use plexicus config set webUrl https://app.plexicus.ai to enable it.
Utilities: src/utils/canOpenBrowser.ts (env-var checks), src/utils/url.ts (deriveWebUrl: strips api. subdomain prefix, returns null for IP:port — set webUrl explicitly for self-hosted).
The TUI uses a stack-based screen router. state.screen: Screen drives which component renders; state.screenStack holds history for Esc-to-go-back.
- Screen 1
repos— Repository list. "All Repos" is a virtual first entry (index 0). Enter on any row pushesfindingsscreen and setsstate.selectedRepoId(null for All Repos, which also setsfindings/filter: {}; a specific repo setsfindings/filter: { repository_ids: [id] }). - Screen 2
findings— Findings scoped byselectedRepoId. Enter pushesdetailscreen and setsstate.selectedFindingId. - Screen 3
detail— Full finding detail (code snippet, SCM link, scores).ropensDiffModalinline;oopens SCM link in browser (falls back to clipboard + URL display);s/fsuppress / toggle false-positive; Esc pops back.
Nav actions: nav/pushScreen, nav/popScreen, repo/select.
Pure useReducer + React Context. AppState.tsx exports AppStateProvider + useAppState. actions.ts has the full discriminated union Action type. No direct state mutation anywhere.
Key state fields:
screen: Screen— current screen (repos | findings | detail)screenStack: Screen[]— navigation history; Esc pops the stackselectedRepoId: string | null— repo in scope for findings screen (null = all)aiModalOpen: boolean/aiModalPrompt: string | null— smart REPL AI overlay stateinputMode: 'navigation' | 'repl' | 'chat' | 'login' | 'filter' | 'scm'— gates ALL keyboard input;'chat'is used when AIModal is openfuzzyOpen: boolean— controls FuzzyPicker (works on both repos and findings screens)filterOpen: boolean— controls FilterModal;filter/opensetsinputMode: 'filter'scmFlowOpen: boolean— controls SCMConnectFlow;scm/opensetsinputMode: 'scm'activeStatusJob: StatusJob | null— drives StatusModal; updated by WebSocket eventsfindingsFilter: FindingsFilter— full server-side filter shape (15+ dimensions); dispatchingfindings/filterresetsfindingsPageto 0findingsPage: number— 0-indexed current page;useFindingspasses to APIfindingsTotal / findingsPageCount— populated frommeta.paginationin API response
Critical: The REPL bar does NOT use ink-text-input. It uses direct useInput char capture in App.tsx because ink-text-input v6 focus is unreliable in tmux. Characters accumulate in replInput state; a replInputRef (updated each render) provides stale-closure-safe access for the Enter handler.
Key bindings by mode:
- Navigation:
j/k(move),gg/G(top/bottom),Enter(drill-down),s/f(suppress/fp from list),a(add repo — repos screen),o(open SCM link — detail screen),F(filter modal),/(fuzzy),:(REPL),?(help),Esc(back) - REPL: printable chars → accumulate;
Backspace→ delete;Enter→ submit;↑/↓→ history or dropdown nav;Tab→ accept dropdown item;Esc→ exit. Unknown input (non-command) → opens AI modal - Chat (AI modal open):
Esc→ close AI modal - Fuzzy:
↑/↓→ cursor;Enter→ select;Esc→ cancel - Filter:
↑/↓→ navigate sections;j/k→ navigate within checkbox sections;Space→ toggle;Enter→ apply;r→ reset;Esc→ cancel - SCM flow:
j/k→ navigate;Space→ toggle repo selection;Enter→ confirm;Esc→ back/cancel
Known commands: :filter, :scan, :theme <plexicus|dark|light>, :config set <key> <value>, :help / :?. Unknown non-empty input → dispatches chat/clear + ai/open(text) + inputMode: 'chat', opening AIModal with the text as the first message.
:scan requires state.selectedRepoId to be set (i.e., user must be on findings screen for a specific repo). It calls api.requestScan(repoId) and opens StatusModal.
App.tsx → AuthGate (FirstRunWizard → LoginForm → AppShell). AppShell: breadcrumb header, screen router (ReposPanel | FindingsPanel | FindingDetailScreen), overlay modals (FilterModal, StatusModal, AIModal), REPL bar + autocomplete dropdown.
FuzzyPicker renders inside ReposPanel or FindingsPanel when state.fuzzyOpen && state.screen === 'repos|findings'.
FilterModal renders in AppShell when state.filterOpen. Holds a local draft of FindingsFilter; dispatches only on Apply (Enter).
FindingDetailScreen — Screen 3. Renders inline DiffModal when r is pressed (r=fix for unfixed findings, r=view remediation for ready or mitigated). Status display: open (yellow), enriched (cyan, ⊕), ready (magenta, ⚡ — has a remediation ready), mitigated (green, ✓). SCM link uses src/utils/scm.ts: scmUrl(repo, finding) builds the URL, openScmLink(url) tries open/xdg-open, falls back to pbcopy/xclip and returns { opened: false, url } for UI display.
DiffModal — inline overlay for AI remediation. Shows 12 scrollable lines of unified diff (j/k or ↑↓ to scroll). When opened: checks for existing ready remediation via HTTP, then creates one if missing, opens StatusModal, and sends a WS status-remediation request. HTTP polling (3s interval, 15 min max) runs as fallback. p creates a PR, Esc cancels.
AIModal — overlay rendered when state.aiModalOpen. Uses useLLMStream. Auto-sends state.aiModalPrompt on mount. TextInput for follow-up questions.
SCMConnectFlow renders inside ReposPanel when state.scmFlowOpen. State machine: pick-provider → authorizing → gitea-form → pick-repos → importing → done/error.
StatusModal renders in AppShell when state.activeStatusJob !== null. Auto-closes 2s after finish events.
plexicusWs singleton connects after login: wss://{serverUrl}/ws/{user.client_id}?token={token} (note /ws/ prefix and client_id not user.id — backend route is WS /ws/{client_id} and rejects if decoded client_id != path param). Reconnects with exponential backoff (1s → 30s max). plexicusWs.send(data) sends a JSON message to the server (used to request remediation status). useWebSocket(config) hook is called in AppShell and routes events to AppState:
trigger-check-repository→status/open(repo scan started)status-repository→status/update(progress + log lines)trigger-finish-repository→status/update+ auto-close after 2sstatus-remediation→ parsesmsg.dataviaRemediationSchema, dispatchesremediation/set; auto-closes StatusModal onready/error. The server sends this in response to a client request{ request_type: "status-remediation", finding_id }.workflow_status(withpage_console === "remediation_generation") →status/update(remediation generation progress)
wsUrl config field overrides derived URL. Default derivation: serverUrl.replace(/^https?:\/\//, 'wss://').
Set via: bun run src/main.tsx config set wsUrl wss://custom.example.com
All findings and repo responses are { data: [{ id, attributes: {...} }], meta: { pagination: {...} } }. plexicusApi.ts parses these via Zod schemas and maps to flat Finding/Repository types. Field renames: name→title, file→file_path, cvss_score→cvssv3_score, created_at→date, repo→repo_id+repo_nickname, cve_id→cve. Finding status values (from libcovulor): enriched (default/processed), ready (has a ready remediation), completed/pr_submitted/solved → mapped to 'mitigated', issued → 'enriched', pending_input → 'open'. Use is_false_positive: boolean (no false_positive status). SCM repos endpoint GET /vulnerability_tool/repositories/{provider} returns { success, data: { repositories: [...] } } — fetch() auto-unwraps to { repositories: [...] }, so read raw.repositories directly (not raw.data.repositories).
useEffect watches [state.isAuthenticated, state.findingsFilter, state.findingsPage]. Uses AbortController to cancel stale requests. Builds a repoMap from state.repos for repo_nickname denormalization. Pagination comes from meta.pagination in the response.
Set MOCK_PLEXICUS=1 to load fixture data from tests/fixtures/plexicus/ instead of making HTTP calls. All responses validated via Zod schemas in src/services/apiSchemas.ts.
Stored at ~/.config/plexicus/config.json. Atomic writes: mkdir(0o700) → chmod → writeFile(tmp, 0o600) → rename → chmod. Key aliases normalized in setConfigValue: llm.api_key → llm.apiKey, llm.base_url → llm.baseUrl.
Config fields: serverUrl, webUrl (optional web frontend URL for browser redirects), wsUrl (optional WebSocket URL), token, llm.{provider,apiKey,model,baseUrl}, theme.
If webUrl is not set, it is derived from serverUrl by stripping the api. subdomain prefix — works for cloud (https://api.app.plexicus.ai → https://app.plexicus.ai) but not for IP:port deployments. Always set webUrl explicitly on self-hosted installs.
streamLLM routes to streamClaude (Anthropic SDK) or streamOpenAI based on config.llm.provider. User supplies their own API key. useLLMStream hook manages AbortController with cleanup on unmount.
Discriminated union: PromptCommand | LocalCommand | LocalJSXCommand. Lazily loaded via lodash-es memoize(). Registered commands: theme, filter, config. The REPL in App.tsx inline-handles filter, scan, theme, help; unknown input routes to the AI modal. ask command is removed — smart REPL replaces it.
Mock API via MOCK_PLEXICUS=1. Config tests use beforeEach/afterEach with mkdtemp + process.env.HOME override to isolate filesystem. Component tests use ink-testing-library. Use dynamic import() (not top-level) in tests when the module reads env vars at init time.