Skip to content

refactor(nuxi): better admin-mcp (admin mode now), Global Config - #2367

Open
HugoRCD wants to merge 15 commits into
mainfrom
refactor/nuxi-admin-access
Open

refactor(nuxi): better admin-mcp (admin mode now), Global Config#2367
HugoRCD wants to merge 15 commits into
mainfrom
refactor/nuxi-admin-access

Conversation

@HugoRCD

@HugoRCD HugoRCD commented Aug 4, 2026

Copy link
Copy Markdown
Member

Replace the if/else chain that decides who can use Nuxi's admin-mcp tools with a single Context model (surface/person/channel) and a per-surface rule table, merging the previously duplicated surface classification in surface.ts and admin-mcp-access.ts into lib/context.ts. Discord's admin gate now checks the allowlist at decision time against a raw channel ID instead of a pre-baked boolean set at auth-build time.

Also move the extra admin GitHub logins list from NUXT_ADMIN_GITHUB_LOGINS (env var, requires a redeploy to change) to Vercel Global Config (adminGithubLogins key), editable from the dashboard.

HugoRCD added 2 commits August 4, 2026 17:13
…r admin logins

Replace the if/else chain deciding who can use Nuxi's admin-mcp tools with a
single Context model (surface/person/channel) and a per-surface rule table,
merging the previously duplicated surface classification in surface.ts and
admin-mcp-access.ts into one lib/context.ts. Discord's admin gate now checks
the allowlist at decision time against a raw channel id instead of a
pre-baked boolean set at auth-build time.

Also move the extra admin GitHub logins list from NUXT_ADMIN_GITHUB_LOGINS
(env var, requires a redeploy to change) to Vercel Global Config
(adminGithubLogins key), editable from the dashboard.
…st to Global Config

canAccessAdminMcp()/AdminMcpAuthContext become isAdminMode()/AuthContext
(admin-mcp-access.ts -> admin-mode.ts) to reflect the actual concept: a
session is either public or in admin mode with every tool and capability,
not just gated on the admin-mcp connection specifically.

DISCORD_ALLOWED_CHANNELS moves to Global Config (discordAllowedChannels key,
alongside adminGithubLogins) so the channel allowlist is editable from the
Vercel dashboard without a redeploy, same rationale as the admin logins list.
@vercel

vercel Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nuxt Ready Ready Preview Aug 7, 2026 10:40am

Request Review

@HugoRCD HugoRCD changed the title refactor(nuxi): better admin-mcp RBAC + Global Config refactor(nuxi): better admin-mcp (admin mode now), Global Config Aug 4, 2026
@socket-security

socket-security Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedmicrosandbox@​0.6.8741009997100
Added@​vercel/​global-config@​1.5.07510010088100
Addedzlib-sync@​0.1.10861008480100

View full report

@HugoRCD HugoRCD self-assigned this Aug 5, 2026
@HugoRCD
HugoRCD marked this pull request as ready for review August 5, 2026 12:03
@HugoRCD
HugoRCD requested a review from atinux as a code owner August 5, 2026 12:03
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@HugoRCD, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f9874d1f-aeb5-45e2-aaeb-8f12cce61864

📥 Commits

Reviewing files that changed from the base of the PR and between 8fbfdc6 and cccb744.

📒 Files selected for processing (9)
  • layers/nuxi/README.md
  • layers/nuxi/agent/lib/discord/access.ts
  • layers/nuxi/agent/lib/global-config.ts
  • layers/nuxi/agent/lib/identity/context.ts
  • layers/nuxi/agent/lib/slack/config.ts
  • layers/nuxi/agent/lib/workflow/config.ts
  • layers/nuxi/package.json
  • test/unit/context.spec.ts
  • test/unit/discord-access.spec.ts
📝 Walkthrough

Walkthrough

The change replaces environment-based administration and channel settings with Vercel Global Config. It adds cached configuration loaders and validation for admin, Discord, Slack, and workflow settings. It centralizes authentication context and admin-mode evaluation across surfaces. Discord gains auto-response channels, full-name attribution, retry handling, and digest mirroring. Slack gains asynchronous configuration and display-name resolution. Workflow routes and schedules now await Global Config values. Unit tests cover identity, admin mode, and Discord access.

Estimated code review effort: 4 (Complex) | ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 52.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title identifies the Nuxi admin-mode refactor and Global Config migration, which are the main changes.
Description check ✅ Passed The description accurately summarizes the Context refactor, Discord authorization change, and Global Config migration.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/nuxi-admin-access

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
test/unit/discord-access.spec.ts (1)

15-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test the autoRespond tier.

The tests do not configure autoRespond. Add a channel in that tier. Assert that isAllowedDiscordChannel returns true and isAdminDiscordChannel returns false.

