Repository navigation
feat(core): generic request-bound capability handoff for extensions (epic #837 Stage B) - #840
Merged
Merged
Conversation
…837 Stage B) Ordinary function/middleware routes have had exactly one way to reach an installed extension's live behavior: sessionUserId()'s one-way projection of a single opaque id through the reserved x-urlcode-context-* header, built before the handler runs. Everything else an extension exports (a caller-scoped store collection, a declared form flow, a templated email) exists only as a live object passed extension-to-extension through HostContext.get, never reachable from a route's own code. Generalize the identity precedent into a live, per-invocation call instead of a second header-projection channel per capability, per Stage B's contract decision (#839): a registration declares the capability names its instance can provide (RuntimeExtension.capabilities, parallel to providesPrincipal/streams); its instance implements provide(capability, invocation), called once per declared name per request, only for a route that already names it in policies.extensions (so it rides the same authorize()/middleware() gate that extension already applies, never a side door around it); the result binds into context.capabilities.<extension>.<capability>, right beside context.signal. invocation (InvocationContext) is frozen and request-scoped: requestId, route.pattern, the committed principal (never caller-supplied) and the request's AbortSignal off the sandbox path. No new YAML: reusing policies.extensions as the existing grant surface needed no new top-level vocabulary. A live bound object cannot cross the sandbox worker's JSON boundary, so sandbox: true plus a route naming a capability-declaring extension refuses at route-compile time (capability-in-sandbox), the same place and pattern as the existing stream-in-sandbox check. Adds RIM-EXT-CAPABILITY-001 to docs/RUNTIME-IMPLEMENTATION.md and a "Request-bound capabilities" section to docs/EXTENSIONS.md. test/extension-capability.test.ts proves the mechanism with a synthetic, non-first-party provider: no first-party import is needed anywhere in core; two requests never share a bound object; missing/undeclared/ provide-less/sandboxed cases each fail or no-op deterministically before or without touching the handler; registration-time validation rejects malformed capability lists. No first-party package declares a capability yet; naming the specific store/auth/mail/audit/abuse operations an application can reach this way is each package's own decision in a later stage. Resolves #839. Part of epic #837 Stage B. Co-Authored-By: Claude Sonnet 5 <[email protected]>
jimhoyd
enabled auto-merge (squash)
September 28, 2026 05:10
This was referenced Sep 28, 2026
Closed
This was referenced Sep 28, 2026
Closed
jimhoyd
added a commit
that referenced
this pull request
Sep 28, 2026
* proof(#843): embedded Better Auth in one local URLCode site Adds proofs/private-requests: a packed-consumer site where Better Auth 1.7.6 on node:sqlite owns accounts, sessions and its tables, an operator adapter mounts its native handler and turns its verified session into the request principal and #840's request-bound `identity` capability, and ordinary function routes implement owner-private requests and one reviewer-only approval with parameterized SQL. The adapter refuses before serving on a missing secret, an uninitialized schema, an origin or basePath mismatch, telemetry left on, or a disabled rate limiter; forwards only an exact allowlist of Better Auth paths (disabledPaths misses parametric routes); and supplies the admitted client address for throttling in a header it always overwrites. test/private-requests.integration.ts (npm run test:proof) packs this checkout, installs it into a copy of the site, and exercises setup, explicit policy approval, provider/target refusals, declarative fixtures with audit ready, and the HTTP flow including foreign-owner and reviewer denial, malformed input, concurrent approval, cancellation, sign-out, revocation and throttling. Core: explain/report state that an extension mount's subpaths are provider-defined and not inspected, and list the capabilities a registration declares on the routes it protects. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci: run the embedded Better Auth proof with the packed add-on integration verify:workspaces and the workspace-integration job now run npm run test:proof after test:addons. The proof packs the already-built core with --ignore-scripts, like the other packaging tests, so prepare never rebuilds dist under another test. Changes under proofs/ or to the proof's test are high-impact, so they select that job on a pull request. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(proof): stop the server before removing the site, run npm without a shell On Windows the proof's behavior passed but teardown did not: separate t.after hooks run in registration order, so the temp site was removed while the served runtime still held its SQLite files (EBUSY), the server-stop hook never ran, and the live child kept the test process alive until the job timeout. One unwind stack now attempts every closer, newest first. npm runs through npm_execpath under this Node, so Windows needs no shell (DEP0190). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
jimhoyd
added a commit
that referenced
this pull request
Sep 28, 2026
…thoring MCP server (#834) (#849) * proof(#843): embedded Better Auth in one local URLCode site Adds proofs/private-requests: a packed-consumer site where Better Auth 1.7.6 on node:sqlite owns accounts, sessions and its tables, an operator adapter mounts its native handler and turns its verified session into the request principal and #840's request-bound `identity` capability, and ordinary function routes implement owner-private requests and one reviewer-only approval with parameterized SQL. The adapter refuses before serving on a missing secret, an uninitialized schema, an origin or basePath mismatch, telemetry left on, or a disabled rate limiter; forwards only an exact allowlist of Better Auth paths (disabledPaths misses parametric routes); and supplies the admitted client address for throttling in a header it always overwrites. test/private-requests.integration.ts (npm run test:proof) packs this checkout, installs it into a copy of the site, and exercises setup, explicit policy approval, provider/target refusals, declarative fixtures with audit ready, and the HTTP flow including foreign-owner and reviewer denial, malformed input, concurrent approval, cancellation, sign-out, revocation and throttling. Core: explain/report state that an extension mount's subpaths are provider-defined and not inspected, and list the capabilities a registration declares on the routes it protects. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci: run the embedded Better Auth proof with the packed add-on integration verify:workspaces and the workspace-integration job now run npm run test:proof after test:addons. The proof packs the already-built core with --ignore-scripts, like the other packaging tests, so prepare never rebuilds dist under another test. Changes under proofs/ or to the proof's test are high-impact, so they select that job on a pull request. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(proof): stop the server before removing the site, run npm without a shell On Windows the proof's behavior passed but teardown did not: separate t.after hooks run in registration order, so the temp site was removed while the served runtime still held its SQLite files (EBUSY), the server-stop hook never ran, and the live child kept the test process alive until the job timeout. One unwind stack now attempts every closer, newest first. npm runs through npm_execpath under this Node, so Windows needs no shell (DEP0190). Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(cli,mcp): the reviewed operator policy reaches inspection and authoring (#834) bootstrap, context, explain, review, plan-feature and mcp accept the operator's --policy. A verified policy pins the host file to its reviewed projectSha256, so no PROJECT_SHA256 export is needed; bootstrap and context repeat it in their emitted commands and drop it from prerequisites. The MCP server verifies it once at startup and its run_validate/run_test/run_audit runners forward the same file, and run_tests uses its grants. No tool argument can name, create or change a policy; an edited project still invalidates it until the operator reviews and replaces the file. An empty, unparseable or missing policy file is now named (#847). bootstrap no longer offers the site's data/ directory for serving, and its serving hint says operator code, credentials and data stay outside the project. The #843 proof now runs its connected MCP workflow: run_validate and run_test pass on the packed site with only the operator's flags. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
jimhoyd
added a commit
that referenced
this pull request
Sep 28, 2026
) * proof(#843): embedded Better Auth in one local URLCode site Adds proofs/private-requests: a packed-consumer site where Better Auth 1.7.6 on node:sqlite owns accounts, sessions and its tables, an operator adapter mounts its native handler and turns its verified session into the request principal and #840's request-bound `identity` capability, and ordinary function routes implement owner-private requests and one reviewer-only approval with parameterized SQL. The adapter refuses before serving on a missing secret, an uninitialized schema, an origin or basePath mismatch, telemetry left on, or a disabled rate limiter; forwards only an exact allowlist of Better Auth paths (disabledPaths misses parametric routes); and supplies the admitted client address for throttling in a header it always overwrites. test/private-requests.integration.ts (npm run test:proof) packs this checkout, installs it into a copy of the site, and exercises setup, explicit policy approval, provider/target refusals, declarative fixtures with audit ready, and the HTTP flow including foreign-owner and reviewer denial, malformed input, concurrent approval, cancellation, sign-out, revocation and throttling. Core: explain/report state that an extension mount's subpaths are provider-defined and not inspected, and list the capabilities a registration declares on the routes it protects. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci: run the embedded Better Auth proof with the packed add-on integration verify:workspaces and the workspace-integration job now run npm run test:proof after test:addons. The proof packs the already-built core with --ignore-scripts, like the other packaging tests, so prepare never rebuilds dist under another test. Changes under proofs/ or to the proof's test are high-impact, so they select that job on a pull request. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(proof): stop the server before removing the site, run npm without a shell On Windows the proof's behavior passed but teardown did not: separate t.after hooks run in registration order, so the temp site was removed while the served runtime still held its SQLite files (EBUSY), the server-stop hook never ran, and the live child kept the test process alive until the job timeout. One unwind stack now attempts every closer, newest first. npm runs through npm_execpath under this Node, so Windows needs no shell (DEP0190). Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(cli,mcp): the reviewed operator policy reaches inspection and authoring (#834) bootstrap, context, explain, review, plan-feature and mcp accept the operator's --policy. A verified policy pins the host file to its reviewed projectSha256, so no PROJECT_SHA256 export is needed; bootstrap and context repeat it in their emitted commands and drop it from prerequisites. The MCP server verifies it once at startup and its run_validate/run_test/run_audit runners forward the same file, and run_tests uses its grants. No tool argument can name, create or change a policy; an edited project still invalidates it until the operator reviews and replaces the file. An empty, unparseable or missing policy file is now named (#847). bootstrap no longer offers the site's data/ directory for serving, and its serving hint says operator code, credentials and data stay outside the project. The #843 proof now runs its connected MCP workflow: run_validate and run_test pass on the packed site with only the operator's flags. Co-Authored-By: Claude Opus 5.5 <[email protected]> * wip: authoring MCP on the official SDK (#846) * docs(tooling): the authoring MCP protocol is the official SDK's (#846) Describe what the SDK now owns (lifecycle, framing, version negotiation, JSON-RPC errors) and what URLCode keeps (tools, argument validation, in-order calls, the 1 MiB bounds), and how malformed input, oversized messages, closing stdin and client cancellation behave. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stage B of epic #837
Resolves #839 (the contract decision issue) and implements it.
The gap
Every typed extension export (
AuthExports,StoreExports,FormsExports,MailExports,AuditExports,AbuseExports) exists only as a live object passed extension-to-extension throughHostContext.get, never reachable from an ordinaryfunction/middlewareroute. The only precedent for ordinary route code reaching anything extension-provided is auth'ssessionUserId()(#833): a narrow, one-way, one-field header projection computed before the handler runs.The decision (#839) and what's implemented
Generalize that precedent into a live, per-invocation call rather than inventing a second header-projection channel per capability:
RuntimeExtension.capabilities?: readonly string[]— a pure availability signal, parallel toprovidesPrincipal/streams, validated atprepareExtensions.ExtensionInstance.provide?(capability, invocation)— called once per declared name per request, only for an extension the route already names inpolicies.extensions(so it rides that extension's existingauthorize()/middleware()gate — no side door around admission, addressing the transitive-authority-parity gap in [Re-scoped; legacy expansion on hold]: Ecosystem integration, discovery and AI authoring #837 §17).InvocationContext— frozen, request-scopedrequestId,route.pattern, the committedprincipal(never caller-supplied), and the request'sAbortSignaloff the sandbox path.context.capabilities.<extension>.<capability>, built right besidecontext.signal.policies.extensionsas the grant surface needed no new top-level vocabulary, per the epic's own bar for adding one.sandbox: true+ a route naming a capability-declaring extension fails route compilation (capability-in-sandbox) — same place and pattern as the existingstream-in-sandboxcheck, not a per-request surprise.provide()returningundefinedjust omits that entry (e.g. an anonymous request asking for a capability that needs a principal) — not an error.Evidence
test/extension-capability.test.ts(8 cases) with a synthetic, non-first-party "vault" provider proves: no first-party import needed anywhere in core; two requests never share a bound object or requestId; a route not naming the extension gets nothing; an extension with no declared capabilities or noprovide()is a no-op, not a crash;sandbox: truerefuses deterministically when capabilities are named and still activates cleanly when they aren't; registration-time validation rejects malformed/duplicate/oversized capability lists.npm run verifypasses in full, includingaudit:packages(core package budget raised 864→870 KiB packed / 3430→3445 KiB unpacked, measured and justified inscripts/package-audit.ts, same pattern as every prior bump) andnpm run test:addons.Docs
New "Request-bound capabilities" section in EXTENSIONS.md;
RIM-EXT-CAPABILITY-001contract card in RUNTIME-IMPLEMENTATION.md.Deliberately out of scope here
No first-party package (store/auth/mail/audit/abuse) declares a capability yet — naming their specific operations is each package's own decision, in Stage C+ per the epic's sequencing. The other three priority gaps from #837 §17 (aggregate budgets/backpressure, discovery-as-untrusted-input, cross-transport value semantics) don't block this mechanism and can land incrementally.
🤖 Generated with Claude Code