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:
@@ -56,6 +56,11 @@ other runtime API.
|
||||
stays at the default overruns the context, and the failure looks like a
|
||||
truncation bug rather than a budgeting one. `describeSmallModel` takes
|
||||
`outputReserveTokens` so readiness checks agree with what generation will do.
|
||||
It may be a **function** of `{ contextTokens, outputTokenLimit }` for callers
|
||||
that want as much answer room as the resolved model allows — they cannot name
|
||||
a number before knowing which model they got. The resolved value comes back as
|
||||
`outputTokens`, which is what the caller should then request, so the reserve
|
||||
and the request are the same number by construction.
|
||||
- Reasoning models can spend the entire output budget thinking and return
|
||||
nothing. That case (empty content with `finish_reason: 'length'`, or content
|
||||
empty while `reasoning_content` is populated) throws with
|
||||
|
||||
@@ -205,6 +205,18 @@ export function listAuthenticatedProviders() {
|
||||
* proxies especially), and treating "unknown" as "unsupported" would hide
|
||||
* models that work fine.
|
||||
*/
|
||||
/**
|
||||
* The reserve, resolved against the model that was actually picked.
|
||||
*
|
||||
* A caller that wants "as much answer room as this model allows" cannot state a
|
||||
* number up front — it does not know which model it will get. Passing a
|
||||
* function lets it decide once the limits are known, and keeps the reserve and
|
||||
* the eventual request the same number by construction.
|
||||
*/
|
||||
const resolveReserveTokens = (outputReserveTokens, limits) => (
|
||||
typeof outputReserveTokens === 'function' ? outputReserveTokens(limits) : outputReserveTokens
|
||||
);
|
||||
|
||||
export async function describeSmallModel({ directory, preferredProviderID, preferredModelID, outputReserveTokens, overrideModel } = {}) {
|
||||
const auth = readAuthFile();
|
||||
const catalog = await getModelCatalog().catch(() => ({}));
|
||||
@@ -224,11 +236,20 @@ export async function describeSmallModel({ directory, preferredProviderID, prefe
|
||||
if (!resolved) return resolved;
|
||||
|
||||
const entry = catalog?.[resolved.providerID]?.models?.[resolved.modelID];
|
||||
const { maxChars, contextTokens, contextKnown } = getModelInputCharBudget({
|
||||
const outputTokenLimit = Number(entry?.limit?.output) > 0 ? Number(entry.limit.output) : null;
|
||||
// Two passes: the first only to learn the context, which a caller-supplied
|
||||
// reserve function needs before it can answer.
|
||||
const { contextTokens, contextKnown } = getModelInputCharBudget({
|
||||
catalog,
|
||||
providerID: resolved.providerID,
|
||||
modelID: resolved.modelID,
|
||||
outputReserveTokens,
|
||||
});
|
||||
const reserveTokens = resolveReserveTokens(outputReserveTokens, { contextTokens, outputTokenLimit });
|
||||
const { maxChars } = getModelInputCharBudget({
|
||||
catalog,
|
||||
providerID: resolved.providerID,
|
||||
modelID: resolved.modelID,
|
||||
outputReserveTokens: reserveTokens,
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -236,7 +257,10 @@ export async function describeSmallModel({ directory, preferredProviderID, prefe
|
||||
inputCharBudget: maxChars,
|
||||
contextTokens,
|
||||
contextKnown,
|
||||
// What the caller should ask for, so the request and the reserve above
|
||||
// cannot drift apart.
|
||||
outputTokens: Number(reserveTokens) > 0 ? Number(reserveTokens) : null,
|
||||
structuredOutput: typeof entry?.structured_output === 'boolean' ? entry.structured_output : null,
|
||||
outputTokenLimit: Number(entry?.limit?.output) > 0 ? Number(entry.limit.output) : null,
|
||||
outputTokenLimit,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -214,6 +214,29 @@ describe('output budget and input reserve', () => {
|
||||
|
||||
expect(described.inputCharBudget).toBe(304_000);
|
||||
});
|
||||
|
||||
// A caller that wants "as much room as this model allows" cannot name a
|
||||
// number before knowing which model it got, so it hands over the decision.
|
||||
it('lets the reserve be decided from the resolved model\'s limits', async () => {
|
||||
readConfigLayers.mockReturnValue({ mergedConfig: { small_model: 'anthropic/roomy' } });
|
||||
|
||||
const described = await describeSmallModel({
|
||||
directory: '/proj',
|
||||
outputReserveTokens: ({ contextTokens, outputTokenLimit }) => Math.min(contextTokens / 10, outputTokenLimit),
|
||||
});
|
||||
|
||||
// 100k context, 8k output limit -> 8k reserved, leaving 92k tokens.
|
||||
expect(described.outputTokens).toBe(8_000);
|
||||
expect(described.inputCharBudget).toBe(92_000 * 4);
|
||||
});
|
||||
|
||||
it('reports the reserve it used so the caller can request the same number', async () => {
|
||||
readConfigLayers.mockReturnValue({ mergedConfig: { small_model: 'anthropic/unlisted' } });
|
||||
|
||||
const described = await describeSmallModel({ directory: '/proj', outputReserveTokens: 24_000 });
|
||||
|
||||
expect(described.outputTokens).toBe(24_000);
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
|
||||
Reference in New Issue
Block a user