feat(walkthrough): write walkthroughs in the reader's language
A guided explanation is only useful in a language the reader reads, so the panel header gets a language picker alongside the model one, defaulting to the interface language. Like the model, it is request state rather than a setting: the language travels with the read and the generation, and the one a walkthrough was written in is stored with it, so reopening a review describes what is there instead of what a fresh one would be. Only prose is translated. Hunk aliases resolve back to hunk ids and icon/importance are validated against fixed English values, so a translated one would be dropped by the normalizer — silently losing an anchor or a style. Identifiers and paths stay as they appear in the code. The language is part of the cache key, and a read now asks the cache for the exact request it was given before falling back to the pointer. Without that the panel answered a request to switch languages with the text it already had, leaving the other language unused in the cache. Alongside it: - The answer budget is derived from the resolved model instead of a flat 24k. That number was the same for a 64k-context model and for one that admits to 384k output tokens, and on the latter it was the only reason generation failed: the model spent the whole allowance reasoning and returned nothing. It is now min(96k, max(24k, a quarter of the context)) capped by the catalog's output limit, decided once so the input reserve and the request cannot drift apart. - A read no longer offers Cancel. It is a few hundred milliseconds of git with nothing to cancel, and the button flickered on every model or language change. When the panel is showing a fallback, a banner names what is on screen versus what was asked for — only once the read has settled. - The header keeps one 32px control height and drops its labels below 680px instead of squeezing them to two letters and an ellipsis. Docs and module documentation updated in every locale.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { DEFAULT_LANGUAGE, languageName } from './languages.js';
|
||||
import { MAX_CHAPTERS, MAX_CHAPTER_TITLE_CHARS, MAX_HUNKS_PER_STOP, MAX_STOPS } from './schema.js';
|
||||
|
||||
const SYSTEM = `You are writing a guided review of a code change for the engineer who is about to read it.
|
||||
@@ -24,6 +25,21 @@ Rules:
|
||||
|
||||
Respond with a single JSON object and nothing else. (Some providers refuse a structured-output request unless the word "json" appears in the request, which is why this is stated explicitly.)`;
|
||||
|
||||
// A reader who cannot follow English prose gets nothing out of a walkthrough,
|
||||
// so the output language is the reader's, not the codebase's.
|
||||
//
|
||||
// Only prose is translated. Hunk aliases are keys the server resolves back to
|
||||
// hunk ids, and `icon`/`importance` are enums the normalizer validates against
|
||||
// fixed English values — translating either produces a walkthrough that drops
|
||||
// its anchors or loses its styling, silently and completely. Identifiers taken
|
||||
// from the diff stay verbatim for the same reason a translated function name
|
||||
// would be unsearchable.
|
||||
const languageInstruction = (language) => `
|
||||
|
||||
Write all prose in ${languageName(language)}: the walkthrough title, the focus line, chapter titles and blurbs, and stop titles and prose. The reader of this review reads ${languageName(language)}.
|
||||
|
||||
Keep these in English exactly as given, regardless of the prose language: hunk aliases (h1, h2, …), the "icon" values, and the "importance" values. Keep identifiers, file paths, and API names as they appear in the code — never translate them.`;
|
||||
|
||||
const sizing = ({ fileCount, hunkCount }) => {
|
||||
const targetStops = Math.max(1, Math.min(MAX_STOPS, Math.round(hunkCount / 2.5) || 1));
|
||||
const targetChapters = hunkCount <= 4
|
||||
@@ -65,7 +81,7 @@ export const JSON_SHAPE_INSTRUCTION = `
|
||||
Return ONLY a JSON object, with no prose around it and no markdown fences, in exactly this shape:
|
||||
{"title": string, "focus": string, "chapters": [{"title": string, "icon": "bug"|"wrench"|"path"|"flask"|"doc"|"gear", "blurb": string, "stops": [{"title": string, "hunks": [string], "importance": "critical"|"normal"|"context", "prose": string}]}]}`;
|
||||
|
||||
export function buildPrompt({ digest, fileCount, hunkCount, source, previousWalkthrough }) {
|
||||
export function buildPrompt({ digest, fileCount, hunkCount, source, previousWalkthrough, language = DEFAULT_LANGUAGE }) {
|
||||
const sourceLine = source.kind === 'working-tree'
|
||||
? `Uncommitted local changes (${source.scope === 'all' ? 'staged and unstaged' : source.scope}).`
|
||||
: source.kind === 'branch'
|
||||
@@ -79,5 +95,9 @@ ${previousWalkthroughSection(previousWalkthrough)}
|
||||
Change digest:
|
||||
${JSON.stringify(digest)}`;
|
||||
|
||||
return { system: SYSTEM, prompt };
|
||||
// The default language adds nothing: the system prompt is already English, so
|
||||
// saying so would only spend context restating it.
|
||||
const system = language === DEFAULT_LANGUAGE ? SYSTEM : `${SYSTEM}${languageInstruction(language)}`;
|
||||
|
||||
return { system, prompt };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user