Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Narrow CMS adapter injection to supported editor routes
Emre Sokullu1b0533dcb332
diff --git a/docs/cms-api-first.md b/docs/cms-api-first.mdindex 880d4add4..958a76d10 100644--- a/docs/cms-api-first.md+++ b/docs/cms-api-first.md@@ -18,21 +18,23 @@ Mid/Full receive names, short summaries and semantic intents in the catalog;service instructions are absent until activation. Compact's skill system isunchanged. `cms-adapters.js` supplies short conditional notes through the existingadapter injection path and makes no skill-tool call. Matching supports standard-self-hosted paths and hosted admin domains, with a last-choice generic-admin/Studio candidate that requires observed CMS evidence. Arbitrarily relocated-editors are not automatically detected by this URL-only matcher: the model can-identify them from subsequent UI/API evidence, use the narrow shared CMS rule,-and in Mid/Full select the appropriate catalog entry. Mere branding in public-content does not authorize an admin workflow.+CMS-specific self-hosted paths and hosted admin domains. Generic `/admin`,+`/administrator`, `/studio` and `/desk` paths do not inject CMS notes. Webflow's+shared root hosts match only `/dashboard` and `/design/<site>` routes; hosted+`*.design.webflow.com` editors also match, while marketing/template pages do not.+Arbitrarily relocated editors are not automatically detected by this URL-only+matcher: the model can identify them from subsequent UI/API evidence, use the+narrow shared CMS rule, and in Mid/Full select the appropriate catalog entry.+Mere branding in public content does not authorize an admin workflow.Loading is semantic selection by the planner/model, not a hard runtime check thatthe CMS is installed and a content task exists. A CMS URL alone does not activateits full recipe; URL-matched adapter notes can appear before a content task isselected. The normal new-run reset clears active skills. The always-visiblecatalog contains summaries, not nine recipes. Budget tests cap the nine-entry-loader description at 2,000 characters, one loaded recipe at 12,000, a specific-CMS adapter at 1,300 and an unconfirmed editor candidate at 450. Character budgets-are not token counts or a guarantee about model behavior.+loader description at 2,000 characters, one loaded recipe at 12,000, and a specific+CMS adapter at 1,300. Character budgets are not token counts or a guarantee about+model behavior.All nine Markdown files and the CMS adapter module are byte-identical acrossChrome/Firefox. Browser-specific agent/tool code keeps its existing differences;diff --git a/docs/site-adapters.md b/docs/site-adapters.mdindex 517ea3f11..dd02d7a93 100644--- a/docs/site-adapters.md+++ b/docs/site-adapters.md@@ -31,9 +31,10 @@ Only ONE adapter fires at a time, so prompt cost is fixed regardless of total adThe nine CMS content adapters live in mirrored `agent/cms-adapters.js` modules,appended after existing site-specific matches. Their short notes reach Compactwithout a skill tool; detailed Mid/Full recipes load from the packaged catalog on-demand. Standard self-hosted admin paths and a conditional custom-editor candidate-support custom domains, but URL matching alone never proves CMS identity or API-access. See [CMS content APIs](cms-api-first.md) for auth and routing limits.+demand. CMS-specific self-hosted paths support custom domains; generic admin/Studio+paths do not inject CMS notes. Webflow matches dashboard/Designer routes instead+of its marketing pages. URL matching alone never proves CMS identity or API access.+See [CMS content APIs](cms-api-first.md) for auth and routing limits.For federated platforms such as Mastodon, keep generic URL shapes conservative.Bare `/@user` and `/users/user` paths appear on many non-Mastodon sites, and thediff --git a/docs/skills.md b/docs/skills.mdindex ac09ef378..65ce9bdb4 100644--- a/docs/skills.md+++ b/docs/skills.md@@ -169,10 +169,11 @@ prerequisite. An otherwise usable API with permission off prompts once forread-only. GraphQL/query POSTs remain subject to the same method-based gate.Compact still has no skill loader or skill prompt. Short CMS adapter notes guide-its existing tools, including conservative candidates for custom-domain admin-and Studio routes. The shared prompt contains only the conditional CMS rule,-not nine endpoint recipes. A URL match is not evidence of API authentication or-authorization; confirm the observed editor/API identity before applying a recipe.+its existing tools on supported CMS routes. Generic admin/Studio paths add no+CMS adapter notes; custom editors require observed CMS evidence. The shared+prompt contains only the conditional CMS rule, not nine endpoint recipes.+A URL match is not evidence of API authentication or authorization; confirm the+observed editor/API identity before applying a recipe.Startup uses the existing default-removal tombstones: newly introduced defaultsare added when there is capacity, while a removed/disabled default stays removeddiff --git a/src/chrome/src/agent/cms-adapters.js b/src/chrome/src/agent/cms-adapters.jsindex b115b421e..c5b470ea9 100644--- a/src/chrome/src/agent/cms-adapters.js+++ b/src/chrome/src/agent/cms-adapters.js@@ -19,7 +19,10 @@ const definitions = ['Drupal: discover /jsonapi links, bundle UUIDs and negotiated language. Cookie writes need X-CSRF-Token from /session/token; JSON:API may be read-only. Preserve body format and taxonomy UUIDs; moderation may require a supported transition instead of status=true.'],['joomla', route(u => /\/administrator(?:\/index\.php)?\/?$/.test(u.pathname) && ['com_content', 'com_categories'].includes(u.searchParams.get('option'))),'Joomla: /api/index.php/v1/content/articles and content/categories need an existing X-Joomla-Token and ACL rights, not just the administrator cookie. Keep catid/language, full articletext and access; use state=0 for a new unpublished article. Workflow-controlled publishing may need the editor.'],- ['webflow', route(u => u.hostname === 'webflow.com' || u.hostname === 'www.webflow.com' || u.hostname.endsWith('.design.webflow.com')),+ // The shared root host also serves marketing pages, which need no CMS notes.+ ['webflow', route(u => u.hostname.endsWith('.design.webflow.com') ||+ (['webflow.com', 'www.webflow.com'].includes(u.hostname) &&+ /^\/(?:dashboard(?:\/|$)|design\/[^/]+(?:\/|$))/.test(u.pathname))),'Webflow: Data API https://api.webflow.com/v2 needs a site/OAuth token with cms:read/write. Read collection fields and CMS locale IDs; create staged isDraft=true, update the same item, then publish only that verified item. Preserve references and rich-text components; never publish the whole site.'],['shopify', route(u => (u.hostname === 'admin.shopify.com' && /^\/store\//.test(u.pathname)) || (u.hostname.endsWith('.myshopify.com') && /^\/admin(?:\/|$)/.test(u.pathname))),'Shopify: use the verified shop .myshopify.com Admin GraphQL endpoint with a supported dated version and X-Shopify-Access-Token. Storefront API/cookies are insufficient. Both query and mutation POSTs are gated. Articles/pages support isPublished=false; blogs have no draft flag. Check errors and userErrors.'],@@ -39,12 +42,3 @@ export const CMS_ADAPTERS = definitions.map(([name, matches, hint]) => ({matches,notes: `${CMS_NOTES}\n- ${hint}`,}));--// Custom installations can place their editor at a generic admin/studio route.-// Keep this last and conditional; /admin alone is not evidence of a CMS.-CMS_ADAPTERS.push({- name: 'cms-editor-candidate',- category: 'general',- matches: route(u => /\/(?:admin|administrator|studio|desk)(?:\/|$)/.test(u.pathname)),- notes: '- Editor candidate only. Apply CMS guidance ONLY after observing Ghost/Drupal/Joomla/Webflow/Shopify/Wix/Strapi/Contentful/Sanity and a matching content task; otherwise use ordinary UI rules. For a confirmed CMS, fetch_url needs verified fields/target/auth/rights and task/API permission. Ask stays read-only. Strict without safe auth means UI. Reconcile uncertain writes before fallback and preserve the record ID.',-});diff --git a/src/firefox/src/agent/cms-adapters.js b/src/firefox/src/agent/cms-adapters.jsindex b115b421e..c5b470ea9 100644--- a/src/firefox/src/agent/cms-adapters.js+++ b/src/firefox/src/agent/cms-adapters.js@@ -19,7 +19,10 @@ const definitions = ['Drupal: discover /jsonapi links, bundle UUIDs and negotiated language. Cookie writes need X-CSRF-Token from /session/token; JSON:API may be read-only. Preserve body format and taxonomy UUIDs; moderation may require a supported transition instead of status=true.'],['joomla', route(u => /\/administrator(?:\/index\.php)?\/?$/.test(u.pathname) && ['com_content', 'com_categories'].includes(u.searchParams.get('option'))),'Joomla: /api/index.php/v1/content/articles and content/categories need an existing X-Joomla-Token and ACL rights, not just the administrator cookie. Keep catid/language, full articletext and access; use state=0 for a new unpublished article. Workflow-controlled publishing may need the editor.'],- ['webflow', route(u => u.hostname === 'webflow.com' || u.hostname === 'www.webflow.com' || u.hostname.endsWith('.design.webflow.com')),+ // The shared root host also serves marketing pages, which need no CMS notes.+ ['webflow', route(u => u.hostname.endsWith('.design.webflow.com') ||+ (['webflow.com', 'www.webflow.com'].includes(u.hostname) &&+ /^\/(?:dashboard(?:\/|$)|design\/[^/]+(?:\/|$))/.test(u.pathname))),'Webflow: Data API https://api.webflow.com/v2 needs a site/OAuth token with cms:read/write. Read collection fields and CMS locale IDs; create staged isDraft=true, update the same item, then publish only that verified item. Preserve references and rich-text components; never publish the whole site.'],['shopify', route(u => (u.hostname === 'admin.shopify.com' && /^\/store\//.test(u.pathname)) || (u.hostname.endsWith('.myshopify.com') && /^\/admin(?:\/|$)/.test(u.pathname))),'Shopify: use the verified shop .myshopify.com Admin GraphQL endpoint with a supported dated version and X-Shopify-Access-Token. Storefront API/cookies are insufficient. Both query and mutation POSTs are gated. Articles/pages support isPublished=false; blogs have no draft flag. Check errors and userErrors.'],@@ -39,12 +42,3 @@ export const CMS_ADAPTERS = definitions.map(([name, matches, hint]) => ({matches,notes: `${CMS_NOTES}\n- ${hint}`,}));--// Custom installations can place their editor at a generic admin/studio route.-// Keep this last and conditional; /admin alone is not evidence of a CMS.-CMS_ADAPTERS.push({- name: 'cms-editor-candidate',- category: 'general',- matches: route(u => /\/(?:admin|administrator|studio|desk)(?:\/|$)/.test(u.pathname)),- notes: '- Editor candidate only. Apply CMS guidance ONLY after observing Ghost/Drupal/Joomla/Webflow/Shopify/Wix/Strapi/Contentful/Sanity and a matching content task; otherwise use ordinary UI rules. For a confirmed CMS, fetch_url needs verified fields/target/auth/rights and task/API permission. Ask stays read-only. Strict without safe auth means UI. Reconcile uncertain writes before fallback and preserve the record ID.',-});diff --git a/test/cms-api-first.mjs b/test/cms-api-first.mjsindex 9db2a4343..02a5aca6a 100644--- a/test/cms-api-first.mjs+++ b/test/cms-api-first.mjs@@ -1,7 +1,7 @@import assert from 'node:assert/strict';import { readFileSync } from 'node:fs';import { test } from 'node:test';-import { CMS_FIXTURES } from './fixtures/cms-api-first.mjs';+import { CMS_FIXTURES, CMS_ADAPTER_ROUTE_CASES } from './fixtures/cms-api-first.mjs';import { buildScenarioPayload } from './llm/lib/scenario-payload.mjs';import { scoreVerdict } from './llm/lib/score.mjs';@@ -167,19 +167,28 @@ for (const v of variants) {assert.equal(v.tools.getToolsForMode('act', { tier: 'compact' }).some(t => t.function.name === 'load_skill'), false);for (const f of CMS_FIXTURES) {const adapter = v.adapters.getActiveAdapter(f.tab);- assert.ok(adapter?.name.startsWith('cms-'), `${f.cms}: missing adapter`);+ // A custom Studio URL alone cannot identify Sanity. Its enabled skill+ // remains loadable after the model observes the CMS and task context.+ if (f.cms === 'sanity') {+ assert.equal(adapter, null);+ continue;+ }+ assert.equal(adapter?.name, `cms-${f.cms}`, `${f.cms}: missing adapter`);assert.ok(adapter.notes.includes('fetch_url'));assert.doesNotMatch(adapter.notes, /load_skill/);assert.ok(adapter.notes.length <= 1300);}- assert.equal(v.adapters.getActiveAdapter('https://news.example.test/admin')?.name, 'cms-editor-candidate');- assert.match(v.adapters.getActiveAdapter('https://news.example.test/admin').notes, /ONLY after observing/);- assert.ok(v.adapters.getActiveAdapter('https://news.example.test/admin').notes.length <= 450);for (const url of ['https://news.example.test/article/ghost', 'https://shopify.com.evil.test/', 'https://wix.com.evil.test/', 'file:///ghost/']) {assert.ok(!v.adapters.getActiveAdapter(url)?.name.startsWith('cms-'), url);}});+ test(`${browser}: CMS routing excludes generic admin and Webflow marketing pages`, () => {+ for (const { url, adapter } of CMS_ADAPTER_ROUTE_CASES) {+ assert.equal(v.adapters.getActiveAdapter(url)?.name ?? null, adapter, url);+ }+ });+test(`${browser}: startup introduces new defaults but Settings removal survives restart and refresh`, async () => {const original = records(v).filter(s => !ids.includes(s.id));const h = hydration(v, { customSkills: original, defaultSkillsSeeded: true });diff --git a/test/cms-browser-smoke.mjs b/test/cms-browser-smoke.mjsindex f95f6f867..92e913bc5 100644--- a/test/cms-browser-smoke.mjs+++ b/test/cms-browser-smoke.mjs@@ -5,7 +5,7 @@ import { readFile } from 'node:fs/promises';import { resolve, relative, isAbsolute } from 'node:path';import { test } from 'node:test';import { chromium, firefox } from 'playwright';-import { CMS_FIXTURES } from './fixtures/cms-api-first.mjs';+import { CMS_FIXTURES, CMS_ADAPTER_ROUTE_CASES } from './fixtures/cms-api-first.mjs';for (const [name, engine] of [['chrome', chromium], ['firefox', firefox]]) {test(`${name}: built CMS packages import and load in the browser engine`, async () => {@@ -22,29 +22,34 @@ for (const [name, engine] of [['chrome', chromium], ['firefox', firefox]]) {await route.fulfill({ contentType: pathname.endsWith('.js') ? 'text/javascript' : 'text/plain', body: await readFile(file) });});await page.goto('http://cms-fixture.test/');- const result = await page.evaluate(async fixtures => {+ const result = await page.evaluate(async ({ fixtures, routingCases }) => {const skills = await import('/src/agent/skills.js');const adapters = await import('/src/agent/adapters.js');const records = await Promise.all(skills.DEFAULT_SKILL_SOURCES.map(async s => ({...s, sourceType: 'built-in', sourceUrl: s.path,content: await (await fetch(`/${s.path}`)).text(),})));- return fixtures.map(f => {+ const packages = fixtures.map(f => {const id = `cms-${f.cms}`;const adapter = adapters.getActiveAdapter(f.tab);const prompt = skills.buildCustomSkillsPrompt(records, { tier: 'mid', mode: 'act', activeSkillIds: [id] });- return { id, adapter: adapter?.name, guided: adapter?.notes.includes('fetch_url'),+ return { id, adapter: adapter?.name ?? null, guided: !!adapter?.notes.includes('fetch_url'),loaded: prompt.includes(`skills/${id}.md`), count: (prompt.match(/<skill /g) || []).length,compact: skills.buildSkillLoaderDefinition(records, { tier: 'compact', mode: 'act' }),};});- }, CMS_FIXTURES.map(({ cms, tab }) => ({ cms, tab })));- assert.equal(result.length, 9);- for (const r of result) {- // The Sanity fixture uses a custom /studio URL: identity needs observed- // UI evidence, so the URL-only matcher must remain a generic candidate.- assert.equal(r.adapter, r.id === 'cms-sanity' ? 'cms-editor-candidate' : r.id);- assert.equal(r.guided, true);+ const routes = routingCases.map(({ url }) => ({+ url, adapter: adapters.getActiveAdapter(url)?.name ?? null,+ }));+ return { packages, routes };+ }, { fixtures: CMS_FIXTURES.map(({ cms, tab }) => ({ cms, tab })), routingCases: CMS_ADAPTER_ROUTE_CASES });+ assert.deepEqual(result.routes, CMS_ADAPTER_ROUTE_CASES);+ assert.equal(result.packages.length, 9);+ for (const r of result.packages) {+ // Custom Studio paths add no adapter notes, but observed CMS/task+ // context can still select the enabled Sanity recipe in Mid/Full.+ assert.equal(r.adapter, r.id === 'cms-sanity' ? null : r.id);+ assert.equal(r.guided, r.id !== 'cms-sanity');assert.equal(r.loaded, true);assert.equal(r.count, 1);assert.equal(r.compact, null);diff --git a/test/fixtures/cms-api-first.mjs b/test/fixtures/cms-api-first.mjsindex edeb51c75..734feb146 100644--- a/test/fixtures/cms-api-first.mjs+++ b/test/fixtures/cms-api-first.mjs@@ -4,6 +4,40 @@const title = 'Revised title';const before = 'Original title';const stamp = '2026-09-30T10:00:00.000Z';++// Shared Node/browser regressions for CMS notes on unrelated pages, with+// positive controls for hosted editors and legacy Webflow Designer links.+export const CMS_ADAPTER_ROUTE_CASES = [+ ...[+ 'https://webflow.com/dashboard',+ 'https://webflow.com/dashboard/sites/site1?workspace=w1',+ 'https://www.webflow.com/dashboard/',+ 'https://webflow.com/design/site1?locale=fr',+ 'https://www.webflow.com/design/site1/',+ 'https://site1.design.webflow.com/?locale=fr',+ ].map(url => ({ url, adapter: 'cms-webflow' })),+ { url: 'https://project1.sanity.studio/structure/story;s1', adapter: 'cms-sanity' },+ ...[+ 'https://internal.example.test/admin',+ 'https://internal.example.test/admin/users',+ 'https://internal.example.test/administrator/index.php',+ 'https://analytics.example.test/studio/report/1',+ 'https://support.example.test/desk/tickets/42',+ 'https://editor.example.test/studio/structure/story;drafts.s1',+ 'https://public.example.test/',+ 'https://webflow.com/',+ 'https://www.webflow.com/templates',+ 'https://webflow.com/made-in-webflow',+ 'https://webflow.com/blog/cms',+ 'https://webflow.com/dashboard-guide',+ 'https://webflow.com/design',+ 'https://webflow.com/design-system/site1',+ 'https://webflow.com.evil.test/dashboard',+ 'https://site1.design.webflow.com.evil.test/',+ 'file://webflow.com/dashboard',+ ].map(url => ({ url, adapter: null })),+];+export const CMS_FIXTURES = [{cms: 'ghost', tab: 'https://editor.example.test/ghost/#/editor/page/g1',