MCPcopy Create free account
hub / github.com/anomalyco/opencode / pruneSessionKeys

Function pruneSessionKeys

packages/app/src/context/layout-helpers.ts:18–38  ·  view source on GitHub ↗
(input: {
  keep?: string
  max: number
  used: Map<string, number>
  view: string[]
  tabs: string[]
})

Source from the content-addressed store, hash-verified

16}
17
18export function pruneSessionKeys(input: {
19 keep?: string
20 max: number
21 used: Map<string, number>
22 view: string[]
23 tabs: string[]
24}) {
25 if (!input.keep) return []
26
27 const keys = new Set<string>([...input.view, ...input.tabs])
28 if (keys.size <= input.max) return []
29
30 const score = (key: string) => {
31 if (key === input.keep) return Number.MAX_SAFE_INTEGER
32 return input.used.get(key) ?? 0
33 }
34
35 return Array.from(keys)
36 .sort((a, b) => score(b) - score(a))
37 .slice(input.max)
38}

Callers 2

pruneFunction · 0.90
layout.test.tsFile · 0.90

Calls 2

scoreFunction · 0.85
fromMethod · 0.45

Tested by

no test coverage detected