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:
Bohdan Triapitsyn
2026-08-03 01:27:27 +03:00
parent e5799c0c67
commit 1d17cb87b3
39 changed files with 1027 additions and 81 deletions
@@ -33,28 +33,35 @@ let generateCalls = 0;
let releaseGeneration: (() => void) | undefined;
let lastReadModel: string | undefined;
let lastGenerateModel: string | undefined;
let lastReadLanguage: string | undefined;
let lastGenerateLanguage: string | undefined;
mock.module('@/lib/walkthrough/api', () => ({
fetchWalkthrough: async (
_directory: string,
_source: WalkthroughSource,
options: { model?: string } = {},
options: { model?: string; language?: string } = {},
) => {
lastReadModel = options.model;
lastReadLanguage = options.language;
return readResult;
},
generateWalkthrough: async (
_directory: string,
_source: WalkthroughSource,
options: { model?: string } = {},
options: { model?: string; language?: string } = {},
) => {
generateCalls += 1;
lastGenerateModel = options.model;
lastGenerateLanguage = options.language;
return new Promise<WalkthroughResult>((resolve) => {
releaseGeneration = () => resolve(finished);
});
},
cancelWalkthroughGeneration: async () => {},
// The store imports this for its progress poller. Leaving it out of the mock
// makes the whole module fail to load, which reads as an unrelated crash.
fetchWalkthroughStage: async () => null,
}));
mock.module('@/lib/runtime-switch', () => ({ getRuntimeKey: () => 'local' }));
@@ -162,3 +169,57 @@ describe('useWalkthroughStore — model selection', () => {
.toBe('anthropic/claude-haiku-4-5');
});
});
describe('useWalkthroughStore — walkthrough language', () => {
beforeEach(() => {
useWalkthroughStore.getState().reset();
readResult = result();
generateCalls = 0;
lastReadLanguage = undefined;
lastGenerateLanguage = undefined;
});
afterEach(() => {
useWalkthroughStore.getState().reset();
});
// The read carries it too: readiness is an answer about a specific request,
// and the language instruction is part of that request.
test('sends the resolved language with both the read and the generation', async () => {
await useWalkthroughStore.getState().load('/repo', SOURCE, { language: 'uk' });
await flush();
expect(lastReadLanguage).toBe('uk');
void useWalkthroughStore.getState().generate('/repo', SOURCE, { language: 'uk' });
await flush();
expect(lastGenerateLanguage).toBe('uk');
releaseGeneration?.();
await flush();
});
test('keeps an explicit choice apart per source', () => {
const branch: WalkthroughSource = { kind: 'branch', baseRef: 'main', headRef: 'feature' };
useWalkthroughStore.getState().selectLanguage('/repo', SOURCE, 'ja');
expect(useWalkthroughStore.getState().getSelectedLanguage('/repo', branch)).toBe(undefined);
expect(useWalkthroughStore.getState().getSelectedLanguage('/repo', SOURCE)).toBe('ja');
});
test('clearing the choice returns to no explicit language', () => {
useWalkthroughStore.getState().selectLanguage('/repo', SOURCE, 'ja');
useWalkthroughStore.getState().selectLanguage('/repo', SOURCE, null);
expect(useWalkthroughStore.getState().getSelectedLanguage('/repo', SOURCE)).toBe(undefined);
});
test('a re-attach after a reload still names the language it would ask for', async () => {
readResult = result({ generating: true });
await useWalkthroughStore.getState().load('/repo', SOURCE, { language: 'pl' });
await flush();
expect(lastGenerateLanguage).toBe('pl');
releaseGeneration?.();
await flush();
});
});