feat(walkthrough): guided AI walkthrough for diffs, branches, and PRs (#2572)

A diff is ordered by file path, which is almost never the order in which a
change makes sense. This adds a Walkthrough surface that reorders it: the model
groups related hunks into stops, explains what each group changes about
behavior, and orders the stops so each builds on the last. It explains and
orders; judging code stays with the existing Review action.

Reviews uncommitted work (all, staged, unstaged), a branch against its base, or
a pull request. Generation is always user-initiated — nothing runs on a timer,
on a file change, or as a side effect of opening a panel.

Invariants worth preserving:

- Hunk identity is derived on the server and only there. Ids are content
  hashes, so an anchor that no longer resolves is proof the code it described
  changed, and staleness needs no heuristics. The client matches ids to ids and
  never recomputes them; two implementations would have to agree forever.
- The digest is never truncated. A diff that does not fit the model's context
  is refused with an actionable reason, because a walkthrough written against
  half a diff reads as confident and is wrong.
- Nothing disappears. Lockfiles and other generated output are excluded from
  the model's input by name — never by size — and everything no stop covers is
  listed at the end, so "have I seen all of it" stays answerable.
- Cost is explicit. Results are content-addressed, so returning the working
  tree to an earlier state costs nothing; generation outlives its request, so a
  refresh detaches the client rather than discarding paid-for work, and only an
  explicit cancel stops it.

Supporting changes to shared modules:

- git: expose the existing getRangeDiff as GET /api/git
  listUntrackedPaths and getUntrackedDiffs. The latter resolve the repository
  once for a batch instead of per file, taking a panel
  ~340ms on an 80-file working tree.
- small-model: structured output across four wire forma
  and abort signal, and an onOverflow policy so an oversized prompt fails
  loudly instead of being silently clipped. A provider
  remembered so the prompt-side fallback goes first next time.
- models.dev metadata: surface structured_output as tri
  false blocks a model, a missing field does not, because the catalog omits it
  for roughly half of all models.

Desktop and tablet only: VS Code serves Git through its
these routes, and the mobile shell does not consume the surface registry.

Docs: packages/docs walkthrough page in English and all eight locales.
This commit is contained in:
Bohdan Triapitsyn
2026-08-02 16:22:55 +03:00
committed by GitHub
parent b1ec34162e
commit 34d0ff7383
99 changed files with 7316 additions and 53 deletions
+106
View File
@@ -0,0 +1,106 @@
import { runtimeFetch } from '@/lib/runtime-fetch';
import {
WalkthroughError,
type WalkthroughResult,
type WalkthroughSource,
type WalkthroughStage,
} from './types';
const BASE = '/api/walkthrough';
interface ErrorPayload {
error?: unknown;
code?: unknown;
model?: unknown;
requiredChars?: unknown;
availableChars?: unknown;
}
// An authoritative read that fails must never look like "there is nothing
// here" — the caller would clear a perfectly good walkthrough off the screen.
const throwFromResponse = async (response: Response, fallback: string): Promise<never> => {
const payload = (await response.json().catch(() => null)) as ErrorPayload | null;
throw new WalkthroughError(typeof payload?.error === 'string' ? payload.error : fallback, {
code: typeof payload?.code === 'string' ? (payload.code as WalkthroughError['code']) : undefined,
model: (payload?.model as WalkthroughResult['model']) ?? undefined,
requiredChars: typeof payload?.requiredChars === 'number' ? payload.requiredChars : undefined,
availableChars: typeof payload?.availableChars === 'number' ? payload.availableChars : undefined,
});
};
export async function fetchWalkthrough(
directory: string,
source: WalkthroughSource,
options: { model?: string; signal?: AbortSignal } = {}
): Promise<WalkthroughResult> {
const response = await runtimeFetch(BASE, {
query: {
directory,
source: JSON.stringify(source),
...(options.model ? { model: options.model } : {}),
},
signal: options.signal,
});
if (!response.ok) {
return throwFromResponse(response, 'Failed to load walkthrough');
}
return response.json();
}
export async function generateWalkthrough(
directory: string,
source: WalkthroughSource,
options: { force?: boolean; model?: string; signal?: AbortSignal } = {}
): Promise<WalkthroughResult> {
const response = await runtimeFetch(`${BASE}/generate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
directory,
source,
force: options.force === true,
...(options.model ? { model: options.model } : {}),
}),
signal: options.signal,
});
if (!response.ok) {
return throwFromResponse(response, 'Failed to generate walkthrough');
}
return response.json();
}
/**
* Stop a running generation. Explicit, because merely leaving the page must not
* throw away work the user is paying for.
*/
export async function cancelWalkthroughGeneration(
directory: string,
source: WalkthroughSource
): Promise<void> {
const response = await runtimeFetch(`${BASE}/cancel`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ directory, source }),
});
if (!response.ok) {
await throwFromResponse(response, 'Failed to cancel walkthrough generation');
}
}
/**
* Current stage of a running generation. Reads server memory only, so this is
* safe to poll — unlike the full read, which re-runs the whole git pipeline.
*/
export async function fetchWalkthroughStage(
directory: string,
source: WalkthroughSource,
signal?: AbortSignal
): Promise<WalkthroughStage | null> {
const response = await runtimeFetch(`${BASE}/progress`, {
query: { directory, source: JSON.stringify(source) },
signal,
});
if (!response.ok) return null;
const payload = (await response.json().catch(() => null)) as { stage?: unknown } | null;
return typeof payload?.stage === 'string' ? (payload.stage as WalkthroughStage) : null;
}