@fabric-harness/agent-registry
v0.5.0
Published
Vertical-neutral agent governance contracts: registration, enrollment, capability grants, budgets, decision boundary, and identity bindings.
Readme
@fabric-harness/agent-registry
Vertical-neutral agent governance contracts, extracted per the Fabric Agent
Contracts Reconciliation ADR (techfabric vault) from the family's origin
vertical packages. This package knows nothing about the applications that
integrate with it — no vertical vocabulary, no product names, CI-guarded in
both src/ and test/. Origin-equivalence tests live in each vertical's own
repository beside its re-export shim.
What lives here:
- registry — agent definitions, hash-pinned versions with hard model
budgets (
resolveAgentRunTokenBudget), tenant registrations, capability grants with the read/propose/execute separation, runs, execution principals, andscopeMatches/isActionAllowedByScopesfor<namespace>.*scope patterns over action IDs. - enrollment — the external-runtime onboarding state machine (invites with
hashed tokens, request/approve with request-hash + envelope-hash fencing,
encrypted credential reveals, operator dispatches/admissions, mutation
fences) and
approvalIsSubset— approval can only narrow, never widen. Runtime kindgeneric-mcpis the channel-hosted ACP agent kind. - decisions —
ActionRouterouting vocabulary with app-owned approvals (approvalRequestId) and Host-owned approvals (approvalOwner: 'host',actionInvocationId), per-actionPolicyDecision/PolicyHint, theclampRouteautonomy ceiling, theApprovalRequestentity, decision events,SignalPendingStep, and the D16 decision boundary:validateExternalDecision(pure — refusals, expiry, verification floor, capability, receipt pins) returning the decision record +SignalOutboxIntentthe vertical action persists atomically with its pending→terminal compare-and-set, andcreateSignalOutboxReconciler(idempotent delivery with CAS checkpointing; receiving workflows dedupe onapprovalRequestId). No neutral code records a decision and then performs an uncheckpointed inline signal. - identity — revocable external identity bindings (
nostr,slack,email, …) between surface identities and Fabric principals. - evidence / skills / envelope / ports / kinds — outcome-evidence and
skill-contract factories, the
X-Fabric-Signature: v1=signed envelope, neutral ports, namespaced kind primitives.
Event-handler runtime (@fabric-harness/agent-registry/event-handler)
createEventHandler({ verify, store, handlers, classify }) returns a
(request: Request) => Promise<Response> handler for signed platform events.
It is written against Web-standard APIs (Request, Response, TextDecoder and
WebCrypto). An import scan in the package tests refuses Node imports and Node
globals in this package's own sources; it allows zod without scanning it,
and no test runs the module inside workerd, so Cloudflare Workers support
without nodejs_compat is the intent rather than a tested result.
import {
createEventHandler,
createInMemoryKeyValueStore,
createProcessedEventStore,
fabricEnvelopeVerifier,
} from '@fabric-harness/agent-registry/event-handler';
const handle = createEventHandler({
verify: fabricEnvelopeVerifier(env.FABRIC_EVENT_SECRET),
store: createProcessedEventStore(env.PROCESSED_EVENTS ?? createInMemoryKeyValueStore()),
handlers: {
'example.updated': async (envelope) => {
// Do the work. Return nothing for completed, or { kind: 'retry' | 'dead_letter' | 'ignored' }.
},
},
classify: (error) => (error instanceof ValidationError ? { kind: 'dead_letter' } : { kind: 'retry' }),
});- Checks before any store access or handler: method (405), body size
(413, default 1,000,000 bytes, refused while the body streams), UTF-8 (400),
X-Fabric-SignatureandX-Fabric-Timestampover the body text exactly as received (401, 300 seconds skew by default), then theagentEventEnvelopeSchemashape (400). A leading byte-order mark is kept in the verified text, so a body changed by adding one fails verification. A verifier that throws, including on a clock that returns a non-finite time, returns 503, since the signature could not be checked. - Options are checked when the handler is built:
maxBodyBytesmust be a positive integer,retryAfterSecondsa number from 0 to 86,400, andfabricEnvelopeVerifier'smaxSkewSecondsa finite number, 0 or more. Anything else throws. - Outcomes and statuses come from
eventOutcomeResponse:completedandignoredreturn 200,retryreturns 503 withRetry-After,dead_letterreturns 422.Retry-Afteris a whole number of seconds, rounded up and capped atMAX_RETRY_AFTER_SECONDS(86,400); an invalid value falls back to the configured default, then to 30. The body is{"outcome": "<kind>"}. - Dispatch: an event type with no handler in the table is
ignoredwithout touching the store, so a handler added later can still take a redelivery. Handlers,classifyandonOutcomereceive the plain parsed envelope. A handler that returnsundefinedhas completed; one that returnsnullor any other value that is not an outcome getsretry. Every outcome is copied into a new object before use, so only a recognized outcome can produce a response or a marker. An outcome is recognized by itskind; an optional field of the wrong type (a non-stringreason, a non-numericretryAfterSeconds) is dropped and the kind still applies. A returned value that is not an outcome isretryand does not reachclassify. A handler that throws is passed toclassify; whenclassifyis absent, throws, or returns anything but retry or dead_letter, the outcome isretry, so a handler failure is not reported as success. - Observer:
onOutcomeruns after the response is built, and a throw or a rejected promise from it is ignored. - Processed events:
createProcessedEventStore(kv, { ttlSeconds, prefix })keeps one marker per tenant and event id (tenantIdandeventIdfrom the envelope) for 7 days by default. Other envelope fields are not part of the scope, so a redelivery whose payload was re-rendered still matches. The key is the prefix followed by the lowercase hex of SHA-256 over the UTF-8 bytes ofJSON.stringify([tenantId, eventId]): always the prefix length plus 64 characters, so it fits the 512-byte key limit of Workers KV whatever the ids hold, and two identities share a key only on a SHA-256 collision. The prefix may be at most 448 UTF-8 bytes (MAX_PROCESSED_EVENT_PREFIX_BYTES); a longer one throws when the store is built. The store is anything withget,put(key, value, { expirationTtl })anddelete(the shape of a Cloudflare KV namespace). The tenant and event id are copied before any handler runs, and both marker operations use that copy. An event is marked only after its handler returnscompleted,ignoredordead_letter; aretryleaves it unmarked. A redelivery of a marked event returns 200 without running the handler. - Store failures: a failed read returns 503 and does not run the handler. A failed write after the handler ran also returns 503, which asks the sender to redeliver. The handler runs again only if no marker is visible at that time, so a store that wrote the marker but reported failure suppresses the redelivery. Handlers must be idempotent.
- Known limit: the marker is written after the handler finishes, so two concurrent deliveries of the same event can both run the handler.
Scope rule (CI-guarded): nothing here names a vertical's domain. Verticals
attach scope via zod .extend() and factory literals in their own packages,
which keeps persisted wire shapes byte-identical through the extraction.
Layering: channel adapters (@fabric-harness/channels/*) carry candidate
identities and never authorize; only a vertical's governed decision-ingress
action — composed from createDecisionIngress — resolves bindings, checks
capabilities, and signals durable workflows.
