Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .claude/docs/V1.2.1_STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,9 @@ Then pushed `v1.2.1` to `origin` at the maintainer's request. **No merge and no

**Measured**: `npm test` 1,139/1,139; ESLint 154 (unchanged); filesOver500 unchanged (`resolveEvolutionFrame`/`evolutionDirectoryOf` moved to `projectEvolutionArtifacts.ts`). Harnesses xr-mode, project-evolution (now asserts each frame loads `data<i>.json` and that no bridge file exists) and xr pass. **Not done**: live evolution still materializes snapshots with one `git show` per file and runs the directory analysis per revision; reusing the export's blob pipeline (`GitTimelineBlobAnalyzer` + worker pool) needs a payload-parity check first and is left as follow-up.

### XR bug-fix epic #72 — S11 evolution follows the checked-out history (#83) [confirmed by unit tests on real repositories] (2026-11-25, branch `claude/project-thread-kvvyg6-history`)

**What changed**: EVO-6, `listTimelineSources(maxCount, tip = 'HEAD', exclude?)` walks `git log --first-parent` of HEAD (or a range tip), never `--all`; the picker's commit list is `--branches --tags --remotes` (no stash, no notes). EVO-7, new `core/history/projectEvolutionTimeline.ts`: the Auto movie lists the whole first-parent history and thins it to `TIMELINE_SCAN_SAMPLE` = 240 spread over all of it (first and last kept), so the eligibility index and the picker cost what the old newest-240 window cost; a range is resolved by Git (`isAncestor`, `mergeBase`, `listTimelineSources(null, newer, older)`), in either order, diverging ends from their merge base; `resolveTimelineIndex` and `TIMELINE_SCAN_LIMIT` are gone; tags whose peeled object is not a commit are dropped. EVO-12, no 1000 clamp, and the timeline log is streamed through the new `core/history/gitLineStream.ts` (spawn + readline, same timeout, cancel signal and error codes as `runGit`); `countTimelineCommits` is `rev-list --first-parent --count HEAD`, 0 in an empty repository. The export prompt names the checked-out branch's history. EVO-19, `PROJECT_EVOLUTION_XR.md` rewritten for the timeline and the export.

**Measured**: new `test/analysis/gitTimeline.test.cjs` (7 tests on real repositories: stash + notes + newer branch + detached HEAD, merge as one step, 300 commits sampled from the root with an old tag as range start, range in either order and across diverging branches, tree tag not offered, 1,100 commits with latest 1,050 returned, empty repository). Behaviour change for the export: other branches are no longer exported, by design of the story.

6 changes: 6 additions & 0 deletions apps/vscode-extension/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@
- **Play** on the last frame starts the movie over instead of stopping at once, and reconnecting to the room keeps the frame you were on instead of jumping back to frame 1.
- Manual movies always play from oldest to newest, as exported movies already did, whatever order the commits were picked in. A 25th pick is refused with a message instead of being dropped without notice.
- The commit picker no longer lists the remote's default-branch alias as a branch named "origin".
- **Project evolution follows the history you have checked out.**
- The movie is now the history of the current branch from its first commit (first parent: a merge counts as one step). Before, it was every commit of every branch, so a `git stash` or a `git notes` entry could appear as a frame, and on an older checkout or a feature branch the movie played newer commits of other branches and then jumped back.
- Long histories start at the beginning. Before, only the newest 240 commits were considered, so a project with a long history never showed its first versions.
- A range now works with any branch, tag or commit the picker offers, in either order. Before, a tag older than the newest 240 commits failed with "project-evolution-range-not-found". Two ends on diverging branches start from their common ancestor.
- Tags that point at a file or a folder instead of a commit are no longer offered: they could not be used.
- Export: the Git timeline is the history of the checked-out branch, and the prompt says so. "Only the latest N commits" exports exactly N; before, N was silently cut to 1000, and a very large history could fail with "git timeline could not be listed".
- A source file of the XR chart-mapping runtime contained a raw control character typed into a string. Behaviour was correct, but the file was invisible to code search and review tools. It now uses the equivalent escape sequence; the runtime value is identical.

