GoogleChrome/modern-web-guidance-src is the source repository for Modern Web Guidance (software Apache 2.0, guide content CC-BY 4.0 per its README): the guides, the CLI, a legacy-code scanner and an eval harness. This post is a source reading at commit 92686ac: I cloned the repo and read README.md, src/rag/ (search.ts, bm25.ts, retrieve.ts, its README), src/cli/modern-web.ts, src/core/feature-gates.ts and the guides/ layout. Facts come from that code; interpretation is marked.
Companion tutorial: how to install and use it is on Cui.Guru: Stop your coding agent writing legacy web code.
The workflow in motion
Architecture
The README’s “How It Works” is three steps: the agent activates the skill, runs search "<query>" locally, then retrieve <guide-id> to pull the guide into its context. The search step needs no API key; the README describes an offline, zero-dependency embedding model plus BM25.
(Conceptual diagram: the CLI also handles list, legacy-scan, install, update and the two set-allow-* commands.)
Inside searchUseCases, dense and lexical rankings meet in reciprocal rank fusion:
The content side is a plain directory layout. Each use case under guides/<category>/<slug>/ has three files, per guides/CONTRIBUTING.md:
(grader.ts and the tasks files appear in the checked-out guides; CONTRIBUTING says graders are generated downstream from the expectations.)
The core design idea
The repo’s premise is that agents write legacy code because training data is full of it, so the fix is retrieval of small curated guides at the moment of need, not a bigger prompt. Three design choices follow from that, each visible in the source.
1. Asymmetric embeddings. src/rag/README.md explains that averaging about 300 words of a markdown chunk collapses documents into a narrow 0.970 cosine cone, so symmetric static embeddings score an unrelated query like “best pizza in new york” at 0.899 against <dialog>. Instead, short queries use a 256-d static lookup table (about 30 µs per query), while guide chunks are embedded at build time with a full transformer teacher model (gemini-embedding-001) and shipped as quantized Int8 vectors. The README says the static table replaces a 23.4 MB all-MiniLM-L6-v2 TensorFlow.js runtime. My reading: this is what keeps the CLI a self-contained package that works offline.
2. Dense plus lexical, fused without calibration. Dense vectors blur literal terms such as API names and acronyms; the comment in bm25.ts says a lexical ranking recovers them, and reciprocal rank fusion combines the two “without score calibration”. Chunk headers are enriched with the guide title, category and feature ids so exact platform identifiers match lexically.
3. Retrieval is where policy lives. Search stays open, so agents can discover that a guide exists. retrieve is the gate: guides about Origin Trials or single-engine “volatile” features throw an error unless .mwgrc opts in, and the error text instructs the agent not to bypass it. The README defines volatile as single-engine features shipped within the last 3 months or still stabilizing.
The loop is closed by evals. The README describes graders calibrated against golden solutions (must pass 100%) and the unmodified app (must fail 100%), then guided versus unguided agent runs. Where models already succeed unguided, content is pruned; where they struggle, guides are refined. The README’s snapshot table reports uplifts of +35pp to +41pp across three agents on its Nov 19 and Nov 20 runs; treat these as the project’s own numbers.
Code excerpts
Fusion, from src/rag/bm25.ts:
/** Reciprocal rank fusion: score(id) = Σ 1 / (k + rank), rank 1-based within each list. */
export function reciprocalRankFusion(rankings: string[][], k = DEFAULT_RRF_K): { id: string; score: number }[] {
const scores = new Map<string, number>();
for (const ranking of rankings) {
ranking.forEach((id, i) => scores.set(id, (scores.get(id) ?? 0) + 1 / (k + i + 1)));
}
return [...scores].map(([id, score]) => ({ id, score })).sort((x, y) => y.score - x.score);
}
DEFAULT_RRF_K is 60 and the BM25 constants are k1 = 1.2, b = 0.75. The fallback gate in src/rag/search.ts rejects out-of-scope queries only when both signals are empty:
const topDenseSim = dense.length > 0 ? dense[0].similarity : 0;
if (topDenseSim < minSimilarity && bm25Matches.length === 0) {
logToolResult("search_use_cases", []);
return [];
}
Because corpus and query vectors are unit length, the comment in the same file notes that cosine similarity is a plain dot product. The gate in src/rag/retrieve.ts checks each category in turn:
for (const { spec, items, ErrorClass } of gateChecks) {
if (items.length > 0 && config[spec.optInKey] !== true) {
const featureIds = items.map((f) => f.id).join(", ");
throw new ErrorClass(
formatGateMessage({
guideId: useCaseId,
featureIds,
optInKey: spec.optInKey,
cliCommand: spec.cliCommand,
headingLabel: spec.headingLabel,
guideSummary: spec.formatSummary(items as any),
verb: items.length === 1 ? "is" : "are",
riskAdjective: spec.riskAdjective,
explicitOptOut: config[spec.optInKey] === false,
}),
);
}
}
An explicit false in .mwgrc selects a stricter message: it tells the agent never to edit .mwgrc, run the opt-in command itself or read raw .md guide files from disk. After the gate, the Baseline target shapes the guide, from formatBaselineTargetBanner:
if (!normalized || normalized === "widely") {
return "";
}
For newly, limited or a year, formatBaselineTargetBanner returns a > [!IMPORTANT] block (the limited one tells the agent to skip the guide’s “Fallback strategies” section), prepended to the guide text, so the project’s browser-support policy rides along in the same context window as the advice.
A harness detail from src/cli/modern-web.ts shows the design is built around real agent behavior: output over MAX_INLINE_STDOUT_BYTES = 9500 on a non-file stdout is saved to mwg-guide-<pid>-<timestamp>.md in the system temp directory (falling back to /tmp), because src/rag/README.md says harnesses silently truncate longer tool output.
Takeaways
- Treat guidance as retrieval, not prompt text: small curated chunks fetched on demand keep token cost low.
- Embed queries and documents asymmetrically when the query encoder must be tiny; it avoids the cone collapse seen with averaged chunk vectors.
- Fuse dense and BM25 with RRF so exact API names still win, and return nothing when both signals are empty.
- Put policy in the retrieval call, not only in the prompt: gated guides cannot be retrieved without the configured opt-in. This governs guide access, not code generation; the gate text itself allows an API the user explicitly named.
- Design CLI output for the agent harness, including its truncation limits.
- Measure uplift with guided versus unguided runs, and prune what models already know.
Want an agent pipeline like this built for your team? Get in touch.
Click to load Disqus comments