Skip to content
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
6ed5770
docs: add community integrations page and adapter template
thegdsks Oct 17, 2026
9c6f60b
feat: add auth.user.create and auth.user.get
thegdsks Oct 17, 2026
cd87b07
feat: add requireScope guard to Hono, Next.js and Express adapters
thegdsks Oct 17, 2026
672e82f
docs: generate repo stats and label package maturity
thegdsks Oct 17, 2026
7210484
docs: add end-to-end agent delegation example
thegdsks Oct 17, 2026
f79f214
docs: use auth.user.create in the quickstart and e2e example
thegdsks Oct 17, 2026
f641dc9
fix: make user.create idempotent per email and portable to MySQL
thegdsks Oct 17, 2026
33239f0
feat: add hook timeout and fail-closed runner
thegdsks Oct 17, 2026
65c1858
feat: typed decision codes and extracted authorize pipeline
thegdsks Oct 17, 2026
071890f
feat: hook delegation chain, fail-closed hooks and audit rows for blocks
thegdsks Oct 17, 2026
db76952
fix: deny agents past expiresAt in authorize()
thegdsks Oct 17, 2026
c10a150
feat: add guardHook and composeBeforeAuthorize for external guards
thegdsks Oct 17, 2026
04e4f74
feat: opt-in typed permissions via definePermissions
thegdsks Oct 17, 2026
b27afb1
feat: order audit rows within a second and audit delegation.revoke
thegdsks Oct 17, 2026
04180c8
feat: add explain() and keep delegated constraints in the simulator
thegdsks Oct 17, 2026
ff1cc3b
feat: type explain in the typed permissions facade
thegdsks Oct 17, 2026
f37410c
fix: stop revoked or expired agents from lending delegated permissions
thegdsks Oct 17, 2026
c8a3e53
refactor: split theauth-core under 500 lines and forward revokedBy
thegdsks Oct 17, 2026
3bf2e5e
fix: apply delegator liveness to the token vault and policy-shrink
thegdsks Oct 17, 2026
24e7561
docs: refresh the e2e example with explain, hook block and revoke audit
thegdsks Oct 17, 2026
d55d605
docs: reconcile errors page with the codes the source emits
thegdsks Oct 18, 2026
2c4cf14
docs: fix stale counts, samples and links; add ui-headless page
thegdsks Oct 18, 2026
7c89ee9
chore: replace em and en dashes in sources, tests and package docs
thegdsks Oct 18, 2026
1fab9c7
refactor: split oversized auth and a2a modules under 500 lines
thegdsks Oct 18, 2026
9094cea
feat: add web-standard HTTP handler in @glinr/theauth/http
thegdsks Oct 18, 2026
1f849c3
feat: explain near misses and a policy testing kit
thegdsks Oct 18, 2026
215c0b5
feat: versioned schema migration ledger and theauth db command
thegdsks Oct 18, 2026
7f6407e
feat: rebuild framework adapters on the core HTTP handler
thegdsks Oct 18, 2026
baefa97
feat: add httpGuard remote guard protocol and conformance check
thegdsks Oct 18, 2026
07db9f3
feat: init v2, doctor v2 and templates on real storage
thegdsks Oct 18, 2026
d5ae8a8
feat: make Postgres work across the whole instance, gate MySQL
thegdsks Oct 18, 2026
335182d
feat: issue agent tokens with the ta_ prefix and keep accepting kv_
thegdsks Oct 18, 2026
d7d6a5b
fix: refuse a file url on the in-memory sqlite provider
thegdsks Oct 18, 2026
2fa20e7
docs: update snippets for the ta_ prefix and sqlite-native, refresh c…
thegdsks Oct 18, 2026
a09fc61
fix: add decision code to agent-frameworks policy decision fixtures
thegdsks Oct 18, 2026
fd961e9
feat: audit API v2 and database-backed MCP stores
thegdsks Oct 18, 2026
4b44678
feat: require signed responses from remote guards
thegdsks Oct 18, 2026
f057b5a
feat: decision events, OpenTelemetry mapping and a logger interface
thegdsks Oct 18, 2026
f02e79e
fix: store refresh token use time as epoch seconds again
thegdsks Oct 18, 2026
e64560c
fix: sign the nextjs-auth session cache cookie
thegdsks Oct 18, 2026
3750f64
fix: default cookies to Secure without NODE_ENV and raise PBKDF2 to 6…
thegdsks Oct 18, 2026
a040609
fix: verify SAML signatures strictly and enforce response checks
thegdsks Oct 18, 2026
a8181f1
feat: revocation-bound MCP tokens, introspection, shared denylist and…
thegdsks Oct 18, 2026
cfbd188
fix: gate nextjs-auth middleware on a signed marker and sign CSRF tokens
thegdsks Oct 18, 2026
8ba05a5
feat: session idle timeout and remember me
thegdsks Oct 18, 2026
0cff92b
feat: no-store by default, opt-in security headers and exact-origin C…
thegdsks Oct 18, 2026
6de2287
test: update adapter tests for opt-in CORS and the 403 owner scope
thegdsks Oct 18, 2026
5642b18
feat: sign-in lockout, fail-closed options and a redirect allowlist
thegdsks Oct 18, 2026
4c34223
feat: doctor parity rules with stable json output
thegdsks Oct 18, 2026
90ff3f5
docs: add the MCP revocation page, a complete upgrade guide and accur…
thegdsks Oct 18, 2026
e6edabb
feat: verify Go receipts in CI, publish audit chain vectors and guard…
thegdsks Oct 18, 2026
75dab89
test: typecheck the tests, fix tests that asserted nothing and add a …
thegdsks Oct 18, 2026
462e02e
feat: 503 on revoke outages, rememberMe on every sign in path, doctor…
thegdsks Oct 18, 2026
7cde59e
feat: sign erasure records, anchor audit chains and verify Go chain e…
thegdsks Oct 18, 2026
f5899c1
fix: close revocation gaps on the MCP token endpoint, exchange and pu…
thegdsks Oct 18, 2026
3dd32fc
feat: add a live revocation demo and tutorial
thegdsks Oct 18, 2026
bd9aa8d
fix: pin the resolved address when fetching client metadata documents
thegdsks Oct 18, 2026
9eecae6
feat: rotate signing secrets without invalidating live sessions or we…
thegdsks Oct 18, 2026
5365f4b
fix: revoke tokens and links when a user is banned or deleted, refuse…
thegdsks Oct 18, 2026
8e0cfbf
fix: require a session for account routes and tighten the HTTP layer
thegdsks Oct 18, 2026
acf9a20
fix: bind approvals to their arguments and fail closed on guard and e…
thegdsks Oct 18, 2026
590c98d
docs: rewrite README, compare pages and stats, fix the conformance ch…
thegdsks Oct 18, 2026
d38ab5f
docs: correct the MCP revocation guide to match the code and add the …
thegdsks Oct 18, 2026
88ac77f
fix: ignore reserved keys when hashing approval arguments and consume…
thegdsks Oct 18, 2026
4c3e4f7
fix: clear static analysis bugs, handle sync hook throws and trim bas…
thegdsks Oct 18, 2026
f252455
test: flip a signature character that carries real bits in the statel…
thegdsks Oct 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 15 additions & 0 deletions .changeset/adapter-astro-http-handler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@glinr/theauth-astro": major
---

