Files
orca/src/main/usage-worktree-metadata.ts
T
OrcaWin 2847bbe9e8 [comment audit] Consolidate completed code comment cleanup
Combine the completed comment cleanup from 319 stacked PRs into one change against `main`, so the full CI suite validates the combined result once. This replaces the previous audit stack; no additional audit work is included.

The change shortens redundant comments across 2,753 source and shell-snapshot files (25,235 net lines removed). Conflicts preserve current-main executable code. Runtime behavior, test assertions, directives, licenses, generated notices, SAFETY rationales, and compatibility markers are preserved. The audit tracker remains local, outside the repository.

Validation:
- Equivalent source/emitted AST and executable tokens across all 2,750 source files, with separate checks for embedded shell, SQL, JavaScript, CSS, and generated fixtures.
- Identical executable lines in the three shell snapshots; protected comments unchanged.
- Changed-code quality gate passed with no new findings.
- 358 tests passed, 2 skipped across 23 focused test files.
- `git diff --check` passed.
2026-10-23 13:15:45 -07:00

76 lines
2.3 KiB
TypeScript

import { basename } from 'node:path'
import type { Repo } from '../shared/repo-types'
import {
getRepoMainWorktreeId,
splitWorktreeId,
splitWorktreeIdForFilesystem
} from '../shared/worktree/id'
import { isFolderRepo } from '../shared/repo-kind'
import type { Store } from './persistence'
import { getRepoRoutingConnectionId } from '../shared/execution-host'
export type UsageWorktreeRef = {
worktreeId: string
path: string
displayName: string
}
function getDefaultUsageWorktreeLabel(pathValue: string): string {
return basename(pathValue)
}
export function loadKnownUsageWorktreesByRepo(
store: Pick<Store, 'getAllWorktreeMeta'>,
repos: Repo[]
): Map<string, UsageWorktreeRef[]> {
const localRepos = repos.filter((repo) => !getRepoRoutingConnectionId(repo))
const localReposById = new Map<string, Repo>()
for (const repo of localRepos) {
const repoId = repo.id
// Preserve the first match if corrupt state repeats a repo id.
if (!localReposById.has(repoId)) {
localReposById.set(repoId, repo)
}
}
const worktreesByRepo = new Map<string, UsageWorktreeRef[]>()
const seenPathsByRepo = new Map<string, Set<string>>()
for (const repo of localRepos) {
worktreesByRepo.set(repo.id, [
{
worktreeId: getRepoMainWorktreeId(repo),
path: repo.path,
displayName: repo.displayName || getDefaultUsageWorktreeLabel(repo.path)
}
])
seenPathsByRepo.set(repo.id, new Set([repo.path]))
}
// Background analytics must not spawn git scans that re-touch macOS protected folders.
for (const [worktreeId, meta] of Object.entries(store.getAllWorktreeMeta())) {
const parsed = splitWorktreeId(worktreeId)
if (!parsed) {
continue
}
const repo = localReposById.get(parsed.repoId)
if (!repo) {
continue
}
const worktreePath = isFolderRepo(repo)
? (splitWorktreeIdForFilesystem(worktreeId)?.worktreePath ?? parsed.worktreePath)
: parsed.worktreePath
const seenPaths = seenPathsByRepo.get(parsed.repoId)
if (seenPaths?.has(worktreePath)) {
continue
}
seenPaths?.add(worktreePath)
worktreesByRepo.get(parsed.repoId)?.push({
worktreeId,
path: worktreePath,
displayName: meta.displayName || getDefaultUsageWorktreeLabel(worktreePath)
})
}
return worktreesByRepo
}