Also applies to: 54-59

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/unit/discord-access.spec.ts` around lines 15 - 20, Add an autoRespond
channel to the mocked Discord channel configuration in the
isAllowedDiscordChannel tests, then assert that channel is accepted by
isAllowedDiscordChannel and isAdminDiscordChannel returns false for it. Apply
the same coverage to the related test block around the second referenced case.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@layers/nuxi/agent/lib/discord/access.ts`:
- Around line 23-30: Update the schemas in
layers/nuxi/agent/lib/discord/access.ts lines 23-30,
layers/nuxi/agent/lib/slack/config.ts lines 21-32, and
layers/nuxi/agent/lib/workflow/config.ts lines 17-20 to reject unknown keys at
every listed configuration level: discord, discord.channels, slack,
slack.channels, channel references, and workflow. Ensure the existing safeParse
validation path reports typoed fields instead of silently stripping them.

In `@layers/nuxi/README.md`:
- Around line 192-208: Update the Global Config reference’s discord example to
include channels.autoRespond, and expand the discord description to state that
this tier enables dispatch without a mention while remaining non-admin. Keep the
existing admin, public, and digestChannel documentation unchanged.

In `@server/utils/team.ts`:
- Around line 20-31: Update getExtraAdminLogins in team.ts to handle
getAll(['admin']) failures by catching the read error and returning an empty
array, so isAuthorizedAdmin can continue to the core-team authorization path.
Keep the existing normalization/filtering logic unchanged, and scope the fix to
the getExtraAdminLogins call site rather than altering isAuthorizedAdmin’s
core-admin checks.

---

Nitpick comments:
In `@test/unit/discord-access.spec.ts`:
- Around line 15-20: Add an autoRespond channel to the mocked Discord channel
configuration in the isAllowedDiscordChannel tests, then assert that channel is
accepted by isAllowedDiscordChannel and isAdminDiscordChannel returns false for
it. Apply the same coverage to the related test block around the second
referenced case.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2778a479-971a-4fa3-a9b9-799f63d41b6c

📥 Commits

Reviewing files that changed from the base of the PR and between 06cfba4 and b74ce6c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (39)
  • .env.example
  • layers/nuxi/README.md
  • layers/nuxi/agent/agent.ts
  • layers/nuxi/agent/channels/discord.ts
  • layers/nuxi/agent/channels/ops.ts
  • layers/nuxi/agent/channels/slack.ts
  • layers/nuxi/agent/connections/admin-mcp.ts
  • layers/nuxi/agent/connections/vercel-mcp.ts
  • layers/nuxi/agent/instructions.ts
  • layers/nuxi/agent/lib/admin-mcp-access.ts
  • layers/nuxi/agent/lib/discord-access.ts
  • layers/nuxi/agent/lib/discord/access.ts
  • layers/nuxi/agent/lib/discord/digest-mirror.ts
  • layers/nuxi/agent/lib/discord/format.ts
  • layers/nuxi/agent/lib/discord/retry.ts
  • layers/nuxi/agent/lib/gateway-attribution.ts
  • layers/nuxi/agent/lib/global-config.ts
  • layers/nuxi/agent/lib/identity/admin-mode.ts
  • layers/nuxi/agent/lib/identity/caller-instructions.ts
  • layers/nuxi/agent/lib/identity/context.ts
  • layers/nuxi/agent/lib/identity/surface-instructions.ts
  • layers/nuxi/agent/lib/slack/api.ts
  • layers/nuxi/agent/lib/slack/config.ts
  • layers/nuxi/agent/lib/slack/connect.ts
  • layers/nuxi/agent/lib/surface.ts
  • layers/nuxi/agent/lib/workflow/config.ts
  • layers/nuxi/agent/lib/workflow/shared.ts
  • layers/nuxi/agent/schedules/discord-gateway.ts
  • layers/nuxi/agent/schedules/firehose-summary.ts
  • layers/nuxi/agent/schedules/weekly-digest.ts
  • layers/nuxi/agent/tools/ai-gateway.ts
  • layers/nuxi/agent/tools/slack-channel-history.ts
  • nuxt.config.ts
  • package.json
  • server/utils/team.ts
  • test/unit/admin-mode.spec.ts
  • test/unit/context.spec.ts
  • test/unit/discord-access.spec.ts
  • test/unit/workflow-prompt.spec.ts
💤 Files with no reviewable changes (4)
  • nuxt.config.ts
  • layers/nuxi/agent/lib/surface.ts
  • layers/nuxi/agent/lib/admin-mcp-access.ts
  • layers/nuxi/agent/lib/discord-access.ts

Comment thread layers/nuxi/agent/lib/discord/access.ts Outdated
Comment thread layers/nuxi/README.md Outdated
Comment thread server/utils/team.ts
Comment thread server/utils/team.ts
…ssing the safe `readGlobalConfig` wrapper), so a Global Config outage throws out of `isAuthorizedAdmin` and breaks all GitHub logins.

This commit fixes the issue reported at server/utils/team.ts:21

## Bug