Rebuild the Astro adapter as a thin wrapper around `createTheAuthHandler` from `@glinr/theauth/http`. The 833 line per-adapter dispatcher and router are gone, so the adapter serves every route core serves, including `POST /mcp/revoke`, `GET /mcp/jwks` and `POST /explain`.

Added: `requireScope(theauth, { action, resource, clientIp? }, handler)`, a Astro route wrapper that sets `locals.agent`. It answers 401 (`invalid_token`, `agent_not_found`, `agent_revoked`, `agent_expired`) or 403 (any other denial) with body `{ error: { code, message } }` and passes the agent on.

Upgrade notes:

- Removed the deprecated aliases `authAstro`, `AuthAstroOptions` and `AuthAstroHandlers`. Use `theAuthAstro` and `TheAuthAstroOptions`.
- `TheAuthAstroOptions` is now the core handler options: `mcp`, `basePath`, `routes`, `maxBodyBytes` plus the shared security options (`authenticate`, `allowUnauthenticated`, `trustedProxy`, `rateLimit`, `trustedOrigins`, `csrf`). Existing option names keep working.
- `POST /authorize/token` now answers 401 (not 403) for a revoked, expired or unknown agent or a bad token, and 403 for every other denial. A known path with the wrong method answers 405. Unexpected errors answer a fixed 500 message.
- Request bodies above 1 MiB answer 413 (`maxBodyBytes`).

