agent-orchestrator/ui-electrobun/src/mainview/main.ts
Hibryda 29a3370e79 fix(electrobun): address all 20 Codex review findings
CRITICAL:
- PTY leak: Terminal.svelte now calls pty.close on destroy, not just unsubscribe
- Agent session cleanup: clearSession() removes done/error sessions, backend
  deletes after 60s grace period

HIGH:
- Clone branch passthrough: user's branch name flows through callback
- Circular imports: extracted rpc.ts singleton, broke main.ts ↔ App.svelte cycle
- Settings wired to runtime: Terminal reads cursor/scrollback from settings
- Security disclaimer: added "prototype — not system keyring" notice
- ThemeEditor: fixed basePalette → initialPalette reference

MEDIUM:
- Clone race: UUID suffix instead of count-based index
- Silent failures: structured error returns from PTY handlers
- WebKitGTK mount: only current + previous group mounted
- Debug listeners: gated behind DEBUG, cleanup on destroy
- NDJSON residual buffer parsed on process exit
- Codex adapter: deduplicated tool_call/tool_result
- extraEnv: rejects CLAUDE*/CODEX*/OLLAMA* keys
- settings-db: runMigrations() with version tracking
- active_group: persisted via settings.set

LOW:
- Removed dead demo code, unused variables
- color-mix() fallbacks added
2026-03-22 01:20:23 +01:00

47 lines
1.5 KiB
TypeScript

import "./app.css";
import "@xterm/xterm/css/xterm.css";
import App from "./App.svelte";
import { mount } from "svelte";
import { Electroview } from "electrobun/view";
import type { PtyRPCSchema } from "../shared/pty-rpc-schema.ts";
import { setAppRpc } from "./rpc.ts";
/**
* Set up Electroview RPC.
*
* The schema is split from the Bun side's perspective:
* - "requests" in PtyRPCSchema = what WE (WebView) call on Bun → these become
* methods on electrobun.rpc.request.*
* - "messages" in PtyRPCSchema = what BUN pushes to us → we listen via
* electrobun.rpc.addMessageListener(name, handler)
*
* Electroview.defineRPC takes the schema where handlers.requests = what the
* WebView handles (i.e., requests FROM Bun to us). Since Bun never calls us
* with requests (only messages), that section is empty.
*/
const rpc = Electroview.defineRPC<PtyRPCSchema>({
maxRequestTime: 10_000,
handlers: {
requests: {
// No request handlers needed — Bun only pushes messages to us, not requests.
},
messages: {
// These are messages that WE send to Bun (fire-and-forget).
// Empty: WebView doesn't initiate any fire-and-forget messages.
},
},
});
// Register the RPC singleton so all modules can import from rpc.ts
setAppRpc(rpc);
export const electrobun = new Electroview({ rpc });
/** @deprecated Import from './rpc.ts' instead. */
export { rpc as appRpc };
const app = mount(App, {
target: document.getElementById("app")!,
});
export default app;