refactor: trim memory core helper exports

This commit is contained in:
Peter Steinberger
2026-05-01 18:07:53 +01:00
parent ccd188a8b7
commit f3d2ae895a
19 changed files with 37 additions and 56 deletions

View File

@@ -2,25 +2,12 @@ import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
import { registerMemoryCli } from "./src/cli.js";
import { registerDreamingCommand } from "./src/dreaming-command.js";
import { registerShortTermPromotionDreaming } from "./src/dreaming.js";
import {
buildMemoryFlushPlan,
DEFAULT_MEMORY_FLUSH_FORCE_TRANSCRIPT_BYTES,
DEFAULT_MEMORY_FLUSH_PROMPT,
DEFAULT_MEMORY_FLUSH_SOFT_TOKENS,
} from "./src/flush-plan.js";
import { buildMemoryFlushPlan } from "./src/flush-plan.js";
import { registerBuiltInMemoryEmbeddingProviders } from "./src/memory/provider-adapters.js";
import { buildPromptSection } from "./src/prompt-section.js";
import { listMemoryCorePublicArtifacts } from "./src/public-artifacts.js";
import { memoryRuntime } from "./src/runtime-provider.js";
import { createMemoryGetTool, createMemorySearchTool } from "./src/tools.js";
export {
buildMemoryFlushPlan,
DEFAULT_MEMORY_FLUSH_FORCE_TRANSCRIPT_BYTES,
DEFAULT_MEMORY_FLUSH_PROMPT,
DEFAULT_MEMORY_FLUSH_SOFT_TOKENS,
} from "./src/flush-plan.js";
export { buildPromptSection } from "./src/prompt-section.js";
export default definePluginEntry({
id: "memory-core",
name: "Memory (Core)",

View File

@@ -3,7 +3,7 @@ import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtim
export const MAX_CONCEPT_TAGS = 8;
export type ConceptTagScriptFamily = "latin" | "cjk" | "mixed" | "other";
type ConceptTagScriptFamily = "latin" | "cjk" | "mixed" | "other";
export type ConceptTagScriptCoverage = {
latinEntryCount: number;

View File

@@ -244,7 +244,7 @@ async function startNarrativeRunOrFallback(params: {
/**
* Build the deterministic subagent session key used for dream narratives.
*/
export function buildNarrativeSessionKey(params: {
function buildNarrativeSessionKey(params: {
workspaceDir: string;
phase: NarrativePhaseData["phase"];
nowMs: number;

View File

@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
import fs from "node:fs/promises";
import path from "node:path";
export type DreamingArtifactsAuditIssue = {
type DreamingArtifactsAuditIssue = {
severity: "warn" | "error";
code:
| "dreaming-session-corpus-unreadable"

View File

@@ -108,7 +108,7 @@ type CronServiceLike = {
remove: (id: string) => Promise<{ removed?: boolean }>;
};
export type ShortTermPromotionDreamingConfig = {
type ShortTermPromotionDreamingConfig = {
enabled: boolean;
cron: string;
timezone?: string;

View File

@@ -31,7 +31,7 @@ export const DEFAULT_MEMORY_FLUSH_PROMPT = [
`If nothing to store, reply with ${SILENT_REPLY_TOKEN}.`,
].join(" ");
export const DEFAULT_MEMORY_FLUSH_SYSTEM_PROMPT = [
const DEFAULT_MEMORY_FLUSH_SYSTEM_PROMPT = [
"Pre-compaction memory flush turn.",
"The session is near auto-compaction; capture durable memories to disk.",
MEMORY_FLUSH_TARGET_HINT,

View File

@@ -1,7 +1,7 @@
import type { MemorySearchRuntimeDebug } from "openclaw/plugin-sdk/memory-core-host-runtime-files";
import { vi } from "vitest";
export type SearchImpl = (opts?: {
type SearchImpl = (opts?: {
maxResults?: number;
minScore?: number;
sessionKey?: string;
@@ -9,7 +9,7 @@ export type SearchImpl = (opts?: {
onDebug?: (debug: MemorySearchRuntimeDebug) => void;
}) => Promise<unknown[]>;
export type MemoryReadParams = { relPath: string; from?: number; lines?: number };
export type MemoryReadResult = {
type MemoryReadResult = {
text: string;
path: string;
truncated?: boolean;

View File

@@ -1,5 +1,4 @@
import {
DEFAULT_LOCAL_MODEL,
getMemoryEmbeddingProvider,
listMemoryEmbeddingProviders,
type MemoryEmbeddingProvider,
@@ -10,12 +9,10 @@ import {
import { formatErrorMessage } from "../dreaming-shared.js";
import { canAutoSelectLocal } from "./provider-adapters.js";
export { DEFAULT_LOCAL_MODEL } from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
export type EmbeddingProvider = MemoryEmbeddingProvider;
export type EmbeddingProviderId = string;
export type EmbeddingProviderRequest = string;
export type EmbeddingProviderFallback = string;
type EmbeddingProviderFallback = string;
export type EmbeddingProviderRuntime = MemoryEmbeddingProviderRuntime;
export type EmbeddingProviderResult = {

View File

@@ -5,12 +5,9 @@ import {
DEFAULT_TEMPORAL_DECAY_CONFIG,
} from "./temporal-decay.js";
export type HybridSource = string;
type HybridSource = string;
export { type MMRConfig, DEFAULT_MMR_CONFIG };
export { type TemporalDecayConfig, DEFAULT_TEMPORAL_DECAY_CONFIG };
export type HybridVectorResult = {
type HybridVectorResult = {
id: string;
path: string;
startLine: number;
@@ -20,7 +17,7 @@ export type HybridVectorResult = {
vectorScore: number;
};
export type HybridKeywordResult = {
type HybridKeywordResult = {
id: string;
path: string;
startLine: number;

View File

@@ -1,7 +1,7 @@
import { randomUUID } from "node:crypto";
import fs from "node:fs/promises";
export async function moveMemoryIndexFiles(sourceBase: string, targetBase: string): Promise<void> {
async function moveMemoryIndexFiles(sourceBase: string, targetBase: string): Promise<void> {
const suffixes = ["", "-wal", "-shm"];
for (const suffix of suffixes) {
const source = `${sourceBase}${suffix}`;
@@ -16,12 +16,12 @@ export async function moveMemoryIndexFiles(sourceBase: string, targetBase: strin
}
}
export async function removeMemoryIndexFiles(basePath: string): Promise<void> {
async function removeMemoryIndexFiles(basePath: string): Promise<void> {
const suffixes = ["", "-wal", "-shm"];
await Promise.all(suffixes.map((suffix) => fs.rm(`${basePath}${suffix}`, { force: true })));
}
export async function swapMemoryIndexFiles(targetPath: string, tempPath: string): Promise<void> {
async function swapMemoryIndexFiles(targetPath: string, tempPath: string): Promise<void> {
const backupPath = `${targetPath}.backup-${randomUUID()}`;
await moveMemoryIndexFiles(targetPath, backupPath);
try {

View File

@@ -1,6 +1,6 @@
export const MEMORY_BATCH_FAILURE_LIMIT = 2;
export type MemoryBatchFailureState = {
type MemoryBatchFailureState = {
enabled: boolean;
count: number;
lastError?: string;

View File

@@ -9,7 +9,7 @@ import {
type EmbeddingProviderRuntime,
} from "./embeddings.js";
export type MemoryResolvedProviderState = {
type MemoryResolvedProviderState = {
provider: EmbeddingProvider | null;
fallbackFrom?: string;
fallbackReason?: string;

View File

@@ -23,7 +23,7 @@ export function resolveConfiguredSourcesForMeta(sources: Iterable<MemorySource>)
return normalized.length > 0 ? normalized : ["memory"];
}
export function normalizeMetaSources(meta: MemoryIndexMeta): MemorySource[] {
function normalizeMetaSources(meta: MemoryIndexMeta): MemorySource[] {
if (!Array.isArray(meta.sources)) {
// Backward compatibility for older indexes that did not persist sources.
return ["memory"];
@@ -38,7 +38,7 @@ export function normalizeMetaSources(meta: MemoryIndexMeta): MemorySource[] {
return normalized.length > 0 ? normalized : ["memory"];
}
export function configuredMetaSourcesDiffer(params: {
function configuredMetaSourcesDiffer(params: {
meta: MemoryIndexMeta;
configuredSources: MemorySource[];
}): boolean {

View File

@@ -11,9 +11,9 @@ const FTS_QUERY_TOKEN_RE = /[\p{L}\p{N}_]+/gu;
const SHORT_CJK_TRIGRAM_RE = /[\u3040-\u30ff\u3400-\u9fff\uac00-\ud7af\u3131-\u3163]/u;
const VECTOR_KNN_OVERSAMPLE_FACTOR = 8;
export type SearchSource = string;
type SearchSource = string;
export type SearchRowResult = {
type SearchRowResult = {
id: string;
path: string;
startLine: number;
@@ -215,7 +215,7 @@ export async function searchVector(params: {
});
}
export function searchChunksByEmbedding(params: {
function searchChunksByEmbedding(params: {
db: DatabaseSync;
providerModel: string;
sourceFilter: { sql: string; params: SearchSource[] };

View File

@@ -112,11 +112,11 @@ const localAdapter: MemoryEmbeddingProviderAdapter = {
},
};
export const builtinMemoryEmbeddingProviderAdapters = [localAdapter] as const;
const builtinMemoryEmbeddingProviderAdapters = [localAdapter] as const;
export { DEFAULT_LOCAL_MODEL };
export function getBuiltinMemoryEmbeddingProviderAdapter(
function getBuiltinMemoryEmbeddingProviderAdapter(
id: string,
): MemoryEmbeddingProviderAdapter | undefined {
return listMemoryEmbeddingProviders().find((adapter) => adapter.id === id);
@@ -169,4 +169,4 @@ export function listBuiltinAutoSelectMemoryEmbeddingProviderDoctorMetadata(): Ar
});
}
export { canAutoSelectLocal, formatLocalSetupError };
export { canAutoSelectLocal };

View File

@@ -14,7 +14,7 @@ export const DEFAULT_TEMPORAL_DECAY_CONFIG: TemporalDecayConfig = {
const DAY_MS = 24 * 60 * 60 * 1000;
const DATED_MEMORY_PATH_RE = /(?:^|\/)memory\/(\d{4})-(\d{2})-(\d{2})\.md$/;
export function toDecayLambda(halfLifeDays: number): number {
function toDecayLambda(halfLifeDays: number): number {
if (!Number.isFinite(halfLifeDays) || halfLifeDays <= 0) {
return 0;
}

View File

@@ -63,16 +63,16 @@ const REM_SUMMARY_FACT_LIMIT = 4;
const REM_SUMMARY_REFLECTION_LIMIT = 4;
const REM_SUMMARY_MEMORY_LIMIT = 3;
export type GroundedRemPreviewItem = {
type GroundedRemPreviewItem = {
text: string;
refs: string[];
};
export type GroundedRemCandidate = GroundedRemPreviewItem & {
type GroundedRemCandidate = GroundedRemPreviewItem & {
lean: "likely_durable" | "unclear" | "likely_situational";
};
export type GroundedRemFilePreview = {
type GroundedRemFilePreview = {
path: string;
facts: GroundedRemPreviewItem[];
reflections: GroundedRemPreviewItem[];

View File

@@ -43,7 +43,7 @@ const DREAMING_DIFF_PREFIX_RE = /@@\s*-\d+(?:,\d+)?\s+[-*+]\s+/iy;
const inProcessShortTermLocks = new Map<string, Promise<void>>();
const ensuredShortTermDirs = new Map<string, Promise<void>>();
export type PromotionWeights = {
type PromotionWeights = {
frequency: number;
relevance: number;
diversity: number;
@@ -52,7 +52,7 @@ export type PromotionWeights = {
conceptual: number;
};
export const DEFAULT_PROMOTION_WEIGHTS: PromotionWeights = {
const DEFAULT_PROMOTION_WEIGHTS: PromotionWeights = {
frequency: 0.24,
relevance: 0.3,
diversity: 0.15,
@@ -102,7 +102,7 @@ type ShortTermPhaseSignalStore = {
entries: Record<string, ShortTermPhaseSignalEntry>;
};
export type PromotionComponents = {
type PromotionComponents = {
frequency: number;
relevance: number;
diversity: number;
@@ -136,7 +136,7 @@ export type PromotionCandidate = {
components: PromotionComponents;
};
export type ShortTermAuditIssue = {
type ShortTermAuditIssue = {
severity: "warn" | "error";
code:
| "recall-store-unreadable"
@@ -179,7 +179,7 @@ export type RepairShortTermPromotionArtifactsResult = {
removedStaleLock: boolean;
};
export type RankShortTermPromotionOptions = {
type RankShortTermPromotionOptions = {
workspaceDir: string;
limit?: number;
minScore?: number;
@@ -192,7 +192,7 @@ export type RankShortTermPromotionOptions = {
nowMs?: number;
};
export type ApplyShortTermPromotionsOptions = {
type ApplyShortTermPromotionsOptions = {
workspaceDir: string;
candidates: PromotionCandidate[];
limit?: number;
@@ -204,7 +204,7 @@ export type ApplyShortTermPromotionsOptions = {
timezone?: string;
};
export type ApplyShortTermPromotionsResult = {
type ApplyShortTermPromotionsResult = {
memoryPath: string;
applied: number;
appended: number;

View File

@@ -49,7 +49,7 @@ export const MemoryGetSchema = Type.Object({
),
});
export function resolveMemoryToolContext(options: MemoryToolOptions) {
function resolveMemoryToolContext(options: MemoryToolOptions) {
const cfg = options.getConfig?.() ?? options.config;
if (!cfg) {
return null;