worktreeIsolation.ts ×13

Frontier kind: Code frontier

unlabeled · c_bb96f7742b6b

10 tests · 24678 LOC · 98 files · introduces 0 tests · 63 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
13 ranges63 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2134 ranges24678 lines · 98 files · Browse complete extent
All tests (intent)
10 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 63 introduced LOC across 13 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/shared/worktreeIsolation.ts 63 introduced LOC · 13 ranges

Open complete file

88 */
89 export function buildWorktreeAnnouncementText(branchName: string): string {
90 > return localize( worktreeIsolation.ts
91 > 'agentHost.worktreeCreated',
92 > "Created isolated worktree for branch {0}",
93 > appendEscapedMarkdownInlineCode(branchName)
94 > ) + '\n\n';
95 > }
96
97 /**
402 return workingDirectory;
403 }
405 > // Idempotent: if a worktree was already created for this session in this
406 > // process (e.g. the caller re-enters materialization after a thread
407 > // restart or a post-creation failure) reuse it rather than creating a
408 > // second branch + worktree.
409 > const already = this._createdWorktrees.get(sessionId);
410 > if (already) {
411 return already.worktree;
412 }
414 > const repositoryRoot = await this._gitService.getRepositoryRoot(workingDirectory);
415 > if (!repositoryRoot) {
416 return workingDirectory;
417 }
419 > const worktreesRoot = getWorktreesRoot(repositoryRoot);
420 > // Prefix (e.g. the user's `git.branchPrefix`) the client forwards for
421 > // worktree-isolated sessions. Prepended ahead of the built-in `agents/`
422 > // prefix when naming the branch and stripped from the worktree dir name.
423 > const worktreeBranchPrefix = typeof config[SessionConfigKey.WorktreeBranchPrefix] === 'string'
424 ? config[SessionConfigKey.WorktreeBranchPrefix] as string
425 > : undefined; worktreeIsolation.ts
426 const selectedBranch = config[SessionConfigKey.Branch] as string;
427 const { branchName, worktree, baseBranch } = await this._worktreeCreationSequencer.queue(repositoryRoot.toString(), async () => {
428 > const branchName = await this._branchNameGenerator.generateBranchName({ worktreeIsolation.ts
429 > sessionId,
430 > message: prompt,
431 > githubToken,
432 > branchPrefix: worktreeBranchPrefix,
433 > branchNameCollides: async candidate => {
434 if (await this._gitService.branchExists(repositoryRoot, candidate).catch(() => true)) {
435 return true;
438 return fileExists(candidateWorktree.fsPath);
439 },
441 > const worktree = URI.joinPath(worktreesRoot, getWorktreeName(branchName, worktreeBranchPrefix));
442 > const baseBranch = await this._resolveBranchStartPoint(repositoryRoot, selectedBranch);
443 > await fs.mkdir(worktreesRoot.fsPath, { recursive: true });
444 > await this._gitService.addWorktree(repositoryRoot, worktree, branchName, baseBranch);
445 > return { branchName, worktree, baseBranch };
446 });
447 > const worktreeIncludeFiles = Array.isArray(config[SessionConfigKey.WorktreeIncludeFiles]) worktreeIsolation.ts
448 && config[SessionConfigKey.WorktreeIncludeFiles].every(pattern => typeof pattern === 'string')
449 ? config[SessionConfigKey.WorktreeIncludeFiles] as readonly string[]
456 }
457 }
458 > this._createdWorktrees.set(sessionId, { repositoryRoot, worktree }); worktreeIsolation.ts
459 > // Queue the worktree announcement so the first turn (live) and any
460 > // subsequent restore (history) both surface the message in the chat.
461 > this._pendingFirstTurnAnnouncements.set(sessionId, buildWorktreeAnnouncementText(branchName));
462 > try {
463 > await this._writeWorktreeMetadata(sessionUri, { branchName, baseBranch, worktreePath: worktree, repositoryRoot });
464 > } catch (error) {
465 this._logService.warn(`[${this._logLabel}:${sessionId}] Failed to persist worktree branch metadata: ${errorMessage(error)}`);
466 }
467 > return worktree; worktreeIsolation.ts
468 }
469
732
733 private async _resolveBranchStartPoint(repositoryRoot: URI, selectedBranch: string): Promise<string> {
734 > const defaultBranch = await this._gitService.getDefaultBranch(repositoryRoot); worktreeIsolation.ts
735 > return defaultBranch?.name === selectedBranch
736 > ? defaultBranch.startPoint
737 : selectedBranch;
739
740 private async _writeWorktreeMetadata(sessionUri: URI, metadata: { branchName: string; baseBranch: string | undefined; worktreePath: URI; repositoryRoot: URI }): Promise<void> {
741 > const dbRef = this._sessionDataService.openDatabase(sessionUri); worktreeIsolation.ts
742 > try {
743 > const work: Promise<void>[] = [
744 > dbRef.object.setMetadata(WORKTREE_META_BRANCH, metadata.branchName),
745 > dbRef.object.setMetadata(WORKTREE_META_PATH, metadata.worktreePath.toString()),
746 > dbRef.object.setMetadata(WORKTREE_META_REPOSITORY_ROOT, metadata.repositoryRoot.toString()),
747 > ];
748 > if (metadata.baseBranch) {
749 > work.push(dbRef.object.setMetadata(META_DIFF_BASE_BRANCH, metadata.baseBranch));
750 > }
751 > await Promise.all(work);
752 > } finally {
753 > dbRef.dispose();
754 > }
755 > }
756
757 private async _readWorktreeMetadata(sessionUri: URI): Promise<{ branchName: string; worktreePath?: URI; repositoryRoot?: URI } | undefined> {