## [1.2.0] - 2026-07-30
Expand Down
42 changes: 34 additions & 8 deletions apps/vscode-extension/docs/features/PROJECT_EVOLUTION_XR.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ versions.
- If the analyzed target is not inside a local Git repository, the option is
disabled and explains the reason on hover/raycaster focus.
- By default, CodeXR builds an automatic timeline from older commits to newer
commits.
- Large histories are sampled to a bounded number of frames so XR playback stays
usable.
- If the working copy has uncommitted changes, it can be used as the final live
frame.
commits: the **first-parent history of the checked-out branch (HEAD)**, from
its very first commit. A merge is one step of the branch it landed on.
Stashes, notes, other branches and commits newer than the checkout are never
frames (until 1.2.1 the timeline was `git log --all`).
- The whole history is listed and spread over at most 240 candidate revisions,
first and last included, then sampled to the movie's frames (24 by default),
so a long history always starts at its beginning. Until 1.2.1 only the newest
240 commits were considered.
- A range movie is resolved by Git, not looked up in a window: any branch, tag
or commit the picker offers works as either end, in either order. Two ends on
diverging branches start from their merge base. The working copy as an end is
the last frame.
- Tags that point at a tree or a blob are not offered: they have no history.
- The movie always ends on the working copy, the branch as it stands now,
whether or not it has uncommitted changes.
- The visualization uses a single chart occupying the normal analysis table,
not the dual chart layout used by historical comparison.

