Skip to content
effectifiedPublic

About

Make any library Effect-native from its GitHub URL, and keep it in step with upstream

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

effectified engine

Give it a library, get it back in Effect, Effect-native rather than Effect-wrapped: every async call a traced Effect, every async iterable and event a Stream, every resource scoped, a value that may be absent an Option, ids branded, secrets Redacted, every failure a branded tagged error with upstream's codes as its reason. Then keep it in step with upstream, every day, by itself.

This repository is the engine. The facades it makes, and the recipes, tests and decisions people and agents add to them, live in effectified/packages: that is where a library is added, synced and released.

# in a checkout of effectified/packages, which pins the engine
pnpm install --ignore-scripts
pnpm effectify make https://github.com/taskforcesh/bullmq     # or an npm name: bullmq, bullmq@6.7.10
bullmq@6.7.10: 114 exports, 27 handles, 647 methods (528 async), types bundled
recipe @effectified/bullmq:
  exports  QueueEvents, FlowProducer, Queue, Worker
  handles  QueueEvents(close), FlowProducer(close)[2 events], Queue(close)[8 events], Worker(close)[15 events], Job
  errors   ConnectionClosedError, DelayedError, RateLimitError, ..., BullmqError
  services BullmqQueueEvents <- QueueEvents, BullmqFlowProducer <- FlowProducer, BullmqQueue <- Queue, BullmqWorker <- Worker
generated into targets/bullmq/package; type checks after 1 round(s)
import { Effect, Stream } from "effect";
import { events, JobId, makeQueue, makeWorker } from "@effectified/bullmq";

const program = Effect.scoped(
	Effect.gen(function* () {
		const queue = yield* makeQueue("emails", { connection });                   // closed with the scope
		const worker = yield* makeWorker("emails", send, { connection });
		const job = yield* queue.add("welcome", { to: "ada@example.com" });           // a span "Queue.add"; Effect<Job, Failure>
		const stored = yield* queue.getJob(job.id ?? JobId.make("unknown"));          // a branded JobId in, an Option<Job> out
		yield* events.Worker.completed(worker).pipe(Stream.take(1), Stream.runDrain); // the worker's events as a Stream
	}),
);

How it works

