@@ -312,14 +312,17 @@ export async function runMemoryPromote(
312312 }
313313 let candidates : Awaited < ReturnType < typeof rankShortTermPromotionCandidates > > ;
314314 try {
315+ const gatherAllForApply = Boolean ( opts . apply ) ;
315316 candidates = await rankShortTermPromotionCandidates ( {
316317 workspaceDir,
317- limit : opts . limit ,
318- minScore : opts . minScore ?? dreaming . minScore ,
319- minRecallCount : opts . minRecallCount ?? dreaming . minRecallCount ,
320- minUniqueQueries : opts . minUniqueQueries ?? dreaming . minUniqueQueries ,
318+ limit : gatherAllForApply ? undefined : opts . limit ,
319+ minScore : gatherAllForApply ? 0 : ( opts . minScore ?? dreaming . minScore ) ,
320+ minRecallCount : gatherAllForApply ? 0 : ( opts . minRecallCount ?? dreaming . minRecallCount ) ,
321+ minUniqueQueries : gatherAllForApply
322+ ? 0
323+ : ( opts . minUniqueQueries ?? dreaming . minUniqueQueries ) ,
321324 recencyHalfLifeDays : dreaming . recencyHalfLifeDays ,
322- maxAgeDays : dreaming . maxAgeDays ,
325+ maxAgeDays : gatherAllForApply ? undefined : dreaming . maxAgeDays ,
323326 includePromoted : Boolean ( opts . includePromoted ) ,
324327 } ) ;
325328 } catch ( err ) {
@@ -347,6 +350,25 @@ export async function runMemoryPromote(
347350 return ;
348351 }
349352 }
353+ const outputLimit =
354+ typeof opts . limit === "number" && Number . isFinite ( opts . limit )
355+ ? Math . max ( 0 , Math . floor ( opts . limit ) )
356+ : candidates . length ;
357+ const rejectedCandidates = applyResult
358+ ? applyResult . rejectedCandidates . slice (
359+ 0 ,
360+ Math . max ( 0 , outputLimit - applyResult . appliedCandidates . length ) ,
361+ )
362+ : [ ] ;
363+ const outputCandidateKeys = applyResult
364+ ? new Set ( [
365+ ...applyResult . appliedCandidates . map ( ( candidate ) => candidate . key ) ,
366+ ...rejectedCandidates . map ( ( rejection ) => rejection . candidate . key ) ,
367+ ] )
368+ : undefined ;
369+ const outputCandidates = outputCandidateKeys
370+ ? candidates . filter ( ( candidate ) => outputCandidateKeys . has ( candidate . key ) )
371+ : candidates ;
350372 const storePath = resolveShortTermRecallStorePath ( workspaceDir ) ;
351373 const lockPath = resolveShortTermRecallLockPath ( workspaceDir ) ;
352374 const audit = await auditShortTermPromotionArtifacts ( { workspaceDir } ) ;
@@ -356,14 +378,15 @@ export async function runMemoryPromote(
356378 storePath,
357379 lockPath,
358380 audit,
359- candidates,
381+ candidates : outputCandidates ,
360382 apply : applyResult
361383 ? {
362384 applied : applyResult . applied ,
363385 appended : applyResult . appended ,
364386 reconciledExisting : applyResult . reconciledExisting ,
365387 memoryPath : applyResult . memoryPath ,
366388 appliedCandidates : applyResult . appliedCandidates ,
389+ rejectedCandidates,
367390 }
368391 : undefined ,
369392 } ) ;
@@ -383,7 +406,7 @@ export async function runMemoryPromote(
383406 lines . push ( `${ heading ( "Short-Term Promotion Candidates" ) } ${ muted ( `(${ agentId } )` ) } ` ) ;
384407 lines . push ( `${ muted ( "Recall store:" ) } ${ shortenHomePath ( storePath ) } ` ) ;
385408 lines . push ( muted ( `Store health: ${ formatAuditCounts ( audit ) } ` ) ) ;
386- for ( const candidate of candidates ) {
409+ for ( const candidate of outputCandidates ) {
387410 lines . push (
388411 `${ success ( candidate . score . toFixed ( 3 ) ) } ${ accent ( `${ shortenHomePath ( candidate . path ) } :${ candidate . startLine } -${ candidate . endLine } ` ) } ` ,
389412 ) ;
@@ -408,6 +431,11 @@ export async function runMemoryPromote(
408431 lines . push ( "" ) ;
409432 }
410433 if ( applyResult ) {
434+ for ( const rejection of rejectedCandidates ) {
435+ const candidate = rejection . candidate ;
436+ const source = `${ shortenHomePath ( candidate . path ) } :${ candidate . startLine } -${ candidate . endLine } ` ;
437+ lines . push ( warn ( `Skipped ${ source } : ${ rejection . reason } .` ) ) ;
438+ }
411439 if ( applyResult . applied > 0 ) {
412440 lines . push (
413441 success (
@@ -419,7 +447,7 @@ export async function runMemoryPromote(
419447 `appended=${ applyResult . appended } reconciledExisting=${ applyResult . reconciledExisting } ` ,
420448 ) ,
421449 ) ;
422- } else {
450+ } else if ( rejectedCandidates . length === 0 ) {
423451 lines . push ( warn ( "No candidates met apply criteria." ) ) ;
424452 }
425453 }
0 commit comments