Skip to content

Commons

Commons holds the configuration bases and small, stable primitives shared by here.build and inhuman.tools. The repository is a standalone pnpm and turbo workspace. It is the public home and the npm publish source for the @here.build/* packages below. Nothing here is a product you run. Each package is something you install into your own package when you need that piece.

Day-to-day development also happens inside the private here.build monorepo. The public history is projected from that monorepo under a single publishing identity.

If you want to… Use
Start a TypeScript package with the house compiler settings @here.build/tsconfig
Lint with the shared ESLint flat configs @here.build/eslint-configs
Use maps that create missing entries, count things, or key by paths @here.build/collections
Assert a condition and narrow its type in one line @here.build/error-invariant
Send WebSocket messages larger than 1 MiB through workerd @here.build/chunked-websocket
Give generated identifiers stable, collision-free names @here.build/lexical-namer
Make shared model classes serializable to Arrival S-expressions without bundling Arrival @here.build/arrival-env
Style a CodeMirror 6 editor to match the products @here.build/editor-theme
Write perceptually correct oklch() colors that stay in gamut @here.build/postcss-oklch-plus

Every package is MIT-licensed except @here.build/lexical-namer, which is FSL-1.1-MIT. See Licensing.

@here.build/tsconfig splits a config into two independent choices. A purpose is what you are compiling. An environment is what you are compiling for. List one of each in extends:

tsconfig.json
{
"extends": [
"@here.build/tsconfig/purpose/lib",
"@here.build/tsconfig/env/node"
],
"compilerOptions": { "rootDir": "./src", "outDir": "./dist" }
}
  • Purposes: purpose/lib for NodeNext libraries that emit declarations, and purpose/app for bundler/ESNext applications.
  • Environments: env/node (also exported as env/cf), env/browser, env/browser-widespread (ES2022) and env/consumer (ES2017).

Install it with pnpm add -D @here.build/tsconfig typescript.

@here.build/eslint-configs exports flat-config arrays. The package lives in packages/eslint-config. Each preset layers the same shared base with globals and browserslist targets for one environment. The shared base is @eslint/js, typescript-eslint, sonarjs, unicorn, compat, import-x, promise, regexp, security and prettier.

eslint.config.mjs
import { nodejs } from "@here.build/eslint-configs";
export default [...nodejs];

The presets are nodejs, browser, shared, cloudflare, landing and reactConfig. Install with pnpm add -D @here.build/eslint-configs eslint.

@here.build/collections is a set of Map and WeakMap utilities with default-value semantics. DefaultedMap is the usual one. Its get creates a missing entry from a factory. Grouping code does not check for an absent key and insert one:

import { DefaultedMap, Counter } from "@here.build/collections";
const groups = new DefaultedMap<string, string[]>(() => []);
groups.get("a").push("x"); // auto-creates the array
const counts = new Counter<string>();
counts.add("hit");

The package also has DefaultedWeakMap, Counter for tallies, PathMap for tuple or path keys, and ArrayMultimap and SetMultimap for one key with many values. The MobX-reactive computed variants are ComputedMap, ComputedWeakMap and ComputedUniformMap. They are exported from the @here.build/collections/mobx subpath, so code that does not use MobX does not pull them in.

ordinal gives objects a process-local identity. ordinal.id(obj) returns a stable integer the first time it sees an object. The integers are assigned monotonically, cached in a WeakMap, and keyed by pointer identity. ordinal.sort(a, b) is a total-order comparator: objects by ordinal, primitives by type and then value. Use it to key a Map by reference, or to put an unordered Set into a canonical order within one session. An ordinal is never serialized and never crosses a process boundary. It is only consistent, not meaningful. When something else guarantees one stable object per logical thing, the ordinal is a session-local id for something that has no shared id yet.

@here.build/error-invariant is a side-effect import. Import it once, typically at an entry point. The import installs invariant on Error and every subclass:

import "@here.build/error-invariant";
Error.invariant(user != null, "user is required");
TypeError.invariant(typeof x === "number", "x must be a number");

When the condition is falsy, invariant throws an instance of the constructor it was called on. TypeError.invariant throws a TypeError. MyError.invariant throws a MyError. When the condition holds, TypeScript narrows the type for the rest of the scope.

This mutates the global Error constructor on purpose. Do not let the bundler tree-shake the import away.

@here.build/chunked-websocket is a transport-layer wrapper. It splits messages over 1 MiB into chunks that can be reassembled, so workerd accepts them. Application code on top, such as Yjs sync, comments or awareness, keeps seeing a normal WebSocket. The package also ships a Durable Object flavor. It exports ./client (ChunkedWebSocket) and ./server (ChunkedDOTransport). The implementation is adapted from partykit’s y-partykit chunking. The package has no README yet. Read packages/chunked-websocket/src for details.

@here.build/lexical-namer assigns names by priority, either in one flat pool or across nested scopes. Each entity offers candidate names keyed by priority. The highest priority wins. On a collision, the entity falls back to its next candidate.

Both APIs use the same resolution algorithm:

  • resolveLexicalNames takes a tree of scopes. A name claimed in a scope is reserved in all of its descendants but not in its siblings, so two sibling scopes can each use the same name. Use it for JavaScript identifiers and other lexically scoped namespaces.
  • assignNames builds a single childless root scope and delegates to the same resolver. Use it for CSS classes or any other single namespace. It postfixes ties by default.
import { resolveLexicalNames, type ScopeSpec } from "@here.build/lexical-namer";
const root: ScopeSpec<string> = {
id: "root",
entities: [
{ key: "a", candidates: { 100: "open", 80: "openState" } },
{ key: "b", candidates: { 100: "open", 80: "openFlag" } },
],
};
const result = resolveLexicalNames(root, {
postfixFor: (key) => key, // must be injective across the entity set
resolveTie: (name, postfix) => `${name}_${postfix}`,
onTie: "burn",
});
result.assignments.get("a"); // the name assigned to "a"

onTie decides what happens when entities contest the same bare name at one priority. "burn" removes the name for lower tiers too. "free" leaves it claimable. "postfix" postfixes every tied entity immediately. The full type surface is in src/index.ts. src/__tests__/resolver.test.ts is the contract.

@here.build/arrival-env is the only Arrival-flavored package in Commons. It lives here because both product families need it. The package defines the Symbol.SExpr and Symbol.toSExpr symbols and does not bundle the serializer. A shared model library can describe how its classes serialize, while only the environments that serialize pay for the runtime. A typical case is models shared between an MCP server, which serializes them for agents, and a browser frontend, which only uses them as classes.

shared-models/src/button.ts
import '@here.build/arrival-env';
export class Button {
constructor(public label: string, public disabled: boolean) {}
[Symbol.SExpr]() {
return 'Button';
}
[Symbol.toSExpr]({ keyword }) {
return [
keyword('label'), this.label,
keyword('disabled'), this.disabled
];
}
}

Only the process that imports the serializer produces text:

import { toSExprString } from '@inhuman.tools/arrival-serializer';
toSExprString(new Button('Click me', false));
// => (Button
// :label "Click me"
// :disabled false)

The context passed to Symbol.toSExpr offers keyword (:clickable, a flag or key), symbol (a bare symbol), quote ('abc123, an identifier to reference), string (always-quoted text) and expr ((onClick ...), an isolated statement). You can return any value, including objects, classes, arrays and sets. The serializer aims to be at least as good as JSON, and custom definitions make chosen entities more expressive and compact. Importing the package more than once is safe. The symbols are defined idempotently.

See Arrival for the language itself.

@here.build/editor-theme is a self-contained look for CodeMirror 6 editors. It ships self-hosted fonts (no CDN or Google Fonts), a Darcula palette with Helmholtz–Kohlrausch compensated syntax colors, and styling for overlays, forms and marks. A host does not need its own CSS for the stock CodeMirror classes.

import { theme, editorFill } from "@here.build/editor-theme";
import "@here.build/editor-theme/fonts.css";
new EditorView({
// editorFill only when the host is a fill-pane (not auto-height cells)
extensions: [/* language */, theme, editorFill, /* host */],
});

