Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge remote-tracking branch 'origin/capy/gbra218-a1-identity' into capy/gbra218-member-reads

garrytanf2a77d150d00
diff --cc src/core/access/caller.ts
index 2f02ee17f1,94ed606c62..045bb2c70c
--- a/src/core/access/caller.ts
+++ b/src/core/access/caller.ts
@@@ -10,30 -14,44 +14,48 @@@
import type { BrainEngine } from '../engine.ts';
import type { AuthInfo } from '../ops/contract.ts';
import { accessRestrictionsPresent, remotePrivacyRelaxed, type CallerAccess } from '../search/private-visibility.ts';
- import { identityFor, normalizePrincipal } from './principals.ts';
+ import { ACCESS_ID_RE, identityFor, normalizePrincipal } from './principals.ts';
- const MEMBER_SQL = (credential: string) => `SELECT m.id, COALESCE(array_agg(g.group_id ORDER BY g.group_id) FILTER (WHERE g.group_id IS NOT NULL), '{}') AS groups
+ /** Config key binding a local stdio MCP server to one member. */
+ export const STDIO_MEMBER_KEY = 'mcp.stdio_member';
+
+ const MEMBER_SQL = (member: string) => `SELECT m.id, COALESCE(array_agg(g.group_id ORDER BY g.group_id) FILTER (WHERE g.group_id IS NOT NULL), '{}') AS groups
FROM access_members m LEFT JOIN access_group_members g ON g.member_id = m.id
- WHERE m.id = (${credential}) AND m.disabled_at IS NULL AND m.tombstoned_at IS NULL
+ WHERE m.id = (${member}) AND m.disabled_at IS NULL AND m.tombstoned_at IS NULL
GROUP BY m.id`;
-async function liveIdentity(engine: BrainEngine, memberSql: string, param: string): Promise<string[]> {
++async function liveIdentity(engine: Pick<BrainEngine, 'executeRaw'>, memberSql: string, param: string): Promise<string[]> {
+ try {
+ const [row] = await engine.executeRaw<{ id: string; groups: string[] }>(MEMBER_SQL(memberSql), [param]);
+ if (!row || normalizePrincipal(`member:${row.id}`) !== `member:${row.id}`) return [];
+ const groups = (row.groups ?? []).filter(g => normalizePrincipal(`group:${g}`) === `group:${g}`);
+ return identityFor(row.id, groups);
+ } catch {
+ return [];
+ }
+ }
+
-/** The member identity bound to `auth`: the verifier's join when present, else a lookup from its principal; empty when unbound, unknown or unreadable. */
-export async function memberIdentityFor(engine: BrainEngine, auth: AuthInfo | undefined): Promise<string[]> {
+/**
- * The member identity bound to `auth`'s principal; empty when unbound, unknown or unreadable. A write's publication
- * passes its stored principal here, so a member disabled or a binding removed after submission takes effect.
++ * The member identity bound to `auth`: the verifier's join when present, else a lookup from its principal; empty
++ * when unbound, unknown or unreadable. A write's publication passes only its stored principal, so a member disabled
++ * or a binding removed after submission takes effect.
+ */
- export async function memberIdentityFor(engine: Pick<BrainEngine, 'executeRaw'>, auth: { principal?: { kind: string; id: string } } | undefined): Promise<string[]> {
++export async function memberIdentityFor(engine: Pick<BrainEngine, 'executeRaw'>, auth: Pick<AuthInfo, 'member'> & { principal?: { kind: string; id: string } } | undefined): Promise<string[]> {
+ if (auth?.member !== undefined) return auth.member ? identityFor(auth.member.id, auth.member.groups) : [];
const principal = auth?.principal;
- if (!principal) return [];
+ if (!principal || (principal.kind !== 'legacy_token' && principal.kind !== 'oauth_client')) return [];
- const credential = principal.kind === 'legacy_token'
+ return liveIdentity(engine, principal.kind === 'legacy_token'
? 'SELECT member_id FROM access_tokens WHERE id::text = $1'
- : 'SELECT member_id FROM oauth_clients WHERE client_id = $1';
+ : 'SELECT member_id FROM oauth_clients WHERE client_id = $1', principal.id);
+ }
+
+ /** The member a local stdio server is bound to (config mcp.stdio_member), or null when unset or ill-formed. */
+ export async function stdioMemberId(engine: BrainEngine): Promise<string | null> {
try {
- const [row] = await engine.executeRaw<{ id: string; groups: string[] }>(MEMBER_SQL(credential), [principal.id]);
- if (!row || normalizePrincipal(`member:${row.id}`) !== `member:${row.id}`) return [];
- const groups = (row.groups ?? []).filter(g => normalizePrincipal(`group:${g}`) === `group:${g}`);
- return identityFor(row.id, groups);
+ const raw = (await engine.getConfig(STDIO_MEMBER_KEY))?.trim();
+ return raw && ACCESS_ID_RE.test(raw) ? raw : null;
} catch {
- return [];
+ return null;
}
}
diff --cc test/postgres-unit-arms.txt
index 8f475c2065,a62497df99..1194f42d96
--- a/test/postgres-unit-arms.txt
+++ b/test/postgres-unit-arms.txt
@@@ -11,7 -11,9 +11,10 @@@
# file is a one-line edit: insert its path in sorted order. Shards balance
# other Postgres lane runs. The unit, serial and slow lanes unset
# themselves from scripts/postgres-arm-weights.json.
+ test/access-as.test.ts
+ test/access-binding.test.ts
+ test/access-members.test.ts
+test/access-writes.test.ts
test/activation-unbound-rooted-6449.test.ts
test/alias-source-cascade-5094.test.ts
test/attribution-backfill-history.test.ts