Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/KNOWLEDGE_COMPOSITION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -140,15 +140,17 @@ 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
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`.
Expand Down
37 changes: 36 additions & 1 deletion src/knowledge-authoring-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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',
Expand Down Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand All @@ -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 [
Expand Down
4 changes: 2 additions & 2 deletions worker/worker-configuration.d.ts
Original file line number Diff line number Diff line change
@@ -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 <identity@pegma.dev>";
Expand Down
2 changes: 1 addition & 1 deletion worker/wrangler.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <identity@pegma.dev>",
Expand Down
Loading