Skip to content

Package Guidelines

Standards for creating and maintaining packages in the n-dx monorepo.

Public API

Every package exposes its public surface through src/public.ts:

json
{
  "exports": {
    ".": { "import": "./dist/public.js", "types": "./dist/public.d.ts" },
    "./dist/*": "./dist/*"
  }
}

What to Export

Consumption patternExport styleExample
Library (runtime imports)Functions + typesrex: resolveStore, findNextTask
MCP server + filesystem readsMCP factory + schema typessourcevision: createSourcevisionMcpServer
CLI + filesystem readsTypes + schema constantshench: HenchConfig, RunRecord

What NOT to Export

  • Zod validation schemas (forces Zod as a transitive dependency)
  • Internal utilities serving a single consumer
  • Complex config factories with internal initialization context

Gateway Modules

See Gateway Modules for the full pattern reference.

Type Duplication

When importing types would create unwanted build-time coupling, types are duplicated with compile-time consistency tests:

ConsumerSourceConsistency test
web viewer (prd-tree/types.ts)rextype-consistency.test.ts
  • Import when packages already have a runtime dependency
  • Duplicate only when the consumer runs in the browser and can't import Node.js packages
  • Always add a compile-time test that verifies sync

Required Scripts

ScriptCommandPurpose
buildtsc (or tsc && node build.js)Compile TypeScript
devtsc --watchWatch mode
typechecktsc --noEmitType checking
testvitest runRun tests
validatetsc --noEmit && vitest runFull validation

The dist/* Wildcard Export

An intentional escape hatch for integration tests and CI scripts. Not public API — files may be renamed or deleted without notice.

Acceptable: Integration tests, CI scripts, temporary gateway migration.

Prohibited: Production runtime imports bypassing the gateway, importing internal types when a public.ts export exists.

.rex/ Write-Access Protocol

Packages share state through filesystem rather than runtime imports:

FileOwnerReadersWrite pattern
prd.jsonrex (FileStore)hench, webAtomic read-modify-write
config.jsonrex (FileStore)hench, webWritten at init
execution-log.jsonlrex (FileStore)webAppend-only
workflow.mdrex (FileStore)webOverwritten on transitions
acknowledged-findings.jsonrex (analyze)Overwritten on acknowledge

Rules:

  1. Single writer per file
  2. No file locking (sequential access assumed)
  3. Readers treat missing/malformed files as non-fatal
  4. Hench agent never writes .rex/ files directly — all mutations go through Rex's store layer

Released under the Elastic License 2.0.