From 37135e8b37f4fed7a23d9b6b47a3df17f24e744a Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Thu, 12 Nov 2026 00:05:23 -0500 Subject: [PATCH 1/2] feat: register observed Grok Bot public OAuth client --- worker/wrangler.jsonc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/wrangler.jsonc b/worker/wrangler.jsonc index ad407ef..6c0f000 100644 --- a/worker/wrangler.jsonc +++ b/worker/wrangler.jsonc @@ -24,7 +24,7 @@ // Controlled staff authoring qualification; registrations are not client acceptance. "PEGMA_KNOWLEDGE_ENABLED": "true", "PEGMA_SUPPORT_LEARNING_REVIEWS_ENABLED": "false", - "PEGMA_AGENT_CLIENTS_JSON": "[{\"clientId\":\"pg-kb-codex-accept-v1\",\"name\":\"Pegma Codex CLI\",\"redirectUris\":[\"http://127.0.0.1/callback\"],\"allowedScopes\":[\"knowledge.article.draft.read\",\"knowledge.article.draft.write\",\"knowledge.article.evidence.submit\"],\"grantTypes\":[\"authorization_code\"]},{\"clientId\":\"pg-kb-claude-accept-v1\",\"name\":\"Pegma Claude Code\",\"redirectUris\":[\"http://localhost:48772/callback\"],\"allowedScopes\":[\"knowledge.article.draft.read\",\"knowledge.article.draft.write\",\"knowledge.article.evidence.submit\"],\"grantTypes\":[\"authorization_code\"]},{\"clientId\":\"pg-kb-device-accept-v1\",\"name\":\"Pegma RFC 8628 control\",\"redirectUris\":[],\"allowedScopes\":[\"knowledge.article.draft.read\",\"knowledge.article.draft.write\",\"knowledge.article.evidence.submit\"],\"grantTypes\":[\"device_code\"]}]", + "PEGMA_AGENT_CLIENTS_JSON": "[{\"clientId\":\"pg-kb-codex-accept-v1\",\"name\":\"Pegma Codex CLI\",\"redirectUris\":[\"http://127.0.0.1/callback\"],\"allowedScopes\":[\"knowledge.article.draft.read\",\"knowledge.article.draft.write\",\"knowledge.article.evidence.submit\"],\"grantTypes\":[\"authorization_code\"]},{\"clientId\":\"pg-kb-claude-accept-v1\",\"name\":\"Pegma Claude Code\",\"redirectUris\":[\"http://localhost:48772/callback\"],\"allowedScopes\":[\"knowledge.article.draft.read\",\"knowledge.article.draft.write\",\"knowledge.article.evidence.submit\"],\"grantTypes\":[\"authorization_code\"]},{\"clientId\":\"pg-kb-device-accept-v1\",\"name\":\"Pegma RFC 8628 control\",\"redirectUris\":[],\"allowedScopes\":[\"knowledge.article.draft.read\",\"knowledge.article.draft.write\",\"knowledge.article.evidence.submit\"],\"grantTypes\":[\"device_code\"]},{\"clientId\":\"pg-kb-grok-accept-v1\",\"name\":\"Pegma Grok Bot\",\"redirectUris\":[\"https://www.cursor.com/agents/mcp/oauth/callback\"],\"allowedScopes\":[\"knowledge.article.draft.read\",\"knowledge.article.draft.write\",\"knowledge.article.evidence.submit\"],\"grantTypes\":[\"authorization_code\"]}]", "PEGMA_KNOWLEDGE_BROWSER_LIMIT": "120", "PEGMA_AGENT_RESOURCE_LIMIT": "300", "IDENTITY_EMAIL_FROM": "Pegma ", From 177af321330b1811443d09c25ca0ef9c5e1e62f7 Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Thu, 12 Nov 2026 00:22:10 -0500 Subject: [PATCH 2/2] test: qualify Grok client registration and generated inventory --- docs/KNOWLEDGE_COMPOSITION.md | 10 ++++--- src/knowledge-authoring-config.test.ts | 37 +++++++++++++++++++++++++- worker/worker-configuration.d.ts | 4 +-- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/docs/KNOWLEDGE_COMPOSITION.md b/docs/KNOWLEDGE_COMPOSITION.md index fbcffa0..017a929 100644 --- a/docs/KNOWLEDGE_COMPOSITION.md +++ b/docs/KNOWLEDGE_COMPOSITION.md @@ -2,7 +2,7 @@ The KB host integration is merged in [PR #59](https://github.com/pegma-dev/pegma.dev/pull/59). The checked-in profile -enables controlled staff authoring qualification with three explicit public client +enables controlled staff authoring qualification with four explicit public client registrations for testing against closed collections. Merging to `main` starts the existing deployment workflow, which deploys the Worker before the Pages site. Confirm that run and the metadata readback below before client tests. @@ -111,7 +111,7 @@ collections. Broader rollout, customer AI and pilot qualification remain pending ## Configuration and activation [`worker/wrangler.jsonc`](../worker/wrangler.jsonc) sets -`PEGMA_KNOWLEDGE_ENABLED=true` and three explicit public client registrations +`PEGMA_KNOWLEDGE_ENABLED=true` and four explicit public client registrations for controlled staff qualification. The prior profile was disabled with an empty list. A push to `main` runs the [deployment workflow](../.github/workflows/deploy.yml) and applies these variables after its checks pass. @@ -140,6 +140,7 @@ them against the installed client. | `pg-kb-codex-accept-v1` | Codex CLI, authorization code with PKCE | `http://127.0.0.1/callback`; Agent Access `0.1.1` permits only the IP-loopback port substitution | | `pg-kb-claude-accept-v1` | Claude Code, authorization code with PKCE | `http://localhost:48772/callback`; configure the client to use that exact port | | `pg-kb-device-accept-v1` | Separate RFC 8628 host control | No redirect URI; device-code grant only | +| `pg-kb-grok-accept-v1` | Hosted Grok Bot, authorization code with PKCE | `https://www.cursor.com/agents/mcp/oauth/callback`; exact HTTPS callback | Port `48772` was available on both IPv4 and IPv6 loopback during the local 2026-11-11 availability check, which closed both listeners immediately. Recheck @@ -147,8 +148,9 @@ availability when starting the client. Record the actual callback, installed version and provider mode during each test. Require the registered hostname and path, with only the declared IP-loopback port substitution. The RFC 8628 host control has its own result, separate from native -CLI proof. Codex CLI and Claude Code acceptance remain pending. Hosted Grok Bot -and T3 Code registrations and acceptance remain pending. +CLI proof. Codex CLI, Claude Code and hosted Grok Bot acceptance remain pending. +The Grok registration uses the HTTPS callback observed from the hosted client. +T3 Code registration and acceptance remain pending. Each registration permits only `knowledge.article.draft.read`, `knowledge.article.draft.write` and `knowledge.article.evidence.submit`. diff --git a/src/knowledge-authoring-config.test.ts b/src/knowledge-authoring-config.test.ts index 052be6e..5057f8e 100644 --- a/src/knowledge-authoring-config.test.ts +++ b/src/knowledge-authoring-config.test.ts @@ -67,7 +67,7 @@ function authorizationRequest(clientId: string, redirectUri: string) { } describe('controlled authoring deployment registrations against released Agent Access', () => { - it('constructs the exact checked-in three-client profile and serves both discovery documents', async () => { + it('constructs the exact checked-in four-client profile and serves both discovery documents', async () => { const config = deploymentConfiguration(); expect(config.vars.PEGMA_KNOWLEDGE_ENABLED).toBe('true'); expect(config.vars.PEGMA_SUPPORT_LEARNING_REVIEWS_ENABLED).toBe('false'); @@ -94,6 +94,13 @@ describe('controlled authoring deployment registrations against released Agent A allowedScopes: [...AGENT_KNOWLEDGE_PERMISSIONS], grantTypes: ['device_code'], }, + { + clientId: 'pg-kb-grok-accept-v1', + name: 'Pegma Grok Bot', + redirectUris: ['https://www.cursor.com/agents/mcp/oauth/callback'], + allowedScopes: [...AGENT_KNOWLEDGE_PERMISSIONS], + grantTypes: ['authorization_code'], + }, ]); expect(AGENT_KNOWLEDGE_PERMISSIONS).toEqual([ 'knowledge.article.draft.read', @@ -126,6 +133,10 @@ describe('controlled authoring deployment registrations against released Agent A it.each([ ['pg-kb-codex-accept-v1', 'http://127.0.0.1:48773/callback'], ['pg-kb-claude-accept-v1', 'http://localhost:48772/callback'], + [ + 'pg-kb-grok-accept-v1', + 'https://www.cursor.com/agents/mcp/oauth/callback', + ], ])( 'hands the registered %s PKCE request to existing login without approving it', async (clientId, redirectUri) => { @@ -147,6 +158,8 @@ describe('controlled authoring deployment registrations against released Agent A ['pg-kb-codex-accept-v1', 'http://localhost:48773/callback'], ['pg-kb-codex-accept-v1', 'http://127.0.0.1:48773/other'], ['pg-kb-claude-accept-v1', 'http://localhost:48773/callback'], + ['pg-kb-grok-accept-v1', 'https://www.cursor.com/agents/mcp/oauth/other'], + ['pg-kb-grok-accept-v1', 'https://cursor.com/agents/mcp/oauth/callback'], ])( 'rejects unregistered callback %s %s before login', async (clientId, redirectUri) => { @@ -158,6 +171,28 @@ describe('controlled authoring deployment registrations against released Agent A }, ); + it.each([ + ['PKCE downgrade', 'code_challenge_method', 'plain'], + ['different resource', 'resource', 'https://pegma.dev/api/mcp'], + ['scope escalation', 'scope', AGENT_LINK_PERMISSION], + ])( + 'rejects hosted Grok %s before login', + async (_name, parameter, value) => { + const request = new URL( + authorizationRequest( + 'pg-kb-grok-accept-v1', + 'https://www.cursor.com/agents/mcp/oauth/callback', + ).url, + ); + request.searchParams.set(parameter, value); + const response = await configuredRuntime().protocol.handle( + new Request(request), + ); + expect(response?.status).toBe(400); + expect(response?.headers.get('Location')).toBeNull(); + }, + ); + it('starts only the registered device control through the actual protocol with no redirect URI', async () => { const runtime = configuredRuntime(); for (const [clientId, expectedStatus] of [ diff --git a/worker/worker-configuration.d.ts b/worker/worker-configuration.d.ts index 7eed01e..6e5ffb5 100644 --- a/worker/worker-configuration.d.ts +++ b/worker/worker-configuration.d.ts @@ -1,12 +1,12 @@ /* eslint-disable */ -// Generated by Wrangler by running `wrangler types --config=worker/wrangler.jsonc worker/worker-configuration.d.ts` (hash: 8fa6956b4f94dd9c45eaa17f2a294bf2) +// Generated by Wrangler by running `wrangler types --config=worker/wrangler.jsonc worker/worker-configuration.d.ts` (hash: bf86522a440f7f7d096a7a3a93ec0f3b) // Runtime types generated with workerd@1.20260831.1 2026-07-28 nodejs_compat interface __BaseEnv_Env { IDENTITY_DB: D1Database; SUPPORT_LEARNING_REVIEWS: Queue; PEGMA_KNOWLEDGE_ENABLED: "true"; PEGMA_SUPPORT_LEARNING_REVIEWS_ENABLED: "false"; - PEGMA_AGENT_CLIENTS_JSON: "[{\"clientId\":\"pg-kb-codex-accept-v1\",\"name\":\"Pegma Codex CLI\",\"redirectUris\":[\"http://127.0.0.1/callback\"],\"allowedScopes\":[\"knowledge.article.draft.read\",\"knowledge.article.draft.write\",\"knowledge.article.evidence.submit\"],\"grantTypes\":[\"authorization_code\"]},{\"clientId\":\"pg-kb-claude-accept-v1\",\"name\":\"Pegma Claude Code\",\"redirectUris\":[\"http://localhost:48772/callback\"],\"allowedScopes\":[\"knowledge.article.draft.read\",\"knowledge.article.draft.write\",\"knowledge.article.evidence.submit\"],\"grantTypes\":[\"authorization_code\"]},{\"clientId\":\"pg-kb-device-accept-v1\",\"name\":\"Pegma RFC 8628 control\",\"redirectUris\":[],\"allowedScopes\":[\"knowledge.article.draft.read\",\"knowledge.article.draft.write\",\"knowledge.article.evidence.submit\"],\"grantTypes\":[\"device_code\"]}]"; + PEGMA_AGENT_CLIENTS_JSON: "[{\"clientId\":\"pg-kb-codex-accept-v1\",\"name\":\"Pegma Codex CLI\",\"redirectUris\":[\"http://127.0.0.1/callback\"],\"allowedScopes\":[\"knowledge.article.draft.read\",\"knowledge.article.draft.write\",\"knowledge.article.evidence.submit\"],\"grantTypes\":[\"authorization_code\"]},{\"clientId\":\"pg-kb-claude-accept-v1\",\"name\":\"Pegma Claude Code\",\"redirectUris\":[\"http://localhost:48772/callback\"],\"allowedScopes\":[\"knowledge.article.draft.read\",\"knowledge.article.draft.write\",\"knowledge.article.evidence.submit\"],\"grantTypes\":[\"authorization_code\"]},{\"clientId\":\"pg-kb-device-accept-v1\",\"name\":\"Pegma RFC 8628 control\",\"redirectUris\":[],\"allowedScopes\":[\"knowledge.article.draft.read\",\"knowledge.article.draft.write\",\"knowledge.article.evidence.submit\"],\"grantTypes\":[\"device_code\"]},{\"clientId\":\"pg-kb-grok-accept-v1\",\"name\":\"Pegma Grok Bot\",\"redirectUris\":[\"https://www.cursor.com/agents/mcp/oauth/callback\"],\"allowedScopes\":[\"knowledge.article.draft.read\",\"knowledge.article.draft.write\",\"knowledge.article.evidence.submit\"],\"grantTypes\":[\"authorization_code\"]}]"; PEGMA_KNOWLEDGE_BROWSER_LIMIT: "120"; PEGMA_AGENT_RESOURCE_LIMIT: "300"; IDENTITY_EMAIL_FROM: "Pegma ";