@opsydyn/oxlint-effect 1.1.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +432 -79
  2. package/dist/index.d.mts +6586 -289
  3. package/dist/index.mjs +1 -1
  4. package/dist/index.mjs.map +1 -1
  5. package/package.json +8 -5
  6. package/skills/oxlint-effect/SKILL.md +120 -0
  7. package/skills/oxlint-effect/assets/contracts.ts +39 -0
  8. package/skills/oxlint-effect/assets/domain-context.bad.ts +18 -0
  9. package/skills/oxlint-effect/assets/domain-context.good.ts +32 -0
  10. package/skills/oxlint-effect/assets/domain-decisions.bad.ts +26 -0
  11. package/skills/oxlint-effect/assets/domain-decisions.good.ts +71 -0
  12. package/skills/oxlint-effect/assets/domain-shapes.bad.ts +22 -0
  13. package/skills/oxlint-effect/assets/domain-shapes.good.ts +39 -0
  14. package/skills/oxlint-effect/assets/domain.bad.ts +16 -0
  15. package/skills/oxlint-effect/assets/domain.good.ts +32 -0
  16. package/skills/oxlint-effect/assets/effect4/contracts.ts +39 -0
  17. package/skills/oxlint-effect/assets/effect4/domain-context.bad.ts +18 -0
  18. package/skills/oxlint-effect/assets/effect4/domain-context.good.ts +32 -0
  19. package/skills/oxlint-effect/assets/effect4/domain-decisions.bad.ts +26 -0
  20. package/skills/oxlint-effect/assets/effect4/domain-decisions.good.ts +71 -0
  21. package/skills/oxlint-effect/assets/effect4/domain-shapes.bad.ts +22 -0
  22. package/skills/oxlint-effect/assets/effect4/domain-shapes.good.ts +39 -0
  23. package/skills/oxlint-effect/assets/effect4/domain.bad.ts +16 -0
  24. package/skills/oxlint-effect/assets/effect4/domain.good.ts +32 -0
  25. package/skills/oxlint-effect/assets/effect4/error-preservation.bad.ts +21 -0
  26. package/skills/oxlint-effect/assets/effect4/error-preservation.good.ts +18 -0
  27. package/skills/oxlint-effect/assets/effect4/expected-state.bad.ts +28 -0
  28. package/skills/oxlint-effect/assets/effect4/expected-state.good.ts +19 -0
  29. package/skills/oxlint-effect/assets/effect4/public-errors.bad.ts +20 -0
  30. package/skills/oxlint-effect/assets/effect4/public-errors.good.ts +33 -0
  31. package/skills/oxlint-effect/assets/error-preservation.bad.ts +21 -0
  32. package/skills/oxlint-effect/assets/error-preservation.good.ts +18 -0
  33. package/skills/oxlint-effect/assets/expected-state.bad.ts +28 -0
  34. package/skills/oxlint-effect/assets/expected-state.good.ts +19 -0
  35. package/skills/oxlint-effect/assets/public-errors.bad.ts +20 -0
  36. package/skills/oxlint-effect/assets/public-errors.good.ts +33 -0
  37. package/skills/oxlint-effect/references/configuration.md +118 -0
  38. package/skills/oxlint-effect/references/domain-context.md +84 -0
  39. package/skills/oxlint-effect/references/domain-decisions.md +93 -0
  40. package/skills/oxlint-effect/references/domain-modeling.md +140 -0
  41. package/skills/oxlint-effect/references/error-preservation.md +76 -0
  42. package/skills/oxlint-effect/references/expected-state.md +78 -0
  43. package/skills/oxlint-effect/references/public-errors.md +80 -0
  44. package/skills/oxlint-effect/references/versioned-rules.md +309 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opsydyn/oxlint-effect",
3
- "version": "1.1.0",
3
+ "version": "2.0.1",
4
4
  "description": "Oxlint plugin rules for Effect TypeScript code shape constraints.",
5
5
  "author": "Alan Currie",
6
6
  "license": "MIT",
@@ -28,10 +28,11 @@
28
28
  "pack:dry-run": "npm pack --dry-run",
29
29
  "prepack": "bun run build",
30
30
  "prelint": "bun run build",
31
- "prepublishOnly": "bun run build",
32
- "release": "bun run build && changeset publish",
31
+ "prepublishOnly": "bun scripts/verify-effect-version-release.ts && bun run build",
32
+ "release": "bun scripts/verify-effect-version-release.ts && bun run build && changeset publish",
33
33
  "size": "size-limit",
34
34
  "test": "bun test ./tests/*.test.ts",
35
+ "test:effect-versions": "bun run build && bun scripts/verify-effect-version-consumers.ts",
35
36
  "test:type-aware": "bun run build && bun scripts/verify-type-aware-consumer.ts",
36
37
  "typecheck": "tsc --noEmit",
37
38
  "version": "changeset version"
@@ -48,7 +49,8 @@
48
49
  "main": "./dist/index.mjs",
49
50
  "files": [
50
51
  "dist",
51
- "README.md"
52
+ "README.md",
53
+ "skills/oxlint-effect"
52
54
  ],
