Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
docs: repair stale anchors and validate fragment destinations (#3568)
Francesco Bonaccif28b0e922484
diff --git a/.github/workflows/ci-check-docs-links.yml b/.github/workflows/ci-check-docs-links.ymlindex de6851202c..d32eda6cd0 100644--- a/.github/workflows/ci-check-docs-links.yml+++ b/.github/workflows/ci-check-docs-links.yml@@ -7,7 +7,10 @@ on:- "docs/src/**"- "docs/package.json"- "docs/scripts/check-links.ts"+ - "docs/scripts/check-links.test.ts"+ - "docs/scripts/fixtures/link-checks/**"- "docs/scripts/check-hygiene.ts"+ - ".github/workflows/ci-check-docs-links.yml"jobs:check-internal-links:@@ -29,6 +32,10 @@ jobs:run: pnpm installworking-directory: docs+ - name: Test link checker regression fixtures+ run: pnpm exec tsx --test scripts/check-links.test.ts+ working-directory: docs+- name: Check internal linksrun: pnpm docs:check-linksworking-directory: docsdiff --git a/docs/content/docs/concepts/how-lume-expands-macos-disks.mdx b/docs/content/docs/concepts/how-lume-expands-macos-disks.mdxindex 8867bdb2e0..333c5b75d2 100644--- a/docs/content/docs/concepts/how-lume-expands-macos-disks.mdx+++ b/docs/content/docs/concepts/how-lume-expands-macos-disks.mdx@@ -71,4 +71,4 @@ filesystem.- [Manage local Lume VMs](/how-to-guides/lume/manage-vms#expand-a-vm-disk)- [How SIP works in Lume VMs](/concepts/how-sip-works-in-lume-vms)-- [Lume CLI reference](/reference/lume/cli-reference#set)+- [Lume CLI reference](/reference/lume/cli-reference#lume-set)diff --git a/docs/content/docs/concepts/the-no-foreground-contract.mdx b/docs/content/docs/concepts/the-no-foreground-contract.mdxindex 8e391c9890..e3bfcb1561 100644--- a/docs/content/docs/concepts/the-no-foreground-contract.mdx+++ b/docs/content/docs/concepts/the-no-foreground-contract.mdx@@ -33,7 +33,7 @@ Windows also has session boundaries. A daemon running in the interactive user seAT-SPI provides the semantic path on Linux. Element actions call the toolkit's own accessibility action (`Action.DoAction`) and do not need pointer injection or foreground focus. On X11, window-addressable input and capture can also route to a target window. On Wayland, synthetic input is intentionally constrained by the compositor, so the background path depends more heavily on AT-SPI and reconstructed element frames.-The remaining Linux gap is raw keyboard injection into native Wayland apps. Typing into accessible fields can still work through AT-SPI, but shortcuts or raw key events may need XWayland or foreground/user-granted compositor paths. See [Known limits](/reference/cua-driver/limits#native-wayland-apps-cant-receive-synthetic-keystrokes).+The remaining Linux gap is raw keyboard injection into native Wayland apps. Typing into accessible fields can still work through AT-SPI, but shortcuts or raw key events may need XWayland or foreground/user-granted compositor paths. See [Known limits](/reference/cua-driver/limits#native-wayland-background-keyboard-input-is-focus-bound).## The agent cursordiff --git a/docs/content/docs/reference/cua-driver/action-selection-policy.mdx b/docs/content/docs/reference/cua-driver/action-selection-policy.mdxindex 6cb473c216..4754675fc5 100644--- a/docs/content/docs/reference/cua-driver/action-selection-policy.mdx+++ b/docs/content/docs/reference/cua-driver/action-selection-policy.mdx@@ -93,7 +93,7 @@ click({ pid, window_id, element_index: 12 })// → { effect: "suspected_noop", escalation: { recommended: "px", reason: "..." } }```-**Wayland exception.** On a native Wayland session, raw keyboard input has no universal background path. When an AX keyboard action no-ops there, prefer an accessible field action or run the app under XWayland; otherwise escalate only that action to foreground. See [Known limits](/reference/cua-driver/limits#native-wayland-apps-cant-receive-synthetic-keystrokes).+**Wayland exception.** On a native Wayland session, raw keyboard input has no universal background path. When an AX keyboard action no-ops there, prefer an accessible field action or run the app under XWayland; otherwise escalate only that action to foreground. See [Known limits](/reference/cua-driver/limits#native-wayland-background-keyboard-input-is-focus-bound).## Use a desktop target only for screen-absolute work@@ -133,7 +133,7 @@ exact window target, or use`target: {kind: "desktop", display_id: "primary"}` for screen-absolute work.**Problem: keystrokes don't land on a Linux app.**-On native Wayland, raw keys have no background path. Type into accessible fields with `type_text`, drive controls by `element_index`, or run the app under XWayland. See [Known limits](/reference/cua-driver/limits#native-wayland-apps-cant-receive-synthetic-keystrokes).+On native Wayland, raw keys have no background path. Type into accessible fields with `type_text`, drive controls by `element_index`, or run the app under XWayland. See [Known limits](/reference/cua-driver/limits#native-wayland-background-keyboard-input-is-focus-bound).## Relateddiff --git a/docs/scripts/check-links.test.ts b/docs/scripts/check-links.test.tsnew file mode 100644index 0000000000..a1554347c4--- /dev/null+++ b/docs/scripts/check-links.test.ts@@ -0,0 +1,106 @@+import assert from 'node:assert/strict';+import * as path from 'node:path';+import test from 'node:test';+import { readFileFromPath, readFiles } from 'next-validate-link';+import { buildScannedUrls, checkLinks, pathToUrl } from './check-links';++const fixtures = path.join(__dirname, 'fixtures/link-checks');+const docs = path.resolve(__dirname, '..');++async function readFixture(name: string) {+ return readFileFromPath(path.join(fixtures, `${name}.mdx`), () => `/${name}`);+}++test('inventories Fumadocs heading IDs and literal MDX anchors', async () => {+ const file = await readFixture('headings');+ const scanned = await buildScannedUrls([file]);+ assert.deepEqual(scanned.urls.get('/headings')?.hashes, [+ 'lume-set',+ 'native-wayland-background-keyboard-input-is-focus-bound',+ 'run-lume-set-with-care',+ 'repeat',+ 'repeat-1',+ 'repeat-1-1',+ 'stable-id',+ 'custom-heading',+ 'explicit-section',+ 'inline-anchor',+ ]);+});++test('valid fragments and existing URL exceptions continue passing', async () => {+ const files = await Promise.all(['headings', 'empty', 'valid'].map(readFixture));+ const scanned = await buildScannedUrls(files);+ assert.deepEqual(scanned.urls.get('/empty')?.hashes, []);+ assert.deepEqual(await checkLinks(files, scanned), []);+});++test('rejects obsolete, missing, and non-rendered fragments with source locations', async () => {+ const files = await Promise.all(['headings', 'empty', 'invalid'].map(readFixture));+ const results = await checkLinks(files, await buildScannedUrls(files));+ assert.equal(results.length, 1);+ assert.equal(results[0].file, path.join(fixtures, 'invalid.mdx'));+ assert.deepEqual(+ results[0].errors.map(({ url, line, column, reason }) => [url, line, column, reason]),+ [+ ['/headings#set', 1, 1, 'invalid-fragment'],+ ['/headings#native-wayland-apps-cant-receive-synthetic-keystrokes', 2, 1, 'invalid-fragment'],+ ['/headings#repeat-2', 3, 1, 'invalid-fragment'],+ ['/headings#custom-heading-stable-id', 4, 1, 'invalid-fragment'],+ ['/headings#fixture-title-is-not-an-anchor', 5, 1, 'invalid-fragment'],+ ['/headings#fenced-heading', 6, 1, 'invalid-fragment'],+ ['/headings#fenced-anchor', 7, 1, 'invalid-fragment'],+ ['/empty#missing', 8, 1, 'invalid-fragment'],+ ['/invalid#missing', 9, 1, 'invalid-fragment'],+ ['/missing-page#section', 10, 1, 'not-found'],+ ]+ );+});++test('maps docs paths consistently for absolute paths and nested index pages', () => {+ assert.equal(pathToUrl('content/docs/index.mdx'), '/');+ assert.equal(+ pathToUrl('content/docs/reference/lume/cli-reference.mdx'),+ '/reference/lume/cli-reference'+ );+ assert.equal(+ pathToUrl(path.join(docs, 'content/docs/reference/lume/index.mdx')),+ '/reference/lume'+ );+});++test('preserves root-page fragments rather than replacing them with an unchecked root', async () => {+ const file = { ...(await readFixture('headings')), url: '/' };+ const scanned = await buildScannedUrls([file]);+ assert.ok(scanned.urls.get('/')?.hashes?.includes('lume-set'));+ const source = {+ path: path.join(fixtures, 'root-links.mdx'),+ url: '/root-links',+ content: '[Good](/#lume-set)\n[Bad](/#missing)',+ };+ const results = await checkLinks([source], scanned);+ assert.deepEqual(+ results[0].errors.map(({ url, reason }) => [url, reason]),+ [['/#missing', 'invalid-fragment']]+ );+});++test('the four repaired source links validate against their current destinations', async () => {+ const files = await readFiles(path.join(docs, 'content/docs/**/*.mdx'), { pathToUrl });+ const scanned = await buildScannedUrls(files);+ const referringPages = files.filter((file) =>+ [+ '/concepts/how-lume-expands-macos-disks',+ '/concepts/the-no-foreground-contract',+ '/reference/cua-driver/action-selection-policy',+ ].includes(file.url!)+ );+ assert.equal(referringPages.length, 3);+ assert.deepEqual(await checkLinks(referringPages, scanned), []);+ for (const file of referringPages) {+ assert.doesNotMatch(+ file.content,+ /cli-reference#set\)|limits#native-wayland-apps-cant-receive-synthetic-keystrokes\)/+ );+ }+});diff --git a/docs/scripts/check-links.ts b/docs/scripts/check-links.tsindex e83bf972ed..32608165c9 100644--- a/docs/scripts/check-links.ts+++ b/docs/scripts/check-links.ts@@ -12,8 +12,15 @@* pnpm docs:check-links:external # Also check external links*/-import { readFiles, validateFiles, printErrors, type ScanResult } from 'next-validate-link';+import {+ readFiles,+ validateFiles,+ printErrors,+ type FileObject,+ type ScanResult,+} from 'next-validate-link';import * as path from 'path';+import { pathToFileURL } from 'node:url';import fg from 'fast-glob';const DOCS_DIR = path.resolve(__dirname, '..');@@ -24,13 +31,42 @@ const BLOG_DIR = path.join(DOCS_DIR, '../blog');* Build the ScanResult (valid URL map) directly from content files.* This is more reliable than scanURLs for catch-all routes.*/-function buildScannedUrls(): ScanResult {- const urls = new Map<string, {}>();- const mdxFiles = fg.sync('**/*.mdx', { cwd: CONTENT_DIR });+export async function buildScannedUrls(files: FileObject[]): Promise<ScanResult> {+ // Fumadocs exposes this plugin through an import-only package export.+ const { remarkHeading } = await import('fumadocs-core/mdx-plugins/remark-heading');+ const urls: ScanResult['urls'] = new Map();- for (const file of mdxFiles) {- const slug = file.replace(/\.mdx$/, '').replace(/\/index$/, '');- urls.set(`/${slug}`, {});+ for (const file of files) {+ if (!file.url) continue;+ const hashes: string[] = [];+ // Reuse the validator's MDX parser and the renderer's heading plugin so+ // inline markup, duplicate headings, and [#custom-id] use Fumadocs IDs.+ await validateFiles([file], {+ scanned: { urls: new Map(), fallbackUrls: [] },+ markdown: {+ remarkPlugins: [[remarkHeading, { generateToc: false }]],+ onNode(node) {+ if (node.type === 'heading') {+ const id = node.data?.hProperties?.id;+ if (typeof id === 'string') hashes.push(id);+ } else if (node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement') {+ for (const attribute of node.attributes) {+ if (+ attribute.type === 'mdxJsxAttribute' &&+ attribute.name === 'id' &&+ typeof attribute.value === 'string'+ ) {+ hashes.push(attribute.value);+ }+ }+ }+ // This pass only inventories anchors. Validate links after every+ // destination has been indexed, including pages without headings.+ return { hrefs: [] };+ },+ },+ });+ urls.set(file.url, { hashes });}// Blog posts share the cua.ai origin with the docs app, so root-relative@@ -41,67 +77,84 @@ function buildScannedUrls(): ScanResult {urls.set(`/blog/${slug}`, {});}- // Also add the root- urls.set('/', {});+ // Preserve root-page anchors when the content includes an index page.+ if (!urls.has('/')) urls.set('/', {});return { urls, fallbackUrls: [] };}-function pathToUrl(filePath: string): string | undefined {- const slug = filePath- .replace(/^content\/docs\//, '')+export function pathToUrl(filePath: string): string {+ const slug = path+ .relative(CONTENT_DIR, path.resolve(DOCS_DIR, filePath))+ .split(path.sep)+ .join('/').replace(/\.mdx$/, '')- .replace(/\/index$/, '');+ .replace(/(^|\/)index$/, '');return `/${slug}`;}-async function main() {- const args = process.argv.slice(2);- const checkExternal = args.includes('--external');-- const scanned = buildScannedUrls();-- // Read all MDX content files- const files = await readFiles('content/docs/**/*.mdx', { pathToUrl });+export async function checkLinks(files: FileObject[], scanned: ScanResult, checkExternal = false) {+ const results = await Promise.all(+ files.map((file) =>+ validateFiles([file], {+ scanned,+ checkExternal,+ // Fumadocs resolves relative MDX links at runtime, skip them here+ checkRelativePaths: false,+ checkRelativeUrls: false,+ pathToUrl,+ markdown: {+ onNode(node) {+ if (node.type !== 'link') return { hrefs: [] };+ // next-validate-link skips bare fragments; resolve them to this page+ // so they go through the same fragment check as cross-page links.+ return {+ hrefs: [node.url.startsWith('#') && file.url ? `${file.url}${node.url}` : node.url],+ };+ },+ },+ whitelist: (url: string) => {+ const pathname = url.split(/[#?]/)[0];+ const ext = path.extname(pathname).toLowerCase();+ const staticExts = new Set([+ '.png',+ '.jpg',+ '.jpeg',+ '.gif',+ '.svg',+ '.ico',+ '.webp',+ '.avif',+ '.mp4',+ '.webm',+ '.pdf',+ '.css',+ '.js',+ '.woff',+ '.woff2',+ '.ttf',+ '.eot',+ ]);+ return staticExts.has(ext);+ },+ })+ )+ );+ return results.flat();+}- // Validate all links in the MDX files- const results = await validateFiles(files, {- scanned,- checkExternal,- // Fumadocs resolves relative MDX links at runtime, skip them here- checkRelativePaths: false,- checkRelativeUrls: false,- pathToUrl,- whitelist: (url: string) => {- const pathname = url.split(/[#?]/)[0];- const ext = path.extname(pathname).toLowerCase();- const staticExts = new Set([- '.png',- '.jpg',- '.jpeg',- '.gif',- '.svg',- '.ico',- '.webp',- '.avif',- '.mp4',- '.webm',- '.pdf',- '.css',- '.js',- '.woff',- '.woff2',- '.ttf',- '.eot',- ]);- return staticExts.has(ext);- },- });+async function main() {+ const checkExternal = process.argv.slice(2).includes('--external');+ const files = await readFiles(path.join(CONTENT_DIR, '**/*.mdx'), { pathToUrl });+ const scanned = await buildScannedUrls(files);+ const results = await checkLinks(files, scanned, checkExternal);printErrors(results, true);}-main().catch((err) => {- console.error('Fatal error:', err);- process.exit(1);-});+if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) {+ main().catch((err) => {+ console.error('Fatal error:', err);+ process.exit(1);+ });+}diff --git a/docs/scripts/fixtures/link-checks/empty.mdx b/docs/scripts/fixtures/link-checks/empty.mdxnew file mode 100644index 0000000000..27c5ec3c4f--- /dev/null+++ b/docs/scripts/fixtures/link-checks/empty.mdx@@ -0,0 +1,5 @@+---+title: Empty page+---++This page has no anchors.diff --git a/docs/scripts/fixtures/link-checks/headings.mdx b/docs/scripts/fixtures/link-checks/headings.mdxnew file mode 100644index 0000000000..d0ecb96863--- /dev/null+++ b/docs/scripts/fixtures/link-checks/headings.mdx@@ -0,0 +1,32 @@+---+title: Fixture title is not an anchor+---++### lume set++## Native Wayland background keyboard input is focus-bound++## Run `lume set` with **care**++## Repeat++## Repeat++## Repeat-1++## Custom heading [#stable-id]++## Custom heading++<section id="explicit-section">Section</section>++An <a id="inline-anchor" /> inline anchor.++```mdx+## Fenced heading++<section id="fenced-anchor" />+```++[Same-page heading](#lume-set)+[Same-page explicit anchor](#explicit-section)diff --git a/docs/scripts/fixtures/link-checks/invalid.mdx b/docs/scripts/fixtures/link-checks/invalid.mdxnew file mode 100644index 0000000000..15a85db5a6--- /dev/null+++ b/docs/scripts/fixtures/link-checks/invalid.mdx@@ -0,0 +1,10 @@+[Obsolete Lume fragment](/headings#set)+[Obsolete Wayland fragment](/headings#native-wayland-apps-cant-receive-synthetic-keystrokes)+[Absent duplicate](/headings#repeat-2)+[Custom heading uses its explicit ID](/headings#custom-heading-stable-id)+[Frontmatter is not a heading](/headings#fixture-title-is-not-an-anchor)+[Fenced heading is not rendered](/headings#fenced-heading)+[Fenced anchor is not rendered](/headings#fenced-anchor)+[Page without anchors](/empty#missing)+[Missing same-page anchor](#missing)+[Missing route](/missing-page#section)diff --git a/docs/scripts/fixtures/link-checks/valid.mdx b/docs/scripts/fixtures/link-checks/valid.mdxnew file mode 100644index 0000000000..91f54dd651--- /dev/null+++ b/docs/scripts/fixtures/link-checks/valid.mdx@@ -0,0 +1,17 @@+[Lume set](/headings#lume-set)+[Wayland limit](/headings#native-wayland-background-keyboard-input-is-focus-bound)+[Inline markup](/headings#run-lume-set-with-care)+[First heading](/headings#repeat)+[Repeated heading](/headings#repeat-1)+[Colliding heading](/headings#repeat-1-1)+[Custom heading](/headings#stable-id)+[Automatic heading after custom heading](/headings#custom-heading)+[Explicit section](/headings#explicit-section)+[Inline anchor](/headings#inline-anchor)+[Query with fragment](/headings?view=full#lume-set)+[No fragment](/empty)+[Empty fragment](/empty#)+[Site root](/)+[Static asset](/images/example.svg#icon)+[External link](https://example.com/#section)+[Runtime relative path](./another-page.mdx#section)