13 changes: 13 additions & 0 deletions .changeset/adapter-express-http-handler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@glinr/theauth-express": major
---

Rebuilt on the core HTTP handler (`createTheAuthHandler` from `@glinr/theauth/http`) using `toWebRequest` and `sendWebResponse`. `theAuthExpress` is now thin glue and serves every route, including `POST /mcp/revoke`, `GET /mcp/jwks` and `POST /explain`.

Upgrade notes:

- `TheAuthExpressOptions` is now the core `TheAuthHandlerOptions` (`mcp`, `basePath`, `routes`, `maxBodyBytes` and the existing security options). `basePath` defaults to where you mount the router. Bodies over `maxBodyBytes` (1 MiB) get 413.
- Removed the deprecated `authExpress` alias. Use `theAuthExpress`.
- `POST /authorize/token` answers 401 for `invalid_token`, `agent_not_found`, `agent_revoked` and `agent_expired`, and 403 for every other denial. A known path with the wrong method answers 405.
- `requireScope` now uses the core `requireAgent` decision-code mapping. Denial bodies are `{ error: { code, message } }` with the decision code (for example `no_permission`) instead of `UNAUTHORIZED` or `FORBIDDEN`. `getAgent(res)` no longer returns the token.
- The client IP now comes from the socket peer address, or from forwarded headers when `trustedProxy` is set.
13 changes: 13 additions & 0 deletions .changeset/adapter-fastify-http-handler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@glinr/theauth-fastify": major
---

Rebuilt on the core HTTP handler (`createTheAuthHandler` from `@glinr/theauth/http`) using `toWebRequest` and `sendWebResponse`. `theAuthFastify` is now thin glue and serves every route, including `POST /mcp/revoke`, `GET /mcp/jwks` and `POST /explain`. New `requireScope(auth, { action, resource })` preHandler and `getAgent(request)`.

Upgrade notes:

- `TheAuthFastifyOptions` is now the core `TheAuthHandlerOptions` (`mcp`, `basePath`, `routes`, `maxBodyBytes` and the existing security options). `basePath` defaults to the prefix the plugin is registered under.
- Inside the plugin the request body is no longer parsed by Fastify (the handler reads it itself). Your own routes outside the plugin are unaffected.
- Removed the deprecated `authFastify` and `AuthFastifyOptions`. Use `theAuthFastify` and `TheAuthFastifyOptions`.
- `POST /authorize/token` answers 401 for `invalid_token`, `agent_not_found`, `agent_revoked` and `agent_expired`, and 403 for every other denial.
- The client IP now comes from the socket peer address, or from forwarded headers when `trustedProxy` is set.
12 changes: 12 additions & 0 deletions .changeset/adapter-hono-http-handler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@glinr/theauth-hono": major
---

Rebuilt on the core HTTP handler (`createTheAuthHandler` from `@glinr/theauth/http`). `theAuthHono` is now about 40 lines of glue and serves every route, including `POST /mcp/revoke`, `GET /mcp/jwks` and `POST /explain`.

Upgrade notes:

- `TheAuthHonoOptions` is now the core `TheAuthHandlerOptions` (`mcp`, `basePath`, `routes`, `maxBodyBytes` and the existing security options). `basePath` defaults to the path you mount the app under.
- Removed the deprecated `authHono` alias. Use `theAuthHono` (or `createHonoAdapter`).
- `POST /authorize/token` answers 401 for `invalid_token`, `agent_not_found`, `agent_revoked` and `agent_expired`, and 403 for every other denial. A known path with the wrong method answers 405.
- `requireScope` now uses the core `requireAgent` decision-code mapping. Denial bodies are `{ error: { code, message } }` with the decision code (for example `no_permission`) instead of `UNAUTHORIZED` or `FORBIDDEN`. `c.get("agent")` no longer carries the token.
13 changes: 13 additions & 0 deletions .changeset/adapter-nestjs-http-handler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@glinr/theauth-nestjs": major
---

