refactor(session-history): build the scope matcher only for scope-only scans and tighten comments

This commit is contained in:
Kelvin Amoaba
2026-11-08 21:17:48 +00:00
parent d314a3b4b6
commit c4b9b2137c
4 changed files with 8 additions and 11 deletions
@@ -94,8 +94,7 @@ export async function inventoryCwdBucketFiles(
let unverified = false
if (layout.agent === 'claude') {
const cwd = await cachedProjectDirCwd(directory, record, layout.agent, args.signal)
// Main's recency pass still shows recent sessions in a name-matched bucket whose newest transcripts
// name no cwd, or another folder sharing the lossy name; scope-only lets their parse decide.
// No cwd found, or a folder sharing the lossy name: without a recency pass, the parse decides.
if (!inScope(cwd, directory)) {
if (!args.scopeOnly) {
continue
@@ -64,13 +64,14 @@ export async function scanInScopeSessions(args: ScopeScanArgs): Promise<AiVaultS
return []
}
const candidates: SessionFileCandidate[] = []
const inScope = createAiVaultScopeCwdMatcher(scopePaths)
const scopeOnly = scopeOnlyScan(args.options)
const inScope = scopeOnly ? createAiVaultScopeCwdMatcher(scopePaths) : null
const workload = aiVaultScanWorkload(args.options.signal)
for (const inventory of args.inventory) {
const files = await selectCwdBucketFiles(inventory, {
scopePaths,
// These agents skip the recency pass, so cover what it and this pass show together.
limit: scopeOnlyScan(args.options) ? args.limit * 2 : args.limit,
limit: scopeOnly ? args.limit * 2 : args.limit,
excludedFilePaths: args.alreadyParsedFilePaths,
issues: args.issues,
signal: args.options.signal
@@ -110,9 +111,7 @@ export async function scanInScopeSessions(args: ScopeScanArgs): Promise<AiVaultS
signal: args.options.signal,
settled: (candidate, parsed) => workload?.settle(candidate, 'bucket', parsed),
// Unverified bucket files are placed by their parsed cwd.
admitSession: scopeOnlyScan(args.options)
? (session) => aiVaultSessionInScope(inScope, session)
: undefined
admitSession: inScope ? (session) => aiVaultSessionInScope(inScope, session) : undefined
})
return [...bucketed, ...walked]
}
@@ -51,8 +51,7 @@ function agentDiscoveries(
issues: AiVaultScanIssue[]
): Promise<SessionFileDiscovery>[] {
const rootDirs = source.rootDirs(options, wslHomeDirs)
// Scope-only scans read cwd-bucket agents through their bucket inventory and can't place cwd-less ones.
// Pi stays listed: OMP shares its folder under PI_CODING_AGENT_DIR, and Pi's listing decides who parses a file.
// Scope-only reads cwd buckets through the scope pass; Pi stays listed because OMP's dedupe needs its listing.
if (
scopeOnlyScan(options) &&
!scopeWalksAgentFiles(agent, options.scopePaths) &&
+2 -2
View File
@@ -103,8 +103,8 @@ async function scanAiVaultSessionStores(options: AiVaultScanOptions): Promise<Ai
(left, right) => sessionSortTime(right) - sessionSortTime(left)
)
// Scope-only keeps the recency pass for agents without cwd buckets, but returns only its in-scope rows.
const inScope = createAiVaultScopeCwdMatcher(options.scopePaths ?? [])
const cappedSessions = scopeOnly
const inScope = scopeOnly ? createAiVaultScopeCwdMatcher(options.scopePaths ?? []) : null
const cappedSessions = inScope
? recentSessions.filter((session) => aiVaultSessionInScope(inScope, session))
: recentSessions.slice(0, limit)