`server/utils/team.ts` reads the extra-admin list straight from the SDK:

```ts
async function getExtraAdminLogins(): Promise<string[]> {
  const config = await getAll<{ admin?: { githubLogins?: string[] } }>(['admin'])
  ...
}
```

The `@vercel/global-config` `getAll` call **rejects** on invalid tokens, deleted/unavailable stores, and network errors (documented explicitly in `layers/nuxi/agent/lib/global-config.ts`). Because `isAuthorizedAdmin` awaits `getExtraAdminLogins()` *before* it ever reaches the `isCoreTeamMember` fallback:

```ts
export async function isAuthorizedAdmin(login: string): Promise<boolean> {
  const normalized = login.toLowerCase()
  const extraLogins = await getExtraAdminLogins() // throws here on GC outage
  if (extraLogins.includes(normalized)) return true
  return isCoreTeamMember(normalized)
}
```

### Concrete failure path
`isAuthorizedAdmin` is awaited inside the GitHub OAuth `onSuccess` handler in `server/api/auth/github.get.ts`:

```ts
const role = (await isAuthorizedAdmin(ghUser.login)) ? 'admin' : 'user'
```

Trigger: Global Config store unavailable / token invalid / transient network error during an OAuth callback → `getAll` rejects → rejection propagates out of `getExtraAdminLogins` → out of `isAuthorizedAdmin` → out of `onSuccess` → caught by `onError`, which redirects **every** user to `/`. Login breaks entirely, including for core team members whose authorization does not depend on the extra-logins list at all. The previous implementation read from `useRuntimeConfig()` and never threw, so this is a regression.

The PR already introduced `readGlobalConfig` for exactly this purpose ("turns a Global Config outage into a logged warning + empty result instead of an unhandled throw"), and the layer README lists `admin` among the keys read through it — but `team.ts` bypassed it.

## Fix

Route the read through the existing safe wrapper instead of calling `getAll` directly:

```ts
import { readGlobalConfig } from '../../layers/nuxi/agent/lib/global-config'
...
const config = await readGlobalConfig<{ admin?: { githubLogins?: string[] } }>(['admin'])
```

`readGlobalConfig` catches read failures, logs a warning, and resolves to `{}`, so `getExtraAdminLogins` degrades to `[]` and `isAuthorizedAdmin` falls back to `isCoreTeamMember` — login keeps working during a GC outage (fail-closed for extra admins, exactly like the prior runtime-config behavior). As a bonus this also picks up the wrapper's 30s cache + in-flight dedupe and matches the design documented in `layers/nuxi/README.md`.

Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: HugoRCD <hugo.richard@vercel.com>
@HugoRCD

HugoRCD commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

@vercel fix the typecheck

Comment thread layers/nuxi/agent/lib/global-config.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
package.json (1)

54-54: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Declare @vercel/global-config in layers/nuxi/package.json.

layers/nuxi/agent/lib/global-config.ts imports @vercel/global-config, but the package is only listed in the root manifest. Add it to layers/nuxi/package.json so typecheck and deployment do not depend on root-level hoisting.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` at line 54, Declare `@vercel/global-config` in
layers/nuxi/package.json dependencies, matching the existing version constraint,
so the import in global-config.ts resolves without relying on root-level
hoisting.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@package.json`:
- Line 54: Declare `@vercel/global-config` in layers/nuxi/package.json
dependencies, matching the existing version constraint, so the import in
global-config.ts resolves without relying on root-level hoisting.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b9b72b54-2c7c-477b-a5f4-3832c3d42418

📥 Commits

Reviewing files that changed from the base of the PR and between 0aa742c and a4c3c48.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • README.md
  • layers/nuxi/agent/agent.ts
  • layers/nuxi/package.json
  • package.json
  • pnpm-workspace.yaml

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@layers/nuxi/agent/lib/identity/context.ts`:
- Around line 39-40: Update isLocalDevPrincipal so it returns true only when
both auth.authenticator and auth.principalType equal 'local-dev', preserving the
intended local-development principal contract before the Slack, Discord, and web
branches.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 506d86b1-659a-4df0-b295-6640385f33ba

📥 Commits

Reviewing files that changed from the base of the PR and between a4c3c48 and 8fbfdc6.

📒 Files selected for processing (7)
  • .env.example
  • README.md
  • layers/nuxi/agent/lib/identity/admin-mode.ts
  • layers/nuxi/agent/lib/identity/context.ts
  • layers/nuxi/agent/tools/ai-gateway.ts
  • test/unit/admin-mode.spec.ts
  • test/unit/context.spec.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • README.md
  • test/unit/context.spec.ts
  • layers/nuxi/agent/tools/ai-gateway.ts
  • test/unit/admin-mode.spec.ts
  • layers/nuxi/agent/lib/identity/admin-mode.ts
  • .env.example

Comment thread layers/nuxi/agent/lib/identity/context.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant