refactor: unify duplicate Logger interfaces into single canonical type (#14)

* refactor: unify duplicate Logger interfaces into single canonical type

23 files had local Logger/StoreLogger/PluginLogger/PipelineLogger/RunnerLogger/ExtractorLogger/TriggerLogger
interface definitions with identical shapes ({debug?, info, warn, error}).

Replace all with imports from the canonical `Logger` in `src/core/types.ts`:
- 17 files: local `interface Logger` → `import type { Logger }`
- 6 files: named variants (StoreLogger, PluginLogger, etc.) → `type X = Logger` alias

Two intentionally different interfaces are preserved:
- `CheckpointLogger` (only info + optional warn) — different contract
- `ensure-hook-policy.ts` Logger (no error) — different contract

Net: -120 lines, zero behavioral change.

Signed-off-by: yuanrengu <heyonggang0811@126.com>

* docs: update Logger JSDoc to reflect canonical relationship

StoreLogger, PluginLogger, etc. are now type aliases of Logger, not the
other way around. Update the comment to clarify this inverted relationship.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Signed-off-by: yuanrengu <heyonggang0811@126.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Andy He
2026-06-01 15:12:46 +08:00
committed by GitHub
parent 438869bec8
commit d1534e488f
24 changed files with 38 additions and 166 deletions
+1 -7
View File
@@ -18,6 +18,7 @@ import fs from "node:fs/promises";
import path from "node:path"; import path from "node:path";
import crypto from "node:crypto"; import crypto from "node:crypto";
import { sanitizeText, stripCodeBlocks, shouldCaptureL0 } from "../../utils/sanitize.js"; import { sanitizeText, stripCodeBlocks, shouldCaptureL0 } from "../../utils/sanitize.js";
import type { Logger } from "../types.js";
// ============================ // ============================
// Types // Types
@@ -63,13 +64,6 @@ export interface L0ConversationRecord {
messages: ConversationMessage[]; messages: ConversationMessage[];
} }
interface Logger {
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
const TAG = "[memory-tdai][l0]"; const TAG = "[memory-tdai][l0]";
// ============================ // ============================
+2 -7
View File
@@ -19,14 +19,9 @@ import type { ConversationMessage } from "../conversation/l0-recorder.js";
import type { IMemoryStore, L0Record } from "../store/types.js"; import type { IMemoryStore, L0Record } from "../store/types.js";
import type { EmbeddingService } from "../store/embedding.js"; import type { EmbeddingService } from "../store/embedding.js";
const TAG = "[memory-tdai] [capture]"; import type { Logger } from "../types.js";
interface Logger { const TAG = "[memory-tdai] [capture]";
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
export interface AutoCaptureResult { export interface AutoCaptureResult {
/** Whether the scheduler was notified (conversation count incremented) */ /** Whether the scheduler was notified (conversation count incremented) */
+1 -7
View File
@@ -20,6 +20,7 @@ import type { IMemoryStore, L1SearchResult, L1FtsResult } from "../store/types.j
import { buildFtsQuery } from "../store/sqlite.js"; import { buildFtsQuery } from "../store/sqlite.js";
import type { EmbeddingService, EmbeddingCallOptions } from "../store/embedding.js"; import type { EmbeddingService, EmbeddingCallOptions } from "../store/embedding.js";
import { sanitizeText } from "../../utils/sanitize.js"; import { sanitizeText } from "../../utils/sanitize.js";
import type { Logger } from "../types.js";
const TAG = "[memory-tdai] [recall]"; const TAG = "[memory-tdai] [recall]";
const RECALL_TRUNCATION_SUFFIX = "…(已截断;可用 tdai_memory_search 或 tdai_conversation_search 查看详情)"; const RECALL_TRUNCATION_SUFFIX = "…(已截断;可用 tdai_memory_search 或 tdai_conversation_search 查看详情)";
@@ -45,13 +46,6 @@ const MEMORY_TOOLS_GUIDE = `<memory-tools-guide>
- 若 3 次搜索后仍无结果,说明该信息不在记忆中,请直接根据已有信息回复用户,不要继续搜索。 - 若 3 次搜索后仍无结果,说明该信息不在记忆中,请直接根据已有信息回复用户,不要继续搜索。
</memory-tools-guide>` </memory-tools-guide>`
interface Logger {
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
/** A single recalled L1 memory with its search score and type. */ /** A single recalled L1 memory with its search score and type. */
export interface RecalledMemory { export interface RecalledMemory {
content: string; content: string;
+1 -8
View File
@@ -13,17 +13,10 @@ import { buildPersonaPrompt } from "../prompts/persona-generation.js";
import { BackupManager } from "../../utils/backup.js"; import { BackupManager } from "../../utils/backup.js";
import { escapeXmlTags } from "../../utils/sanitize.js"; import { escapeXmlTags } from "../../utils/sanitize.js";
import { report } from "../report/reporter.js"; import { report } from "../report/reporter.js";
import type { LLMRunner } from "../types.js"; import type { LLMRunner, Logger } from "../types.js";
const TAG = "[memory-tdai] [persona]"; const TAG = "[memory-tdai] [persona]";
interface Logger {
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
export class PersonaGenerator { export class PersonaGenerator {
private dataDir: string; private dataDir: string;
private runner: LLMRunner; private runner: LLMRunner;
+3 -6
View File
@@ -8,14 +8,11 @@ import path from "node:path";
import { CheckpointManager } from "../../utils/checkpoint.js"; import { CheckpointManager } from "../../utils/checkpoint.js";
import { stripSceneNavigation } from "../scene/scene-navigation.js"; import { stripSceneNavigation } from "../scene/scene-navigation.js";
import type { Logger } from "../types.js";
const TAG = "[memory-tdai] [trigger]"; const TAG = "[memory-tdai] [trigger]";
interface TriggerLogger { type TriggerLogger = Logger;
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
export interface TriggerResult { export interface TriggerResult {
should: boolean; should: boolean;
+1 -7
View File
@@ -4,6 +4,7 @@ import path from "node:path";
import type { IMemoryStore, ProfileRecord, ProfileSyncRecord } from "../store/types.js"; import type { IMemoryStore, ProfileRecord, ProfileSyncRecord } from "../store/types.js";
import { readSceneIndex, syncSceneIndex } from "../scene/scene-index.js"; import { readSceneIndex, syncSceneIndex } from "../scene/scene-index.js";
import { generateSceneNavigation, stripSceneNavigation } from "../scene/scene-navigation.js"; import { generateSceneNavigation, stripSceneNavigation } from "../scene/scene-navigation.js";
import type { Logger } from "../types.js";
const PROFILE_SCOPE = "global"; const PROFILE_SCOPE = "global";
@@ -13,13 +14,6 @@ function isRenameRaceError(err: unknown): boolean {
return code === "ENOTEMPTY" || code === "EEXIST"; return code === "ENOTEMPTY" || code === "EEXIST";
} }
interface Logger {
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
export interface ProfileBaseline { export interface ProfileBaseline {
version: number; version: number;
contentMd5: string; contentMd5: string;
+1 -8
View File
@@ -19,14 +19,7 @@ import { sanitizeJsonForParse } from "../../utils/sanitize.js";
import type { IMemoryStore } from "../store/types.js"; import type { IMemoryStore } from "../store/types.js";
import { buildFtsQuery } from "../store/sqlite.js"; import { buildFtsQuery } from "../store/sqlite.js";
import type { EmbeddingService } from "../store/embedding.js"; import type { EmbeddingService } from "../store/embedding.js";
import type { LLMRunner } from "../types.js"; import type { LLMRunner, Logger } from "../types.js";
interface Logger {
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
const TAG = "[memory-tdai][l1-dedup]"; const TAG = "[memory-tdai][l1-dedup]";
+1 -8
View File
@@ -22,14 +22,7 @@ import { sanitizeJsonForParse, shouldExtractL1 } from "../../utils/sanitize.js";
import type { IMemoryStore } from "../store/types.js"; import type { IMemoryStore } from "../store/types.js";
import type { EmbeddingService } from "../store/embedding.js"; import type { EmbeddingService } from "../store/embedding.js";
import { report } from "../report/reporter.js"; import { report } from "../report/reporter.js";
import type { LLMRunner } from "../types.js"; import type { LLMRunner, Logger } from "../types.js";
interface Logger {
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
const TAG = "[memory-tdai][l1-extractor]"; const TAG = "[memory-tdai][l1-extractor]";
+1 -7
View File
@@ -19,13 +19,7 @@ import type { IMemoryStore, L1RecordRow, L1QueryFilter } from "../store/types.js
// Re-export types that readers need // Re-export types that readers need
export type { MemoryRecord, MemoryType, EpisodicMetadata } from "./l1-writer.js"; export type { MemoryRecord, MemoryType, EpisodicMetadata } from "./l1-writer.js";
export type { L1QueryFilter } from "../store/types.js"; export type { L1QueryFilter } from "../store/types.js";
import type { Logger } from "../types.js";
interface Logger {
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
const TAG = "[memory-tdai] [l1-reader]"; const TAG = "[memory-tdai] [l1-reader]";
+1 -7
View File
@@ -21,6 +21,7 @@ import path from "node:path";
import crypto from "node:crypto"; import crypto from "node:crypto";
import type { IMemoryStore } from "../store/types.js"; import type { IMemoryStore } from "../store/types.js";
import type { EmbeddingService } from "../store/embedding.js"; import type { EmbeddingService } from "../store/embedding.js";
import type { Logger } from "../types.js";
// ============================ // ============================
// Types // Types
@@ -110,13 +111,6 @@ export interface DedupDecision {
merged_timestamps?: string[]; merged_timestamps?: string[];
} }
interface Logger {
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
const TAG = "[memory-tdai][l1-writer]"; const TAG = "[memory-tdai][l1-writer]";
// ============================ // ============================
+2 -7
View File
@@ -28,16 +28,11 @@ import { generateSceneNavigation, stripSceneNavigation } from "../scene/scene-na
import { normalizeSceneFilenames } from "./filename-normalizer.js"; import { normalizeSceneFilenames } from "./filename-normalizer.js";
import { buildSceneExtractionPrompt } from "../prompts/scene-extraction.js"; import { buildSceneExtractionPrompt } from "../prompts/scene-extraction.js";
import { report } from "../report/reporter.js"; import { report } from "../report/reporter.js";
import type { LLMRunner } from "../types.js"; import type { LLMRunner, Logger } from "../types.js";
const TAG = "[memory-tdai] [extractor]"; const TAG = "[memory-tdai] [extractor]";
interface ExtractorLogger { type ExtractorLogger = Logger;
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
export interface ExtractionResult { export interface ExtractionResult {
memoriesProcessed: number; memoriesProcessed: number;
+2 -7
View File
@@ -13,6 +13,8 @@
* check health to dynamically downgrade to pure semantic search. * check health to dynamically downgrade to pure semantic search.
*/ */
import type { Logger } from "../types.js";
// ============================ // ============================
// Types // Types
// ============================ // ============================
@@ -20,13 +22,6 @@
/** Sparse vector: array of [token_hash, weight] pairs. */ /** Sparse vector: array of [token_hash, weight] pairs. */
export type SparseVector = Array<[number, number]>; export type SparseVector = Array<[number, number]>;
interface Logger {
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
export interface BM25ClientConfig { export interface BM25ClientConfig {
/** Sidecar service URL (default: "http://127.0.0.1:8084") */ /** Sidecar service URL (default: "http://127.0.0.1:8084") */
serviceUrl: string; serviceUrl: string;
+1 -7
View File
@@ -11,16 +11,10 @@
import { BM25Encoder } from "@tencentdb-agent-memory/tcvdb-text"; import { BM25Encoder } from "@tencentdb-agent-memory/tcvdb-text";
import type { SparseVector } from "@tencentdb-agent-memory/tcvdb-text"; import type { SparseVector } from "@tencentdb-agent-memory/tcvdb-text";
import type { Logger } from "../types.js";
export type { SparseVector }; export type { SparseVector };
interface Logger {
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
export interface BM25LocalConfig { export interface BM25LocalConfig {
/** Whether BM25 sparse encoding is enabled (default: true) */ /** Whether BM25 sparse encoding is enabled (default: true) */
enabled: boolean; enabled: boolean;
+2 -11
View File
@@ -13,6 +13,8 @@
* - Throws on failure; callers decide fallback strategy. * - Throws on failure; callers decide fallback strategy.
*/ */
import type { Logger } from "../types.js";
// ============================ // ============================
// Types // Types
// ============================ // ============================
@@ -104,17 +106,6 @@ export class EmbeddingNotReadyError extends Error {
} }
} }
// ============================
// Logger interface
// ============================
interface Logger {
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
const TAG = "[memory-tdai][embedding]"; const TAG = "[memory-tdai][embedding]";
// ============================ // ============================
+1 -7
View File
@@ -33,6 +33,7 @@ import type {
L0SearchResult, L0SearchResult,
L0FtsResult, L0FtsResult,
} from "./types.js"; } from "./types.js";
import type { Logger } from "../types.js";
// ============================ // ============================
// Types // Types
@@ -106,13 +107,6 @@ export interface L1QueryFilter {
updatedAfter?: string; updatedAfter?: string;
} }
interface Logger {
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
const TAG = "[memory-tdai][sqlite]"; const TAG = "[memory-tdai][sqlite]";
/** Persisted metadata about the embedding provider used to generate stored vectors. */ /** Persisted metadata about the embedding provider used to generate stored vectors. */
+2 -6
View File
@@ -17,6 +17,7 @@
import type { MemoryRecord } from "../record/l1-writer.js"; import type { MemoryRecord } from "../record/l1-writer.js";
import type { EmbeddingProviderInfo } from "./embedding.js"; import type { EmbeddingProviderInfo } from "./embedding.js";
import type { Logger } from "../types.js";
// Re-export so consumers can import everything from types.ts // Re-export so consumers can import everything from types.ts
export type { MemoryRecord, EmbeddingProviderInfo }; export type { MemoryRecord, EmbeddingProviderInfo };
@@ -26,12 +27,7 @@ export type { MemoryRecord, EmbeddingProviderInfo };
// ============================ // ============================
/** Minimal logger interface accepted by store implementations. */ /** Minimal logger interface accepted by store implementations. */
export interface StoreLogger { export type StoreLogger = Logger;
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
// ============================ // ============================
// L1 Types (Structured Memories) // L1 Types (Structured Memories)
+1 -7
View File
@@ -13,18 +13,12 @@
import type { IMemoryStore, L0SearchResult } from "../store/types.js"; import type { IMemoryStore, L0SearchResult } from "../store/types.js";
import { buildFtsQuery } from "../store/sqlite.js"; import { buildFtsQuery } from "../store/sqlite.js";
import type { EmbeddingService } from "../store/embedding.js"; import type { EmbeddingService } from "../store/embedding.js";
import type { Logger } from "../types.js";
// ============================ // ============================
// Types // Types
// ============================ // ============================
interface Logger {
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
export interface ConversationSearchResultItem { export interface ConversationSearchResultItem {
id: string; id: string;
session_key: string; session_key: string;
+1 -7
View File
@@ -13,18 +13,12 @@
import type { IMemoryStore, L1SearchResult } from "../store/types.js"; import type { IMemoryStore, L1SearchResult } from "../store/types.js";
import { buildFtsQuery } from "../store/sqlite.js"; import { buildFtsQuery } from "../store/sqlite.js";
import type { EmbeddingService } from "../store/embedding.js"; import type { EmbeddingService } from "../store/embedding.js";
import type { Logger } from "../types.js";
// ============================ // ============================
// Types // Types
// ============================ // ============================
interface Logger {
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
export interface MemorySearchResultItem { export interface MemorySearchResultItem {
id: string; id: string;
content: string; content: string;
+3 -3
View File
@@ -15,10 +15,10 @@
// ============================ // ============================
/** /**
* Minimal logger interface used throughout TDAI Core. * Canonical logger interface used across all TDAI modules.
* *
* Matches the existing `StoreLogger` and `RunnerLogger` interfaces * Named variants (StoreLogger, PluginLogger, etc.) are type aliases
* already used in the codebase — no migration needed for existing callers. * of this interface, kept for backward compatibility.
*/ */
export interface Logger { export interface Logger {
debug?: (message: string) => void; debug?: (message: string) => void;
+3 -6
View File
@@ -3,6 +3,8 @@
* Ported from context-offload-plugin with updated runtime defaults. * Ported from context-offload-plugin with updated runtime defaults.
*/ */
import type { Logger } from "../core/types.js";
// ============================ // ============================
// Data types // Data types
// ============================ // ============================
@@ -212,12 +214,7 @@ export interface PluginConfig {
// ============================ // ============================
/** Logger interface used by offload plugin components */ /** Logger interface used by offload plugin components */
export interface PluginLogger { export type PluginLogger = Logger;
info: (msg: string) => void;
warn: (msg: string) => void;
error: (msg: string) => void;
debug?: (msg: string) => void;
}
// ============================ // ============================
// Plugin defaults // Plugin defaults
+2 -6
View File
@@ -17,6 +17,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/core"; import type { OpenClawPluginApi } from "openclaw/plugin-sdk/core";
import { getEnv } from "./env.js"; import { getEnv } from "./env.js";
import { report } from "../core/report/reporter.js"; import { report } from "../core/report/reporter.js";
import type { Logger } from "../core/types.js";
/** /**
* Resolve a preferred temporary directory for memory-tdai operations. * Resolve a preferred temporary directory for memory-tdai operations.
@@ -49,12 +50,7 @@ function resolveOpenClawTmpDir(): string {
const TAG = "[memory-tdai] [runner]"; const TAG = "[memory-tdai] [runner]";
interface RunnerLogger { type RunnerLogger = Logger;
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
// Dynamic import type — runEmbeddedPiAgent is an internal API // Dynamic import type — runEmbeddedPiAgent is an internal API
// Prefer the public plugin runtime signature so host-injected runtimes stay assignable. // Prefer the public plugin runtime signature so host-injected runtimes stay assignable.
+1 -7
View File
@@ -3,13 +3,7 @@ import path from "node:path";
import type { IMemoryStore } from "../core/store/types.js"; import type { IMemoryStore } from "../core/store/types.js";
import { ManagedTimer } from "./managed-timer.js"; import { ManagedTimer } from "./managed-timer.js";
import type { Logger } from "../core/types.js";
interface Logger {
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
export interface MemoryCleanerOptions { export interface MemoryCleanerOptions {
baseDir: string; baseDir: string;
+3 -6
View File
@@ -36,6 +36,7 @@ import { SceneExtractor } from "../core/scene/scene-extractor.js";
import { PersonaTrigger } from "../core/persona/persona-trigger.js"; import { PersonaTrigger } from "../core/persona/persona-trigger.js";
import { PersonaGenerator } from "../core/persona/persona-generator.js"; import { PersonaGenerator } from "../core/persona/persona-generator.js";
import { pullProfilesToLocal, syncLocalProfilesToStore } from "../core/profile/profile-sync.js"; import { pullProfilesToLocal, syncLocalProfilesToStore } from "../core/profile/profile-sync.js";
import type { Logger } from "../core/types.js";
const TAG = "[memory-tdai] [pipeline-factory]"; const TAG = "[memory-tdai] [pipeline-factory]";
@@ -47,12 +48,8 @@ function supportsProfileSyncWrite(store?: IMemoryStore): boolean {
// Logger interface // Logger interface
// ============================ // ============================
export interface PipelineLogger { /** @deprecated Use `Logger` from `../core/types.js` directly. */
debug?: (message: string) => void; export type PipelineLogger = Logger;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
// ============================ // ============================
// Factory options // Factory options
+1 -7
View File
@@ -81,18 +81,12 @@ import { SessionFilter } from "./session-filter.js";
import { ManagedTimer } from "./managed-timer.js"; import { ManagedTimer } from "./managed-timer.js";
import { SerialQueue } from "./serial-queue.js"; import { SerialQueue } from "./serial-queue.js";
import { report } from "../core/report/reporter.js"; import { report } from "../core/report/reporter.js";
import type { Logger } from "../core/types.js";
// ============================ // ============================
// Types // Types
// ============================ // ============================
interface Logger {
debug?: (message: string) => void;
info: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
/** A single captured message ready for L1 processing. */ /** A single captured message ready for L1 processing. */
export interface CapturedMessage { export interface CapturedMessage {
role: "user" | "assistant" | "tool"; role: "user" | "assistant" | "tool";