From 9074f5ac82af117e7899961736c02ce93e27e56f Mon Sep 17 00:00:00 2001
From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com>
Date: Sat, 7 Nov 2026 14:50:25 +0000
Subject: [PATCH] feat(admin): make a human member's email optional
Email is only used to link a member to a Supabase login (auth.users), so
neither the admin CLI nor setup.ts requires it any more. create-member takes
--email
(the older --human still works); with neither it
creates a human member with no email. setup.ts no longer falls back to
git config user.email: an email is stored only when given. --bot with an
email is refused.
Co-Authored-By: Claude Opus 5.5
---
README.md | 5 +++--
scripts/admin.ts | 20 ++++++++++----------
scripts/lib/admin-db.ts | 9 +++++----
scripts/setup.ts | 13 ++-----------
tests/integration/admin.test.ts | 6 +++++-
5 files changed, 25 insertions(+), 28 deletions(-)
diff --git a/README.md b/README.md
index 32a26e7..ffca3dd 100644
--- a/README.md
+++ b/README.md
@@ -30,7 +30,7 @@ deno run -A scripts/setup.ts --configure-claude
`.env` is reused.
Flags: `--env-file ` (default `.env`), `--scope ` (default `default`), `--member `,
-`--email ` (a human member needs one; defaults to `git config user.email`), `--bot` (a bot member instead of a
+`--email ` (optional; only links the member to a Supabase login), `--bot` (a bot member instead of a
human), `--new-token` (issue another token even if `.env` has a live one), `--skip-deploy`, `--configure-claude` and
`--name ` (default `shared-memory`).
@@ -89,7 +89,8 @@ password (for example `@` as `%40`, `/` as `%2F`, `#` as `%23`), or the URL will
export AGENT_MEMORY_DB_URL='postgresql://postgres.:@:5432/postgres'
deno run -A scripts/admin.ts create-scope my-team --description "Team memory"
-deno run -A scripts/admin.ts create-member alice --human alice@example.com
+deno run -A scripts/admin.ts create-member alice # email optional: --email alice@example.com
+ # links a Supabase login if one exists
deno run -A scripts/admin.ts create-member ci-bot --bot
deno run -A scripts/admin.ts grant alice my-team write
deno run -A scripts/admin.ts grant ci-bot my-team read
diff --git a/scripts/admin.ts b/scripts/admin.ts
index 756a903..aad32d7 100644
--- a/scripts/admin.ts
+++ b/scripts/admin.ts
@@ -22,7 +22,7 @@ import {
const USAGE = `Usage: deno run -A scripts/admin.ts ...
create-scope [--description ]
list-scopes
- create-member --human | --bot
+ create-member [--email ] | --bot (email optional; links a Supabase login)
grant read|write
revoke
list-grants
@@ -50,7 +50,7 @@ const DELETED_COLS: (keyof DeletedRow & string)[] = ['id', 'scope', 'deletedAt',
/** Returns the process exit code. */
async function main(): Promise {
const args = parseArgs(Deno.args, {
- string: ['description', 'human', 'expires', 'scope', 'by', 'since'],
+ string: ['description', 'human', 'email', 'expires', 'scope', 'by', 'since'],
boolean: ['bot', 'yes'],
});
const [cmd, ...p] = args._.map(String);
@@ -80,16 +80,16 @@ async function main(): Promise {
console.log(table(await listScopes(sql), ['name', 'description']));
break;
case 'create-member': {
- need(1, 'create-member --human | --bot');
- if (!!args.human === args.bot) throw new Error('Specify exactly one of --human or --bot');
- const m = await createMember(
- sql,
- p[0],
- args.bot ? { kind: 'bot' } : { kind: 'human', email: args.human },
- );
+ need(1, 'create-member [--email ] | --bot');
+ // --human is the older spelling of --email and still works.
+ const email = args.email || args.human || undefined;
+ if (args.bot && email) throw new Error('A bot member has no email: give --bot or --email, not both');
+ const m = await createMember(sql, p[0], args.bot ? { kind: 'bot' } : { kind: 'human', email });
console.log(
`Created ${m.kind} member '${m.name}'` +
- (m.kind === 'human' ? (m.authUserId ? ' (linked to auth user)' : ' (no matching auth user)') : ''),
+ (m.kind === 'human'
+ ? (m.authUserId ? ' (linked to auth user)' : email ? ' (no matching auth user)' : ' (no email)')
+ : ''),
);
break;
}
diff --git a/scripts/lib/admin-db.ts b/scripts/lib/admin-db.ts
index 6808277..67a2698 100644
--- a/scripts/lib/admin-db.ts
+++ b/scripts/lib/admin-db.ts
@@ -70,18 +70,19 @@ export async function createMember(
name: string,
opts: { kind: 'human' | 'bot'; email?: string },
): Promise {
- if (opts.kind === 'human' && !opts.email) throw new Error('A human member requires an email (--human )');
+ // Email is optional: it is only used to link the member to a Supabase login (auth.users).
+ const email = opts.email?.trim() || null;
const [dup] = await sql`select 1 from agent_memory.members where display_name = ${name}`;
if (dup) throw new Error(`Member '${name}' already exists`);
let authUserId: string | null = null;
- if (opts.email) {
+ if (email) {
// Read-only lookup; nothing is ever written to auth.
- const [u] = await sql`select id from auth.users where lower(email) = lower(${opts.email})`;
+ const [u] = await sql`select id from auth.users where lower(email) = lower(${email})`;
authUserId = u?.id ?? null;
}
const [r] = await sql`
insert into agent_memory.members (display_name, kind, email, auth_user_id)
- values (${name}, ${opts.kind}, ${opts.email ?? null}, ${authUserId})
+ values (${name}, ${opts.kind}, ${email}, ${authUserId})
returning id, display_name as name, kind, auth_user_id as "authUserId"`;
return r as Member;
}
diff --git a/scripts/setup.ts b/scripts/setup.ts
index c392bb6..d15e48b 100644
--- a/scripts/setup.ts
+++ b/scripts/setup.ts
@@ -138,17 +138,8 @@ export async function setup(o: SetupOptions): Promise {
log(`[5/7] Scope '${scope}' ${step}`);
const [existing] = await sql`select id from agent_memory.members where display_name = ${member}`;
if (!existing) {
- let email = o.email;
- if (kind === 'human' && !email) {
- const g = await run('git', ['config', 'user.email']).catch(() => ({ code: 1, stdout: '', stderr: '' }));
- email = g.code === 0 ? g.stdout.trim() || undefined : undefined;
- }
- if (kind === 'human' && !email) {
- throw new Error(
- `A human member needs an email: pass --email , or --bot. Nothing was created for '${member}'.`,
- );
- }
- await createMember(sql, member, { kind, email });
+ // Email is optional and only links a Supabase login, so it is stored only when given.
+ await createMember(sql, member, { kind, email: kind === 'human' ? o.email : undefined });
}
await grant(sql, member, scope, 'write');
log(`[6/7] Member '${member}' (${existing ? 'existing' : kind}) can write to '${scope}'`);
diff --git a/tests/integration/admin.test.ts b/tests/integration/admin.test.ts
index 8e9bbe6..9e6de8b 100644
--- a/tests/integration/admin.test.ts
+++ b/tests/integration/admin.test.ts
@@ -121,7 +121,11 @@ Deno.test('create-member --human links auth.users by email, case-insensitively',
assertEquals(linked.authUserId, uid);
const unlinked = await createMember(sql, `h2-${s}`, { kind: 'human', email: `none-${s}@example.test` });
assertEquals(unlinked.authUserId, null);
- await assertRejects(() => createMember(sql, `h3-${s}`, { kind: 'human' }), Error, 'requires an email');
+ const noEmail = await createMember(sql, `h3-${s}`, { kind: 'human' });
+ assertEquals(noEmail.kind, 'human');
+ assertEquals(noEmail.authUserId, null);
+ const [row] = await sql`select email from agent_memory.members where id = ${noEmail.id}`;
+ assertEquals(row.email, null);
} finally {
await sql`delete from auth.users where id = ${uid}`;
}