8.1 KiB
8.1 KiB
title, model, effort, input, tools, include, conclusion, showToolCalls
| title | model | effort | input | tools | include | conclusion | showToolCalls | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Effect Service Conventions | claude-opus-4-8 | high | full_diff |
|
|
failure | true |
Effect service review
Review changed TypeScript and directly affected call sites for the conventions below. Apply them when a pull request creates, moves, refactors, or consumes an Effect service. Do not demand unrelated repository-wide cleanup. Treat these instructions as authoritative when older code differs.
Imports and module namespaces
- Import Effect library modules from their subpaths as namespaces, for example
import * as Effect from "effect/Effect"andimport * as Layer from "effect/Layer". Flag consolidated named imports from"effect"in touched Effect service code. - At a service boundary, import the local service module as a namespace and use its public module shape:
WorkspacePaths.WorkspacePaths,WorkspacePaths.make, andWorkspacePaths.layer. Flag aliases such asimport { layer as workspacePathsLayer }that erase the module namespace. - Namespace imports are not a blanket rule. Keep named imports for whole packages such as
@t3tools/contracts, and for modules used only for a pure helper, error, schema, config value, or standalone type. Do not requestimport type * as Contracts. - A package subpath that is itself a service module may use a namespace import when callers access its service/tag,
make, orlayermembers. - When a barrel exposes an entire service module, prefer
export * as TokenStore from "./tokenStore.ts"so consumers can useTokenStore.TokenStoreandTokenStore.layer. Do not individually renamemakeandlayerexports to simulate a namespace.
Service definition
- Use the canonical single-file order: imports, error/schema declarations, the
Context.Servicetag with its inline interface,make, thenlayer. - Keep a service's schemas/errors,
Context.Servicetag, construction, and layer in one canonical module when they form one implementation. - Define the service interface inline in the
Context.Servicedeclaration. Do not retain a standaloneFooShapeorFooServiceShapeinterface/type. - Refer to the inferred service interface as
Foo["Service"], including in mechanically updated orchestration, MCP, tests, and integration harnesses. - Export a real
makewhen the module owns construction. Do not createmake = Effect.succeed(...)solely to forceLayer.effect. - Export the canonical layer as
export const layer = Layer....Layer.effectis not required: useLayer.succeed,Layer.scoped, or another appropriate constructor when that matches the implementation. - In a concrete implementation module already named for the implementation, use plain
makeandlayer(for exampleBunPtyAdapter.tsandNodePtyAdapter.ts). - Keep implementation-specific names when an abstract port module contains one of several possible implementations, for example
makeCloudflaredRelayClientandlayerCloudflaredinRelayClient.ts. infra/relay/src/db.tsis an intentional exception: an inlineLayer.succeed(RelayDb, db)is acceptable without genericmake/layerexports.
Errors and predicates
- Define service failures with
Schema.TaggedErrorClassand structured attributes. Derivemessagefrom those attributes rather than storing an unstructured message as the only data. Schema.Defect()is not a substitute for modeling a generic error: its tag, fields, or both must identify the failure structurally, and itsmessagemust not merely stringify an opaque cause. A semantically precise error tag may preserve a realcausewithout inventing a redundant singleton field when no additional variable context exists; still retain any real path, resource, request, or entity context available at the wrapping site.- Capture stable, serializable domain context such as the operation or stage, resource/path or entity identifier, and normalized category/status. Map failures where that context is known instead of wrapping an entire multi-step pipeline in one generic error. Do not add a
detailfield that merely copiescause.messageand then use it to construct the wrapper message. - When translating or wrapping a real failure, preserve the immediate underlying error itself as
causealongside the structural fields so the complete error chain and stack remain available. If every construction wraps a failure,causeshould be required; make it optional only when the same error can legitimately originate without an underlying failure. - Derive the wrapper's
messageexclusively from its stable structural attributes, never fromcause,cause.message, or a stringified defect. Do not replace the immediate error with onlyerror.cause, erase a structured upstream error into a string, or manufacture anErrormerely to populatecause. Pure validation/domain errors created without an underlying failure do not need a cause. - Do not encode the same distinction twice with both a specific error tag and a single-value
operation,reason,kind, orphaseliteral. Choose one coherent model: use distinct error classes and omit the redundant discriminator when callers or messages treat the failures as genuinely different, or use one service-level error with a multi-value operation discriminator and a generic message derived from that operation when the failures share the same semantics. - Treat an error message exposed through an HTTP/RPC response, persisted state, UI, or another caller-visible boundary as behavior. Preserve those messages during a structural refactor. Existing distinct caller-visible messages are evidence that the failures should normally remain distinct error tags without redundant singleton discriminators, rather than being collapsed into a generic operation error.
- Split semantically distinct failures into separate error classes when a
reason,kind,phase, or similar discriminator is used to choose the user-facing message or drive caller control flow. A discriminator used only for internal diagnostics may remain a field. - Use
Schema.Unionof error classes when a shared schema, predicate, or helper type is useful. - Export direct schema predicates such as
export const isFoo = Schema.is(Foo). Flag a privateSchema.isconstant wrapped by a redundant function with the same signature. - Do not introduce a large
switchor lookup table in an error'smessagegetter to model failures that deserve separate error classes.
File layout and migrations
- When combining
domain/Services/Foo.tsanddomain/Layers/Foo.ts, hoist the result todomain/Foo.ts. - Delete the old service/layer files. Do not leave compatibility re-export shims. Mechanically update every consumer, including orchestration, MCP, tests, and integration harnesses, to the canonical path.
- Do not flag genuinely separate implementation/adapter modules merely because they remain in an implementation-oriented directory.
- Avoid substantive orchestration or MCP redesign in service-cleanup PRs. Mechanical import, layer, and
Service["Service"]updates are expected when required to remove obsolete paths or shapes.
Change discipline
- Preserve useful comments, invariants, and specification documentation while moving code.
- Do not add large tests solely to prove a mechanical refactor. Update existing tests and imports as needed.
- If backend behavior changes, require focused tests. Use test implementations/layers for external services only; do not mock out core business logic.
- Do not require
Layer.effect, universal namespace imports, genericmake/layernames for abstract-port implementations, separate error classes for diagnostic-only fields, or new tests for import-only changes.
Reporting
Report only concrete violations introduced or retained in the pull request's changed scope. Prefer precise inline comments on the smallest relevant line range and state the expected fix. A clear convention violation may fail the check. Do not fail for optional style preferences or unrelated legacy code. If there are no findings, report exactly All clear.