Import fonts.css once at the app root, not as a side effect of a JS module, because bundlers drop nested library CSS. The writing font under the caret is JetBrains Mono. Reading text in completions and tooltips uses Monaspace Argon for values and Krypton for types.

With theme in place, CodeMirror’s autocomplete, lint and language extensions pick up the shared styling with no extra work. For IntelliJ-style find and replace, add ideaSearch() (Mod-f to find, Mod-Alt-f to find and replace). Do not also add the bare search() or searchKeymap, because ideaSearch() owns them. When you need finer control, the individual pieces are exported separately: darcula, overlayTheme, formTheme, searchMarks, lintMarks, structureMarks, the font stacks and the palette tokens. pnpm --filter @here.build/editor-theme storybook shows them all together.

@here.build/postcss-oklch-plus adds three PostCSS color functions. They compile to plain oklch() and do the perceptual math at build time.

Function What it does
oklch-safe(L C H [/ A]) Clamps to the gamut by reducing chroma. Browsers currently clip out-of-gamut OKLCH per channel, which shifts the hue.
oklch-hk(L C H [/ A]) Helmholtz–Kohlrausch compensation: saturated colors look brighter than their measured L, so this lowers lightness until a colored element sits level with a gray of the same L. It does not clamp.
oklch-safe-hk(L C H [/ A]) Compensation, then the clamp.
/* you write */
.btn-accent { background: oklch-safe-hk(0.62 0.18 255); }
/* you ship */
.btn-accent { background: oklch(0.5986 0.18 255); }

Static arguments fold to constants. Dynamic arguments (var(), calc()) stay live. The trigonometry in the compensation depends only on hue, so a static hue means no trigonometry ships at all, even when lightness or chroma animate. Only a dynamic hue falls back to a live cos() expression. The default gamut: "p3" (or "srgb") clamps to the real gamut boundary. "bell" is a stylistic taper that does not keep colors in gamut and exists only as the dynamic-hue fallback. Register it in postcss.config.js with oklchPlus({ /* options */ }). The pure math is also exported from @here.build/postcss-oklch-plus/core.

Commons is MIT-licensed, except @here.build/lexical-namer, which is licensed under FSL-1.1-MIT. Each version of it converts to MIT two years after release. Until then it permits everything except Competing Use, meaning offering it in a commercial product or service that substitutes for it. Internal use, non-commercial education and research, and professional services built on top of it are always permitted. Questions go to team@here.build.