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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ The boundary, in brief:
many discovery and page fetches, so each call reports its own request ledger and
the run reports totals.
- **Root-only in routed monorepos** (it starts a host process); scope configs
cannot alter it. Result-cache reuse is disabled while research is enabled,
because web content can change without a config change.
cannot alter it. Research results are fetched and audited per run; cached review
results remain keyed by the ordinary trusted review inputs and make no network call.

Full detail — providers, query grammar, `fetch_platform_doc` modes, provenance and
citation grounding: [LLP 0013](./llp/0013-platform-research.explainer.md).
Expand Down
11 changes: 10 additions & 1 deletion llp/0013-platform-research.explainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,16 @@ the queries and bounded results.

The built-in source catalog covers Apple, Android, platform releases, Swift
Evolution, SDWebImage, Media3, Glide, OkHttp, Kotlin coroutines, Gradle/AGP, selected JetBrains
issues, Expo, React Native, Reanimated, Gesture Handler, Screens, and Worklets.
issues, Expo, React, React Native, WHATWG and W3C web specifications, Chrome DevTools
Protocol, Flow, TypeScript, the Android NDK, CMake, CocoaPods, Metro, Reanimated,
Gesture Handler, Screens, and Worklets. The React Native
additions cover the contracts its implementation must preserve: React semantics, its
web-compatible APIs, the repository's type systems, and its native build and dependency
managers. Hermes documentation is intentionally not fetched from the engine's `main`
branch because it can disagree with React Native's vendored revision. Repository PR and
issue history is intentionally not a
live evidence provider: it belongs in a versioned offline evaluation corpus used to
improve prompts, while the runtime MCP remains an API-contract channel.
The canonical OkHttp host is backed by both the
[maintainer's transfer announcement](https://jakewharton.com/the-lysine-contingency/)
and [Commonhaus's project-transfer record](https://www.commonhaus.org/activity/315.html).
Expand Down
88 changes: 88 additions & 0 deletions scripts/research/evaluate-corpora.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,94 @@ const cases = [
title: "FlatList",
body: "getItemLayout is an optional optimization for FlatList. It lets the list skip the measurement of dynamic content when the row height is known ahead of time.",
},
{
label: "react",
provider: "react",
platform: "react-native",
providers: ["react"],
query: "useEffect dependency array",
expected: "react.dev/reference/react/useEffect",
url: "https://react.dev/reference/react/useEffect",
title: "useEffect",
body: "useEffect synchronizes a component with an external system. Every reactive value read by the effect belongs in its dependency array.",
},
{
label: "flow",
provider: "flow",
platform: "react-native",
providers: ["flow"],
query: "exact object types",
expected: "flow.org/en/docs/types/objects",
url: "https://flow.org/en/docs/types/objects/",
title: "Object Types",
body: "An exact object type rejects extra properties. Flow object types are exact by default unless they are explicitly declared inexact.",
},
{
label: "typescript",
provider: "typescript",
platform: "react-native",
providers: ["typescript"],
query: "declaration file module exports",
expected: "typescriptlang.org/docs/handbook/declaration-files",
url: "https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html",
title: "Modules .d.ts",
body: "A module declaration file describes the runtime exports of a JavaScript module. Its export shape must match the values consumers can import.",
},
{
label: "web-standards",
provider: "web-standards",
platform: "react-native",
providers: ["web-standards"],
sourceKind: "standard",
query: "AbortSignal fetch cancellation",
expected: "fetch.spec.whatwg.org",
url: "https://fetch.spec.whatwg.org/",
title: "Fetch Standard",
body: "An AbortSignal can abort a fetch operation. The fetch promise rejects when the request is terminated by the signal.",
},
{
label: "chrome-devtools-protocol",
provider: "chrome-devtools-protocol",
platform: "react-native",
providers: ["chrome-devtools-protocol"],
sourceKind: "standard",
query: "Runtime evaluate awaitPromise",
expected: "chromedevtools.github.io/devtools-protocol/tot/Runtime",
url: "https://chromedevtools.github.io/devtools-protocol/tot/Runtime/",
title: "Runtime domain",
body: "Runtime.evaluate evaluates an expression on the inspected page. The awaitPromise option waits for a returned promise and reports its resolved result.",
},
{
label: "android-ndk",
provider: "android-ndk",
providers: ["android-ndk"],
query: "JNIEnv local references",
expected: "developer.android.com/ndk/guides/jni-tips",
url: "https://developer.android.com/ndk/guides/jni-tips",
title: "JNI tips",
body: "JNI local references are valid only for the duration of the current native method call and on the current thread. Long-lived references must be promoted to global references.",
},
{
label: "cmake",
provider: "cmake",
providers: ["cmake"],
query: "target_link_libraries transitive",
expected: "cmake.org/cmake/help/latest/command/target_link_libraries",
url: "https://cmake.org/cmake/help/latest/command/target_link_libraries.html",
title: "target_link_libraries",
body: "target_link_libraries links a target to libraries and can publish transitive link dependencies through the target's interface.",
},
{
label: "cocoapods",
provider: "cocoapods",
platform: "apple",
providers: ["cocoapods"],
query: "Podfile use_frameworks linkage",
expected: "guides.cocoapods.org/syntax/podfile",
url: "https://guides.cocoapods.org/syntax/podfile.html",
title: "Podfile Syntax Reference",
body: "The use_frameworks directive configures pods to build as frameworks and accepts a linkage option for static or dynamic frameworks.",
},
{
label: "react-native-reanimated",
provider: "react-native-reanimated",
Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/research-mcp/direct-fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,16 @@ test("direct URL inference prefers narrow release and dependency providers", ()
"https://developer.android.com/reference/androidx/media3/common/Player",
).provider,
).toBe("media3");
expect(
resolveDirectDocumentationTarget("https://developer.android.com/ndk/guides/cpp-support"),
).toMatchObject({ provider: "android-ndk", sourceKind: "official-guide" });
expect(resolveDirectDocumentationTarget("https://fetch.spec.whatwg.org/")).toMatchObject({
provider: "web-standards",
sourceKind: "standard",
});
expect(
resolveDirectDocumentationTarget(
"https://chromedevtools.github.io/devtools-protocol/tot/Runtime/",
),
).toMatchObject({ provider: "chrome-devtools-protocol", sourceKind: "standard" });
});
13 changes: 12 additions & 1 deletion src/__tests__/research-mcp/mcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@ test("stdio MCP advertises the read-only documentation tools and their enforced
expect(searchTool?.description ?? "").toContain("Native source retains platform context");
expect(searchTool?.description ?? "").toContain("react-native-worklets=Worklets");
expect(searchTool?.description ?? "").toContain("metro=Metro bundler");
expect(searchTool?.description ?? "").toContain(
"web-standards=WHATWG and W3C web platform standards",
);
expect(searchTool?.description ?? "").toContain("android-ndk=Android NDK");
expect(fetchTool?.annotations?.readOnlyHint).toBe(true);
expect(fetchTool?.description ?? "").toMatch(/every redirect/);
const inputSchema = searchTool?.inputSchema as {
properties?: {
query?: { description?: string };
providers?: { description?: string };
providers?: { description?: string; items?: { enum?: string[] } };
sourceKinds?: { description?: string; items?: { enum?: string[] } };
};
};
const fetchInputSchema = fetchTool?.inputSchema as {
Expand All @@ -60,6 +65,12 @@ test("stdio MCP advertises the read-only documentation tools and their enforced
expect(inputSchema.properties?.providers?.description ?? "").toContain(
"jetbrains-issues=JetBrains YouTrack context",
);
expect(inputSchema.properties?.providers?.items?.enum).toContain("typescript");
expect(inputSchema.properties?.providers?.items?.enum).toContain("chrome-devtools-protocol");
expect(inputSchema.properties?.sourceKinds?.items?.enum).toContain("standard");
expect(inputSchema.properties?.sourceKinds?.description ?? "").toContain(
"external compatibility specification",
);
expect(fetchInputSchema.properties?.context?.default).toBe("section");
expect(fetchInputSchema.properties?.context?.description ?? "").toContain(
"document=bounded extracted page text",
Expand Down
54 changes: 54 additions & 0 deletions src/__tests__/research-mcp/providers.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { expect, test } from "bun:test";

import {
androidNdkProvider,
androidProvider,
appleProvider,
appleReleasesProvider,
chromeDevtoolsProtocolProvider,
cmakeProvider,
cocoaPodsProvider,
expoProvider,
flowProvider,
glideProvider,
jetbrainsIssuesProvider,
metroProvider,
Expand All @@ -14,10 +19,13 @@ import {
reactNativeReanimatedProvider,
reactNativeScreensProvider,
reactNativeWorkletsProvider,
reactProvider,
resolveAllowedUrl,
resolveAllowedRequestUrl,
sdWebImageProvider,
swiftEvolutionProvider,
typescriptProvider,
webStandardsProvider,
} from "../../research-mcp/providers.js";

test("Apple provider accepts only HTTPS documentation paths on the exact host", () => {
Expand Down Expand Up @@ -199,3 +207,49 @@ test("React Native ecosystem providers stay on their exact documentation hosts a
resolveAllowedUrl(metroProvider, "https://metrobundler.dev.evil.example/docs/configuration"),
).toThrow(/outside the metro documentation allowlist/);
});

test("React Native contract providers admit only their fixed authoritative corpora", () => {
for (const [provider, url] of [
[reactProvider, "https://react.dev/reference/react/useEffect"],
[flowProvider, "https://flow.org/en/docs/types/unions/"],
[typescriptProvider, "https://www.typescriptlang.org/docs/handbook/declaration-files/"],
[androidNdkProvider, "https://developer.android.com/ndk/guides/cpp-support"],
[cmakeProvider, "https://cmake.org/cmake/help/v3.31/command/add_library.html"],
[cocoaPodsProvider, "https://guides.cocoapods.org/syntax/podfile.html"],
[webStandardsProvider, "https://fetch.spec.whatwg.org/"],
[webStandardsProvider, "https://w3c.github.io/IntersectionObserver/"],
[
chromeDevtoolsProtocolProvider,
"https://chromedevtools.github.io/devtools-protocol/tot/Runtime/",
],
] as const) {
expect(resolveAllowedUrl(provider, url).hostname).toBe(new URL(url).hostname);
}

for (const [provider, url] of [
[reactProvider, "https://react.dev/reference/react-dom/components/form"],
[reactProvider, "https://react.dev/learn/escape-hatches"],
[flowProvider, "https://flow.org/blog/"],
[typescriptProvider, "https://www.typescriptlang.org/play"],
[androidNdkProvider, "https://developer.android.com/studio/projects/install-ndk"],
[cmakeProvider, "https://cmake.org/community/"],
[cocoaPodsProvider, "https://guides.cocoapods.org/blog/"],
[webStandardsProvider, "https://w3c.github.io/permissions/"],
[webStandardsProvider, "https://whatwg.org/"],
[chromeDevtoolsProtocolProvider, "https://chromedevtools.github.io/debugger-protocol-viewer/"],
] as const) {
expect(() => resolveAllowedUrl(provider, url)).toThrow(
/outside the .* documentation allowlist/,
);
}

expect(() =>
resolveAllowedUrl(webStandardsProvider, "https://user:password@fetch.spec.whatwg.org/"),
).toThrow(/outside the web-standards documentation allowlist/);
expect(() =>
resolveAllowedUrl(androidNdkProvider, "https://developer.android.com.evil.example/ndk/guides"),
).toThrow(/outside the android-ndk documentation allowlist/);
expect(() =>
resolveAllowedUrl(reactNativeProvider, "https://reactnative.dev/contributing/overview"),
).toThrow(/outside the react-native documentation allowlist/);
});
64 changes: 64 additions & 0 deletions src/__tests__/research-mcp/remote-search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,67 @@ test("Apple release searches select the platform-specific fixed scope", async ()
expect(queries[0]).toContain("site:developer.apple.com/documentation/xcode-release-notes");
expect(queries[1]).toContain("site:developer.apple.com/documentation/ios-ipados-release-notes");
});

test("web standards discovery uses fixed WHATWG and W3C scopes with standards provenance", async () => {
let searchRequests = 0;
const fetchImplementation = async (input: string | URL | Request): Promise<Response> => {
const url = new URL(input instanceof Request ? input.url : input.toString());
if (url.hostname === "api.search.brave.com") {
searchRequests++;
const query = url.searchParams.get("q") ?? "";
expect(query).toContain("site:whatwg.org");
expect(query).toContain("site:w3c.github.io");
return jsonResponse({
web: {
results: [
{ title: "Fetch Standard", url: "https://fetch.spec.whatwg.org/" },
{ title: "Unrelated W3C draft", url: "https://w3c.github.io/permissions/" },
],
},
});
}
expect(url.href).toBe("https://fetch.spec.whatwg.org/");
return new Response(
"<!doctype html><html><head><title>Fetch Standard</title></head><body><main>" +
"<h1>Fetch</h1><p>The AbortSignal controls cancellation of a fetch request and " +
"causes the fetch promise to reject when the operation is terminated.</p>" +
"</main></body></html>",
{ headers: { "content-type": "text/html; charset=utf-8" } },
);
};

const response = await searchRemoteDocumentation(
"web-standards",
"AbortSignal fetch cancellation",
2,
{ apiKey: "test-key", fetchImplementation, sourceKinds: ["standard"] },
);

expect(searchRequests).toBe(1);
expect(response.warnings).toEqual([]);
expect(response.results).toHaveLength(1);
expect(response.results[0]).toMatchObject({
provider: "web-standards",
sourceKind: "standard",
url: "https://fetch.spec.whatwg.org/",
});
});

test("provenance filtering skips a standards provider before network access", async () => {
let requests = 0;
const response = await searchRemoteDocumentation(
"chrome-devtools-protocol",
"Runtime evaluate",
1,
{
apiKey: "test-key",
sourceKinds: ["official-api"],
fetchImplementation: async () => {
requests++;
return jsonResponse({ web: { results: [] } });
},
},
);
expect(requests).toBe(0);
expect(response).toEqual({ results: [], warnings: [] });
});
34 changes: 34 additions & 0 deletions src/__tests__/research-mcp/search-index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,40 @@ test("search filters named corpora and provenance classes", () => {
]);
});

test("search filters external standards separately from implementation documentation", () => {
const index = buildSearchIndex([
{
id: "standard:fetch",
platform: "react-native",
provider: "web-standards",
sourceKind: "standard",
title: "Fetch Standard",
url: "https://fetch.spec.whatwg.org/",
passage: "AbortSignal controls cancellation of a fetch request.",
indexedAt: "2026-08-06T00:00:00.000Z",
},
{
id: "rn:fetch",
platform: "react-native",
provider: "react-native",
sourceKind: "official-api",
title: "React Native global fetch",
url: "https://reactnative.dev/docs/global-fetch",
passage: "React Native exposes fetch as a global API.",
indexedAt: "2026-08-06T00:00:00.000Z",
},
]);

const results = searchDocumentation(index, "fetch AbortSignal", {
platform: "react-native",
sourceKinds: ["standard"],
limit: 5,
});
expect(results.map(({ provider, sourceKind }) => ({ provider, sourceKind }))).toEqual([
{ provider: "web-standards", sourceKind: "standard" },
]);
});

test("a language filter excludes otherwise matching untagged documents", () => {
const index = buildSearchIndex([
...chunks,
Expand Down
Loading