Prettier: AGENTS.md (#1677)

This commit is contained in:
Will Chen
2025-10-30 11:27:31 -07:00
committed by GitHub
parent 04b1a36f4a
commit 8ce23cd175

View File

@@ -1,23 +1,28 @@
# Repository Agent Guide # Repository Agent Guide
## Project context ## Project context
- This is an Electron application with a secure IPC boundary. - This is an Electron application with a secure IPC boundary.
- Frontend is a React app that uses TanStack Router (not Next.js or React Router). - Frontend is a React app that uses TanStack Router (not Next.js or React Router).
- Data fetching/mutations should be handled with TanStack Query when touching IPC-backed endpoints. - Data fetching/mutations should be handled with TanStack Query when touching IPC-backed endpoints.
## IPC architecture expectations ## IPC architecture expectations
1. `src/ipc/ipc_client.ts` runs in the renderer. Access it via `IpcClient.getInstance()` and expose dedicated methods per IPC channel. 1. `src/ipc/ipc_client.ts` runs in the renderer. Access it via `IpcClient.getInstance()` and expose dedicated methods per IPC channel.
2. `src/preload.ts` defines the renderer allowlist. New IPC APIs must be added here. 2. `src/preload.ts` defines the renderer allowlist. New IPC APIs must be added here.
3. `src/ipc/ipc_host.ts` registers handlers that live in files under `src/ipc/handlers/` (e.g., `app_handlers.ts`, `chat_stream_handlers.ts`, `settings_handlers.ts`). 3. `src/ipc/ipc_host.ts` registers handlers that live in files under `src/ipc/handlers/` (e.g., `app_handlers.ts`, `chat_stream_handlers.ts`, `settings_handlers.ts`).
4. IPC handlers should `throw new Error("...")` on failure instead of returning `{ success: false }` style payloads. 4. IPC handlers should `throw new Error("...")` on failure instead of returning `{ success: false }` style payloads.
## React + IPC integration pattern ## React + IPC integration pattern
When creating hooks/components that call IPC handlers: When creating hooks/components that call IPC handlers:
- Wrap reads in `useQuery`, providing a stable `queryKey`, async `queryFn` that calls the relevant `IpcClient` method, and conditionally use `enabled`/`initialData`/`meta` as needed. - Wrap reads in `useQuery`, providing a stable `queryKey`, async `queryFn` that calls the relevant `IpcClient` method, and conditionally use `enabled`/`initialData`/`meta` as needed.
- Wrap writes in `useMutation`; validate inputs locally, call the IPC client, and invalidate related queries on success. Use shared utilities (e.g., toast helpers) in `onError`. - Wrap writes in `useMutation`; validate inputs locally, call the IPC client, and invalidate related queries on success. Use shared utilities (e.g., toast helpers) in `onError`.
- Synchronize TanStack Query data with any global state (like Jotai atoms) via `useEffect` only if required. - Synchronize TanStack Query data with any global state (like Jotai atoms) via `useEffect` only if required.
## General guidance ## General guidance
- Favor descriptive module/function names that mirror IPC channel semantics. - Favor descriptive module/function names that mirror IPC channel semantics.
- Keep Electron security practices in mind (no `remote`, validate/lock by `appId` when mutating shared resources). - Keep Electron security practices in mind (no `remote`, validate/lock by `appId` when mutating shared resources).
- Add tests in the same folder tree when touching renderer components. - Add tests in the same folder tree when touching renderer components.