Expand Down Expand Up @@ -110,12 +120,28 @@ entity:
}
```

The browser runtime, `projectEvolutionRuntime.js`, listens for the shared entity
and keeps all connected clients on the same generated movie.
Which revisions a movie can show is decided by `projectEvolutionTimeline.ts`
(automatic and range timelines) over `GitRepositoryService.listTimelineSources`,
which streams `git log --first-parent` line by line, so a very large history
cannot overflow a buffer.

The browser runtime, `projectEvolutionRuntime.js`, is assembled from the parts
listed in `templates/components/codexr/project-evolution/projectEvolutionRuntime/manifest.json`.
It listens for the shared entity and keeps all connected clients on the same
generated movie.

### Export

The export's Git timeline is the same history: the first-parent history of
HEAD. "Entire history" exports all of it, "Only the latest N commits" the
newest N, with no hidden cap (until 1.2.1 N was silently clamped to 1000). The
prompt says how many commits the checked-out branch has and that other
branches, stashes and notes are not exported.

## Initial Limits

- Version units are local Git commits.
- Version units are local Git commits of the checked-out branch's first-parent
history.
- "Pushes" are represented by commits already present in the local repository.
- GitHub, GitLab or other hosting provider APIs are not queried in this version.
- Frames are precalculated before playback to avoid analysis work during the
Expand Down
80 changes: 80 additions & 0 deletions apps/vscode-extension/src/core/history/gitLineStream.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import * as childProcess from 'child_process';
import * as readline from 'readline';

/**
* Runs `git -C cwd ...args` and hands stdout to `onLine` one line at a time
* (EVO-12). `execFile` buffers the whole output and fails past its
* `maxBuffer`, which a full `git log` of a very large history reaches; a
* stream has no such ceiling. Same timeout and cancel signal as the buffered
* runner, and the same error codes.
*/
export function streamGitLines(
cwd: string,
args: string[],
onLine: (line: string) => void,
options: { timeoutMs: number; signal?: AbortSignal; describeFailure: (error: unknown) => Error },
): Promise<void> {
return new Promise((resolve, reject) => {
let settled = false;
const finish = (error?: unknown) => {
if (settled) {
return;
}
settled = true;
clearTimeout(timer);
options.signal?.removeEventListener('abort', onAbort);
if (error === undefined) {
resolve();
} else {
reject(options.describeFailure(error));
}
};
const child = childProcess.spawn('git', ['-C', cwd, ...args], {
windowsHide: true,
stdio: ['ignore', 'pipe', 'pipe'],
});
const timer = setTimeout(() => {
child.kill();
finish(Object.assign(new Error('git command timed out'), { killed: true }));
}, options.timeoutMs);
const onAbort = () => {
child.kill();
finish(Object.assign(new Error('git command cancelled'), { name: 'AbortError' }));
};
if (options.signal?.aborted) {
onAbort();
return;
}
options.signal?.addEventListener('abort', onAbort, { once: true });

let stderr = '';
child.stderr.setEncoding('utf8');
child.stderr.on('data', (chunk: string) => {
// Only the head of stderr is kept: it is for the error message.
if (stderr.length < 4096) {
stderr += chunk;
}
});
const lines = readline.createInterface({ input: child.stdout, crlfDelay: Infinity });
lines.on('line', (line) => {
if (settled || !line) {
return;
}
try {
onLine(line);
} catch (error) {
child.kill();
finish(error);
}
});
child.on('error', (error) => finish(error));
// 'close' fires after stdout ended, so every line was delivered.
child.on('close', (code) => {
if (code === 0) {
finish();
} else {
finish(new Error(`git exited with code ${code}: ${stderr.trim()}`));
}
});
});
}
146 changes: 93 additions & 53 deletions apps/vscode-extension/src/core/history/gitRepositoryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
shouldIgnoreDirectoryName,
} from '../analysis/watchers/analysisFilePolicy';
import { currentLaunchSignal } from '../analysis/launch/launchControl';
import { streamGitLines } from './gitLineStream';
import type {
ComparisonSource,
GitReferenceType,
Expand Down Expand Up @@ -79,12 +80,16 @@ export class GitRepositoryService {
])).stdout;
const tagOutput = (await this.runGit(repositoryRoot, [
'for-each-ref',
'--format=%(refname)%00%(*objectname)%00%(objectname)%00%(refname:short)%00%(*committerdate:short)%00%(committerdate:short)%00%(*committerdate:unix)%00%(committerdate:unix)',
'--format=%(refname)%00%(*objectname)%00%(objectname)%00%(refname:short)%00%(*committerdate:short)%00%(committerdate:short)%00%(*committerdate:unix)%00%(committerdate:unix)%00%(*objecttype)%00%(objecttype)',
'refs/tags',
])).stdout;
const commitOutput = (await this.runGit(repositoryRoot, [
'log',
'--all',
// Branches, tags and remotes, not `--all`: `--all` also walks
// refs/stash and refs/notes, whose commits are not history (EVO-6).
'--branches',
'--tags',
'--remotes',
'--max-count=50',
'--date=short',
'--format=%H%x00%ad%x00%ct%x00%P%x00%s',
Expand Down Expand Up @@ -146,55 +151,56 @@ export class GitRepositoryService {
return { ...source, commitSha: resolved };
}

public async listTimelineSources(maxCount: number | null = 200): Promise<ComparisonSource[]> {
/**
* Oldest first: the first-parent history of `tip` (HEAD), never `--all`
* (EVO-6), so stashes, notes and other branches are never frames. `exclude`
* stops the walk (a range start). No clamp, and streamed (EVO-12).
*/
public async listTimelineSources(
maxCount: number | null = 200,
tip = 'HEAD',
exclude?: string,
): Promise<ComparisonSource[]> {
const repositoryRoot = await this.resolveRepositoryRoot();
const limitArguments = maxCount === null
? []
: [`--max-count=${Math.max(1, Math.min(1000, Math.floor(maxCount)))}`];
const commitLines = (await this.runGit(repositoryRoot, [
if (!await this.revisionExists(repositoryRoot, tip)) {
return [];
}
const limitArguments = maxCount === null ? [] : [`--max-count=${Math.max(1, Math.floor(maxCount))}`];
const sources: ComparisonSource[] = [];
await streamGitLines(repositoryRoot, [
'log',
'--all',
'--first-parent',
'--reverse',
...limitArguments,
'--date=short',
'--format=%H%x00%ad%x00%ct%x00%P%x00%s',
])).stdout.split(/\r?\n/).filter(Boolean);
const sources: ComparisonSource[] = [];
for (const line of commitLines) {
const [commitSha, date, committerUnix, parents, subject] = line.split('\0');
if (!this.isCommitSha(commitSha)) {
continue;
tip,
...(exclude ? [`^${exclude}`] : []),
'--',
], (line) => {
const source = this.parseCommitLine(line);
if (source) {
sources.push(source);
}
const parentCount = this.countParents(parents);
sources.push(this.createGitSource(
'commit',
commitSha,
commitSha.slice(0, 8),
commitSha,
`${date || ''} ${subject || ''}`.trim(),
parentCount > 1 ? 'merge' : 'commit',
parentCount,
date,
committerUnix,
));
}
}, { timeoutMs: GIT_COMMAND_TIMEOUT_MS, signal: currentLaunchSignal(), describeFailure: describeGitFailure });
for (const source of sources) {
this.sourceById.set(source.id, source);
}
return sources;
}

/**
* Lightweight export preflight. Unlike listTimelineSources(), this does
* not enumerate or materialize commits; it only tells the user how much
* work the complete offline timeline will require.
*/
/** Export preflight: the commits listTimelineSources(null) would list. */
public async countTimelineCommits(): Promise<number> {
const repositoryRoot = await this.resolveRepositoryRoot();
if (!await this.revisionExists(repositoryRoot, 'HEAD')) {
return 0;
}
const rawCount = (await this.runGit(repositoryRoot, [
'rev-list',
'--all',
'--first-parent',
'--count',
'HEAD',
'--',
])).stdout.trim();
const count = Number.parseInt(rawCount, 10);
if (!Number.isFinite(count) || count < 0) {
Expand All @@ -203,6 +209,28 @@ export class GitRepositoryService {
return count;
}

/** Whether `ancestor` is reachable from `descendant` (a commit is its own ancestor). */
public async isAncestor(ancestor: string, descendant: string): Promise<boolean> {
return this.isCommitSha(ancestor) && this.isCommitSha(descendant) && await this.tryRunGit(
await this.resolveRepositoryRoot(), ['merge-base', '--is-ancestor', ancestor, descendant],
) !== null;
}

/** The best common ancestor of two commits, or null for unrelated histories. */
public async mergeBase(first: string, second: string): Promise<string | null> {
const base = this.isCommitSha(first) && this.isCommitSha(second)
? (await this.tryRunGit(await this.resolveRepositoryRoot(), ['merge-base', first, second]))?.stdout.trim()
: '';
return base && this.isCommitSha(base) ? base : null;
}

/** The commit HEAD points at, or null in an empty repository. */
public async resolveHeadCommit(): Promise<string | null> {
const head = await this.tryRunGit(await this.resolveRepositoryRoot(), ['rev-parse', '--verify', '--quiet', 'HEAD^{commit}']);
const sha = head?.stdout.trim() ?? '';
return this.isCommitSha(sha) ? sha : null;
}

public async resolveSourcesInChronologicalOrder(sourceIds: string[]): Promise<ComparisonSource[]> {
if (!Array.isArray(sourceIds) || sourceIds.length === 0) {
return [];
Expand Down Expand Up @@ -476,8 +504,13 @@ export class GitRepositoryService {
private parseTagRefs(stdout: string): ComparisonSource[] {
const sources: ComparisonSource[] = [];
for (const line of splitGitLines(stdout)) {
const [fullRef, peeledSha, objectSha, shortName, peeledDate, tagDate, peeledUnix, tagUnix] = line.split('\0');
const [fullRef, peeledSha, objectSha, shortName, peeledDate, tagDate, peeledUnix, tagUnix, peeledType, objectType] = line.split('\0');
const commitSha = peeledSha || objectSha;
// A tag on a tree or a blob has no history to show and cannot be
// resolved as a commit: it is not offered (EVO-7).
if ((peeledType || objectType) !== 'commit') {
continue;
}
if (!fullRef || !this.isCommitSha(commitSha) || !shortName) {
continue;
}
Expand All @@ -488,26 +521,29 @@ export class GitRepositoryService {

/** Recent commits from `git log`, merges typed as such. */
private parseCommitLog(stdout: string): ComparisonSource[] {
const sources: ComparisonSource[] = [];
for (const line of splitGitLines(stdout)) {
const [commitSha, date, committerUnix, parents, subject] = line.split('\0');
if (!this.isCommitSha(commitSha)) {
continue;
}
const parentCount = this.countParents(parents);
sources.push(this.createGitSource(
'commit',
commitSha,
commitSha.slice(0, 8),
commitSha,
`${date || ''} ${subject || ''}`.trim(),
parentCount > 1 ? 'merge' : 'commit',
parentCount,
date,
committerUnix,
));
return splitGitLines(stdout)
.map((line) => this.parseCommitLine(line))
.filter((source): source is ComparisonSource => source !== null);
}

/** One `%H %ad %ct %P %s` log line (NUL-separated) as a commit source. */
private parseCommitLine(line: string): ComparisonSource | null {
const [commitSha, date, committerUnix, parents, subject] = line.split('\0');
if (!this.isCommitSha(commitSha)) {
return null;
}
return sources;
const parentCount = this.countParents(parents);
return this.createGitSource(
'commit',
commitSha,
commitSha.slice(0, 8),
commitSha,
`${date || ''} ${subject || ''}`.trim(),
parentCount > 1 ? 'merge' : 'commit',
parentCount,
date,
committerUnix,
);
}

private createGitSource(
Expand Down Expand Up @@ -563,6 +599,10 @@ export class GitRepositoryService {
return relativePath.split(path.sep).join('/');
}

private async revisionExists(repositoryRoot: string, revision: string): Promise<boolean> {
return (await this.tryRunGit(repositoryRoot, ['rev-parse', '--verify', '--quiet', `${revision}^{commit}`])) !== null;
}

private async gitObjectExists(repositoryRoot: string, objectSpec: string): Promise<boolean> {
try {
await this.runGit(repositoryRoot, ['cat-file', '-e', objectSpec]);
Expand Down
Loading
Loading