MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / retainActiveFirst

Function retainActiveFirst

src/utils/autonomyPersistence.ts:17–32  ·  view source on GitHub ↗
(
  records: readonly T[],
  isActive: (record: T) => boolean,
  getTimestamp: (record: T) => number,
  max: number,
)

Source from the content-addressed store, hash-verified

15 * consume it directly without re-sorting.
16 */
17export function retainActiveFirst<T>(
18 records: readonly T[],
19 isActive: (record: T) => boolean,
20 getTimestamp: (record: T) => number,
21 max: number,
22): T[] {
23 const sortDesc = (left: T, right: T) =>
24 getTimestamp(right) - getTimestamp(left)
25 const active = records.filter(isActive).slice().sort(sortDesc)
26 const history = records
27 .filter(record => !isActive(record))
28 .slice()
29 .sort(sortDesc)
30 .slice(0, Math.max(0, max - active.length))
31 return [...active, ...history].sort(sortDesc)
32}
33
34export function getAutonomyPersistenceLockCountForTests(): number {
35 if (process.env.NODE_ENV !== 'test') {

Callers 2

Calls 2

isActiveFunction · 0.85
maxMethod · 0.80

Tested by

no test coverage detected