refactor(session-search): move the AI Vault project key to shared

The host must spell a project key exactly as the client does, so the two
sides share one function instead of two copies that can drift.
This commit is contained in:
Jinwoo-H
2026-09-18 14:00:09 -04:00
parent f24f38bd41
commit 5d2aed9bf4
3 changed files with 20 additions and 16 deletions
@@ -1,18 +1,9 @@
import type { ProjectHostSetup } from '../../../../shared/project-types'
import type { Repo } from '../../../../shared/repo-types'
import type { Worktree } from '../../../../shared/worktree/types'
import { toAiVaultProjectKey } from '../../../../shared/ai-vault-project-key'
export function toAiVaultProjectKey(
projectId: string | null | undefined,
repoId?: string | null
): string | null {
if (projectId) {
// Why: legacy projections can already use repo-prefixed project ids; wrapping
// them again would split active scope and resolved session keys.
return projectId.startsWith('repo:') ? projectId : `project:${projectId}`
}
return repoId ? `repo:${repoId}` : null
}
export { toAiVaultProjectKey } from '../../../../shared/ai-vault-project-key'
export function resolveActiveProjectKey(
activeRepo: Repo | null,
@@ -6,6 +6,7 @@ import type { ProjectHostSetupProjection } from '../../../../shared/project-host
import type { ProjectHostSetup } from '../../../../shared/project-types'
import type { Worktree } from '../../../../shared/worktree/types'
import { splitWorktreeIdForFilesystem } from '../../../../shared/worktree/id'
import { toAiVaultProjectKey } from '../../../../shared/ai-vault-project-key'
export function deriveAiVaultWorkspaceScopePaths(
activeWorktree: Pick<Worktree, 'id' | 'path' | 'priorWorktreeIds' | 'repoId'> | null,
@@ -103,11 +104,7 @@ function worktreeProjectKey(
entry: Pick<Worktree, 'projectId' | 'repoId'> | { projectId?: string | null; repoId?: string },
setup?: { projectId?: string | null; repoId?: string }
): string | null {
const projectId = entry.projectId ?? setup?.projectId ?? null
if (projectId) {
return projectId.startsWith('repo:') ? projectId : `project:${projectId}`
}
return entry.repoId ? `repo:${entry.repoId}` : null
return toAiVaultProjectKey(entry.projectId ?? setup?.projectId ?? null, entry.repoId)
}
/**
+16
View File
@@ -0,0 +1,16 @@
/**
* One spelling of "which project" for the sessions panel and for a host
* resolving a search scope, so a key minted on a client and a key matched on the
* execution host cannot drift apart.
*/
export function toAiVaultProjectKey(
projectId: string | null | undefined,
repoId?: string | null
): string | null {
if (projectId) {
// Why: legacy projections can already use repo-prefixed project ids; wrapping
// them again would split active scope and resolved session keys.
return projectId.startsWith('repo:') ? projectId : `project:${projectId}`
}
return repoId ? `repo:${repoId}` : null
}