Rebuilt on the core HTTP handler (`createTheAuthHandler` from `@glinr/theauth/http`) using `toWebRequest` and `sendWebResponse`. `TheAuthModule` and `theAuthMiddleware` are now thin glue and serve every route, including `POST /mcp/revoke`, `GET /mcp/jwks` and `POST /explain`. New `requireScope(auth, { action, resource })` guard for `@UseGuards` and `getAgent(request)`.

Upgrade notes:

- `TheAuthModuleOptions` and `TheAuthNestjsOptions` are now `theauth` plus the core `TheAuthHandlerOptions` (`mcp`, `basePath`, `routes`, `maxBodyBytes` and the existing security options). For `theAuthMiddleware`, `basePath` defaults to where you mount it.
- Removed the deprecated `AuthModule`, `AuthModuleOptions`, `AuthNestjsOptions`, `authMiddleware` and `buildAuthRouter`. Use `TheAuthModule`, `TheAuthModuleOptions`, `TheAuthNestjsOptions` and `theAuthMiddleware`.
- `buildTheAuthRouter(auth, mcp?, options?)` now returns a middleware function instead of an Express `Router`. Mount it with `app.use(path, ...)` as before.
- `POST /authorize/token` answers 401 for `invalid_token`, `agent_not_found`, `agent_revoked` and `agent_expired`, and 403 for every other denial.
- The client IP now comes from the socket peer address, or from forwarded headers when `trustedProxy` is set.
12 changes: 12 additions & 0 deletions .changeset/adapter-nextjs-http-handler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@glinr/theauth-nextjs": major
---

Rebuilt on the core HTTP handler (`createTheAuthHandler` from `@glinr/theauth/http`). `theAuthNextjs` returns the handler for each method and serves every route, including `POST /mcp/revoke`, `GET /mcp/jwks` and `POST /explain`.

Upgrade notes:

- `TheAuthNextjsOptions` is now the core `TheAuthHandlerOptions` (`mcp`, `basePath` default `/api/theauth`, `routes`, `maxBodyBytes` and the existing security options).
- Removed the deprecated `authNextjs`, `AuthNextjsOptions` and `AuthNextjsHandlers`. Use `theAuthNextjs`, `TheAuthNextjsOptions` and `TheAuthNextjsHandlers`.
- `POST /authorize/token` answers 401 for `invalid_token`, `agent_not_found`, `agent_revoked` and `agent_expired`, and 403 for every other denial. `GET /audit/export` answers 403 when the `userId` query value belongs to another user.
- `requireScope` now uses the core `requireAgent` decision-code mapping. Denial bodies are `{ error: { code, message } }` with the decision code (for example `no_permission`) instead of `UNAUTHORIZED` or `FORBIDDEN`. The handler receives the agent without its token.
15 changes: 15 additions & 0 deletions .changeset/adapter-nuxt-http-handler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@glinr/theauth-nuxt": major
---

Rebuild the Nuxt adapter as a thin wrapper around `createTheAuthHandler` from `@glinr/theauth/http`. The 833 line per-adapter dispatcher and router are gone, so the adapter serves every route core serves, including `POST /mcp/revoke`, `GET /mcp/jwks` and `POST /explain`.

Added: `requireScope(theauth, { action, resource, clientIp? }, handler)`, a Nuxt event handler wrapper that sets `event.context.agent`. It answers 401 (`invalid_token`, `agent_not_found`, `agent_revoked`, `agent_expired`) or 403 (any other denial) with body `{ error: { code, message } }` and passes the agent on.

Upgrade notes:

