MCPcopy Create free account
hub / github.com/GongShichen/LuminaCode / selectRecoveryRecords

Function selectRecoveryRecords

skills/persistence.go:285–317  ·  view source on GitHub ↗
(candidates []recoveryCandidate, totalCharsBudget int)

Source from the content-addressed store, hash-verified

283}
284
285func selectRecoveryRecords(candidates []recoveryCandidate, totalCharsBudget int) []recoveryCandidate {
286 if len(candidates) == 0 {
287 return nil
288 }
289 fixedOverhead := runeLen(recoveryHeader) + runeLen(recoveryFooter)
290 if fixedOverhead >= totalCharsBudget {
291 return nil
292 }
293 latestTurn := 0
294 for _, candidate := range candidates {
295 if candidate.record.LastTurnIndex > latestTurn {
296 latestTurn = candidate.record.LastTurnIndex
297 }
298 }
299 sort.SliceStable(candidates, func(i, j int) bool {
300 return recoverySelectionLess(candidates[j], candidates[i], latestTurn)
301 })
302 var selected []recoveryCandidate
303 totalChars := fixedOverhead
304 for _, candidate := range candidates {
305 separatorChars := 0
306 if len(selected) > 0 {
307 separatorChars = runeLen(recoverySectionSeparator)
308 }
309 nextTotal := totalChars + separatorChars + runeLen(candidate.section)
310 if nextTotal > totalCharsBudget {
311 continue
312 }
313 selected = append(selected, candidate)
314 totalChars = nextTotal
315 }
316 return selected
317}
318
319func recoverySelectionLess(a, b recoveryCandidate, latestTurn int) bool {
320 ad := recoveryDensity(a, latestTurn)

Callers 1

Calls 2

runeLenFunction · 0.85
recoverySelectionLessFunction · 0.85

Tested by

no test coverage detected