53
55
  "devDependencies": {
54
56
  "@changesets/cli": "^2.31.0",
@@ -61,6 +63,7 @@
61
63
  "publint": "^0.3.21",
62
64
  "react": "^19.2.7",
63
65
  "size-limit": "^12.1.0",
66
+ "terser": "5.51.2",
64
67
  "tsdown": "^0.22.3",
65
68
  "typedoc": "^0.28.19",
66
69
  "typescript": "^5.9.3"
@@ -68,7 +71,7 @@
68
71
  "size-limit": [
69
72
  {
70
73
  "path": "dist/index.mjs",
71
- "limit": "27 KB"
74
+ "limit": "30 KB"
72
75
  }
73
76
  ],
74
77
  "publishConfig": {
@@ -0,0 +1,120 @@
1
+ ---
2
+ name: oxlint-effect
3
+ description: Use when configuring @opsydyn/oxlint-effect, investigating linteffect diagnostics, or repairing Effect domain-modeling and error-modeling code in a consuming project.
4
+ ---
5
+
6
+ # Oxlint Effect
7
+
8
+ Use the installed npm package as the rule implementation. This skill provides
9
+ configuration and domain-modeling guidance; it does not vendor or replace rules.
10
+
11
+ ## Establish the Consumer Contract
12
+
13
+ Read the repository instructions, working-tree changes, package manifests,
14
+ lockfile, and resolved Oxlint configuration. Identify the relevant workspace,
15
+ package manager, installed Effect/Oxlint/plugin versions, selected presets,
16
+ overrides, and lint/typecheck commands. Match guidance to those installed
17
+ versions. A skill obtained from GitHub may describe exports newer than the
18
+ consumer package; verify exports before adding them.
19
+
20
+ Published 2.x defaults to Effect 4. Published 1.x remains Effect 3 and does not
21
+ export the `effect3` namespace; that namespace is available after upgrading the
22
+ plugin to 2.x, without upgrading the consumer's Effect dependency.
23
+ For every group, consult [versioned rule guidance](references/versioned-rules.md)
24
+ and the matching pinned consumer's annotated failures, repairs and scope notes.
25
+ Legacy uses `effect3`; manual sensitive rules default to 4. Do not mix a legacy
26
+ repair with current APIs merely because the rule ID is stable.
27
+
28
+ ## Choose The Matching Corpus
29
+
30
+ Effect 4 assets are first-class and verified with the pinned current dependency:
31
+
32
+ - Identifiers and failures: [bad](assets/effect4/domain.bad.ts), [good](assets/effect4/domain.good.ts).
33
+ - Commands, units and options: [bad](assets/effect4/domain-shapes.bad.ts), [good](assets/effect4/domain-shapes.good.ts).
34
+ - Vocabulary and lifecycles: [bad](assets/effect4/domain-decisions.bad.ts), [good](assets/effect4/domain-decisions.good.ts).
35
+ - Context and clock: [bad](assets/effect4/domain-context.bad.ts), [good](assets/effect4/domain-context.good.ts).
36
+ - Public error channels: [bad](assets/effect4/public-errors.bad.ts), [good](assets/effect4/public-errors.good.ts).
37
+ - Error identity: [bad](assets/effect4/error-preservation.bad.ts), [good](assets/effect4/error-preservation.good.ts).
38
+ - Expected state: [bad](assets/effect4/expected-state.bad.ts), [good](assets/effect4/expected-state.good.ts).
39
+
40
+ The original assets below are explicitly **legacy Effect 3**. Retain them for
41
+ legacy consumers; use the current counterparts above for Effect 4. Both corpora
42
+ are packed, typechecked, linted and runtime-tested against their matching major.
43
+ These are executable contract checks, not proof of an agent's live adherence.
44
+
45
+ ## Configure
46
+
47
+ Read [configuration](references/configuration.md) when installing, upgrading,
48
+ selecting a group, or enabling type-aware linting. Preserve existing plugins,
49
+ rules, overrides, ignore patterns, and package-manager conventions. Choose the
50
+ requested policy, register this plugin once, and validate the resolved config.
51
+ Do not enable every group merely because it is available.
52
+
53
+ ## Diagnose Or Repair Domain Code
54
+
55
+ Use the Effect 4 pairs above for current consumers. The links in the following
56
+ legacy walkthrough target Effect 3; substitute their `assets/effect4/`
57
+ counterparts for Effect 4 and consult the versioned guide before adapting APIs.
58
+
59
+ Read [domain modeling](references/domain-modeling.md) for DDD warnings. Identify
60
+ the exact rule ID, source span, enabled policy, and surrounding domain contract.
61
+ Separate what the syntax detector observed from what the application actually
62
+ requires. Explain a potential false positive rather than treating a warning as
63
+ proof of incorrect business behaviour.
64
+
65
+ For assessment requests, report findings without editing. For requested repairs,
66
+ make the smallest change that expresses the domain invariant. Reuse existing
67
+ brands, schemas, errors, constructors, and services. Preserve boundary formats,
68
+ error handling, state transitions, and caller behaviour; include necessary
69
+ call-site changes in the same repair. Do not invent business rules, rename symbols
70
+ to evade detection, add casts, or suppress diagnostics to obtain a clean run.
71
+
72
+ The paired [failures](assets/domain.bad.ts) and [repairs](assets/domain.good.ts)
73
+ cover identifiers, behaviour modes, and structured failures. They are examples,
74
+ not replacements to copy over a consumer's model. Verify APIs against the
75
+ consumer's Effect version before adapting them.
76
+
77
+ For primitive-heavy commands, time fields, and overloaded options, read the
78
+ [domain shapes failures](assets/domain-shapes.bad.ts) with their
79
+ [repairs](assets/domain-shapes.good.ts). Keep wire units, optional-field
80
+ semantics, and boundary validation policy explicit.
81
+
82
+ For status vocabulary, business predicates, and lifecycle flags, read
83
+ [domain decisions](references/domain-decisions.md) and its paired examples.
84
+ Establish valid states and transitions from the consumer's contract before
85
+ replacing flags with a tagged union.
86
+
87
+ For explicit policy context, clock ownership, and empty error payloads, read
88
+ [domain context](references/domain-context.md) and its paired examples. Distinguish
89
+ typed identity from authority, time conversion from clock reads, and expected
90
+ state from failure before changing a consumer's contract.
91
+
92
+ For generic, unknown, or mixed public Effect error channels, read
93
+ [public errors](references/public-errors.md) and its paired examples. Preserve
94
+ original failure details, migrate callers with the error representation, and
95
+ keep defects and interruptions distinct from typed failures.
96
+
97
+ For message-only failures, generic rethrows, or log-only handlers, read
98
+ [error preservation](references/error-preservation.md). Establish recovery
99
+ ownership and distinguish `catchAll` from `tapError` before changing semantics.
100
+ For current Effect use the versioned guide: broad `catch`/`catchEager` differs
101
+ from failure-preserving observers, and legacy `catch` is discriminator-specific.
102
+
103
+ For ordinary absence, broad null fallback, or thrown expected rejection, read
104
+ [expected state](references/expected-state.md). Classify the outcome with its
105
+ owner and migrate callers whenever the success or failure channel changes.
106
+
107
+ The paired corpus covers all exported DDD rules with representative failures
108
+ and passing controls; it does not prove every detection variant or agent repair.
109
+
110
+ ## Verify And Report
111
+
112
+ Run the consumer's lint and typecheck commands plus relevant behavioural tests.
113
+ Check that the original diagnostic is resolved without creating another one.
114
+ Report changes, commands/results, and any remaining uncertainty. A clean lint
115
+ run does not prove correct domain semantics or resource/concurrency safety.
116
+
117
+ Files annotated with `EXPECT` and `QA` may be intentional failure corpora. Preserve
118
+ their failures unless updating those examples is the task. Verify expected
119
+ diagnostics separately from clean controls; never fix the corpus just to make
120
+ the repository's example lint command exit zero.
@@ -0,0 +1,39 @@
1
+ // Legacy Effect 3 packaged repair runtime contract.
2
+ import { Effect, Logger } from "effect";
3
+ import { decodeUserId, decodeInvoiceId, settleInvoice, rejectTransfer, TransferRejected } from "./domain.good";
4
+ import { decodeTransferCommand, encodeTransferCommand, transferFunds, decodeSessionLease, encodeSessionLease, decodePaymentIntent, encodePaymentIntent, createPaymentIntent } from "./domain-shapes.good";
5
+ import { decodeOrderStatus, isApproved, canApplyDiscount, decodeLegacyOrderState, encodeLegacyOrderState, Open, Shipped, shipOrder } from "./domain-decisions.good";
6
+ import { DeletionPolicy, DeletionDenied, deleteUserFromAdminPanel, decodeEpochMillis, isLeaseExpired } from "./domain-context.good";
7
+ import { ProfileUnavailable, loadProfile, refreshSession, readInventory } from "./public-errors.good";
8
+ import { rejectProfile, rethrowProfile, observeProfile } from "./error-preservation.good";
9
+ import { lookupSelection, recoverProfile, rejectCheckout, CheckoutRejectedError } from "./expected-state.good";
10
+ const check = (valid: boolean, message: string) => { if (!valid) throw new Error(message); };
11
+ const user = decodeUserId("user-1"); const invoice = decodeInvoiceId("invoice-1");
12
+ check(settleInvoice(invoice, "Notify").shouldNotifyCustomer && !settleInvoice(invoice, "Silent").shouldNotifyCustomer, "Notification payload changed");
13
+ const denied = Effect.runSync(Effect.flip(rejectTransfer(user)));
14
+ check(denied instanceof TransferRejected && denied.userId === user && denied.reason === "not allowed", "Domain rejection payload changed");
15
+ for (const input of [123, ""]) { let failed = false; try { decodeUserId(input); } catch { failed = true; } check(failed, "Invalid identifier accepted"); }
16
+ for (const amount of [0, -12.5, 12.5]) { const input = { fromAccountId: "", toAccountId: "account-2", transferAmount: amount }; check(JSON.stringify(encodeTransferCommand(transferFunds(decodeTransferCommand(input)))) === JSON.stringify(input), "Transfer wire changed"); }
17
+ for (const expiresAt of [0, -1, 1700000000123.5]) check(encodeSessionLease(decodeSessionLease({ expiresAt })).expiresAt === expiresAt, "Clock unit changed");
18
+ for (const input of [{ invoiceId: "invoice-1", amount: 12.5 }, { invoiceId: "invoice-1", amount: 12.5, memo: undefined }, { invoiceId: "invoice-1", amount: 12.5, memo: "" }]) {
19
+ const output = encodePaymentIntent(createPaymentIntent(decodePaymentIntent(input)));
20
+ check(JSON.stringify(output) === JSON.stringify(input) && Object.hasOwn(output, "memo") === Object.hasOwn(input, "memo"), "Optional field shape changed");
21
+ }
22
+ check(isApproved(decodeOrderStatus("approved")) && !isApproved(decodeOrderStatus("pending")), "Status vocabulary changed");
23
+ check(canApplyDiscount({ total: 101, itemCount: 2, discountPercentage: 20 }) && !canApplyDiscount({ total: 100, itemCount: 2, discountPercentage: 20 }), "Business threshold changed");
24
+ for (const flags of [{ cancelled: false, shipped: false }, { cancelled: true, shipped: false }, { cancelled: false, shipped: true }]) check(JSON.stringify(encodeLegacyOrderState(decodeLegacyOrderState(flags))) === JSON.stringify(flags), "Lifecycle wire changed");
25
+ check(shipOrder(Open.make({}))._tag === Shipped.make({})._tag, "Lifecycle transition changed");
26
+ const authorization = new DeletionDenied({ userId: user, reason: "denied" });
27
+ const operation = Effect.provideService(deleteUserFromAdminPanel(user), DeletionPolicy, { authorizeDelete: () => Effect.fail(authorization) });
28
+ check(Effect.runSync(Effect.flip(operation)) === authorization, "Policy failure identity changed");
29
+ check(isLeaseExpired(decodeSessionLease({ expiresAt: 41 }), decodeEpochMillis(42)), "Explicit clock comparison changed");
30
+ const cause = new Error("original"); const failure = new ProfileUnavailable({ cause });
31
+ check(Effect.runSync(Effect.flip(loadProfile(Effect.fail(cause)))).cause === cause, "Public cause identity changed");
32
+ check(Effect.runSync(Effect.flip(refreshSession(Effect.fail(cause)))).cause === cause, "Unknown cause identity changed");
33
+ check(Effect.runSync(Effect.flip(readInventory(Effect.fail(42))))._tag === "InventoryUnavailable", "Mixed failure discriminator changed");
34
+ const logger = Logger.make<unknown, void>(() => undefined);
35
+ const quiet = Logger.replace(Logger.defaultLogger, logger);
36
+ for (const task of [rejectProfile(failure), rethrowProfile(Effect.fail(failure)), observeProfile(Effect.fail(failure)), recoverProfile(Effect.fail(failure))]) check(Effect.runSync(Effect.provide(Effect.flip(task), quiet)) === failure, "Preserved error identity changed");
37
+ check(Effect.runSync(lookupSelection(undefined))._tag === "None" && Effect.runSync(lookupSelection("selected"))._tag === "Some", "Absence representation changed");
38
+ const rejected = Effect.runSync(Effect.flip(rejectCheckout("expected rejection")));
39
+ check(rejected instanceof CheckoutRejectedError && rejected.reason === "expected rejection", "Expected rejection lost typed payload");
@@ -0,0 +1,18 @@
1
+ // Legacy Effect 3 asset; use assets/effect4 for current policy.
2
+ import { Data, Effect } from "effect";
3
+
4
+ // EXPECT: linteffect/no-domain-meaning-by-folder-only
5
+ // QA: An admin helper name does not establish caller authority.
6
+ export function deleteUserFromAdminPanel(id: string) {
7
+ return Effect.succeed(id);
8
+ }
9
+
10
+ // EXPECT: linteffect/no-new-date-in-domain-logic
11
+ // QA: Reading wall-clock time inside domain logic prevents fixed-time tests.
12
+ export function readDomainTime() {
13
+ return new Date().getTime();
14
+ }
15
+
16
+ // EXPECT: linteffect/no-empty-error-tag
17
+ // QA: The caller cannot identify the rejected target or reason.
18
+ export class DeletionDenied extends Data.TaggedError("DeletionDenied")<{}> {}
@@ -0,0 +1,32 @@
1
+ // Legacy Effect 3 asset; use assets/effect4 for current policy.
2
+ import { Context, Data, Effect, Schema } from "effect";
3
+ import { type UserId } from "./domain.good";
4
+ import { EpochMillis, type SessionLease } from "./domain-shapes.good";
5
+
6
+ export class DeletionDenied extends Data.TaggedError("DeletionDenied")<{
7
+ readonly userId: UserId;
8
+ readonly reason: string;
9
+ }> {}
10
+
11
+ export class DeletionPolicy extends Context.Tag("agent-skill/DeletionPolicy")<
12
+ DeletionPolicy,
13
+ {
14
+ readonly authorizeDelete: (userId: UserId) => Effect.Effect<void, DeletionDenied>;
15
+ }
16
+ >() {}
17
+
18
+ export function deleteUserFromAdminPanel(userId: UserId) {
19
+ return Effect.gen(function* () {
20
+ const policy = yield* DeletionPolicy;
21
+ yield* policy.authorizeDelete(userId);
22
+ return userId;
23
+ });
24
+ }
25
+
26
+ const FiniteEpochMillis = EpochMillis.pipe(Schema.finite());
27
+ export const decodeEpochMillis = Schema.decodeUnknownSync(FiniteEpochMillis);
28
+ const validateEpochMillis = Schema.validateSync(FiniteEpochMillis);
29
+
30
+ export function isLeaseExpired(lease: SessionLease, now: typeof EpochMillis.Type) {
31
+ return validateEpochMillis(now) >= validateEpochMillis(lease.expiresAt);
32
+ }
@@ -0,0 +1,26 @@
1
+ // Legacy Effect 3 asset; use assets/effect4 for current policy.
2
+ import { Schema } from "effect";
3
+
4
+ // EXPECT: linteffect/no-magic-domain-string
5
+ // QA: Raw status strings scatter the domain vocabulary.
6
+ export function isApproved(order: { readonly status: string }) {
7
+ return order.status === "approved";
8
+ }
9
+
10
+ // EXPECT: linteffect/no-domain-logic-in-conditional
11
+ // QA: Eligibility combines three business comparisons without named predicates.
12
+ export function canApplyDiscount(order: {
13
+ readonly total: number;
14
+ readonly itemCount: number;
15
+ readonly discountPercentage: number;
16
+ }) {
17
+ return order.total > 100 && order.itemCount >= 2 && order.discountPercentage <= 20;
18
+ }
19
+
20
+ // EXPECT: linteffect/no-implicit-state-machine-object
21
+ // QA: The intended lifecycle permits neither, cancelled, or shipped, but never both.
22
+ export function hasContradictoryState(order: { readonly cancelled: boolean; readonly shipped: boolean }) {
23
+ return order.cancelled && order.shipped;
24
+ }
25
+
26
+ void Schema;
@@ -0,0 +1,71 @@
1
+ // Legacy Effect 3 asset; use assets/effect4 for current policy.
2
+ import { Match, Predicate, Schema } from "effect";
3
+
4
+ const ApprovedStatus = Schema.Literal("approved");
5
+ export const OrderStatus = Schema.Union(
6
+ Schema.Literal("pending", "shipped", "cancelled"),
7
+ ApprovedStatus,
8
+ );
9
+ export type OrderStatus = typeof OrderStatus.Type;
10
+ export const decodeOrderStatus = Schema.decodeUnknownSync(OrderStatus);
11
+ const matchesApprovedStatus = Schema.is(ApprovedStatus);
12
+
13
+ export function isApproved(status: OrderStatus) {
14
+ return matchesApprovedStatus(status);
15
+ }
16
+
17
+ const exceedsMinimumTotal = (total: number) => total > 100;
18
+ const meetsItemMinimum = (itemCount: number) => itemCount >= 2;
19
+ const withinDiscountCap = (discountPercentage: number) => discountPercentage <= 20;
20
+
21
+ export const canApplyDiscount = Predicate.struct({
22
+ total: exceedsMinimumTotal,
23
+ itemCount: meetsItemMinimum,
24
+ discountPercentage: withinDiscountCap,
25
+ });
26
+
27
+ export const Open = Schema.TaggedStruct("Open", {});
28
+ export type Open = typeof Open.Type;
29
+ export const Shipped = Schema.TaggedStruct("Shipped", {});
30
+ export const Cancelled = Schema.TaggedStruct("Cancelled", {});
31
+ export const OrderState = Schema.Union(Open, Shipped, Cancelled);
32
+ export type OrderState = typeof OrderState.Type;
33
+
34
+ const LegacyOrderState = Schema.Union(
35
+ Schema.Struct({ cancelled: Schema.Literal(false), shipped: Schema.Literal(false) }),
36
+ Schema.Struct({ cancelled: Schema.Literal(true), shipped: Schema.Literal(false) }),
37
+ Schema.Struct({ cancelled: Schema.Literal(false), shipped: Schema.Literal(true) }),
38
+ );
39
+ const decodeLegacyFlags = Schema.decodeUnknownSync(LegacyOrderState, {
40
+ onExcessProperty: "error",
41
+ });
42
+
43
+ export function decodeLegacyOrderState(input: unknown): OrderState {
44
+ const flags = decodeLegacyFlags(input);
45
+ return Match.value(flags).pipe(
46
+ Match.when({ cancelled: true }, () => Cancelled.make({})),
47
+ Match.when({ shipped: true }, () => Shipped.make({})),
48
+ Match.orElse(() => Open.make({})),
49
+ );
50
+ }
51
+
52
+ export function encodeLegacyOrderState(state: OrderState) {
53
+ const validated = Schema.validateSync(OrderState, { onExcessProperty: "error" })(state);
54
+ return Match.value(validated).pipe(Match.tagsExhaustive({
55
+ Open: () => ({ cancelled: false, shipped: false }),
56
+ Shipped: () => ({ cancelled: false, shipped: true }),
57
+ Cancelled: () => ({ cancelled: true, shipped: false }),
58
+ }));
59
+ }
60
+
61
+ const validateOpen = Schema.validateSync(Open, { onExcessProperty: "error" });
62
+
63
+ export function shipOrder(state: Open) {
64
+ validateOpen(state);
65
+ return Shipped.make({});
66
+ }
67
+
68
+ export function cancelOrder(state: Open) {
69
+ validateOpen(state);
70
+ return Cancelled.make({});
71
+ }
@@ -0,0 +1,22 @@
1
+ // Legacy Effect 3 asset; use assets/effect4 for current policy.
2
+ import { Schema } from "effect";
3
+
4
+ // EXPECT: linteffect/no-raw-domain-primitive-params
5
+ // QA: Positional strings and numbers do not express account and amount contracts.
6
+ export function transferFunds(fromAccountId: string, toAccountId: string, transferAmount: number) {
7
+ return { fromAccountId, toAccountId, transferAmount };
8
+ }
9
+
10
+ // EXPECT: linteffect/no-raw-time-domain-field
11
+ // QA: This contract uses epoch milliseconds, but a raw number does not encode the unit.
12
+ export interface SessionLease {
13
+ readonly expiresAt: number;
14
+ }
15
+
16
+ // EXPECT: linteffect/no-overloaded-options-object
17
+ // QA: Intended fields are invoiceId, amount, and optional memo; any cannot enforce them.
18
+ export function createPaymentIntent(opts: any) {
19
+ return opts;
20
+ }
21
+
22
+ void Schema;
@@ -0,0 +1,39 @@
1
+ // Legacy Effect 3 asset; use assets/effect4 for current policy.
2
+ import { Schema } from "effect";
3
+
4
+ export const AccountId = Schema.String.pipe(Schema.brand("AccountId"));
5
+ export const TransferAmount = Schema.Number.pipe(Schema.brand("TransferAmount"));
6
+
7
+ export const TransferCommand = Schema.Struct({
8
+ fromAccountId: AccountId,
9
+ toAccountId: AccountId,
10
+ transferAmount: TransferAmount,
11
+ });
12
+ export type TransferCommand = typeof TransferCommand.Type;
13
+ export const decodeTransferCommand = Schema.decodeUnknownSync(TransferCommand);
14
+ export const encodeTransferCommand = Schema.encodeSync(TransferCommand);
15
+
16
+ export function transferFunds(command: TransferCommand) {
17
+ return command;
18
+ }
19
+
20
+ export const EpochMillis = Schema.Number.pipe(Schema.brand("EpochMillis"));
21
+ export const SessionLease = Schema.Struct({ expiresAt: EpochMillis });
22
+ export type SessionLease = typeof SessionLease.Type;
23
+ export const decodeSessionLease = Schema.decodeUnknownSync(SessionLease);
24
+ export const encodeSessionLease = Schema.encodeSync(SessionLease);
25
+
26
+ export const PaymentIntent = Schema.Struct({
27
+ invoiceId: Schema.String,
28
+ amount: Schema.Number,
29
+ memo: Schema.optional(Schema.String),
30
+ });
31
+ export type PaymentIntent = typeof PaymentIntent.Type;
32
+ export const decodePaymentIntent = Schema.decodeUnknownSync(PaymentIntent, {
33
+ onExcessProperty: "error",
34
+ });
35
+ export const encodePaymentIntent = Schema.encodeSync(PaymentIntent);
36
+
37
+ export function createPaymentIntent(options: PaymentIntent) {
38
+ return options;
39
+ }
@@ -0,0 +1,16 @@
1
+ // Legacy Effect 3 asset; use assets/effect4 for current policy.
2
+ import { Effect } from "effect";
3
+
4
+ // EXPECT: linteffect/no-raw-domain-id-alias
5
+ // QA: Raw aliases do not distinguish user identifiers from other strings.
6
+ export type UserId = string;
7
+
8
+ // EXPECT: linteffect/no-boolean-domain-flag
9
+ // QA: The caller must remember what true and false mean.
10
+ export function settleInvoice(invoiceId: string, shouldNotifyCustomer: boolean) {
11
+ return { invoiceId, shouldNotifyCustomer };
12
+ }
13
+
14
+ // EXPECT: linteffect/no-adhoc-domain-error
15
+ // QA: String failures lose structured operation context.
16
+ export const rejectedTransfer = Effect.fail("not allowed");
@@ -0,0 +1,32 @@
1
+ // Legacy Effect 3 asset; use assets/effect4 for current policy.
2
+ import { Data, Effect, Schema } from "effect";
3
+
4
+ export const UserId = Schema.NonEmptyString.pipe(Schema.brand("UserId"));
5
+ export type UserId = typeof UserId.Type;
6
+ export const decodeUserId = Schema.decodeUnknownSync(UserId);
7
+
8
+ export const InvoiceId = Schema.NonEmptyString.pipe(Schema.brand("InvoiceId"));
9
+ export type InvoiceId = typeof InvoiceId.Type;
10
+ export const decodeInvoiceId = Schema.decodeUnknownSync(InvoiceId);
11
+
12
+ export const NotificationMode = Schema.Literal("Notify", "Silent");
13
+ export type NotificationMode = typeof NotificationMode.Type;
14
+
15
+ const notificationSettings: Record<NotificationMode, boolean> = {
16
+ Notify: true,
17
+ Silent: false,
18
+ };
19
+
20
+ export function settleInvoice(invoiceId: InvoiceId, notification: NotificationMode) {
21
+ return { invoiceId, shouldNotifyCustomer: notificationSettings[notification] };
22
+ }
23
+
24
+ export class TransferRejected extends Data.TaggedError("TransferRejected")<{
25
+ readonly userId: UserId;
26
+ readonly reason: string;
27
+ }> {}
28
+
29
+ export function rejectTransfer(userId: UserId) {
30
+ const error = new TransferRejected({ userId, reason: "not allowed" });
31
+ return Effect.fail(error);
32
+ }
@@ -0,0 +1,39 @@
1
+ // Effect 4 first-class packaged repair runtime contract.
2
+ import { Effect, Logger } from "effect";
3
+ import { decodeUserId, decodeInvoiceId, settleInvoice, rejectTransfer, TransferRejected } from "./domain.good";
4
+ import { decodeTransferCommand, encodeTransferCommand, transferFunds, decodeSessionLease, encodeSessionLease, decodePaymentIntent, encodePaymentIntent, createPaymentIntent } from "./domain-shapes.good";
5
+ import { decodeOrderStatus, isApproved, canApplyDiscount, decodeLegacyOrderState, encodeLegacyOrderState, Open, Shipped, shipOrder } from "./domain-decisions.good";
6
+ import { DeletionPolicy, DeletionDenied, deleteUserFromAdminPanel, decodeEpochMillis, isLeaseExpired } from "./domain-context.good";
7
+ import { ProfileUnavailable, loadProfile, refreshSession, readInventory } from "./public-errors.good";
8
+ import { rejectProfile, rethrowProfile, observeProfile } from "./error-preservation.good";
9
+ import { lookupSelection, recoverProfile, rejectCheckout, CheckoutRejectedError } from "./expected-state.good";
10
+ const check = (valid: boolean, message: string) => { if (!valid) throw new Error(message); };
11
+ const user = decodeUserId("user-1"); const invoice = decodeInvoiceId("invoice-1");
12
+ check(settleInvoice(invoice, "Notify").shouldNotifyCustomer && !settleInvoice(invoice, "Silent").shouldNotifyCustomer, "Notification payload changed");
13
+ const denied = Effect.runSync(Effect.flip(rejectTransfer(user)));
14
+ check(denied instanceof TransferRejected && denied.userId === user && denied.reason === "not allowed", "Domain rejection payload changed");
15
+ for (const input of [123, ""]) { let failed = false; try { decodeUserId(input); } catch { failed = true; } check(failed, "Invalid identifier accepted"); }
16
+ for (const amount of [0, -12.5, 12.5]) { const input = { fromAccountId: "", toAccountId: "account-2", transferAmount: amount }; check(JSON.stringify(encodeTransferCommand(transferFunds(decodeTransferCommand(input)))) === JSON.stringify(input), "Transfer wire changed"); }
17
+ for (const expiresAt of [0, -1, 1700000000123.5]) check(encodeSessionLease(decodeSessionLease({ expiresAt })).expiresAt === expiresAt, "Clock unit changed");
18
+ for (const input of [{ invoiceId: "invoice-1", amount: 12.5 }, { invoiceId: "invoice-1", amount: 12.5, memo: undefined }, { invoiceId: "invoice-1", amount: 12.5, memo: "" }]) {
19
+ const output = encodePaymentIntent(createPaymentIntent(decodePaymentIntent(input)));
20
+ check(JSON.stringify(output) === JSON.stringify(input) && Object.hasOwn(output, "memo") === Object.hasOwn(input, "memo"), "Optional field shape changed");
21
+ }
22
+ check(isApproved(decodeOrderStatus("approved")) && !isApproved(decodeOrderStatus("pending")), "Status vocabulary changed");
23
+ check(canApplyDiscount({ total: 101, itemCount: 2, discountPercentage: 20 }) && !canApplyDiscount({ total: 100, itemCount: 2, discountPercentage: 20 }), "Business threshold changed");
24
+ for (const flags of [{ cancelled: false, shipped: false }, { cancelled: true, shipped: false }, { cancelled: false, shipped: true }]) check(JSON.stringify(encodeLegacyOrderState(decodeLegacyOrderState(flags))) === JSON.stringify(flags), "Lifecycle wire changed");
25
+ check(shipOrder(Open.make({}))._tag === Shipped.make({})._tag, "Lifecycle transition changed");
26
+ const authorization = new DeletionDenied({ userId: user, reason: "denied" });
27
+ const operation = Effect.provideService(deleteUserFromAdminPanel(user), DeletionPolicy, { authorizeDelete: () => Effect.fail(authorization) });
28
+ check(Effect.runSync(Effect.flip(operation)) === authorization, "Policy failure identity changed");
29
+ check(isLeaseExpired(decodeSessionLease({ expiresAt: 41 }), decodeEpochMillis(42)), "Explicit clock comparison changed");
30
+ const cause = new Error("original"); const failure = new ProfileUnavailable({ cause });
31
+ check(Effect.runSync(Effect.flip(loadProfile(Effect.fail(cause)))).cause === cause, "Public cause identity changed");
32
+ check(Effect.runSync(Effect.flip(refreshSession(Effect.fail(cause)))).cause === cause, "Unknown cause identity changed");
33
+ check(Effect.runSync(Effect.flip(readInventory(Effect.fail(42))))._tag === "InventoryUnavailable", "Mixed failure discriminator changed");
34
+ const logger = Logger.make<unknown, void>(() => undefined);
35
+ const quiet = Logger.layer([logger]);
36
+ for (const task of [rejectProfile(failure), rethrowProfile(Effect.fail(failure)), observeProfile(Effect.fail(failure)), recoverProfile(Effect.fail(failure))]) check(Effect.runSync(Effect.provide(Effect.flip(task), quiet)) === failure, "Preserved error identity changed");
37
+ check(Effect.runSync(lookupSelection(undefined))._tag === "None" && Effect.runSync(lookupSelection("selected"))._tag === "Some", "Absence representation changed");
38
+ const rejected = Effect.runSync(Effect.flip(rejectCheckout("expected rejection")));
39
+ check(rejected instanceof CheckoutRejectedError && rejected.reason === "expected rejection", "Expected rejection lost typed payload");
@@ -0,0 +1,18 @@
1
+ // Effect 4 first-class asset; qualify against the pinned current consumer.
2
+ import { Data, Effect } from "effect";
3
+
4
+ // EXPECT: linteffect/no-domain-meaning-by-folder-only
5
+ // QA: An admin helper name does not establish caller authority.
6
+ export function deleteUserFromAdminPanel(id: string) {
7
+ return Effect.succeed(id);
8
+ }
9
+
10
+ // EXPECT: linteffect/no-new-date-in-domain-logic
11
+ // QA: Reading wall-clock time inside domain logic prevents fixed-time tests.
12
+ export function readDomainTime() {
13
+ return new Date().getTime();
14
+ }
15
+
16
+ // EXPECT: linteffect/no-empty-error-tag
17
+ // QA: The caller cannot identify the rejected target or reason.
18
+ export class DeletionDenied extends Data.TaggedError("DeletionDenied")<{}> {}
@@ -0,0 +1,32 @@
1
+ // Effect 4 first-class asset; qualify against the pinned current consumer.
2
+ import { Context, Data, Effect, Schema } from "effect";
3
+ import { type UserId } from "./domain.good";
4
+ import { EpochMillis, type SessionLease } from "./domain-shapes.good";
5
+
6
+ export class DeletionDenied extends Data.TaggedError("DeletionDenied")<{
7
+ readonly userId: UserId;
8
+ readonly reason: string;
9
+ }> {}
10
+
11
+ export class DeletionPolicy extends Context.Service<
12
+ DeletionPolicy,
13
+ {
14
+ readonly authorizeDelete: (userId: UserId) => Effect.Effect<void, DeletionDenied>;
15
+ }
16
+ >()("agent-skill/DeletionPolicy") {}
17
+
18
+ export function deleteUserFromAdminPanel(userId: UserId) {
19
+ return Effect.gen(function* () {
20
+ const policy = yield* DeletionPolicy;
21
+ yield* policy.authorizeDelete(userId);
22
+ return userId;
23
+ });
24
+ }
25
+
26
+ const FiniteEpochMillis = EpochMillis.check(Schema.isFinite());
27
+ export const decodeEpochMillis = Schema.decodeUnknownSync(FiniteEpochMillis);
28
+ const validateEpochMillis = Schema.decodeUnknownSync(FiniteEpochMillis);
29
+
30
+ export function isLeaseExpired(lease: SessionLease, now: typeof EpochMillis.Type) {
31
+ return validateEpochMillis(now) >= validateEpochMillis(lease.expiresAt);
32
+ }
@@ -0,0 +1,26 @@
1
+ // Effect 4 first-class asset; qualify against the pinned current consumer.
2
+ import { Schema } from "effect";
3
+
4
+ // EXPECT: linteffect/no-magic-domain-string
5
+ // QA: Raw status strings scatter the domain vocabulary.
6
+ export function isApproved(order: { readonly status: string }) {
7
+ return order.status === "approved";
8
+ }
9
+
10
+ // EXPECT: linteffect/no-domain-logic-in-conditional
11
+ // QA: Eligibility combines three business comparisons without named predicates.
12
+ export function canApplyDiscount(order: {
13
+ readonly total: number;
14
+ readonly itemCount: number;
15
+ readonly discountPercentage: number;
16
+ }) {
17
+ return order.total > 100 && order.itemCount >= 2 && order.discountPercentage <= 20;
18
+ }
19
+
20
+ // EXPECT: linteffect/no-implicit-state-machine-object
21
+ // QA: The intended lifecycle permits neither, cancelled, or shipped, but never both.
22
+ export function hasContradictoryState(order: { readonly cancelled: boolean; readonly shipped: boolean }) {
23
+ return order.cancelled && order.shipped;
24
+ }
25
+
26
+ void Schema;