- Removed the deprecated aliases `authNuxt` and `AuthNuxtOptions`. Use `theAuthNuxt` and `TheAuthNuxtOptions`.
- `TheAuthNuxtOptions` is now the core handler options: `mcp`, `basePath`, `routes`, `maxBodyBytes` plus the shared security options (`authenticate`, `allowUnauthenticated`, `trustedProxy`, `rateLimit`, `trustedOrigins`, `csrf`). Existing option names keep working.
- `POST /authorize/token` now answers 401 (not 403) for a revoked, expired or unknown agent or a bad token, and 403 for every other denial. A known path with the wrong method answers 405. Unexpected errors answer a fixed 500 message.
- Request bodies above 1 MiB answer 413 (`maxBodyBytes`).
- The Nuxt handler now streams the raw request body through h3 `toWebRequest` instead of re-serialising it as JSON, so form encoded bodies such as `POST /mcp/token` work.
15 changes: 15 additions & 0 deletions .changeset/adapter-solidstart-http-handler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@glinr/theauth-solidstart": major
---

Rebuild the SolidStart adapter as a thin wrapper around `createTheAuthHandler` from `@glinr/theauth/http`. The 833 line per-adapter dispatcher and router are gone, so the adapter serves every route core serves, including `POST /mcp/revoke`, `GET /mcp/jwks` and `POST /explain`.

Added: `requireScope(theauth, { action, resource, clientIp? }, handler)`, a SolidStart route wrapper that passes the agent as the second argument and sets `event.locals.agent`. It answers 401 (`invalid_token`, `agent_not_found`, `agent_revoked`, `agent_expired`) or 403 (any other denial) with body `{ error: { code, message } }` and passes the agent on.

Upgrade notes:

- Removed the deprecated aliases `authSolidStart`, `AuthSolidStartOptions` and `AuthSolidStartHandlers`. Use `theAuthSolidStart` and `TheAuthSolidStartOptions`.
- `TheAuthSolidStartOptions` is now the core handler options: `mcp`, `basePath`, `routes`, `maxBodyBytes` plus the shared security options (`authenticate`, `allowUnauthenticated`, `trustedProxy`, `rateLimit`, `trustedOrigins`, `csrf`). Existing option names keep working.
- `POST /authorize/token` now answers 401 (not 403) for a revoked, expired or unknown agent or a bad token, and 403 for every other denial. A known path with the wrong method answers 405. Unexpected errors answer a fixed 500 message.
- Request bodies above 1 MiB answer 413 (`maxBodyBytes`).
- Route handlers now accept either an `APIEvent` or a bare `Request`.
15 changes: 15 additions & 0 deletions .changeset/adapter-sveltekit-http-handler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@glinr/theauth-sveltekit": major
---

Rebuild the SvelteKit adapter as a thin wrapper around `createTheAuthHandler` from `@glinr/theauth/http`. The 833 line per-adapter dispatcher and router are gone, so the adapter serves every route core serves, including `POST /mcp/revoke`, `GET /mcp/jwks` and `POST /explain`.

Added: `requireScope(theauth, { action, resource, clientIp? }, handler)`, a SvelteKit endpoint wrapper that sets `event.locals.agent`. It answers 401 (`invalid_token`, `agent_not_found`, `agent_revoked`, `agent_expired`) or 403 (any other denial) with body `{ error: { code, message } }` and passes the agent on.

Upgrade notes:

- Removed the deprecated aliases `authSvelteKit`, `AuthSvelteKitOptions` and `AuthSvelteKitHandlers`. Use `theAuthSvelteKit` and `TheAuthSvelteKitOptions`.
- `TheAuthSvelteKitOptions` is now the core handler options: `mcp`, `basePath`, `routes`, `maxBodyBytes` plus the shared security options (`authenticate`, `allowUnauthenticated`, `trustedProxy`, `rateLimit`, `trustedOrigins`, `csrf`). Existing option names keep working.
- `POST /authorize/token` now answers 401 (not 403) for a revoked, expired or unknown agent or a bad token, and 403 for every other denial. A known path with the wrong method answers 405. Unexpected errors answer a fixed 500 message.
- Request bodies above 1 MiB answer 413 (`maxBodyBytes`).

15 changes: 15 additions & 0 deletions .changeset/adapter-tanstack-http-handler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@glinr/theauth-tanstack": major
---

Rebuild the TanStack adapter as a thin wrapper around `createTheAuthHandler` from `@glinr/theauth/http`. The 833 line per-adapter dispatcher and router are gone, so the adapter serves every route core serves, including `POST /mcp/revoke`, `GET /mcp/jwks` and `POST /explain`.

