green-tea is new, so coding agents have no training data on it and
write Express: app.use, next(), res.status().json(). llms.txt states
what differs: the mental model, a complete app, the decorators and
built-in tokens, how to return responses, the options agents usually
need, common mistakes with the correct form, testing, and how to
inspect an app first.
Every code block was typechecked against src/, and each behavioural
claim was checked with a small probe app.
The file ships inside the package, so it always matches the installed
version. matcha's scaffolded AGENTS.md points at it. Only a packaged
file is added; the API is unchanged.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
The CARD-22 gate audit found these runtime cells without tests:
- CARD-17 T1-T3 (booting, ok, degraded) existed only on Node. Add them
on Deno and Bun. T1 goes through app.fetch, because serveDeno and
serveBun boot before they bind. T2 and T3 go through a real listener
and assert the response body, not only the status.
- CARD-16 T6 (encodings ['gzip'] with a br-only client gives identity)
was missing on Deno and Bun.
- CARD-16 T8 on Deno and Bun lacked the handler-set content-encoding
case and the 204 case.
A negative run of T6 against compression: true fails with 'encoded as
br', so the check can tell the two cases apart.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Make the wording consistent: mesh is alpha and may change in any
release. The JSDoc tags said 'a minor release' while the README said
'any'.
State the rule mesh now follows. Its surface is the @experimental
exports, MeshConfig and the mesh:* events. A mesh change stays inside
that surface: it adds no createApp option, App method or decorator, and
it changes no stable type. Mesh adapts to the stable API instead of
moving it.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
ResponseShape reaches the public API only through the mesh signatures
MeshControlDeps and RemoteRoute. The CHANGELOG already lists it with
the mesh types, so tag it like them, which keeps it outside the
freeze.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
#181 exported Link, ReconnectOptions, ManifestPolicy, SocketCtor,
EventfulSocket, RouteEntry, RemoteScopeNode, RemoteRoute and
MeshControlDeps without the tag the other mesh exports carry, so they
would have read as part of the frozen API. They are mesh plumbing,
outside the freeze like MeshConfig.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Add an API stability section to the README with the policy. From RC.1
to stable, releases are fixes only, with no additions and no
deprecations. After stable, a deprecated API gets at least two monthly
releases, JSDoc @deprecated, and a single app.logger warning before it
is removed under ### Breaking. The committed API reports make every
change visible, and mesh stays outside the promise.
Correct the wording added in #181 and #182, which said the API could
still grow until stable. That contradicted D18.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Deno lists package.json's dependencies in deno.lock, so the new dev
dependency added a line on the first deno test. CI's deno publish
--dry-run then aborted on the dirty tree.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
CARD-22 / D20. api-extractor 7.59.4 is now a dev dependency.
scripts/api-report.mjs reads the declarations that tsup emits for each
export-map entry (".", "./deno", "./bun", "./edge") and writes
api/<entry>.api.md.
`npm run api` regenerates the reports. `npm run api:check` runs in the
CI build job and fails when a report differs from the build, so a
public type change has to arrive with its regenerated report in the
same PR.
The check also fails on ae-forgotten-export: a public signature that
names a type its entry does not export. In the adapter entries, a root
type such as App or Logger is accepted, because it is importable from
@green-tea/core; any other unexported type still fails. Both failure
paths were verified locally, by adding a field to TlsOptions and by
un-exporting DenoServeOptions.
The reports are not published: npm ships dist/ and JSR ships src/.
CONTRIBUTING documents the check and the additions-only rule.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
The README no longer describes the API as still moving, or the radix
matcher as future work. It also states that native TLS is Node-only.
The CHANGELOG gains a Breaking entry, with migration notes, for the
Deno and Bun TLS refusal, and an Added entry listing the newly
exported types.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Only Node's listen() reads tls. serveDeno and serveBun serve through
the runtime's own listener, so an app created with tls came up as
plain HTTP without warning, for a caller who had asked for HTTPS.
createApp now marks the app with a symbol, following the MARK_EDGE
pattern. Both adapters throw on that mark before they boot or bind.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Public declarations named types the entry points did not export, so a
caller could invoke the API but could not name its parameters or
results. The affected types were ModuleOptions, Ctor, BusLike,
ArgSource, GraphNodeView, GraphRouteView, StandardIssue,
StandardResult, the experimental mesh types, and the adapter option
types: DenoServeOptions, BunServeOptions and EdgeCtx.
Export them all. The changes are additive only, and no beta.2 name
moves. Bun's private BunServeShortOptions becomes the exported
BunServeOptions, and the ambient Bun.serve shape is renamed so the two
cannot collide.
channel() had started returning TappableChannel, which leaked the
internal tap symbol into its public return type. Restore the beta.2
return type, Channel<T>. ws-core still finds the tap through the
symbol, not through the signature.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Regenerate the cross-framework, step-scaling, runtime and security
tables at 4566f31, unpinned on the same Ryzen box as September so the
ratios stay comparable.
Add the 26.9.0-beta.2 -> RC.1 release gate. It runs fifteen cases on
Node, Deno and Bun, and attributes the Deno drift to the router
trade-off accepted under D4, plus residual per-feature work. The
compression rows get their own table, because beta.2 has no
compression to compare against. A comparison against raw-http shows
where the field moved: green-tea gained on hello, param and pipeline,
and Fastify 5.12 gained on validate.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
A buffered body under the threshold is sent identity whatever the client
accepts, so Accept-Encoding played no part in it and RFC 9110 asks for
no Vary. A cache that stores it for everyone is right to: every client
accepts identity. Responses that are encoded, or that are identity for
a request-side reason (identity client, HEAD), and every 304 keep Vary,
as does every compressible edge response, since Cloudflare encodes
there.
Deno pays about 10% of a small request for the header, Bun about 3%.
The size is also measured with Buffer.byteLength instead of allocating
the bytes, which are now built only when the body is encoded.
Measured on the Mac, hello with compression on against compression off:
Deno -17% -> -2%, Bun -7% -> -3%.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
eligible() read four headers through findHeader, each an Object.keys and
a toLowerCase per key, then ran two regexes, on every response while
compression is on. It now walks the keys once, keeps the first value of
each name as findHeader did, memoizes the content-type decision for the
last type seen, and tests no-transform only when cache-control is set.
Measured on Deno, hello with compression on (under the threshold): +2-5%.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
trackHealth wraps the memoized boot in an async function, so every
app.fetch request paid a new promise and microtask hops awaiting a boot
that had already settled. A built route table means the boot succeeded,
so the fetch handler now goes straight to it; only requests before the
table exists await the boot. A failed boot still rejects every request,
because the table is never built.
Measured in-process on Deno (app.fetch in a loop, param route): about
+3-6%.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
CONTRIBUTING said none of the Deno, Bun or edge suites run in CI. They do:
the runtimes job runs all three on every push and gates a merge. It now
says so, names test:all, and lists the audit step CI runs.
The README's benchmark section quoted a ranking against Fastify that went
stale with the next measurement. It now explains what the harness measures
and why, and leaves every number to BENCHMARKS.md. The install section
states the Node 22 floor and that Node 18 and 20 are not supported.
The PR template asks which runtime suites were run. The example README
pointed at ts-node, which is not a dependency, and a dist path tsup never
builds; it now runs each example with tsx. example/server.ts crashed at
boot because its teacup lacked experimental: true.
docs/plans held agent implementation plans from August and September.
Those belong in .specs/, which is not committed, so they leave the
repository. The three places that linked the mesh degrade plan now
describe the planned expects list instead.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Every Bun request called server.requestIP() for ctx.ip (#116), a native
call that builds an object, whether anything read the address or not. On
Mac that measured 7-11% of a small request; recording the server in the
peer map instead costs nothing.
The neutral request now carries a resolver rather than an address. The
handler request and the pipeline seed expose ctx.ip as an accessor that
resolves once on first read, and a step may still assign it. runPipeline
uses the seed it is given instead of spreading it, which would have
evaluated the accessor; both callers build the seed fresh per request.
Inside a stream body ctx.ip is '' unless a step or the handler read it
before the stream was returned: the body runs after the response has
started, when the socket may be gone.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
The chunked reader added for the incremental 413 (4d1639f) cut a Bun JSON
POST by more than half: 37.6k -> 11.7k req/s on jarvis. A well-formed
Content-Length inside the limit already bounds the body, because the
runtime frames it by that header, so arrayBuffer() is safe there and native
in Bun, Deno and workerd. byteLength is still checked for a Request built in
user code whose header and body disagree. Chunked uploads keep the bounded
read.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
toWebHeaders copied every response's headers into a Headers object one by
one, so set-cookie arrays survive. Deno and Bun build native headers from a
record directly, and the JS copy cost 5-8% on every Deno request (bisected to
50010da). A record holding only strings is now returned as it is; anything
else still goes through Headers.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
On Node every request goes through readBody, GET included. Subscribing
listeners to an empty request stream measured ~4% slower than the old
async iterator on an 8 KB GET response, in both orders on jarvis.
A request with no Transfer-Encoding and no or a zero Content-Length has
no body (RFC 9112 6.3), so resolve undefined without touching the
stream. Node drains the unread request when the response ends.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
The A/B harness had no case with compression on, so a change to the
response write path was measured only on its uncompressed branch. Add an
8 KB JSON response uncompressed, identity-negotiated, gzip and br, plus a
small response under the threshold with compression enabled.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Profiling the validate (POST) bench route against 4d1639f showed the
loss since then spread over several small costs on the Node request
path rather than one regression. This removes the ones that do not
change behaviour:
- readBody reads with data/end/error/close listeners instead of
`for await`, whose async iterator costs a promise and a microtask per
chunk. It keeps the iterator's semantics: the running total enforces
the limit, an over-limit body destroys the request as leaving the loop
did, an error or a close before `end` rejects (the latter with
ERR_STREAM_PREMATURE_CLOSE), and the declared-length 413 is still a
rejection rather than a synchronous throw. A single chunk is returned
without Buffer.concat.
- writeResult is no longer async. A buffered response without
compression is written synchronously and returns nothing to await;
only a stream or a compressed body returns a promise, which serve
awaits, so a failure still reaches failSafe. The compression request
object is not built when compression is off.
- declaresOverLimit compares the number first and runs its /^\d+$/
shape test only when the length is over the limit.
The `serve().catch(failSafe)` wrapper stays: it is the #108 guarantee,
and handle() is asynchronous, so there is no synchronous path to skip.
Local A/B against 74faa55 (5 s x 4 rounds, macOS, indicative only):
validate (POST) +4.6%. test/read-body.test.ts pins readBody's
semantics: joining, empty body, 413 with destroy, declared-length 413,
stream error and premature close.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
tsup.config.ts gives every ESM output a banner that calls
createRequire(import.meta.url) at module scope, so the lazy
require('ws') / require('busboy') resolve. On workerd import.meta.url
is not a file URL: createRequire throws during module evaluation and
the worker fails to start. dist/edge.mjs, and the chunk it shares with
the other entry points, could therefore not be loaded from npm at all.
test/edge/run.ts bundles src/, which has no banner, so it never saw it.
The banner now wraps the call in a try and leaves `require` undefined
when it throws. esbuild's __require shim and src/node-require.ts
already handle an undefined require: the latter falls back to
process.getBuiltinModule, and its callers report a missing module in
their own terms. The static node:module import is kept: edge already
requires nodejs_compat, which provides it, and dropping it for
getBuiltinModule would lose Node 22.0-22.2, which lack that API.
Building edge separately was ruled out because it would duplicate
module state (MARK_EDGE) between @green-tea/core and its /edge entry.
test/edge/dist.ts bundles a worker that imports dist/index.mjs and
dist/edge.mjs, as wrangler does with the installed package, and serves
a request on Miniflare. It fails with the old banner and passes now.
npm run test:edge builds before running it, so CI's edge job covers it.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
JsonTransformer passed the handler's value to JSON.stringify, which
returns undefined for undefined, while TransformerFn promises a string
body. The Node server wrote that as an empty 200 with content-type
application/json; the fetch adapter's toBodyInit read `body.buffer` on
it and threw, so Deno, Bun and the edge answered 500 for a handler with
no `return`.
JsonTransformer now returns status 204 and an empty body (no headers)
for undefined. outcomeToResponse already sends a null body for 204 and
the Node server ends with the empty string, so all four runtimes give
the same answer. null is a JSON value and still renders as 200 `null`.
Routes with their own @Transformer are unchanged.
BREAKING CHANGE: a handler with no return value now answers 204 instead
of an empty 200 on Node (and instead of 500 elsewhere). Return a value
to keep a 200.
test/undefined-return.test.ts covers app.fetch and the Node server
(both fail without the fix) and pins null to 200.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Node's IncomingHttpHeaders and the fetch adapter's headersToRecord
both store request header names lower-cased, but resolveOne looked a
@header/@headers key up exactly as the decorator wrote it. Any name
with a capital letter, such as @header('Content-Type'), therefore
reached the handler as undefined.
resolveOne now lower-cases the key for the headers source before the
lookup. A picked bag (@headers([...])) keeps the names as written, so a
handler reads back the key it asked for; @headers() with no argument
still returns the whole lower-cased bag.
test/params.test.ts covers the single and picked forms on resolveArgs;
test/header-case.test.ts sends a request over app.fetch and the Node
server. All three fail without the fix.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
busboy emits `partsLimit` once its part count reaches `limits.parts`,
not when it passes it, and parseMultipart treats that event as a
malformed body. With `maxParts: N` a body of exactly N parts was
therefore rejected with 400 and only N-1 were accepted.
parseMultipart now passes `maxParts + 1` to busboy, the same one-unit
headroom it already gives `fieldSize`. N parts are accepted, N+1 are
rejected. Route-level and server-level maxParts share this path, as do
the Node server and app.fetch.
test/multipart.test.ts adds the exact-N case on parseMultipart;
test/multipart-http.test.ts sends exactly N parts at route and server
level. All three new assertions fail without the fix.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
parseMultipart created busboy with `limits: { parts }` only, so
busboy's `fieldSize` default of 1 MiB applied whatever maxBodyBytes
allowed. busboy cuts a field at that size and only sets
`valueTruncated`, which nothing read: with the body limit raised, a
1,100,000-character field reached the handler as 1,048,576 characters.
acquireBody now passes the route's resolved body limit down as
`maxFieldBytes`, and parseMultipart gives it to busboy as `fieldSize`.
busboy flags a field once it reaches `fieldSize`, so it gets one byte
of headroom; otherwise a field of exactly the limit would count as
cut. A field that busboy still reports as truncated rejects with
HttpError 413, which parseRequestBody already renders with that
status, matching how an over-limit body fails. Node and app.fetch
(Deno, Bun, edge) share this path.
test/multipart-http.test.ts sends a 1,100,000-character field to a
route with maxBodyBytes 2,000,000 over both app.fetch and the Node
server. test/multipart.test.ts checks the 413 and the exact-limit
boundary on parseMultipart directly.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
A node that needs the token it provides is a cycle of one, so say so in
the same words as every other cycle (`cycle detected: a -> a`), and name
the token and the fix:
cycle detected: auth -> auth (it needs 'user', which only it provides).
Remove 'user' from its needs, or move the work that produces 'user'
into a step it needs.
"missing dependency … it provides it itself" pointed the reader at a
missing producer, when the producer is there and the problem is the
loop.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
topoSort validated each need with producedBy.has(key), and the visit
skipped a dependency whose producer was the node itself. So a step with
needs: ['user'] and provides: ['user'], and nothing else providing user,
passed the graph check and booted. At request time it read a value
nobody had written, where every other missing dependency fails at boot.
The check now treats a node's own token as missing unless it is seeded.
The issue also allowed "provided by another node", but since CARD-18
(GitHub #35) a token has exactly one producer, so a second node that
provides it fails boot on its own; the self-producer is the only
producer there can be. A seeded token (req, params) still satisfies the
need, because the step reads the seed from the context before its
output is merged over it. The visit keeps skipping the node itself for
that case, so it is not reported as a cycle.
overrides do not exempt the node. They replace a runner after
finalizeGraph has run topoSort, and change no needs, so the graph check
sees the same node either way.
BREAKING CHANGE: an app with a node that needs a token only it
provides now fails createApp with "missing dependency: <token> needed
by <node> — it provides '<token>' itself". Remove the token from the
node's needs, or move the work that produces it into a separate
provider or step.
Refs: GitHub #43
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Container.resolve marked an app-scoped binding resolved only after its
factory settled. Two resolutions that started before then both found
nothing cached and both ran the factory, so one token could open two
pools.
The binding now caches the promise as soon as the factory starts, and
every resolution returns that promise. Retry semantics are unchanged:
before, a rejected factory set nothing and the next resolution ran it
again. Now a rejection clears the cached promise, so the next
resolution still retries, and only the callers already waiting on the
failed attempt share its rejection. The factory runs inside an async
wrapper so a synchronous throw takes the same path.
createApp was not exposed to this in practice. bootProvider runs each
provider's runner once, inside the memoized boot, and registers the
finished value as a constant factory, and Container is not exported.
The fix makes the container's own guarantee hold instead of relying on
that.
Refs: GitHub #46
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>