hook_layer_rules

Coding rules for custom React hooks, which are reusable functions that manage component state and related behavior. They require TypeScript, consistent naming, clear results, state-status handling, and cleanup for background effects.

In plain words
What is it for?
Use them when adding or reviewing hooks for authentication, configuration, chat, memory, shared data, fetching, timers, or subscriptions.
Why use it?
They keep state logic organized and make loading, errors, success, and side effects behave consistently across a React application.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/modelengine-group/nexent/hook_layer_rules
Clone the repo
git clone --depth 1 https://github.com/ModelEngine-Group/nexent

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 634 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00634
Opus 5 $0.00000 $0.00317
Sonnet 5 $0.00000 $0.00127
Haiku 4.5 $0.00000 $0.00063

Measured 2d ago against content hash e21d4f7e1ae3, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

hook_layer_rules scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/frontend/hook_layer_rules.mdc · 86 lines

What it actually says

Purpose and Scope

  • Hook layer contains custom React hooks for frontend/hooks/**/*.ts
  • Responsibilities: Encapsulate state logic, provide service interfaces, handle loading/error states
  • MANDATORY: All hooks must be named useXxx and use TypeScript

Hook Organization

  • hooks/useAuth.ts - Authentication state and operations
  • hooks/useConfig.ts - Configuration management
  • hooks/useChat.ts - Chat-related state and operations
  • hooks/useMemory.ts - Memory management
  • Use descriptive names indicating the hook's purpose

Hook Structure

  • Use TypeScript for all hook definitions
  • Return objects with descriptive property names
  • Handle loading, error, and success states consistently
  • Implement proper cleanup for side effects
  • Use proper dependency arrays in useEffect

Essential Hook Usage

Hook Purpose When to Use
useState Store component state Simple state like toggles, counters
useReducer Complex state logic Multiple state dependencies
useContext Share data between components Theme, user info, global state
useEffect Handle side effects Data fetching, subscriptions, timers
useCallback Prevent function recreation Callbacks passed to child components
useMemo Cache calculations Expensive computations
useRef Store mutable values DOM nodes, timer IDs

State Management

  • Use useState for local component state
  • Use useReducer for complex state logic
  • Use useContext for shared state across components
  • Implement proper state updates and immutability
  • Handle async state updates correctly
  • CRITICAL: All logging must use logger.ts - never use console.log

Error Handling

  • Handle async errors gracefully
  • Provide meaningful error messages
  • Log errors appropriately for debugging
  • Implement retry logic for transient failures

Example

// frontend/hooks/useAuth.ts
import { useState, useEffect, useCallback } from 'react';
import { authService } from '@/services/authService';

export function useAuth() {
  const [user, setUser] = useState(null);
  const [isLoading, setIsLoading] = useState(true);
  const [error, setError] = useState(null);

  const login = useCallback(async (credentials) => {
    setIsLoading(true);
    setError(null);
    try {
      const response = await authService.login(credentials);
      if (response.success) {
        setUser(response.data.user);
      } else {
        setError(response.error);
      }
    } catch (err) {
      setError(err.message);
    } finally {
      setIsLoading(false);
    }
  }, []);

  return { user, isLoading, error, login };
}
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 86 lines · 0 tokens per session scan A e21d4f7e1ae3

Subscribe to this mod's changes

hook_layer_rules is a cursor rule published in the GitHub repository ModelEngine-Group/nexent (5,841 stars, last pushed 3d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 634 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.