@@ -30,11 +30,17 @@ import type {
3030 MemoryPromoteCommandOptions ,
3131 MemorySearchCommandOptions ,
3232} from "./cli.types.js" ;
33+ import { resolveShortTermPromotionDreamingConfig } from "./dreaming.js" ;
3334import {
3435 applyShortTermPromotions ,
36+ auditShortTermPromotionArtifacts ,
37+ repairShortTermPromotionArtifacts ,
3538 recordShortTermRecalls ,
3639 rankShortTermPromotionCandidates ,
40+ resolveShortTermRecallLockPath ,
3741 resolveShortTermRecallStorePath ,
42+ type RepairShortTermPromotionArtifactsResult ,
43+ type ShortTermAuditSummary ,
3844} from "./short-term-promotion.js" ;
3945
4046type MemoryManager = NonNullable < Awaited < ReturnType < typeof getMemorySearchManager > > [ "manager" ] > ;
@@ -59,6 +65,13 @@ type LoadedMemoryCommandConfig = {
5965 diagnostics : string [ ] ;
6066} ;
6167
68+ function asRecord ( value : unknown ) : Record < string , unknown > | null {
69+ if ( ! value || typeof value !== "object" || Array . isArray ( value ) ) {
70+ return null ;
71+ }
72+ return value as Record < string , unknown > ;
73+ }
74+
6275function getMemoryCommandSecretTargetIds ( ) : Set < string > {
6376 return new Set ( [
6477 "agents.defaults.memorySearch.remote.apiKey" ,
@@ -96,6 +109,57 @@ function emitMemorySecretResolveDiagnostics(
96109 }
97110}
98111
112+ function resolveMemoryPluginConfig ( cfg : OpenClawConfig ) : Record < string , unknown > {
113+ const entry = asRecord ( cfg . plugins ?. entries ?. [ "memory-core" ] ) ;
114+ return asRecord ( entry ?. config ) ?? { } ;
115+ }
116+
117+ function formatDreamingSummary ( cfg : OpenClawConfig ) : string {
118+ const pluginConfig = resolveMemoryPluginConfig ( cfg ) ;
119+ const dreaming = resolveShortTermPromotionDreamingConfig ( { pluginConfig, cfg } ) ;
120+ if ( ! dreaming . enabled ) {
121+ return "off" ;
122+ }
123+ const timezone = dreaming . timezone ? ` (${ dreaming . timezone } )` : "" ;
124+ return `${ dreaming . cron } ${ timezone } · limit=${ dreaming . limit } · minScore=${ dreaming . minScore } · minRecallCount=${ dreaming . minRecallCount } · minUniqueQueries=${ dreaming . minUniqueQueries } ` ;
125+ }
126+
127+ function formatAuditCounts ( audit : ShortTermAuditSummary ) : string {
128+ const scriptCoverage = audit . conceptTagScripts
129+ ? [
130+ audit . conceptTagScripts . latinEntryCount > 0
131+ ? `${ audit . conceptTagScripts . latinEntryCount } latin`
132+ : null ,
133+ audit . conceptTagScripts . cjkEntryCount > 0
134+ ? `${ audit . conceptTagScripts . cjkEntryCount } cjk`
135+ : null ,
136+ audit . conceptTagScripts . mixedEntryCount > 0
137+ ? `${ audit . conceptTagScripts . mixedEntryCount } mixed`
138+ : null ,
139+ audit . conceptTagScripts . otherEntryCount > 0
140+ ? `${ audit . conceptTagScripts . otherEntryCount } other`
141+ : null ,
142+ ]
143+ . filter ( Boolean )
144+ . join ( ", " )
145+ : "" ;
146+ const suffix = scriptCoverage ? ` · scripts=${ scriptCoverage } ` : "" ;
147+ return `${ audit . entryCount } entries · ${ audit . promotedCount } promoted · ${ audit . conceptTaggedEntryCount } concept-tagged · ${ audit . spacedEntryCount } spaced${ suffix } ` ;
148+ }
149+
150+ function formatRepairSummary ( repair : RepairShortTermPromotionArtifactsResult ) : string {
151+ const actions : string [ ] = [ ] ;
152+ if ( repair . rewroteStore ) {
153+ actions . push (
154+ `rewrote store${ repair . removedInvalidEntries > 0 ? ` (-${ repair . removedInvalidEntries } invalid)` : "" } ` ,
155+ ) ;
156+ }
157+ if ( repair . removedStaleLock ) {
158+ actions . push ( "removed stale lock" ) ;
159+ }
160+ return actions . length > 0 ? actions . join ( " · " ) : "no changes" ;
161+ }
162+
99163function formatSourceLabel ( source : string , workspaceDir : string , agentId : string ) : string {
100164 if ( source === "memory" ) {
101165 return shortenHomeInString (
@@ -367,6 +431,8 @@ export async function runMemoryStatus(opts: MemoryCommandOptions) {
367431 embeddingProbe ?: Awaited < ReturnType < MemoryManager [ "probeEmbeddingAvailability" ] > > ;
368432 indexError ?: string ;
369433 scan ?: MemorySourceScan ;
434+ audit ?: ShortTermAuditSummary ;
435+ repair ?: RepairShortTermPromotionArtifactsResult ;
370436 } > = [ ] ;
371437
372438 for ( const agentId of agentIds ) {
@@ -440,7 +506,28 @@ export async function runMemoryStatus(opts: MemoryCommandOptions) {
440506 extraPaths : status . extraPaths ,
441507 } )
442508 : undefined ;
443- allResults . push ( { agentId, status, embeddingProbe, indexError, scan } ) ;
509+ let audit : ShortTermAuditSummary | undefined ;
510+ let repair : RepairShortTermPromotionArtifactsResult | undefined ;
511+ if ( workspaceDir ) {
512+ if ( opts . fix ) {
513+ repair = await repairShortTermPromotionArtifacts ( { workspaceDir } ) ;
514+ }
515+ const customQmd = asRecord ( asRecord ( status . custom ) ?. qmd ) ;
516+ audit = await auditShortTermPromotionArtifacts ( {
517+ workspaceDir,
518+ qmd :
519+ status . backend === "qmd"
520+ ? {
521+ dbPath : status . dbPath ,
522+ collections :
523+ typeof customQmd ?. collections === "number"
524+ ? customQmd . collections
525+ : undefined ,
526+ }
527+ : undefined ,
528+ } ) ;
529+ }
530+ allResults . push ( { agentId, status, embeddingProbe, indexError, scan, audit, repair } ) ;
444531 } ,
445532 } ) ;
446533 }
@@ -460,7 +547,7 @@ export async function runMemoryStatus(opts: MemoryCommandOptions) {
460547 const label = ( text : string ) => muted ( `${ text } :` ) ;
461548
462549 for ( const result of allResults ) {
463- const { agentId, status, embeddingProbe, indexError, scan } = result ;
550+ const { agentId, status, embeddingProbe, indexError, scan, audit , repair } = result ;
464551 const filesIndexed = status . files ?? 0 ;
465552 const chunksIndexed = status . chunks ?? 0 ;
466553 const totalFiles = scan ?. totalFiles ?? null ;
@@ -490,6 +577,7 @@ export async function runMemoryStatus(opts: MemoryCommandOptions) {
490577 `${ label ( "Dirty" ) } ${ status . dirty ? warn ( "yes" ) : muted ( "no" ) } ` ,
491578 `${ label ( "Store" ) } ${ info ( storePath ) } ` ,
492579 `${ label ( "Workspace" ) } ${ info ( workspacePath ) } ` ,
580+ `${ label ( "Dreaming" ) } ${ info ( formatDreamingSummary ( cfg ) ) } ` ,
493581 ] . filter ( Boolean ) as string [ ] ;
494582 if ( embeddingProbe ) {
495583 const state = embeddingProbe . ok ? "ready" : "unavailable" ;
@@ -580,6 +668,24 @@ export async function runMemoryStatus(opts: MemoryCommandOptions) {
580668 lines . push ( `${ label ( "Batch error" ) } ${ warn ( status . batch . lastError ) } ` ) ;
581669 }
582670 }
671+ if ( audit ) {
672+ lines . push ( `${ label ( "Recall store" ) } ${ info ( formatAuditCounts ( audit ) ) } ` ) ;
673+ lines . push ( `${ label ( "Recall path" ) } ${ info ( shortenHomePath ( audit . storePath ) ) } ` ) ;
674+ if ( audit . updatedAt ) {
675+ lines . push ( `${ label ( "Recall updated" ) } ${ info ( audit . updatedAt ) } ` ) ;
676+ }
677+ if ( status . backend === "qmd" && audit . qmd ) {
678+ const qmdBits = [
679+ audit . qmd . dbPath ? shortenHomePath ( audit . qmd . dbPath ) : "<unknown>" ,
680+ typeof audit . qmd . dbBytes === "number" ? `${ audit . qmd . dbBytes } bytes` : null ,
681+ typeof audit . qmd . collections === "number" ? `${ audit . qmd . collections } collections` : null ,
682+ ] . filter ( Boolean ) ;
683+ lines . push ( `${ label ( "QMD audit" ) } ${ info ( qmdBits . join ( " · " ) ) } ` ) ;
684+ }
685+ }
686+ if ( repair ) {
687+ lines . push ( `${ label ( "Repair" ) } ${ info ( formatRepairSummary ( repair ) ) } ` ) ;
688+ }
583689 if ( status . fallback ?. reason ) {
584690 lines . push ( muted ( status . fallback . reason ) ) ;
585691 }
@@ -592,6 +698,17 @@ export async function runMemoryStatus(opts: MemoryCommandOptions) {
592698 lines . push ( ` ${ warn ( issue ) } ` ) ;
593699 }
594700 }
701+ if ( audit ?. issues . length ) {
702+ if ( ! scan ?. issues . length ) {
703+ lines . push ( label ( "Issues" ) ) ;
704+ }
705+ for ( const issue of audit . issues ) {
706+ lines . push ( ` ${ issue . severity === "error" ? warn ( issue . message ) : muted ( issue . message ) } ` ) ;
707+ }
708+ if ( ! opts . fix ) {
709+ lines . push ( ` ${ muted ( `Fix: openclaw memory status --fix --agent ${ agentId } ` ) } ` ) ;
710+ }
711+ }
595712 defaultRuntime . log ( lines . join ( "\n" ) ) ;
596713 defaultRuntime . log ( "" ) ;
597714 }
@@ -846,11 +963,26 @@ export async function runMemoryPromote(opts: MemoryPromoteCommandOptions) {
846963 }
847964
848965 const storePath = resolveShortTermRecallStorePath ( workspaceDir ) ;
966+ const lockPath = resolveShortTermRecallLockPath ( workspaceDir ) ;
967+ const customQmd = asRecord ( asRecord ( status . custom ) ?. qmd ) ;
968+ const audit = await auditShortTermPromotionArtifacts ( {
969+ workspaceDir,
970+ qmd :
971+ status . backend === "qmd"
972+ ? {
973+ dbPath : status . dbPath ,
974+ collections :
975+ typeof customQmd ?. collections === "number" ? customQmd . collections : undefined ,
976+ }
977+ : undefined ,
978+ } ) ;
849979
850980 if ( opts . json ) {
851981 defaultRuntime . writeJson ( {
852982 workspaceDir,
853983 storePath,
984+ lockPath,
985+ audit,
854986 candidates,
855987 apply : applyResult
856988 ? {
@@ -866,6 +998,11 @@ export async function runMemoryPromote(opts: MemoryPromoteCommandOptions) {
866998 if ( candidates . length === 0 ) {
867999 defaultRuntime . log ( "No short-term recall candidates." ) ;
8681000 defaultRuntime . log ( `Recall store: ${ shortenHomePath ( storePath ) } ` ) ;
1001+ if ( audit . issues . length > 0 ) {
1002+ for ( const issue of audit . issues ) {
1003+ defaultRuntime . log ( issue . message ) ;
1004+ }
1005+ }
8691006 return ;
8701007 }
8711008
@@ -879,6 +1016,7 @@ export async function runMemoryPromote(opts: MemoryPromoteCommandOptions) {
8791016 ) } `,
8801017 ) ;
8811018 lines . push ( `${ colorize ( rich , theme . muted , "Recall store:" ) } ${ shortenHomePath ( storePath ) } ` ) ;
1019+ lines . push ( colorize ( rich , theme . muted , `Store health: ${ formatAuditCounts ( audit ) } ` ) ) ;
8821020 for ( const candidate of candidates ) {
8831021 lines . push (
8841022 `${ colorize ( rich , theme . success , candidate . score . toFixed ( 3 ) ) } ${ colorize (
@@ -891,14 +1029,26 @@ export async function runMemoryPromote(opts: MemoryPromoteCommandOptions) {
8911029 colorize (
8921030 rich ,
8931031 theme . muted ,
894- `recalls=${ candidate . recallCount } avg=${ candidate . avgScore . toFixed ( 3 ) } queries=${ candidate . uniqueQueries } age=${ candidate . ageDays . toFixed ( 1 ) } d` ,
1032+ `recalls=${ candidate . recallCount } avg=${ candidate . avgScore . toFixed ( 3 ) } queries=${ candidate . uniqueQueries } age=${ candidate . ageDays . toFixed ( 1 ) } d consolidate= ${ candidate . components . consolidation . toFixed ( 2 ) } conceptual= ${ candidate . components . conceptual . toFixed ( 2 ) } ` ,
8951033 ) ,
8961034 ) ;
1035+ if ( candidate . conceptTags . length > 0 ) {
1036+ lines . push ( colorize ( rich , theme . muted , `concepts=${ candidate . conceptTags . join ( ", " ) } ` ) ) ;
1037+ }
8971038 if ( candidate . snippet ) {
8981039 lines . push ( colorize ( rich , theme . muted , candidate . snippet ) ) ;
8991040 }
9001041 lines . push ( "" ) ;
9011042 }
1043+ if ( audit . issues . length > 0 ) {
1044+ lines . push ( colorize ( rich , theme . warn , "Audit issues:" ) ) ;
1045+ for ( const issue of audit . issues ) {
1046+ lines . push (
1047+ colorize ( rich , issue . severity === "error" ? theme . warn : theme . muted , issue . message ) ,
1048+ ) ;
1049+ }
1050+ lines . push ( "" ) ;
1051+ }
9021052 if ( applyResult ) {
9031053 if ( applyResult . applied > 0 ) {
9041054 lines . push (
0 commit comments