Step What With
study Resolves a GitHub URL or npm name to a published version, installs it (scripts off), and reads its surface: exports, the objects it hands out (handles) reached from them, every overload, what each returns (promise, iterable, handle, builder), properties, event names, generic signatures with their type parameters. Then scans its JavaScript for the error classes it throws, its error codes and the events it emits, and imports it in Node, which runs the target library's own code: study only on a library you would install. TypeScript 7's native checker through its API (typescript/unstable/sync); ast-grep; Node
draft Writes recipe.json: every decision the types cannot make (which exports to offer, each handle's release method, which events become Streams, the error mapping, the services), each with its reason and who decided it. A redraft keeps what agents and people decided. the package README, the scan
generate Writes the facade package. Its types are derived from upstream's (Effectified<Upstream.Page, ...> keeps every overload, drops callback overloads, lifts the handles the runtime wraps, scopes releasable ones); generic methods and exports are written out from upstream's own declarations so their type parameters survive. Every handle's spec satisfies what upstream's types say, so a facade that no longer matches upstream does not compile and names what moved; and what each member gives (raw, a facade owned or borrowed, a list, an Option, a Stream) agrees between its type and the runtime's spec (CheckedGives), so a member typed otherwise than it runs does not compile either. a self-contained runtime (src/runtime/effectify.ts) copied into each facade
reconcile Type checks with TypeScript 7 and turns what the compiler says into recipe overrides, until the package compiles: the facade's types are the compiler's, and the runtime follows them. Then holds the facade's sources and tests to the Effect-native standard. tsc 7.0.2 (native), the compiler facades' users build with; @effect/tsgo's rules run by its Effect-patched tsrs (Rust), the idioms of src/idioms.ts (an oxlint plugin)
plan Splits the judgment work (review the recipe, test each handle, settle overrides, write the docs) into units with self-contained briefs, file boundaries, dependencies and acceptance commands, for coding agents fanned out by T3 Code. skills/effectify-t3 in effectified/packages
sync Every day (effectified/packages' sync.yml): a newer upstream version is studied, its drift written (DRIFT.md: added, removed, changed, breaking or not), the recipe redrafted, the facade regenerated, type checked and tested, and a pull request opened. drift, sync
docs With every generate: the facade's README, its agent skill (SKILL.md, shipped in the package) and docs.json, which effectified.dev renders as its page. Examples are regions of its passing tests (// #region example: <title>); a frontend facade's fixtures are also built into a live demo, attached to its release. src/docs.ts
usages Lists where an application uses a library, as a checklist for moving it onto the facade. ast-grep

Every step is a command: study, draft, generate, reconcile, verify, test, plan, drift, sync, usages, release (pack, then publish), bootstrap; make runs the first five.

Install

On npm, and as the tarball of the GitHub release v<version>, which effectified/packages pins; a release is never replaced:

pnpm add -D @effectified/engine
pnpm add -D https://github.com/effectified/engine/releases/download/v0.5.0/effectified-engine-0.5.0.tgz

The package carries the effectify command, built to JavaScript, with the idioms it holds facades to (dist/idioms.js, an oxlint plugin), and the runtimes it copies into every facade (src/runtime). After CI passes on main, release.yml (scripts/release.ts) publishes the version in package.json on npm and makes its GitHub release, each where it is missing. It publishes through the workflow's identity, npm's trusted publishing: no token is stored, nobody signs in, and the tarball has a provenance attestation that names its commit. npm trusts a workflow only for a package it has, so the engine's package was made known to npm once by a person signed in to it, effectify bootstrap --engine; until then a run warns and makes only the GitHub release.

Facades and skills

The facades (15 so far: nodemailer, simple-git, sharp, puppeteer-core, bullmq, and ten frontend libraries on Effect UI) and the skills agents follow to make and keep them (effectify, effectify-t3, effectify-recipe, effectify-tests, effectify-ui, effectify-sync, effectify-migrate) are in effectified/packages. This repository keeps skills/effectify-engine: improving the engine when a facade exposes a gap.

Known limits

  • A web component's properties are read from upstream's types (HTMLElementTagNameMap), inherited ones included (Material's disabled): public, writable, not methods, functions or DOM nodes, not @internal; a member the manifest knows as the element's own state (no attribute, no description) is left out. A tag the types do not name keeps the manifest's list.

  • A facade declares the packages its emitted declarations name (recipe.typeDependencies, written by reconcile), so a strict install resolves them.

  • Interrupting a call aborts the AbortSignal upstream takes, as a parameter or as the signal field of an options object (combined with one the caller passes); a Stream aborts its signal when it ends. A call that takes no signal cannot be cancelled upstream: interrupting it stops waiting for it. An acquisition, a call that may give a releasable handle, is the exception, as with Effect's acquireRelease and as in 0.3.0: interrupting it aborts its signal, waits for the call to settle, and leaves what it gave to the scope, which releases it as it closes, in the scope's order (at once, when the scope closed already). So when the interrupter resumes nothing of the call still runs, and nothing it gave is left without an owner. An upstream that honours its signal ends at once; one that ignores it, or a call that takes none, holds the interrupter until it settles.

  • A facade re-exports only the upstream values Node can import by name: study marks the others erased in the surface, from the declarations (a const enum, a namespace of const enums such as puppeteer's Protocol) and from importing the package in Node (a bundled .d.ts re-exporting another package's namespace, puppeteer's Session; a CommonJS module whose named exports Node's lexer cannot see, sharp's block, reachable as Upstream.default.block), under Node's conditions and a browser's: a name one build lacks is erased. A surface studied before 0.4.0 has no such marks (nor its runtime field), so its facade re-exports no value, as 0.3.0's did, and reconcile notes that study finds which of them Node can import. That import runs the target library's own code, the code its tests run, with your user's rights: run study only on a library you would install. It runs in a Node process with only PATH and HOME of the engine's environment, under Node's permission model (files read, only its results file written, no child process or worker; native addons allowed, as sharp needs), within a 60-second deadline the engine keeps, past which the process group is killed and study fails. These are hygiene against accidents (a hang, a stray process, an inherited token), not a sandbox: a native addon, or a library that sets out to, can do anything your user can. verify and release build the facade and import every entry point of dist/ (a wildcard export that matches no file fails), in order, in one Node process with the engine's whole environment, as the facade's tests run, within a deadline the engine keeps: 120 seconds, or EFFECTIFY_IMPORTS_DEADLINE seconds when that is set. The process records each entry point's result as it settles in a results file of its own, never on stdout, which stays the library's (as does study's import with the names it finds): however the process ends, every entry point recorded by then keeps its result. Past the deadline its process group is killed, and the one that never settled (a top-level await of what never resolves while a timer keeps Node running) and those after it, which never ran, did not settle; when the process exits first, they name its exit code or the signal that ended it. None is imported again alone: an entry point may import only after an earlier one ran, as in its user's bundle. A runtime facade fails on any error importing it, and on an import that does not settle. For a frontend facade that import is a report and fails nothing: the facade ships as its bundler resolves it (a dependency's object-form browser map, conditions, aliases), which Node only approximates, and its Vite bundle and its browser tests in Chrome are what check it. The report tells an error linking it in Node (a name a module lacks there, a file or package not found, a module that does not parse: "did not link") from one while its modules run ("threw or did not settle while running", with an import that did not settle within the deadline), each with its message, by when the error came (Node links a module graph before it runs any module of it), never by the error's words or the module's source; a name missing from a module only a top-level await import() reaches is reported as thrown while running, since that import links as the module runs.

  • A method returning a releasable handle owns it: an Effect acquires it in the caller's scope, a synchronous call hands the caller its facade, release methods and all. The recipe's borrowed names the exceptions, handles upstream already holds: lookups (puppeteer's Target.page(), waitForTarget, Frame.page()), the receiver itself (bullmq's Queue.on, puppeteer's ElementHandle.move()), a handle the receiver holds. A borrowed handle is wrapped, never released, needs no Scope, and its facade has none of the methods that release it, in its type or at run time, where the types make it certain the method is no step to another handle: it gives nothing the facade wraps, or upstream declares it to return this. A release whose result names a handle by its class stays on a borrowed facade, as every release did in 0.3.0: the types cannot tell zmq's Socket.close(): Socket, which closes the socket and returns it, from cheerio's end(), which steps back to another selection. The types cannot tell the two apart: without a list the engine's rule decides (a method named after the handle it returns; for a synchronous method also one returning its own handle's type, which is how the analyzer reads a declared this, or a type the receiver holds as a property), and the draft writes the rule's list for a person to confirm; a list, empty too, wins over the rule both ways. A synchronous method named a copy (clone, copy, duplicate) makes a new handle: the rule leaves it owned. A property's handle is always borrowed, and so is each handle of an array a synchronous call or a property gives (browser.targets(), a terminal's markers): such a list hands out what upstream holds. An Effect's array follows the rule for one handle: each handle of a list it makes is the caller's, acquired in its scope and released when it closes (puppeteer's $$, as $; an interrupted acquisition's list is left to the scope, as one handle is), and one it finds is borrowed (browser.pages(), named after its handle, which the draft proposes). A borrowed facade drops only the release methods its recipe names, so a handle a property holds needs its release declared (nodemailer's Mail.transporter, whose close would shut its owner's pool). The draft offers a release, for such a handle as for any, only by one rule: named as one (close, quit, disconnect, destroy, shutdown, terminate, stop, end, dispose, release), and callable with no argument, as the scope's finalizer calls it (a trailing callback it reports through aside), whatever it gives, as 0.3.0 offered one (cheerio's end(), zmq's close()). A method that releases under another name (MapLibre's Map.remove, puppeteer's CDPSession.detach) is a person's to declare: the same name destroys elsewhere (postcss's Node.remove() takes a node out of its tree), and the finalizer would call it on what the program still holds. The scope releases what it acquired when it closes, whatever you did with it, as Effect's acquireRelease does and as 0.3.0 did, and each upstream object once, however many acquisitions of it there are: a list that holds one handle twice, and two calls that hand it back, are released once. Your own call of a release (the recipe's release, puppeteer's and bullmq's close, or another release method such as disconnect) reaches upstream and gives its own value, as any other call does, and changes nothing the scope does: a release called twice runs twice, and the scope's release as it closes is one more call, in the release's form (a release that reports through a callback is given one). So call a release yourself only when you need its result or its failure. When the scope's release fails (often because your own call closed the object already), the failure is logged as a warning, <Handle>.<release> failed while its scope closed, with the facade's error as its cause, and the scope still closes successfully. The engine's releases of one object never wait for one another, or for yours: the first marks the object as it starts and any other skips it at once, so a release still running never holds up the scope's closing (a server's shutdown() you started that waits for a connection a later finalizer of the scope closes). A scope registers one release per object, however many of its acquisitions give it, interrupted ones included; a release that fails is logged and not tried again, as with acquireRelease. Two scopes that acquire one object release it once each. A result that is one of several handles by the call's type arguments (puppeteer's HandleFor<T>, bullmq's JobBase<T>) is wrapped as the handle it is (an ElementHandle's facade for a DOM node, a JSHandle's for any other value), owned or borrowed as one handle is.

  • A facade handed back to upstream is unwrapped (setFocus(editor), connect(transport)), and parameter types accept it.

  • A class whose constructor is private or that is abstract is made by its static factories, offered under the class's name (ModelRuntime.create(...)) when they are async or make a wrapped handle.

  • A tagged error carries only the fields its upstream class declares (status, body, a numeric code), each with a Schema that follows its type; anything but strings, numbers, booleans and string literals is upstream's own value, carried as Redacted (an identifier, code, errno or syscall, as it is, Unknown). Upstream's failure itself is never copied or walked: it is the error's cause, Redacted, printed nowhere (Cause.pretty, JSON, inspection, logs) and reached on purpose with Redacted.value(error.cause). Both have the Schema Effectify.Sealed, whose canonical JSON form (Schema.toCodecJson) is the marker "<redacted>" whatever the value, decoded back as Redacted of the marker: Schema.Redacted's own JSON codec writes the value out. A synchronous method's throw is the facade's error, thrown, classified as an Effect's failure is; so is every failure of a stream's iteration: its iterator's making, a return method that throws as it is read (read once, as the stream starts), each step, a step whose result throws as it is read, and a return() that fails as the stream ends. Codes the recipe names are the cases of its reason; the analyzer reads no codes from types, only the scan's string literals.

  • A value that may be absent becomes an Option only when every overload the facade keeps says so in its printed type (T | null, T | undefined), and only for Effects: a synchronous method and a property keep upstream's type, a synchronous method's handle that may be absent as its facade or the absence (ElementHandle.asElement()); a property's handle that may be absent stays upstream's. An array of handles is lifted only as itself (Page[], ReadonlyArray<Page>): not an array that may be absent, of a union, a tuple, a Map or a callback's value.

  • Secrets and brands are types only, at places the recipe names and the compiler checks: a brand on a generic method's result is refused, and the runtime reveals a Redacted only along plain objects and arrays. A property's value and a method's result show a secret as Redacted again wherever a plain object in them keeps it at the path it was given, at any depth (a transport's options.auth.pass, a pool's pool.options.auth.pass), in one walk over their plain objects and arrays that copies each once, cycles and shared branches kept as they are; any other value (a class instance, a Buffer, a Map, a Date) is kept as upstream's, or Redacted itself where a path ends at it, and a value that keeps the secret in such a shape (nodemailer's DKIM signer) is excluded in the recipe. A secret is read once, at the call, and the value read is the one sent. Every failure of a call that was given a secret, and of the handles it made, has its message and declared string fields scrubbed of it (<redacted>), so an SMTP server echoing a password in its reply shows none; codes are never scrubbed, and neither is a secret shorter than four characters, which matches ordinary text more often than it echoes the secret and is guessed by trying all values anyway (the secret A would turn EAUTH into E<redacted>UTH). A secret upstream receives inside a class instance, or as bytes (a Buffer key), is not scrubbed from messages. A facade prints, serialises and inspects as its handle's name, never upstream's state, whatever upstream's own toJSON or toString do (neither is wrapped). Known escapes, upstream's own: facade.upstream, secrets and all, and upstream's code (nodemailer's logger, a Mail.use("compile", ...) plugin reading message.mailer.options). A property's getter of upstream's that throws throws upstream's error unscrubbed.

  • onX(listener) methods (xterm's onData) are not Streams yet: no runtime facade has one; a mount subscribes to them itself.

  • Every export is annotated with a type that names typeof Upstream.X, so its declaration never spells a type upstream does not export. A lifted method whose type cannot be named that way keeps its derived type (recipe.unlifted), and loses its type parameters.

  • Synchronous methods stay synchronous: one that throws throws the facade's error, which its type does not name. A function-valued field is read as a method (an optional one stays a property).

  • What a member gives is decided by its spec, the generator's reading of upstream's text, and its type follows it: a member the spec gives as it is keeps upstream's type, though the checker would read a handle in it (an inline Base | Derived, ts-morph's asKind result KindToNodeMappings[TKind] | undefined). A method whose overloads give its handle or another value (cheerio's html() and html(value), attr() and attr(name, value)) is typed overload by overload, and wraps a result only when it has every method of the handle that upstream does not declare optional (a refresh?() it may lack), so a handle whose methods are all optional wraps any object. CheckedGives checks the kind of what each member of a handle gives (raw, a facade owned or borrowed, a list, an Option, a Stream), not which handle a facade is of. It does not cover exported functions, constructors or statics, nor a property whose handle may be absent, nor overloads TypeScript cannot split (a method whose Overloads is never is read from its one signature).

  • A generic method whose signature names a type upstream does not export is typed through a call (Effectify.lifted), which keeps its type parameters: puppeteer's page.$eval("input#name", (input) => input.value) is an Effect<string>. When TypeScript cannot infer through the call (type parameters whose defaults depend on each other, recipe.unlifted), the method keeps the derived type, its type parameters as their constraints. An overloaded generic method keeps its written-out overloads, or the derived type.

  • Event payloads are typed when the emitter keys its listeners by name (on<U extends keyof Listeners>(event: U, listener: Listeners[U]), as bullmq and puppeteer do): events.Worker.completed(worker) is a Stream of [job, result, previous]. Other emitters give ReadonlyArray<unknown>.

  • A method without a promise overload whose trailing callback reports its result is an Effect too: the analyzer reads the callback's shape (node: an error first, then the value; done: a parameterless callback, done or next), and the facade completes when upstream calls back (nodemailer's Transport.send). Any other callback is an argument like the rest (a key handler), and the method keeps upstream's type.

  • Facades are published on npm by effectified/packages' release.yml, through the workflow's identity (npm's trusted publishing: no token, a provenance attestation per tarball, which needs the package.json's repository to name effectified/packages, as the generator writes it). A facade's version is DefinitelyTyped's scheme, <upstream major>.<upstream minor>.<n>, n counting the facade's earlier releases for that major.minor (recipe.revision - 1: a redraft starts it at 1 for a new major.minor and raises it by one for another version of the same one, a person for a fix), since npm drops +build metadata; upstream's exact version is the facade's dependency. A prerelease of upstream's has no such version, and generate refuses it. npm is the record of what is released: after CI passes there, effectify release (in CI pack, which runs upstream's code, then publish in a job of its own, the only one with the identity npm takes) publishes every facade whose version npm lacks and makes its GitHub release <slug>-v<version> (its notes, and a frontend facade's demo), each where it is missing, so a run that stopped half way is finished by the next. A facade npm has never seen is left out with a warning, never a failure: npm trusts a workflow only for a package it has, which a person signed in to npm makes known once, effectify bootstrap (a placeholder 0.0.0 and the trusted publisher of each such facade; --dry-run signs in nowhere and changes nothing).

  • The Effect rules hold every TypeScript source of a facade's src/ and test/ (.ts, .tsx, .mts, .cts), and a rule is turned off only for one line with its reason at the site: @effect-diagnostics-next-line <rule>:off <reason>, the reason inside the directive's comment (in a block comment, before its end; code after it is no reason); any other directive (for the rest of a file, *, skip-file, a rule lowered to warning, a rule's name with anything glued to it such as -floatingEffect:off, no reason) fails reconcile and verify. The check reads directives with tsrs's own patterns, so every directive tsrs honours is checked, and tsrs reads one even inside a string.

  • The Effect rules run on tsrs, which type checks as TypeScript 7.1 does. Where 7.1 is stricter than 7.0.2, the compiler a facade's users build with (a destructured parameter default typed by its context: TS7031), the error is printed as a "TypeScript 7.1 note" and fails nothing.

Develop

pnpm check   # types and @effect/tsgo's correctness and antipattern rules in one tsrs pass, oxfmt and oxlint, on the engine itself
pnpm format  # oxfmt over src/ (not src/runtime: facades carry it byte for byte), test/*.ts and bin/
pnpm test    # the runtime's type rules and behaviour, the engine's parts, the generator against test/fixtures, and the standard on generated code
pnpm build   # dist/, what the release runs

test/fixtures holds the surface, recipe and generated src/index.ts of eight facades from effectified/packages. A change to the generator that changes them is either a bug or intended: then pnpm test -u rewrites them, and the facades are regenerated in effectified/packages when it moves to the new engine (see skills/effectify-engine).

Node 24 or later. Built on Effect 4. Not an official Effect project. MIT.

About

Make any library Effect-native from its GitHub URL, and keep it in step with upstream

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages