@nacre.work/api 0.31.1 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,81 @@
1
+ import { type Permission, type PrincipalType } from '@nacre.work/core';
2
+ import type { Pool } from 'pg';
3
+ import { type PrincipalsCache } from './adapters.js';
4
+ import { type AuthContext } from './auth.js';
5
+ /**
6
+ * What somebody else can reach, computed by the resolver — for an
7
+ * administrator asking "what does Petya see, and why".
8
+ *
9
+ * docs/mcp-admin.md lists it among the administrative reads, and it is the one
10
+ * that cannot be answered by reading the grant list. A grant list says what
11
+ * was *issued*; what a principal reaches is what the resolver makes of those
12
+ * grants, their groups' grants, the denies beneath them and their role — and
13
+ * an administrator adding that up by hand from a list is exactly how the wrong
14
+ * conclusion gets drawn about who can read a contract.
15
+ *
16
+ * So it asks the **active resolver**, the same one search asks, with the same
17
+ * input `contextFor` builds for a request — the subject's own effective
18
+ * principals, their grants, the scope tree. A module that replaces the
19
+ * resolver replaces this answer with it, which is the property: the access
20
+ * view and the search path cannot disagree about who sees what.
21
+ *
22
+ * No ceiling, deliberately. The subject is a principal and not a token, and
23
+ * what a connection of theirs may do is the connection's own ceiling on top of
24
+ * this, which the Connections listing already says.
25
+ */
26
+ export interface AccessSubject {
27
+ readonly type: PrincipalType;
28
+ readonly id: string;
29
+ }
30
+ /** One permission's reach, as the resolver plans it. */
31
+ export interface Reach {
32
+ /** Every layer in the organization, by role or by grants. */
33
+ readonly all: boolean;
34
+ /** Layers reachable in full, by id — at most `MAX_REACH_LAYERS` of them. */
35
+ readonly layers: readonly string[];
36
+ /** How many more layers the plan reaches than `layers` lists. */
37
+ readonly moreLayers: number;
38
+ /** Documents reached outside those layers, by a document-scoped grant. */
39
+ readonly extraDocuments: number;
40
+ /** Documents a deny excludes inside a reached layer. */
41
+ readonly deniedDocuments: number;
42
+ }
43
+ export interface EffectiveAccess {
44
+ readonly subject: AccessSubject;
45
+ /** The role, for a user; `member` for anything else. */
46
+ readonly role: AuthContext['role'];
47
+ /** The groups the subject belongs to, directly or through other groups. */
48
+ readonly groups: readonly string[];
49
+ readonly read: Reach;
50
+ readonly write: Reach;
51
+ readonly admin: Reach;
52
+ /**
53
+ * The grants that decide it: every grant naming the subject or one of their
54
+ * groups. A grant naming somebody else cannot change this answer, so it is
55
+ * not here.
56
+ */
57
+ readonly grants: readonly {
58
+ readonly principal: string;
59
+ readonly scopeType: string;
60
+ readonly scopeId: string;
61
+ readonly permission: Permission;
62
+ readonly effect: 'allow' | 'deny';
63
+ }[];
64
+ }
65
+ /** Bounded, because a scoped plan on an installation sized in layers is unbounded. */
66
+ export declare const MAX_REACH_LAYERS = 200;
67
+ export declare class PostgresAccess {
68
+ private readonly pool;
69
+ private readonly role?;
70
+ private readonly principalsCache?;
71
+ constructor(pool: Pool, role?: string | undefined, principalsCache?: PrincipalsCache | undefined);
72
+ /**
73
+ * `undefined` when the caller does not administer the organization, or the
74
+ * subject is not a live principal in it — one answer, invariant 4. A
75
+ * disabled user is still answered: an administrator asking what somebody
76
+ * who has left could reach is asking the question this exists for, and
77
+ * their grants still stand until somebody removes them.
78
+ */
79
+ effective(auth: AuthContext, subject: AccessSubject): Promise<EffectiveAccess | undefined>;
80
+ }
81
+ //# sourceMappingURL=access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAC/F,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAE9B,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,WAAW,CAAA;AAEzD;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,aAAa,C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AQ,CAAC,eAAe,CAAC;gBAFhB,IAAI,EAAE,IAAI,EACV,IAAI,CAAC,EAAE,MAAM,YAAA,EACb,eAAe,CAAC,EAAE,eAAe,YAAA;IAGpD;;;;;;OAMG;IACG,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;CAqDjG"}
package/dist/access.js ADDED
@@ -0,0 +1,92 @@
1
+ import { activeResolver, withOrg } from '@nacre.work/core';
2
+ import { contextFor } from './adapters.js';
3
+ import { administers } from './auth.js';
4
+ /** Bounded, because a scoped plan on an installation sized in layers is unbounded. */
5
+ export const MAX_REACH_LAYERS = 200;
6
+ const PERMISSIONS = ['read', 'write', 'admin'];
7
+ export class PostgresAccess {
8
+ pool;
9
+ role;
10
+ principalsCache;
11
+ constructor(pool, role, principalsCache) {
12
+ this.pool = pool;
13
+ this.role = role;
14
+ this.principalsCache = principalsCache;
15
+ }
16
+ /**
17
+ * `undefined` when the caller does not administer the organization, or the
18
+ * subject is not a live principal in it — one answer, invariant 4. A
19
+ * disabled user is still answered: an administrator asking what somebody
20
+ * who has left could reach is asking the question this exists for, and
21
+ * their grants still stand until somebody removes them.
22
+ */
23
+ async effective(auth, subject) {
24
+ if (!administers(auth))
25
+ return undefined;
26
+ return withOrg(this.pool, auth.orgId, async (client) => {
27
+ const role = await subjectRole(client, auth.orgId, subject);
28
+ if (role === undefined)
29
+ return undefined;
30
+ const asSubject = { orgId: auth.orgId, principal: subject, role };
31
+ const context = await contextFor(client, asSubject, this.principalsCache);
32
+ const resolver = activeResolver();
33
+ const reach = (permission) => {
34
+ const plan = resolver.resolve(context, permission);
35
+ if (plan.kind === 'all')
36
+ return { all: true, layers: [], moreLayers: 0, extraDocuments: 0, deniedDocuments: 0 };
37
+ if (plan.kind === 'none')
38
+ return { all: false, layers: [], moreLayers: 0, extraDocuments: 0, deniedDocuments: 0 };
39
+ const sorted = [...plan.layers].sort();
40
+ return {
41
+ all: false,
42
+ layers: sorted.slice(0, MAX_REACH_LAYERS),
43
+ moreLayers: Math.max(0, sorted.length - MAX_REACH_LAYERS),
44
+ extraDocuments: plan.extraDocs.length,
45
+ deniedDocuments: plan.deniedDocs.length,
46
+ };
47
+ };
48
+ const self = `${subject.type}:${subject.id}`;
49
+ return {
50
+ subject,
51
+ role,
52
+ groups: [...context.principals]
53
+ .filter((ref) => ref !== self && ref.startsWith('group:'))
54
+ .map((ref) => ref.slice('group:'.length))
55
+ .sort(),
56
+ read: reach(PERMISSIONS[0]),
57
+ write: reach(PERMISSIONS[1]),
58
+ admin: reach(PERMISSIONS[2]),
59
+ grants: context.grants
60
+ .filter((g) => g.orgId === auth.orgId && context.principals.has(`${g.principal.type}:${g.principal.id}`))
61
+ .map((g) => ({
62
+ principal: `${g.principal.type}:${g.principal.id}`,
63
+ scopeType: g.scope.type,
64
+ scopeId: g.scope.id,
65
+ permission: g.permission,
66
+ effect: g.effect,
67
+ })),
68
+ };
69
+ }, this.role === undefined ? {} : { role: this.role });
70
+ }
71
+ }
72
+ /**
73
+ * The subject's role, or `undefined` when it is not a principal of this
74
+ * organization. Every statement names the organization in its own literal, on
75
+ * top of the row-level policy, because a deployment connecting as a superuser
76
+ * has no policy to fall back on.
77
+ */
78
+ async function subjectRole(client, orgId, subject) {
79
+ if (!/^[0-9a-f-]{36}$/i.test(subject.id))
80
+ return undefined;
81
+ if (subject.type === 'user') {
82
+ const { rows } = await client.query(`SELECT role FROM users WHERE org_id = $1 AND id = $2`, [orgId, subject.id]);
83
+ return rows[0]?.role;
84
+ }
85
+ if (subject.type === 'group') {
86
+ const { rows } = await client.query(`SELECT 1 FROM groups WHERE org_id = $1 AND id = $2`, [orgId, subject.id]);
87
+ return rows.length === 0 ? undefined : 'member';
88
+ }
89
+ const { rows } = await client.query(`SELECT 1 FROM service_accounts WHERE org_id = $1 AND id = $2 AND revoked_at IS NULL`, [orgId, subject.id]);
90
+ return rows.length === 0 ? undefined : 'member';
91
+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,SAAS,CAAA;IAC1D,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC5B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,CACjC,sDAAsD,EACtD,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,CACpB,CAAA;QACD,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAA;IACtB,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC7B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,oDAAoD,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;QAC9G,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAA;IACjD,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,CACjC,qFAAqF,EACrF,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,CACpB,CAAA;IACD,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAA;AACjD,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { type AddressResolver, buildFilter, VectorStore, type CacheStore, type Metadata } from '@nacre.work/core';
2
2
  import type { Pool } from 'pg';
3
3
  import { type Reranker } from './rerank.js';
4
- import type { Reindex, ReindexOutcome, RetryOutcome, EmbeddingProviderRemoval, ReindexStatus, ReferenceQueries, ReferenceQuery, AuditEvent, AuditQuery, AuditReader, AuditRecord, AuditWriter, Documents, GrantInput, GrantRecord, Grants, Ingest, IngestOutcome, IngestRefused, IngestRequest, Job, Jobs, Layer, LayerOutcome, DocumentView, Layers, Page, PageResult, EmbeddingProvider as EmbeddingProviderView, EmbeddingProviderOutcome, EmbeddingProviders, Workspace, WorkspaceOutcome, Workspaces, SearchHit, SearchOptions, SearchService } from './server.js';
4
+ import type { Reindex, ReindexOutcome, RetryOutcome, EmbeddingProviderRemoval, ReindexStatus, ReferenceQueries, ReferenceQuery, AuditEvent, AuditQuery, AuditReader, AuditRecord, AuditWriter, Documents, GrantInput, GrantRecord, GrantFilter, Grants, Ingest, IngestOutcome, IngestRefused, IngestRequest, Job, Jobs, Layer, LayerOutcome, DocumentView, Layers, Page, PageResult, EmbeddingProvider as EmbeddingProviderView, EmbeddingProviderOutcome, EmbeddingProviders, Workspace, WorkspaceOutcome, Workspaces, SearchHit, SearchOptions, SearchService } from './server.js';
5
5
  import { type AuthContext } from './auth.js';
6
6
  /**
7
7
  * The adapters that put the permission model on the request path.
@@ -622,7 +622,7 @@ export declare class PostgresGrants implements Grants {
622
622
  * removed after it, which is a page of grants silently missing from an
623
623
  * administrator's view of who can reach what.
624
624
  */
625
- list(auth: AuthContext, page?: Page): Promise<PageResult<GrantRecord>>;
625
+ list(auth: AuthContext, page?: Page, filter?: GrantFilter): Promise<PageResult<GrantRecord>>;
626
626
  issue(auth: AuthContext, input: GrantInput): Promise<GrantRecord | undefined>;
627
627
  /**
628
628
  * Withdraw a grant.
@@ -662,6 +662,18 @@ export declare class PostgresGrants implements Grants {
662
662
  * produce a first page that works and a second page that silently returns the
663
663
  * beginning of the log.
664
664
  */
665
+ /** What `summarize` groups by. Each is a fixed expression; nothing a caller sends reaches the SQL. */
666
+ export type AuditGrouping = 'actor' | 'action' | 'result' | 'surface' | 'connection' | 'layer' | 'document' | 'day' | 'hour';
667
+ export declare const AUDIT_GROUPINGS: readonly AuditGrouping[];
668
+ export interface AuditBucket {
669
+ /** The value grouped on; `null` where events carry none, such as a document for a sign-in. */
670
+ readonly key: string | null;
671
+ readonly events: number;
672
+ readonly denied: number;
673
+ readonly errors: number;
674
+ readonly first: string;
675
+ readonly last: string;
676
+ }
665
677
  export declare class PostgresAuditReader implements AuditReader {
666
678
  private readonly pool;
667
679
  private readonly role?;
@@ -694,6 +706,27 @@ export declare class PostgresAuditReader implements AuditReader {
694
706
  * against every writer, which is what keeps this derivation honest.
695
707
  */
696
708
  private static readonly DOCUMENT_ACCESS;
709
+ /**
710
+ * The predicates every read of the log shares beyond time, actor, action and
711
+ * result — and the platform administrator's restriction, which is here so
712
+ * that `summarize` cannot be written without it. A count of document reads
713
+ * is a record of document access as much as the rows are.
714
+ */
715
+ private static narrowing;
716
+ /**
717
+ * Counts, computed in the database. docs/mcp-admin.md's `summarize_audit`:
718
+ * an agent asked "who read `contracts` most this month" must not page
719
+ * through a million rows to count them, and a person asking the console the
720
+ * same thing should not have to export a CSV.
721
+ *
722
+ * The window is **required** and bounded. A count over a whole retention
723
+ * window on every call is the expensive thing `read` was written never to
724
+ * do, and an unbounded `GROUP BY` is that with extra steps.
725
+ */
726
+ summarize(auth: AuthContext, query: AuditQuery & {
727
+ readonly from: string;
728
+ readonly to: string;
729
+ }, by: AuditGrouping, limit: number): Promise<readonly AuditBucket[]>;
697
730
  read(auth: AuthContext, query: AuditQuery, page: Page): Promise<PageResult<AuditRecord>>;
698
731
  private scopeFor;
699
732
  }
@@ -1 +1 @@
1
- {"version":3,"file":"adapters.d.ts","sourceRoot":"","sources":["../src/adapters.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,WAAW,EAiBX,WAAW,EASX,KAAK,UAAU,EAEf,KAAK,QAAQ,EAQd,MAAM,kBAAkB,CAAA;AAGzB,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,IAAI,CAAA;AAG1C,OAAO,EAAgB,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEzD,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,YAAY,EACZ,wBAAwB,EACxB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,UAAU,EACV,WAAW,EACX,WAAW,EACX,WAAW,EACX,SAAS,EACT,UAAU,EACV,WAAW,EACX,MAAM,EACN,MAAM,EAC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AA0E;IACzD,eAAe,CAAC,EAAE,eAAe,YAAA;IAGpD,OAAO,KAAK,KAAK,GAEhB;IAEK,KAAK,CACT,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;IAkJhC,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAsCpF;;;;;;;OAOG;YACW,SAAS;IAevB,OAAO,CAAC,QAAQ;CAgCjB;AAED;;;;;;;;GAQG;AACH,qBAAa,wBAAyB,YAAW,gBAAgB;IAE7D,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;IACtB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;gBAFhB,IAAI,EAAE,IAAI,EACV,IAAI,CAAC,EAAE,MAAM,YAAA,EACb,eAAe,CAAC,EAAE,eAAe,YAAA;IAGpD,OAAO,KAAK,KAAK,GAEhB;IAED;;;;;;OAMG;YACW,aAAa;IAgBrB,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,cAAc,EAAE,GAAG,SAAS,CAAC;IAkBxF,OAAO,CACX,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,SAAS;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,EAAE,GACjE,OAAO,CAAC,SAAS,cAAc,EAAE,GAAG,SAAS,CAAC;CA0ClD"}
package/dist/adapters.js CHANGED
@@ -1,4 +1,4 @@
1
- import { admitEmbeddingEndpoint, egressFetch, endpointOrigin, buildFilter, cachedEffectivePrincipals, documentKey, effectivePrincipals, encodeQuery, fromStateJson, isEmpty, loadGrants, loadGroupsVersion, loadScopeTree, PostgresGroupGraph, referenceAllows, reindexProgress, activeResolver, admitIngest, SPARSE_VECTOR_NAME, toStateJson, VectorStore, vectorName, withOrg, DEFAULT_EMBED_BATCH, embedInBatches, endpointReason, endpointUrl, modelEndpointRefused, classifyIngestFailure, withoutHosts, DOCUMENT_ACCESS_ACTIONS, } from '@nacre.work/core';
1
+ import { admitEmbeddingEndpoint, egressFetch, endpointOrigin, buildFilter, cachedEffectivePrincipals, documentKey, effectivePrincipals, encodeQuery, fromStateJson, isEmpty, loadGrants, loadGroupsVersion, loadScopeTree, PostgresGroupGraph, referenceAllows, reindexProgress, activeResolver, admitIngest, SPARSE_VECTOR_NAME, toStateJson, VectorStore, vectorName, withOrg, DEFAULT_EMBED_BATCH, embedInBatches, endpointReason, endpointUrl, modelEndpointRefused, classifyIngestFailure, withoutHosts, DOCUMENT_ACCESS_ACTIONS, auditClient, } from '@nacre.work/core';
2
2
  import { createHash } from 'node:crypto';
3
3
  import { encodeCursor, pageOf } from './pagination.js';
4
4
  import { applyRanking } from './rerank.js';
@@ -696,8 +696,8 @@ export class PostgresAudit {
696
696
  // and the schema were right from the first migration; only the write
697
697
  // was not.
698
698
  `INSERT INTO audit_events
699
- (org_id, actor_type, actor_id, actor_label, action, surface, target, result, detail, request_id)
700
- VALUES ($1,$2,$3,$4,$5,$6,$7::jsonb,$8,$9,$10)`, [
699
+ (org_id, actor_type, actor_id, actor_label, action, surface, target, result, detail, request_id, client)
700
+ VALUES ($1,$2,$3,$4,$5,$6,$7::jsonb,$8,$9,$10,$11)`, [
701
701
  event.orgId,
702
702
  actorType ?? 'unknown',
703
703
  /^[0-9a-f-]{36}$/i.test(actorId ?? '') ? actorId : null,
@@ -708,6 +708,10 @@ export class PostgresAudit {
708
708
  event.result,
709
709
  JSON.stringify(event.detail),
710
710
  event.requestId,
711
+ // From the event, or from the request's scope where a port was
712
+ // not wrapped by `withAuditSinks`. NULL for anything that did not
713
+ // come through a connection — a console session, a service key.
714
+ event.client ?? auditClient() ?? null,
711
715
  ]);
712
716
  }, this.role === undefined ? {} : { role: this.role });
713
717
  // Forwarding to a module's sinks is deliberately *not* here. It is
@@ -1950,18 +1954,31 @@ export class PostgresGrants {
1950
1954
  * removed after it, which is a page of grants silently missing from an
1951
1955
  * administrator's view of who can reach what.
1952
1956
  */
1953
- async list(auth, page) {
1957
+ async list(auth, page, filter) {
1954
1958
  return withOrg(this.pool, auth.orgId, async (client) => {
1955
1959
  const context = await contextFor(client, auth, this.principalsCache);
1956
1960
  const plan = activeResolver().resolve(context, 'admin');
1957
1961
  if (plan.kind === 'none')
1958
1962
  return { items: [], nextCursor: null };
1963
+ const params = [auth.orgId];
1964
+ const bind = (value) => {
1965
+ params.push(value);
1966
+ return `$${params.length}`;
1967
+ };
1959
1968
  const after = page?.after;
1960
- const seek = after === undefined ? '' : ' AND (created_at, id) > ($2::timestamptz, $3::uuid)';
1969
+ const seek = after === undefined
1970
+ ? ''
1971
+ : ` AND (created_at, id) > (${bind(after.createdAt)}::timestamptz, ${bind(after.id)}::uuid)`;
1972
+ const narrowed = [
1973
+ filter?.principalType === undefined ? '' : ` AND principal_type = ${bind(filter.principalType)}`,
1974
+ filter?.principalId === undefined ? '' : ` AND principal_id = ${bind(filter.principalId)}::uuid`,
1975
+ filter?.scopeType === undefined ? '' : ` AND scope_type = ${bind(filter.scopeType)}`,
1976
+ filter?.scopeId === undefined ? '' : ` AND scope_id = ${bind(filter.scopeId)}::uuid`,
1977
+ ].join('');
1961
1978
  const cap = page === undefined ? '' : ` LIMIT ${page.limit}`;
1962
1979
  const { rows } = await client.query(`SELECT id, principal_type, principal_id, scope_type, scope_id, permission, effect, source,
1963
1980
  created_at, created_at::text AS created_at_text
1964
- FROM grants WHERE org_id = $1${seek} ORDER BY created_at, id${cap}`, after === undefined ? [auth.orgId] : [auth.orgId, after.createdAt, after.id]);
1981
+ FROM grants WHERE org_id = $1${seek}${narrowed} ORDER BY created_at, id${cap}`, params);
1965
1982
  const visible = rows
1966
1983
  .filter((r) => referenceAllows(context, { type: r.scope_type, id: r.scope_id }, 'admin'))
1967
1984
  .map((r) => ({
@@ -2122,28 +2139,33 @@ export class PostgresGrants {
2122
2139
  }, this.scope);
2123
2140
  }
2124
2141
  }
2142
+ /** A JSON array in `target`, or an empty one: `jsonb_array_elements_text` raises on anything else. */
2143
+ const targetArray = (field) => `jsonb_array_elements_text(CASE WHEN jsonb_typeof(e.target->'${field}') = 'array' THEN e.target->'${field}' ELSE '[]'::jsonb END)`;
2125
2144
  /**
2126
- * Reading the access log back.
2127
- *
2128
- * Scoped through `withOrg` like every other tenant read, so the row-level
2129
- * policy on `audit_events` is the second line of defence behind the role check
2130
- * in the handler. `SELECT` is the only grant the application role has on this
2131
- * table and that stays true — nothing here writes.
2132
- *
2133
- * ## Newest first, and what that does to the cursor
2145
+ * The keys one event contributes, as a set-returning subquery over `e`.
2134
2146
  *
2135
- * Every other paged collection here reads oldest-first, because a catalog is a
2136
- * set and the order is arbitrary. A log is not: the useful end is the recent
2137
- * one, and an auditor paging forward from the beginning of a 400-day retention
2138
- * window to find yesterday is not a feature. So this orders
2139
- * `(occurred_at, id) DESC` and the seek predicate is `<` rather than `>`.
2140
- *
2141
- * The cursor still means "everything after the last row you saw", which is the
2142
- * same contract read in the other direction. It is worth being explicit because
2143
- * copying the seek clause from the layers adapter — where it is `>` — would
2144
- * produce a first page that works and a second page that silently returns the
2145
- * beginning of the log.
2147
+ * A layer is reported by slug whichever shape recorded it: an id is looked up
2148
+ * in this organization's own layers, so two spellings of one layer are one
2149
+ * bucket rather than two half-counts.
2146
2150
  */
2151
+ const GROUPING_KEYS = {
2152
+ actor: 'SELECT e.actor_label',
2153
+ // A template rather than a quoted string: `lint:audit-actions` reads every
2154
+ // quoted `action:` under the writers as an action somebody records, and this
2155
+ // is a grouping, not a record.
2156
+ action: `SELECT e.action`,
2157
+ result: 'SELECT e.result',
2158
+ surface: 'SELECT e.surface',
2159
+ connection: 'SELECT e.client',
2160
+ layer: `SELECT l.slug FROM layers l WHERE l.org_id = e.org_id AND l.id::text = e.target->>'layer_id'
2161
+ UNION SELECT e.target->>'layer' WHERE e.target->>'layer' IS NOT NULL
2162
+ UNION SELECT ${targetArray('layers')}`,
2163
+ document: `SELECT e.target->>'document_id' WHERE e.target->>'document_id' IS NOT NULL
2164
+ UNION SELECT ${targetArray('returned_docs')}`,
2165
+ day: "SELECT to_char(date_trunc('day', e.occurred_at AT TIME ZONE 'UTC'), 'YYYY-MM-DD')",
2166
+ hour: "SELECT to_char(date_trunc('hour', e.occurred_at AT TIME ZONE 'UTC'), 'YYYY-MM-DD\"T\"HH24:00\"Z\"')",
2167
+ };
2168
+ export const AUDIT_GROUPINGS = Object.keys(GROUPING_KEYS);
2147
2169
  export class PostgresAuditReader {
2148
2170
  pool;
2149
2171
  role;
@@ -2179,6 +2201,90 @@ export class PostgresAuditReader {
2179
2201
  * against every writer, which is what keeps this derivation honest.
2180
2202
  */
2181
2203
  static DOCUMENT_ACCESS = DOCUMENT_ACCESS_ACTIONS;
2204
+ /**
2205
+ * The predicates every read of the log shares beyond time, actor, action and
2206
+ * result — and the platform administrator's restriction, which is here so
2207
+ * that `summarize` cannot be written without it. A count of document reads
2208
+ * is a record of document access as much as the rows are.
2209
+ */
2210
+ static narrowing(query, bind) {
2211
+ const where = [];
2212
+ // A layer and a document are each recorded in three shapes: an
2213
+ // administrative write names `layer_id`, an ingest the `layer` slug, and a
2214
+ // search the `layers` it reached and the `returned_docs` it answered with.
2215
+ // A filter on one shape would miss the reads, which are the rows an
2216
+ // investigation is usually after.
2217
+ if (query.layer !== undefined) {
2218
+ const slug = bind(query.layer.slug);
2219
+ where.push(`(target->>'layer_id' = ${bind(query.layer.id)} OR target->>'layer' = ${slug} OR target->'layers' ? ${slug})`);
2220
+ }
2221
+ if (query.documentId !== undefined) {
2222
+ const id = bind(query.documentId);
2223
+ where.push(`(target->>'document_id' = ${id} OR target->'returned_docs' ? ${id})`);
2224
+ }
2225
+ if (query.client !== undefined)
2226
+ where.push(`client = ${bind(query.client)}`);
2227
+ if (query.surface !== undefined)
2228
+ where.push(`surface = ${bind(query.surface)}`);
2229
+ if (query.administrativeOnly === true) {
2230
+ where.push(`action <> ALL(${bind(PostgresAuditReader.DOCUMENT_ACCESS)}::text[])`);
2231
+ }
2232
+ return where;
2233
+ }
2234
+ /**
2235
+ * Counts, computed in the database. docs/mcp-admin.md's `summarize_audit`:
2236
+ * an agent asked "who read `contracts` most this month" must not page
2237
+ * through a million rows to count them, and a person asking the console the
2238
+ * same thing should not have to export a CSV.
2239
+ *
2240
+ * The window is **required** and bounded. A count over a whole retention
2241
+ * window on every call is the expensive thing `read` was written never to
2242
+ * do, and an unbounded `GROUP BY` is that with extra steps.
2243
+ */
2244
+ async summarize(auth, query, by, limit) {
2245
+ return withOrg(this.pool, auth.orgId, async (client) => {
2246
+ const where = ['org_id = $1'];
2247
+ const params = [auth.orgId];
2248
+ const bind = (value) => {
2249
+ params.push(value);
2250
+ return `$${params.length}`;
2251
+ };
2252
+ where.push(`occurred_at >= ${bind(query.from)}::timestamptz`);
2253
+ where.push(`occurred_at < ${bind(query.to)}::timestamptz`);
2254
+ if (query.actorId !== undefined)
2255
+ where.push(`actor_id = ${bind(query.actorId)}::uuid`);
2256
+ if (query.action !== undefined)
2257
+ where.push(`action = ${bind(query.action)}`);
2258
+ if (query.result !== undefined)
2259
+ where.push(`result = ${bind(query.result)}`);
2260
+ where.push(...PostgresAuditReader.narrowing(query, bind));
2261
+ const keys = GROUPING_KEYS[by];
2262
+ const { rows } = await client.query(
2263
+ // One row per (event, key). For most groupings an event has exactly
2264
+ // one key; for a layer or a document a search has several, and an
2265
+ // event naming none drops out — "reads by document" is not about a
2266
+ // sign-in. UNION inside the lateral, so one event counts once per
2267
+ // key however many of its shapes name it.
2268
+ `SELECT k.key, count(*) AS events,
2269
+ count(*) FILTER (WHERE result = 'deny') AS denied,
2270
+ count(*) FILTER (WHERE result = 'error') AS errors,
2271
+ min(occurred_at)::text AS first, max(occurred_at)::text AS last
2272
+ FROM audit_events e
2273
+ CROSS JOIN LATERAL (${keys}) AS k(key)
2274
+ WHERE ${where.join(' AND ')}
2275
+ GROUP BY k.key
2276
+ ORDER BY 2 DESC, 1 NULLS LAST
2277
+ LIMIT ${Math.max(1, Math.min(limit, 200))}`, params);
2278
+ return rows.map((r) => ({
2279
+ key: r.key,
2280
+ events: Number(r.events),
2281
+ denied: Number(r.denied),
2282
+ errors: Number(r.errors),
2283
+ first: new Date(r.first).toISOString(),
2284
+ last: new Date(r.last).toISOString(),
2285
+ }));
2286
+ }, this.scopeFor());
2287
+ }
2182
2288
  async read(auth, query, page) {
2183
2289
  return withOrg(this.pool, auth.orgId, async (client) => {
2184
2290
  const where = ['org_id = $1'];
@@ -2197,9 +2303,7 @@ export class PostgresAuditReader {
2197
2303
  where.push(`action = ${bind(query.action)}`);
2198
2304
  if (query.result !== undefined)
2199
2305
  where.push(`result = ${bind(query.result)}`);
2200
- if (query.administrativeOnly === true) {
2201
- where.push(`action <> ALL(${bind(PostgresAuditReader.DOCUMENT_ACCESS)}::text[])`);
2202
- }
2306
+ where.push(...PostgresAuditReader.narrowing(query, bind));
2203
2307
  // Descending, and `<` to match. See the note on the class.
2204
2308
  if (page.after !== undefined) {
2205
2309
  where.push(`(occurred_at, id) < (${bind(page.after.createdAt)}::timestamptz, ${bind(page.after.id)}::bigint)`);