AliFullStack / rules
Cursor rule82 starsChanged 15 months agoApache-2.0View on GitHub
You're building an Electron app following good security practices Okay, I can help you summarize this pattern for creating a new Cursor rule, focusing on the TanStack Query integration and the preferred error handling strategy. Here's a summary of the pattern: The pattern involves a client-side React hook interacting with main process IPC handlers via an IpcClient layer, leveraging TanStack Query for managing asynchronous operations, state, and caching. 1. React Hook (e.g., useSomething.ts): 2. IPC Client (ipc_client.ts): 3. IPC Handlers…
1 other project uses a version of this.
Adopted by
Most recently taken up by
- United-Visions/Prestige-Aiword for word, first seen Sep 11, 2025
Other versions1 project uses a version of this.
Word for word · 1
- United-Visions/Prestige-Ai★ 4100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
The file
We split this ipc.mdc into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 36
Use the enabled option if the query depends on certain conditions (e.g., entityId !== null).
- Distinctive: line 80
If successful, it returns data.
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description:
globs:
alwaysApply: true
---
You're building an Electron app following good security practices
# IPC
Structure:
- [ipc_client.ts](mdc:src/ipc/ipc_client.ts) - lives in the renderer process and is used to send IPCs to the main process.
- to use it just do `IpcClient.getInstance()`
- [preload.ts](mdc:src/preload.ts) - allowlist
- [ipc_host.ts](mdc:src/ipc/ipc_host.ts) - contains the various IPC handlers attached which are: [app_handlers.ts](mdc:src/ipc/handlers/app_handlers.ts), [chat_stream_handlers.ts](mdc:src/ipc/handlers/chat_stream_handlers.ts), [settings_handlers.ts](mdc:src/ipc/handlers/settings_handlers.ts) etc.
# React
- This is a React app
- Using TanStack router, NOT next.js, NOT react Router.
# IPC & React query patterns
Okay, I can help you summarize this pattern for creating a new Cursor rule, focusing on the TanStack Query integration and the preferred error handling strategy.
Here's a summary of the pattern:
The pattern involves a client-side React hook interacting with main process IPC handlers via an `IpcClient` layer, leveraging TanStack Query for managing asynchronous operations, state, and caching.
**1. React Hook (e.g., `useSomething.ts`):**
* **Data Fetching (`useQuery`):**
* Define a `queryKey` (e.g., `["entity", entityId]`) for caching and invalidation.
* The `queryFn` is an asynchronous function that:
* Retrieves an `IpcClient` instance.
* Calls the appropriate method on `IpcClient` (e.g., `ipcClient.listEntities({ parentId })`). This method corresponds to an IPC channel.
* Use the `enabled` option if the query depends on certain conditions (e.g., `entityId !== null`).
* Optionally provide `initialData` and `meta` (e.g., for global error display like `showErrorToast: true`).
* The hook returns `data`, `isLoading`, `error`, and a `refetch` function from `useQuery`.
* **Data Mutations (`useMutation`):**
* The `mutationFn` is an asynchronous function that:
* Performs any necessary input validation, potentially throwing an error directly if client-side checks fail (e.g., `if (!entityId) throw new Error("Entity ID is required");`).
* Retrieves an `IpcClient` instance.
* Calls the appropriate method on `IpcClient` (e.g., `ipcClient.createEntity({ data })`).
* `onSuccess`:
* Invalidate relevant queries using `queryClient.invalidateQueries({ queryKey: ["entity"] })` to ensure data consistency and trigger refetches.
* Optionally, update local state directly or refetch specific related data.
* `onError`:
* Handle errors, often by displaying a notification to the user (e.g., using a `showError(error)` utility).
* The hook exposes an asynchronous function (e.g., `createEntity`) that internally calls `mutation.mutateAsync(params)`.
* **Local State Management (Optional, e.g., Jotai):**
* `useEffect` can synchronize data fetched by TanStack Query with global state atoms if needed.
* Atoms can also store UI-related state or parameters for hooks.
**2. IPC Client (`ipc_client.ts`):**
* Acts as an intermediary between the renderer process (React hooks) and the main process (IPC handlers).
* For each IPC channel, it has a corresponding asynchronous method (e.g., `async listEntities(params) { return this.ipcRenderer.invoke("list-entities", params); }`).
* It uses `ipcRenderer.invoke` to send messages and receive `Promise`s. If the main process handler throws an error, the `Promise` will be rejected, and this rejection will be handled by TanStack Query in the hook.
**3. IPC Handlers (e.g., `entity_handlers.ts` in the main process):**
* **Registration:**
* Handlers are registered using `ipcMain.handle("channel-name", async (event, args) => { /* ... */ })`. The `channel-name` must match what `IpcClient` calls.
* **Logic:**
* Contains the core business logic, interacting with databases (e.g., `db`), file system (`fs`), or other main-process services (e.g., `git`).
* **Error Handling (Crucial):**
* **Handlers MUST `throw new Error("Descriptive error message")` when an operation fails or an invalid state is encountered.** This is the preferred pattern over returning objects like `{ success: false, errorMessage: "..." }`.
* **Concurrency (If Applicable):**
* For operations that modify shared resources related to a specific entity (like an `appId`), use a locking mechanism (e.g., `withLock(appId, async () => { ... })`) to prevent race conditions.
**Flow Summary:**
1. React component calls a function from the custom hook.
2. The hook's `queryFn` (for reads) or `mutationFn` (for writes) calls a method on `IpcClient`.
3. `IpcClient` uses `ipcRenderer.invoke` to send a message to the main process.
4. The corresponding `ipcMain.handle` in the main process executes.
* If successful, it returns data.
* **If an error occurs, it `throw`s an `Error`.**
5. The `Promise` from `ipcRenderer.invoke` resolves or rejects.
6. TanStack Query handles the resolved data or the rejection:
* `useQuery`: Populates `data` or `error`.
* `useMutation`: Calls `onSuccess` or `onError`.
This pattern ensures that errors are propagated correctly from the main process back to the React application, where TanStack Query can manage the error state and allow for robust error handling and UI feedback.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

