workrail / console
CLAUDE.md4 starsChanged 6 months agoMITView on GitHub
The WorkRail Console uses a strict MVI (Model-View-Intent) architecture adapted for React/TypeScript. Every view follows this layering. Do not introduce new views without following it.
In this repository3 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/workrail-executor.mdcCursor rule
The file
We split this CLAUDE.md into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are 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.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 29
Use query.isLoading (not isFetching) to avoid SSE-triggered loading flicker.
- Very specific: line 37
Skip this file when: all derivations are trivial (one-line find, filter, map).
- Very specific: line 42
Always end the switch with default: return assertNever(event) for exhaustiveness.
- Very specific: line 52
Never returns { data: X | null.
- Distinctive: line 81
When building a new view, read these first:
≈ “Common” is an estimate: at least 1 in 5 of the 28,633 CLAUDE.md 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
Console Architecture Guide
The WorkRail Console uses a strict MVI (Model-View-Intent) architecture adapted for React/TypeScript. Every view follows this layering. Do not introduce new views without following it.
Layer Stack (bottom to top)
API hooks (React Query)
↓
Repository hook useXxxRepository.ts console/src/hooks/
↓
Use cases xxx-use-cases.ts console/src/views/
↓
Reducer xxx-reducer.ts console/src/views/
↓
ViewModel hook useXxxViewModel.ts console/src/hooks/
↓
View (pure presenter) XxxView.tsx console/src/views/Layer Rules
Repository hook (useXxxRepository.ts)
- Wraps React Query hooks. Returns a clean domain interface -- no React Query types leak out.
- Use
query.isLoading(notisFetching) to avoid SSE-triggered loading flicker. - Maps API errors to typed domain errors at this boundary.
- Filters data at the boundary (e.g. strip
routinesfrom workflow list here, not in the view).
Use cases (xxx-use-cases.ts)
- Pure functions only. Zero React imports. No side effects.
- Contains: filtering, sorting, grouping, aggregation, derived calculations.
- Add this file when logic is complex enough to test independently (more than one line).
- Skip this file when all derivations are trivial (one-line
find,filter,map).
Reducer (xxx-reducer.ts)
- Pure function:
reducer(state, event) -> state. Zero React imports. - State and events are TypeScript discriminated unions (
readonlyeverywhere). - Always end the
switchwithdefault: return assertNever(event)for exhaustiveness. - Add this file when there are 2+ interdependent state fields with non-trivial transition rules.
- Skip this file when there is only one state field (use
useStatein the ViewModel instead). - Key invariant examples: scope change resets focusedIndex; tag/source change clears selectedWorkflowId; any filter change resets page to 0.
ViewModel hook (useXxxViewModel.ts)
- The only place that calls React hooks AND mixes data concerns.
- Calls the repository, wires
useReducer(oruseStatefor simple cases), calls use cases inuseMemo. - Owns all side effects: keyboard listeners, focus management, scroll lock, body scroll.
- Returns a
XxxViewStatediscriminated union:loading | error | ready(and other states as needed). - Never returns
{ data: X | null; isLoading: boolean }-- use a discriminated union instead. - Destructure individual stable values from the repository before using them as
useMemodeps (the repository object itself is a new literal every render). - Multi-repository ViewModels are valid: a ViewModel may call multiple repositories when it needs to join data from two sources. Reference:
useWorkflowDetailViewModelcalls bothuseWorkflowDetailRepository(current workflow) anduseWorkflowsRepository(adjacent workflow list for prev/next navigation). - ViewModel hooks are not unit tested under the current strategy -- only pure functions (reducers, use cases) have tests. ViewModel behavior is covered indirectly through integration. A future investment would be
@testing-library/reactrenderHooktests for state transitions.
View (XxxView.tsx)
- Pure presenter. Receives
{ viewModel: UseXxxViewModelResult }as its only data prop. - Zero API hooks. Zero
useQuery/useMutation. Zero business logic. - May call animation hooks (
useModalTransition,useAutoAnimate) -- these are pure visual effects, not data. - May hold DOM refs (scroll container, panel ref for focus target) -- these are UI concerns.
- Renders based on
viewModel.state.kinddiscriminated union. Everykindmust be handled. - Inline sub-panel exception: when a view renders a named sub-panel that is not a separate route (e.g. the archive panel in
WorkspaceView, the workflow detail modal inWorkflowsView), the sub-panel's ViewModel may be called inside the parent view rather than AppShell. The parent view is the correct scoping boundary because the ViewModel lifetime should match the sub-panel's visibility. This is NOT a violation of the pure-presenter rule -- it is a documented exception for co-located sub-panels.
Decision Criteria
| Question | Answer → Action |
| Does the view fetch data? | Yes → add repository hook |
| Is there filtering/sorting/grouping logic? | Yes and non-trivial → add use cases file |
| Are there 2+ state fields with rules between them? | Yes → add reducer |
| Is there only one state field (a toggle or nullable)? | Yes → use useState in ViewModel, skip reducer |
| Are there pure functions (use cases or reducer)? | Yes → add tests in tests/unit/console-*.test.ts |
Reference Implementations
When building a new view, read these first:
| Layer | Reference file |
| Repository | console/src/hooks/useWorkspaceRepository.ts |
| Use cases | console/src/views/workspace-types.ts |
| Reducer | console/src/views/workspace-reducer.ts |
| ViewModel (complex) | console/src/hooks/useWorkspaceViewModel.ts |
| ViewModel (simple, no reducer) | console/src/hooks/useSessionDetailViewModel.ts |
| View | console/src/views/WorkspaceView.tsx |
| Tests | tests/unit/console-workspace-reducer.test.ts |
File Naming
| Layer | Pattern | Location |
| Repository | use{Name}Repository.ts | console/src/hooks/ |
| Use cases | {name}-use-cases.ts | console/src/views/ |
| Reducer | {name}-reducer.ts | console/src/views/ |
| ViewModel | use{Name}ViewModel.ts | console/src/hooks/ |
| Pure function tests | console-{name}-reducer.test.ts / console-{name}-use-cases.test.ts | tests/unit/ |
| ViewModel hook tests | use{Name}ViewModel.test.tsx | console/src/hooks/__tests__/ |
Two test locations:
- Pure function tests (reducers, use cases) -- no React, run in the root
tests/unit/directory vianpm run test:unitfrom the repo root. - ViewModel hook tests -- require jsdom + React, live in
console/src/hooks/__tests__/, run viacd console && npx vitest run. Uses@testing-library/reactrenderHookwithvi.mockfor repository boundaries.
Common Mistakes to Avoid
- Calling API hooks in views -- all data flows through the ViewModel.
data: X | null+isLoading: boolean-- use a discriminated union instead.repoobject asuseMemodep -- the repository returns a new object literal every render. Destructure the individual fields you need as deps.- Side effects in reducers -- reducers are pure. Navigation, fetch calls, focus management go in the ViewModel.
refetch_requestedas a reducer event -- side effects are not events. Call the side effect directly (e.g.onRefetch()) instead of routing through the reducer.- Tests co-located with source -- all tests go in
tests/unit/console-*.test.ts. - Reducer for a single boolean/nullable --
useStateis correct for one field.
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.