Added: `requireScope(theauth, { action, resource, clientIp? }, handler)`, a TanStack Start route wrapper that passes the agent as the second argument and sets `context.agent` when present. It answers 401 (`invalid_token`, `agent_not_found`, `agent_revoked`, `agent_expired`) or 403 (any other denial) with body `{ error: { code, message } }` and passes the agent on.

Upgrade notes:

- Removed the deprecated aliases `authTanStack`, `AuthTanStackOptions` and `AuthTanStackHandlers`. Use `theAuthTanStack` and `TheAuthTanStackOptions`.
- `TheAuthTanStackOptions` is now the core handler options: `mcp`, `basePath`, `routes`, `maxBodyBytes` plus the shared security options (`authenticate`, `allowUnauthenticated`, `trustedProxy`, `rateLimit`, `trustedOrigins`, `csrf`). Existing option names keep working.
- `POST /authorize/token` now answers 401 (not 403) for a revoked, expired or unknown agent or a bad token, and 403 for every other denial. A known path with the wrong method answers 405. Unexpected errors answer a fixed 500 message.
- Request bodies above 1 MiB answer 413 (`maxBodyBytes`).
- Route handlers now accept either the server route context (an object with `request`) or a bare `Request`.
5 changes: 5 additions & 0 deletions .changeset/agent-expiry-enforced.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@glinr/theauth": major
---

Security fix: `authorize(agentId)` now denies an agent whose `expiresAt` has passed, with code `agent_expired` and a denied audit row. Before, it checked only the stored `status`, so an elapsed agent kept passing until its status was flipped. Marked major because an agent that passed before can now fail. `authorizeByToken()`, `agent.validateToken()` and `policy.evaluate()` were already correct. See `docs/upgrading-to-2.mdx`.
10 changes: 10 additions & 0 deletions .changeset/agent-token-prefix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@glinr/theauth": minor
"@glinr/theauth-mcp": minor
---

Agent tokens now start with `ta_` instead of `kv_` (a leftover of the old kavachOS name). The format is otherwise unchanged: `ta_` plus 43 base64url characters (32 random bytes), SHA-256 hashed at rest.

Compatible migration: tokens already issued with `kv_` keep validating. Lookups are by token hash, so no stored data is rewritten and no database migration is needed. `agent.rotate` issues a `ta_` token for a legacy agent and retires the old one. A bearer string with neither prefix is now rejected before any database lookup.

Added `AGENT_TOKEN_PREFIX`, `LEGACY_AGENT_TOKEN_PREFIXES`, `isAgentToken` and `agentTokenLookupPrefix` to `@glinr/theauth`. The MCP `inspect_token` tool recognizes both prefixes. If you match agent tokens by prefix in your own code (proxies, log scrubbers, secret scanners), accept both `ta_` and `kv_`. "Token format" in `docs/agents.mdx` has a scanning regex for GitHub secret scanning and gitleaks.
18 changes: 18 additions & 0 deletions .changeset/audit-api-v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"@glinr/theauth": major
"@glinr/theauth-mcp": major
---

Audit API v2: explicit order, cursor paging and one event vocabulary.

- `audit.query()` takes `order: "asc" | "desc"`. The default stays `"desc"` (newest first), so existing calls return the same order. New filters: `events`, `resource` (exact, or prefix with a trailing `*`) and `cursor`. `actions` is now applied in the query, before `limit`, instead of after it.
- New `audit.page(filter)` returns `{ entries, nextCursor }`. The cursor is opaque and keyed on `recorded_at_ms` plus `id`, so pages are stable when rows share a millisecond or arrive between requests. `offset` is deprecated and ignored when a cursor is set.
- New nullable `event` column (migration `0005`, index `(agent_id, event, recorded_at_ms)`) and `AuditEntry.event`. `event` says what happened (`authorize`, `policy.evaluate`, `delegation.create`, ...), `action` keeps the domain verb. Migration `0005` backfills `event` from the old action for rows it can classify and leaves the rest NULL. `event` is not part of the audit hash, like `decision_code` and `recorded_at_ms`: hash inputs are unchanged, existing chains keep verifying.
- `GET /audit` still answers a bare array. Add `paged=true` or `cursor` for `{ entries, nextCursor }`; it also accepts `order`, `events` and `resource`. An invalid cursor answers 400.
- The `query_audit` MCP tool gains `events`, `resource`, `order` and `cursor`, drops `offset`, and now returns `{ returned, nextCursor, entries }`.

