Skip to content

reactive/data-client / .agents/skills/data-client-manager

data-client-manager

Verified

Write @data-client Managers, the runtime layer that bridges the store to the world outside the view framework: global side effects and real-time data such as websockets, SSE and polling. A Manager reacts to every request or to events from outside the app, and moves data into or out of the store. Use one instead of useEffect for behavior that belongs to the whole app, such as error toasts and reporting, logging and analytics, auth failures, refetching on focus or reconnect, and cross-tab sync. Not for the shape of data: data built from responses (joined, derived, or accumulated) is defined in a schema, so use data-client-schema.

evals/evals.json

View on GitHub
{
  "skill_name": "data-client-manager",
  "evals": [
    {
      "id": 1,
      "name": "websocket-snapshot",
      "prompt": "Write src/managers/TickerManager.ts for our exchange websocket (wss://feed.example.com). On connect it sends `{ type: 'snapshot', tickers: [...] }` with ~300 tickers, then `{ type: 'ticker', product_id, price, volume }` one at a time. Get both into the Data Client store so `useQuery(Ticker, { product_id })` updates. Ticker is in src/resources/Ticker.ts:\n\n```ts\nimport { Entity } from '@data-client/rest';\nexport class Ticker extends Entity {\n  product_id = '';\n  price = 0;\n  volume = 0;\n  pk() { return this.product_id; }\n  static key = 'Ticker';\n}\n```",
      "expected_output": "A Manager that opens the socket in init(), closes it in cleanup(), writes the snapshot with one controller.set([Ticker], msg.tickers) call, and writes single ticker messages with controller.set(Ticker, { product_id }, msg).",
      "files": [],
      "assertions": [
        "The snapshot is written with a single `controller.set([Ticker], tickers)` or `controller.set(new schema.Array(Ticker), tickers)` call that passes the rows and no args.",
        "The snapshot rows are not written by calling `controller.set(Ticker, …)` once per row (no loop, forEach, or map over rows that calls set).",
        "No endpoint is defined and `setResponse()` is not called to write the snapshot.",
        "No `as any` or other cast is used to make the `controller.set` call typecheck.",
        "The socket is closed in `cleanup()`."
      ]
    },
    {
      "id": 2,
      "name": "buffered-flush",
      "prompt": "our ticker feed pushes ~500 msgs/sec and calling controller.set on every message is tanking perf. can you change the manager so it buffers messages and flushes to the store every 100ms? each message is `{ product_id, price, volume }` and the entity is `Ticker` (pk is product_id) from src/resources/Ticker.ts. current code:\n\n```ts\nimport type { Manager, Middleware } from '@data-client/react';\nimport { Ticker } from '../resources/Ticker';\n\nexport default class TickerManager implements Manager {\n  declare protected ws: WebSocket;\n  middleware: Middleware = controller => {\n    this.ws = new WebSocket('wss://feed.example.com');\n    this.ws.onmessage = e => {\n      const msg = JSON.parse(e.data);\n      controller.set(Ticker, { product_id: msg.product_id }, msg);\n    };\n    return next => async action => next(action);\n  };\n  cleanup() { this.ws.close(); }\n}\n```",
      "expected_output": "The manager buffers messages (optionally keeping only the latest per product_id), and on each 100ms flush writes the whole buffer with one controller.set([Ticker], rows) call, then clears the buffer. The interval is cleared in cleanup().",
      "files": [],
      "assertions": [
        "Each flush writes the buffer with a single `controller.set([Ticker], rows)` or `controller.set(new schema.Array(Ticker), rows)` call that passes the rows and no args.",
        "The flush does not call `controller.set(Ticker, …)` once per buffered row (no loop, forEach, or map over rows that calls set).",
        "No endpoint is defined and `setResponse()` is not called to batch the writes.",
        "No `as any` or other cast is used to make the `controller.set` call typecheck.",
        "The flush interval or timer is cleared in `cleanup()`."
      ]
    },
    {
      "id": 3,
      "name": "setresponse-suggestion",
      "prompt": "Reviewing a PR: to batch ticker writes, a teammate added `const pushTickers = new Endpoint(async (rows: Ticker[]) => rows, { schema: [Ticker], key: () => 'pushTickers' })` and flushes with `controller.setResponse(pushTickers, rows, rows)`. The comment says `controller.set([Ticker], rows)` doesn't typecheck. Is this the right approach? If not, rewrite the flush in src/managers/TickerManager.ts. We're on the latest @data-client/react.",
      "expected_output": "Rejects the push-only endpoint and setResponse as unnecessary for batching (it caches an endpoint response nothing reads) and rewrites the flush as one controller.set([Ticker], rows) call with no cast.",
      "files": [],
      "assertions": [
        "The response says the push-only endpoint plus `setResponse()` is not the right way to batch entity writes.",
        "The rewritten flush uses a single `controller.set([Ticker], rows)` or `controller.set(new schema.Array(Ticker), rows)` call that passes the rows and no args.",
        "The rewrite keeps no push-only endpoint and no `setResponse()` call for the batch.",
        "The rewrite does not call `controller.set(Ticker, …)` once per row.",
        "No `as any` or other cast is used to make the `controller.set` call typecheck."
      ]
    },
    {
      "id": 4,
      "name": "timing-manager",
      "changeset": "manager-middleware-required",
      "prompt": "Add src/managers/TimingManager.ts: a Manager that logs how long each fetch takes, from when the fetch action is dispatched until its result is in the store, as `console.log(key, ms)`. It has no timers or sockets to close. Also show how to add it to our `DataProvider` in src/index.tsx next to the default managers.",
      "expected_output": "A class implementing Manager with a `middleware: Middleware` property that records the start time on FETCH and logs when `action.meta.promise` settles (or on the SET_RESPONSE with the same key), passing every action to `next(action)`; a `cleanup()` method; and a module-level `managers = () => [new TimingManager(), ...getDefaultManagers()]` function passed to DataProvider.",
      "files": [],
      "assertions": [
        "The Manager defines `middleware` as a property or field typed `Middleware` (not a `getMiddleware()` method).",
        "The class has no `getMiddleware` method or property.",
        "The class defines a `cleanup()` method (an empty body is fine).",
        "The middleware calls `next(action)` for every action, not only fetches, and returns or awaits its result.",
        "The timer starts on `actionTypes.FETCH` and stops when that action's `meta.promise` settles or on the `actionTypes.SET_RESPONSE` with the same `action.key`, not when `next()` of the FETCH returns.",
        "DataProvider receives `managers` that include `...getDefaultManagers()` with the new TimingManager placed before them."
      ]
    },
    {
      "id": 5,
      "name": "clock-manager",
      "changeset": "manager-cleanup-keeps-store",
      "prompt": "Add src/managers/ClockManager.ts: a Manager that writes the current time to our `CurrentTime` entity (src/resources/CurrentTime.ts: `class CurrentTime extends Entity { id = 0; time = 0; }`) once per second with `controller.set()`, so components can show a live clock with `useQuery(CurrentTime, { id: 1 })`. Also show how to add it to our `DataProvider` in src/index.tsx next to the default managers.",
      "expected_output": "A class implementing Manager whose `middleware` stores the controller and passes every action to `next(action)`, whose `init()` starts a 1000 ms `setInterval` that calls `this.controller.set(CurrentTime, { id: 1 }, { id: 1, time: Date.now() })`, and whose `cleanup()` clears that interval; plus a module-level `managers = () => [new ClockManager(), ...getDefaultManagers()]` function passed to DataProvider.",
      "files": [],
      "assertions": [
        "The interval is started in `init()`, not in `middleware`, the constructor, or a field initializer.",
        "`cleanup()` clears the interval started in `init()`.",
        "The interval callback writes with a controller kept from `middleware` (for example `this.controller = controller`), not a controller created by the Manager.",
        "The middleware passes every action to `next(action)` and returns or awaits its result.",
        "DataProvider receives `managers` that include `...getDefaultManagers()` along with the new ClockManager."
      ]
    },
    {
      "id": 6,
      "name": "presence-socket-provider",
      "changeset": "managers-function",
      "prompt": "Add src/managers/PresenceManager.ts: a Manager that takes the socket URL as a constructor option, connects a WebSocket to it, and on each `{ userId, online }` message writes it to our `Presence` entity (src/resources/Presence.ts: `class Presence extends Entity { userId = ''; online = false; pk() { return this.userId; } }`) with `controller.set()`. Then wire it into src/index.tsx, which currently renders `<DataProvider><App /></DataProvider>` with the default managers, using `wss://presence.example.com`.",
      "expected_output": "A Manager whose constructor only stores the URL, which opens the WebSocket in init() and closes it in cleanup(), writing messages with this.controller.set(Presence, { userId }, msg); and a module-level `const managers = () => [new PresenceManager('wss://presence.example.com'), ...getDefaultManagers()]` passed as `<DataProvider managers={managers}>`.",
      "files": [],
      "assertions": [
        "`managers` passed to DataProvider is a function that returns the Manager list (for example `() => [new PresenceManager(url), ...getDefaultManagers()]`), not an array.",
        "The managers function is defined at module level (outside any component) or inline in a module-level call, not built with useMemo, useState or useRef inside a component.",
        "The constructor only stores its options: the WebSocket is not created in the constructor, a field initializer, or `middleware`.",
        "The WebSocket is opened in `init()` and closed in `cleanup()`.",
        "PresenceManager is listed before `...getDefaultManagers()`."
      ]
    },
    {
      "id": 7,
      "name": "delivers-not-shapes",
      "source": "A domain the docs never use, from the #4687 skill runs (2026-11-14). With master's skills, 5 of 5 runs made the Manager build the history: it copied each `SET_RESPONSE` and each socket message into a second `SensorHistory` entity.",
      "prompt": "Two changes.\n\n1. New readings now arrive on a websocket. While the app is open, connect to `wss://feed.example.com/readings`. It sends one JSON message for each new reading:\n\n```json\n{ \"sensorId\": \"s1\", \"reading\": { \"id\": \"r9\", \"value\": 72.25, \"takenAt\": \"10:05\" } }\n```\n\nEach message must update that sensor's latest value on the overview (src/pages/Overview.tsx) without another request. Close the socket when the app goes away.\n\n2. Add a page, with its route in src/App.tsx. `src/pages/SensorPage.tsx`, default export `SensorPage({ id }: { id: string })`, at `/sensors/:id`: the sensor's name in an `<h1>`, then one `<li>` for every reading this app has received for that sensor since it opened, oldest first. Each reads `71.5 at 10:00` (the value, then `takenAt`).\n\nThe overview already loads `SensorResource.getList` from `GET /api/sensors`, which returns:\n\n```json\n[\n  { \"id\": \"s1\", \"name\": \"Boiler\", \"latest\": { \"id\": \"r1\", \"value\": 71.5, \"takenAt\": \"10:00\" } },\n  { \"id\": \"s2\", \"name\": \"Freezer\", \"latest\": { \"id\": \"r2\", \"value\": -18, \"takenAt\": \"10:00\" } }\n]\n```\n\n`GET /api/sensors/:id` returns one sensor in the same shape. The API keeps no history: a response has only a sensor's latest reading, no endpoint returns earlier ones, and we can't change the API.\n\nPeople reach a sensor's page from the overview. The page must list the readings that arrived before it was opened, from the overview's response and from the socket, and add each new one as it arrives. A reading shows once, however many times it arrived. Resources are in src/resources/Sensor.ts; keep `SensorResource` exported from there.",
      "expected_output": "A Manager opens the socket in `init()`, closes it in `cleanup()`, and writes each message with `controller.set(Sensor, { id: sensorId }, { id: sensorId, latest: reading })`. The history is data, so the schema defines it: for example `Sensor` nests `readings: [Reading]`, `process()` starts the list from `latest`, and `merge()` joins the ids. Responses and socket messages then reach the history the same way.",
      "files": [],
      "assertions": [
        "A Manager connects the socket in `init()` and closes it in `cleanup()`; it is not opened in a component or a `useEffect()`.",
        "Each socket message is written to the store with `controller.set()` so that the sensor's `latest` changes.",
        "The history is defined in the schema (the Entity's `process()` and `merge()`, or a `Query`), not built by the Manager.",
        "The Manager does not copy `SET_RESPONSE` payloads or socket messages into a second entity or a field of its own.",
        "`DataProvider` gets `managers` as a module-level function that lists the new Manager before `...getDefaultManagers()`."
      ]
    }
  ]
}
deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
Agent Cost Reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
Agent Cost Reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall