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
1 change: 0 additions & 1 deletion config/max-lines-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ inline src/renderer/src/runtime/web-session-tabs-sync.ts
inline src/renderer/src/store/slices/agent-status.ts
inline src/renderer/src/store/slices/browser.ts
inline src/renderer/src/store/slices/diffComments.ts
inline src/renderer/src/store/slices/github.ts
inline src/renderer/src/store/slices/hosted-review.ts
inline src/renderer/src/store/slices/jira.ts
inline src/renderer/src/store/slices/linear.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { cn } from '@/lib/utils'
import { callRuntimeRpc, getActiveRuntimeTarget } from '@/runtime/runtime-rpc-client'
import { useAppStore } from '@/store'
import { useMountedRef } from '@/hooks/useMountedRef'
import { projectViewCacheKey } from '@/store/slices/github'
import { projectViewCacheKey } from '@/store/github/cache-identity'
import type {
GitHubIssueType,
GitHubProjectFieldMutationValue,
Expand Down
9 changes: 4 additions & 5 deletions src/renderer/src/components/right-sidebar/ChecksPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ import {
import { useAppStore, type AppState } from '@/store'
import {
buildGitHubPRRefreshStateClearToken,
getGitHubPRRefreshStateExpiryAt,
mergePRCommentIntoList,
prChecksCacheSuffix,
prCommentsCacheSuffix
} from '@/store/slices/github'
getGitHubPRRefreshStateExpiryAt
} from '@/store/github/pr-refresh-state'
import { mergePRCommentIntoList } from '@/store/github/pr-comment-cache'
import { prChecksCacheSuffix, prCommentsCacheSuffix } from '@/store/github/cache-identity'
import { getGitHubPRCacheKey, getGitHubRepoCacheKey } from '@/store/slices/github-cache-key'
import { useActiveWorktree, useRepoById } from '@/store/selectors'
import { useChecksPanelTerminalWorktree } from './use-checks-panel-terminal-worktree'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { HostedReviewInfo } from '../../../../shared/hosted-review'
import { folderWorkspaceKey, worktreeWorkspaceKey } from '../../../../shared/workspace-scope'
import { getHostedReviewCacheKey } from '@/store/slices/hosted-review'
import { getGitHubRepoCacheKey } from '@/store/slices/github-cache-key'
import { prChecksCacheSuffix } from '@/store/slices/github'
import { prChecksCacheSuffix } from '@/store/github/cache-identity'

type MockStoreState = {
activeWorktreeId: string | null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it, vi } from 'vitest'
import type { PRRefreshState } from '@/store/slices/github'
import type { PRRefreshState } from '@/store/github/pr-refresh-state'
import {
buildChecksPanelPRRefreshBreadcrumbData,
recordChecksPanelPRRefreshBreadcrumb
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { recordRendererCrashBreadcrumb } from '@/lib/crash-diagnostics'
import { getGitHubPRRefreshStateExpiryAt, type PRRefreshState } from '@/store/slices/github'
import {
getGitHubPRRefreshStateExpiryAt,
type PRRefreshState
} from '@/store/github/pr-refresh-state'
import type {
CrashReportBreadcrumbData,
CrashReportDetailValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
getGitHubRepoCacheKey,
getLegacyGitHubPRCacheKey
} from '@/store/slices/github-cache-key'
import { prChecksCacheSuffix } from '@/store/slices/github'
import { prChecksCacheSuffix } from '@/store/github/cache-identity'
import {
buildParentPrChecksProjection,
getParentPrChecksRefreshIdentity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getWorktreeCardPrDisplay } from '@/components/sidebar/worktree-card-pr-
import { getWorktreeGitIdentityDisplay } from '@/lib/worktree-git-identity-display'
import { getGitHubRepoCacheKey } from '@/store/slices/github-cache-key'
import { getHostedReviewCacheKey, linkedReviewHintKey } from '@/store/slices/hosted-review'
import { prChecksCacheSuffix } from '@/store/slices/github'
import { prChecksCacheSuffix } from '@/store/github/cache-identity'
import {
PARENT_PR_CHECKS_GROUP_LABELS,
PARENT_PR_CHECKS_GROUP_ORDER,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getWorktreeGitIdentityDisplay } from '@/lib/worktree-git-identity-display'
import { useAppStore } from '@/store'
import { getGitHubPRCacheKey } from '@/store/slices/github-cache-key'
import { issueCacheKey as getIssueCacheKey } from '@/store/slices/github'
import { issueCacheKey as getIssueCacheKey } from '@/store/github/cache-identity'
import { getHostedReviewCacheKey } from '@/store/slices/hosted-review'
import { hostedReviewInfoFromGitHubPRInfo } from '../../../../shared/hosted-review-github'
import type { HostedReviewInfo } from '../../../../shared/hosted-review'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useMemo, useRef, useState } from 'react'
import { useAppStore } from '@/store'
import { parseGitHubIssueOrPRNumber } from '@/lib/github-links'
import { issueCacheKey as getIssueCacheKey } from '@/store/slices/github'
import { issueCacheKey as getIssueCacheKey } from '@/store/github/cache-identity'
import { useMountedRef } from '@/hooks/useMountedRef'
import { findIndexedWorktreeOwner } from '@/lib/worktree-runtime-owner-index'
import { buildLinearIssueUrl, parseLinearIssueInput } from '../../../../shared/linear/links'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import {
getWorktreeOnHostFromState
} from '../../store/selectors'
import { getHostedReviewCacheKey } from '../../store/slices/hosted-review'
import { issueCacheKey as getIssueCacheKey } from '../../store/slices/github'
import { issueCacheKey as getIssueCacheKey } from '../../store/github/cache-identity'
import { findRepoForHost } from '@/store/slices/repo-host-identity'
import {
getSelectedDeletableWorkspaceRows,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { describe, expect, it } from 'vitest'
import { shallow } from 'zustand/shallow'

import { workItemsCacheKey, type CacheEntry } from '@/store/slices/github'
import { workItemsCacheKey } from '@/store/github/cache-identity'
import type { CacheEntry } from '@/store/github/cache-model'
import type { GitHubWorkItem } from '../../../shared/github/work-item-types'
import type { LinearIssue } from '../../../shared/linear/issue-types'
import type { LinearCollectionResult } from '../../../shared/linear/workspace-types'
Expand Down
12 changes: 6 additions & 6 deletions src/renderer/src/components/task-page-cache-selectors.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
workItemsCacheKey,
type CacheEntry,
type WorkItemsCacheError,
type WorkItemsCacheSources
} from '@/store/slices/github'
import { workItemsCacheKey } from '@/store/github/cache-identity'
import type {
CacheEntry,
WorkItemsCacheError,
WorkItemsCacheSources
} from '@/store/github/cache-model'
import type { GitHubWorkItem } from '../../../shared/github/work-item-types'
import {
taskPageWorkItemKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CacheEntry } from '@/store/slices/github'
import type { CacheEntry } from '@/store/github/cache-model'
import {
getTaskSourceCacheScope,
type TaskSourceContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CacheEntry } from '@/store/slices/github'
import type { CacheEntry } from '@/store/github/cache-model'
import type { LinearIssue } from '../../../shared/linear/issue-types'
import type { LinearCollectionResult } from '../../../shared/linear/workspace-types'
import { sortedStrings } from './task-page-work-item-signatures'
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/lib/worktree-palette-document.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getWorktreeHostIdentity } from '../../../shared/worktree/host-qualified-identity'
import { getRepoExecutionHostId, LOCAL_EXECUTION_HOST_ID } from '../../../shared/execution-host'
import { issueCacheKey as getIssueCacheKey } from '@/store/slices/github'
import { issueCacheKey as getIssueCacheKey } from '@/store/github/cache-identity'
import { buildPaletteDocument, type PaletteDocument } from './palette-match/palette-document'
import type { PaletteComposedEvidence } from './palette-match/evidence-composer'
import {
Expand Down
227 changes: 227 additions & 0 deletions src/renderer/src/store/github/cache-identity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
import { githubRepoIdentityKey } from '../../../../shared/github/repository-identity-key'
import { githubProjectIdentityKey } from '../../../../shared/github/project-identity'
import type { PRCheckDetail } from '../../../../shared/github/check-types'
import type { GitHubOwnerRepo } from '../../../../shared/github/pull-request-types'
import type { GlobalSettings } from '../../../../shared/global-settings-types'
import type { GetProjectViewTableArgs } from '../../../../shared/github/project-request-types'
import type { TaskSourceContext } from '../../../../shared/task-source-context'
import { getTaskSourceCacheScope } from '../../../../shared/task-source-context'
import {
LOCAL_EXECUTION_HOST_ID,
normalizeExecutionHostId
} from '../../../../shared/execution-host'
import { getGitHubPRCacheKey, getGitHubRepoCacheKey } from '../slices/github-cache-key'
import type { AppState } from '../types'
import { getActiveRuntimeTarget } from '../../runtime/runtime-rpc-client'
import type { CacheEntry } from './cache-model'

function queryOverrideKeyPart(queryOverride: string | undefined): string {
return queryOverride === undefined ? '' : `:q=${queryOverride}`
}

export function projectViewCacheKey(
ownerType: GetProjectViewTableArgs['ownerType'],
owner: string,
projectNumber: number,
resolvedViewId: string,
queryOverride?: string,
sourceScope = 'local',
host?: string
): string {
const projectKey = githubProjectIdentityKey({ ownerType, owner, number: projectNumber, host })
return `github-project:${sourceScope}:${projectKey}:${resolvedViewId}${queryOverrideKeyPart(queryOverride)}`
}

export function projectViewRequestKey(args: GetProjectViewTableArgs, sourceScope: string): string {
const selector = args.viewId
? `id:${args.viewId}`
: args.viewNumber !== undefined
? `num:${args.viewNumber}`
: args.viewName
? `name:${args.viewName}`
: 'default'
const projectKey = githubProjectIdentityKey({
ownerType: args.ownerType,
owner: args.owner,
number: args.projectNumber,
host: args.host
})
return `${sourceScope}:${projectKey}:${selector}${queryOverrideKeyPart(args.queryOverride)}`
}

export function projectViewSourceScope(settings: AppState['settings']): string {
const target = getActiveRuntimeTarget(settings)
return target.kind === 'environment' ? `runtime:${target.environmentId}` : 'local'
}

export function settingsForProjectViewCacheKey(
settings: AppState['settings'],
cacheKey: string
): Pick<NonNullable<AppState['settings']>, 'activeRuntimeEnvironmentId'> {
const runtimeMatch = /^github-project:runtime:([^:]+):/.exec(cacheKey)
return runtimeMatch
? { ...settings, activeRuntimeEnvironmentId: runtimeMatch[1] }
: { ...settings, activeRuntimeEnvironmentId: null }
}

export function workItemsCacheKey(
repoId: string,
limit: number,
query: string,
executionHostId?: string | null
): string {
const scope = executionHostId?.trim() ?? ''
const hostId = normalizeExecutionHostId(scope)
const owner = `${repoId}::${limit}::${query}`
if (hostId) {
return hostId !== LOCAL_EXECUTION_HOST_ID ? `${hostId}::${owner}` : owner
}
return scope ? `${scope}::${owner}` : owner
}

export function workItemsInflightRequestKey(
cacheKey: string,
target: { kind: 'environment'; environmentId: string; runtimeRepoId: string } | { kind: 'local' }
): string {
const targetPart =
target.kind === 'environment' ? `env:${target.environmentId}:${target.runtimeRepoId}` : 'local'
return `${cacheKey}::${targetPart}`
}

export function issueCacheKey(
repoPath: string,
repoId: string | undefined,
issueNumber: number | string,
settings?: Pick<GlobalSettings, 'activeRuntimeEnvironmentId'> | null,
connectionId?: string | null,
executionHostId?: string | null,
hasRepoOwner = false
): string {
return getGitHubRepoCacheKey(
repoPath,
repoId,
String(issueNumber),
settings,
connectionId,
executionHostId,
hasRepoOwner
)
}

export function runtimeScopedRepoCacheKey(
repoPath: string,
repoId: string | undefined,
suffix: string,
settings?: AppState['settings'],
connectionId?: string | null,
executionHostId?: string | null,
hasRepoOwner = false
): string {
return getGitHubRepoCacheKey(
repoPath,
repoId,
suffix,
settings,
connectionId,
executionHostId,
hasRepoOwner
)
}

export function sourceScopedRepoCacheKey(
repoPath: string,
repoId: string | undefined,
suffix: string,
settings?: AppState['settings'],
connectionId?: string | null,
executionHostId?: string | null,
sourceContext?: TaskSourceContext | null,
hasRepoOwner = false
): string {
if (sourceContext?.provider === 'github') {
return `${getTaskSourceCacheScope(sourceContext)}::${repoId ?? repoPath}::${suffix}`
}
return runtimeScopedRepoCacheKey(
repoPath,
repoId,
suffix,
settings,
connectionId,
executionHostId,
hasRepoOwner
)
}

export function prCacheKey(
repoPath: string,
repoId: string | undefined,
branch: string,
settings?: AppState['settings'],
connectionId?: string | null,
executionHostId?: string | null,
hasRepoOwner = false
): string {
return getGitHubPRCacheKey(
repoPath,
repoId,
branch,
settings,
connectionId,
executionHostId,
hasRepoOwner
)
}

export function repoCacheKeyPrefixes(repoId: string, repoPath?: string): string[] {
const prefixes = [`${repoId}::`]
if (repoPath && repoPath !== repoId) {
prefixes.push(`${repoPath}::`)
}
return prefixes
}

export function matchesRepoCacheKey(key: string, prefixes: readonly string[]): boolean {
return prefixes.some((prefix) => key.startsWith(prefix))
}

export function evictRepoCacheEntries<T>(
cache: Record<string, CacheEntry<T>>,
prefixes: readonly string[]
): { cache: Record<string, CacheEntry<T>>; evicted: boolean } {
let next: Record<string, CacheEntry<T>> | null = null
for (const key of Object.keys(cache)) {
if (!matchesRepoCacheKey(key, prefixes)) {
continue
}
next ??= { ...cache }
delete next[key]
}
return next ? { cache: next, evicted: true } : { cache, evicted: false }
}

function normalizedHeadSha(headSha?: string): string | null {
const trimmed = headSha?.trim()
return trimmed ? trimmed.toLowerCase() : null
}

export function prChecksCacheSuffix(
prNumber: number,
prRepo?: GitHubOwnerRepo | null,
headSha?: string
): string {
const headSuffix = normalizedHeadSha(headSha)
const base = prRepo
? `pr-checks::${githubRepoIdentityKey(prRepo)}::${prNumber}`
: `pr-checks::${prNumber}`
return headSuffix ? `${base}::head::${headSuffix}` : base
}

export function prCommentsCacheSuffix(prNumber: number, prRepo?: GitHubOwnerRepo | null): string {
return prRepo
? `pr-comments::${githubRepoIdentityKey(prRepo)}::${prNumber}`
: `pr-comments::${prNumber}`
}

export function getPRChecksCacheTtl(entry: CacheEntry<PRCheckDetail[]> | undefined): number {
return entry?.data?.length === 0 ? 10_000 : 60_000
}
Loading
Loading