Upgrade notes:

- `AuditEntry` has a new `event` field (`null` when unknown). Code that builds `AuditEntry` values by hand must set it.
- Delegation rows now carry `action: "delegate"` with `event: "delegation.create"` or `"delegation.revoke"`. Rows written before the upgrade keep `action: "delegation.create"` or `"delegation.revoke"` (the column is hashed, so it is not rewritten); filter on `event` to see both. Anything that matched `action === "delegation.create"` must match `event` instead.
- With `skipMigrations: true`, apply `0005` by hand (`theauth db sql --from 0005`) before deploying.
5 changes: 5 additions & 0 deletions .changeset/audit-decision-code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@glinr/theauth": minor
---

Add a nullable `decision_code` column to `theauth_audit_logs` (not part of the audit hash, so existing chains stay valid). Every authorization row now records its decision code, `AuditEntry.code` exposes it, and `audit.query({ codes })` filters on it. A `beforeAuthorize` block, timeout or error now writes a chained audit row (code `hook_denied`, `hook_timeout`, `hook_error` or `approval_required`, with `theauthHook` details in `parameters`) and returns its id as `auditId`. `createTables()` migrates existing databases on startup; with `skipMigrations: true` apply `src/db/migrations/0002_add_audit_decision_code.sql` by hand before upgrading.
9 changes: 9 additions & 0 deletions .changeset/audit-receipt-interop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@glinr/theauth": minor
---

Audit receipts now have conformance coverage against the Go library, and the audit chain has published test vectors. The Go receipt fixture is vendored and verified in the normal test run, `packages/core/tests/fixtures/audit-chain-vectors.json` holds row hash vectors for hash versions 1 and 2 (generated by `scripts/gen-audit-chain-vectors.mjs`), and `docs/audit-receipts.mdx` specifies the leaf encoding and what does and does not interoperate with `theauth-go` (receipts do, the chains do not).

Migrations and `skipMigrations` startup now throw `AUDIT_SECRETS_LAYOUT_MISMATCH` when `theauth_audit_secrets` already exists with a layout this library did not create, for example because `theauth-go` created it in the same database. The table is not touched. Databases that use only TheAuth are unaffected; if you hit the error, give each library its own database or schema.

`chainPayload` is exported from the audit chain module so offline verifiers can build the exact hashed string.
11 changes: 11 additions & 0 deletions .changeset/audit-verify-hardening.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@glinr/theauth": patch
---

Audit chain verification no longer trusts records anyone with database write access could write.

- `audit.erasure` records are now appended to the agent's hash chain, and every entry carries an HMAC (audit key) over the erased row's id, seq, hash, previous hash, hash version and erasure reason. For an anonymized version 1 row the entry also pins the hash of the row as erasure left it, so editing it later is still tamper. `verifyAuditChain` recomputes the MACs and reports `erasure_unchained` or `erasure_forged` instead of excusing the gap or edit. Unsigned erasure records from earlier unreleased 2.0 builds are not accepted and there is no compatibility path for them.
- A chained row whose `hash_version` was rewritten to NULL or 1 is reported as `version_downgrade`.
- Deleting the oldest rows of a chain is reported as `truncated_prefix`. A chain may start at seq 1, after a retention checkpoint (now HMAC signed), or at an anchor written by the new `theauth.audit.checkpoint()`, which also returns anchors and heads to pin outside the database. `verifyAuditChain` accepts them as `anchors` (`anchor_mismatch` when a pinned row changed) next to `expectedHeads`. `allowUnanchoredPrefix: true` restores the old lenient start check.
- `theauth.audit.verifyAuditChain` is now on the public `audit` facade, as the docs already showed.
- Tool arguments can no longer plant system fields in audit `parameters`: `approvalId` and every key starting with `theauth` are stripped from caller arguments before they are written.
Loading
Loading