refactor(memory-host): narrow runtime adapters

This commit is contained in:
Peter Steinberger
2026-04-28 06:40:33 +01:00
parent 29a34e0a4d
commit 89079a32ef
20 changed files with 219 additions and 59 deletions

View File

@@ -1,2 +1,2 @@
282897f1e044b79bd444e164646e492602f987fa0fefb20a3336aa0b2445e6b7 plugin-sdk-api-baseline.json
49cc5b3330e19a86a4884c71d08070034a39463d7e25ab8eca124f65028f1114 plugin-sdk-api-baseline.jsonl
ffc0924db91ebb9b79c488879bc9938b199047a2577fc469e194af673c9e1303 plugin-sdk-api-baseline.json
f2445b07d3ead6c38ab2a37c2e0eccb6414ade36d3fb9eb3dd157e5104f88b0d plugin-sdk-api-baseline.jsonl

View File

@@ -5,7 +5,7 @@ export {
listRegisteredMemoryEmbeddingProviders,
listMemoryEmbeddingProviders,
listRegisteredMemoryEmbeddingProviderAdapters,
} from "./host/openclaw-runtime.js";
} from "./host/openclaw-runtime-memory.js";
export type {
MemoryEmbeddingBatchChunk,
MemoryEmbeddingBatchOptions,
@@ -14,7 +14,7 @@ export type {
MemoryEmbeddingProviderCreateOptions,
MemoryEmbeddingProviderCreateResult,
MemoryEmbeddingProviderRuntime,
} from "./host/openclaw-runtime.js";
} from "./host/openclaw-runtime-memory.js";
export { createLocalEmbeddingProvider, DEFAULT_LOCAL_MODEL } from "./host/embeddings.js";
export { extractBatchErrorMessage, formatUnavailableBatchError } from "./host/batch-error-utils.js";
export { postJsonWithRetry } from "./host/batch-http.js";

View File

@@ -6,37 +6,37 @@ export {
resolveAgentWorkspaceDir,
resolveDefaultAgentId,
resolveSessionAgentId,
} from "./host/openclaw-runtime.js";
} from "./host/openclaw-runtime-agent.js";
export {
resolveMemorySearchConfig,
resolveMemorySearchSyncConfig,
type ResolvedMemorySearchConfig,
type ResolvedMemorySearchSyncConfig,
} from "./host/openclaw-runtime.js";
export { parseDurationMs } from "./host/openclaw-runtime.js";
export { loadConfig } from "./host/openclaw-runtime.js";
export { resolveStateDir } from "./host/openclaw-runtime.js";
export { resolveSessionTranscriptsDirForAgent } from "./host/openclaw-runtime.js";
} from "./host/openclaw-runtime-agent.js";
export { parseDurationMs } from "./host/openclaw-runtime-config.js";
export { loadConfig } from "./host/openclaw-runtime-config.js";
export { resolveStateDir } from "./host/openclaw-runtime-config.js";
export { resolveSessionTranscriptsDirForAgent } from "./host/openclaw-runtime-config.js";
export {
hasConfiguredSecretInput,
normalizeResolvedSecretInputString,
} from "./host/openclaw-runtime.js";
export { writeFileWithinRoot } from "./host/openclaw-runtime.js";
export { createSubsystemLogger } from "./host/openclaw-runtime.js";
export { detectMime } from "./host/openclaw-runtime.js";
export { resolveGlobalSingleton } from "./host/openclaw-runtime.js";
export { onSessionTranscriptUpdate } from "./host/openclaw-runtime.js";
export { splitShellArgs } from "./host/openclaw-runtime.js";
export { runTasksWithConcurrency } from "./host/openclaw-runtime.js";
} from "./host/openclaw-runtime-config.js";
export { writeFileWithinRoot } from "./host/openclaw-runtime-io.js";
export { createSubsystemLogger } from "./host/openclaw-runtime-io.js";
export { detectMime } from "./host/openclaw-runtime-io.js";
export { resolveGlobalSingleton } from "./host/openclaw-runtime-io.js";
export { onSessionTranscriptUpdate } from "./host/openclaw-runtime-session.js";
export { splitShellArgs } from "./host/openclaw-runtime-io.js";
export { runTasksWithConcurrency } from "./host/openclaw-runtime-io.js";
export {
shortenHomeInString,
shortenHomePath,
resolveUserPath,
truncateUtf16Safe,
} from "./host/openclaw-runtime.js";
export type { OpenClawConfig } from "./host/openclaw-runtime.js";
export type { SessionSendPolicyConfig } from "./host/openclaw-runtime.js";
export type { SecretInput } from "./host/openclaw-runtime.js";
} from "./host/openclaw-runtime-io.js";
export type { OpenClawConfig } from "./host/openclaw-runtime-config.js";
export type { SessionSendPolicyConfig } from "./host/openclaw-runtime-config.js";
export type { SecretInput } from "./host/openclaw-runtime-config.js";
export type {
MemoryBackend,
MemoryCitationsMode,
@@ -44,5 +44,5 @@ export type {
MemoryQmdIndexPath,
MemoryQmdMcporterConfig,
MemoryQmdSearchMode,
} from "./host/openclaw-runtime.js";
export type { MemorySearchConfig } from "./host/openclaw-runtime.js";
} from "./host/openclaw-runtime-config.js";
export type { MemorySearchConfig } from "./host/openclaw-runtime-config.js";

View File

@@ -12,7 +12,7 @@ export {
type SessionFileEntry,
type SessionTranscriptClassification,
} from "./host/session-files.js";
export { parseUsageCountedSessionIdFromFileName } from "./host/openclaw-runtime.js";
export { parseUsageCountedSessionIdFromFileName } from "./host/openclaw-runtime-session.js";
export { parseQmdQueryJson, type QmdQueryResult } from "./host/qmd-query-parser.js";
export {
deriveQmdScopeChannel,

View File

@@ -1,5 +1,5 @@
import type { EmbeddingProviderOptions } from "./embeddings.types.js";
import { requireApiKey, resolveApiKeyForProvider } from "./openclaw-runtime.js";
import { requireApiKey, resolveApiKeyForProvider } from "./openclaw-runtime-auth.js";
import { buildRemoteBaseUrlPolicy } from "./remote-http.js";
import { resolveMemorySecretInputString } from "./secret-input.js";
import type { SsrFPolicy } from "./ssrf-policy.js";

View File

@@ -16,10 +16,12 @@ import {
CHARS_PER_TOKEN_ESTIMATE,
detectMime,
estimateStringChars,
resolveCanonicalRootMemoryFile,
runTasksWithConcurrency,
} from "./openclaw-runtime-io.js";
import {
resolveCanonicalRootMemoryFile,
shouldSkipRootMemoryAuxiliaryPath,
} from "./openclaw-runtime.js";
} from "./openclaw-runtime-memory.js";
export { hashText } from "./hash.js";
import { hashText } from "./hash.js";

View File

@@ -0,0 +1,21 @@
export {
DEFAULT_PI_COMPACTION_RESERVE_TOKENS_FLOOR,
asToolParamsRecord,
jsonResult,
parseAgentSessionKey,
readNumberParam,
readStringParam,
resolveAgentContextLimits,
resolveAgentDir,
resolveAgentWorkspaceDir,
resolveCronStyleNow,
resolveDefaultAgentId,
resolveMemorySearchConfig,
resolveMemorySearchSyncConfig,
resolveSessionAgentId,
} from "./openclaw-runtime.js";
export type {
AnyAgentTool,
ResolvedMemorySearchConfig,
ResolvedMemorySearchSyncConfig,
} from "./openclaw-runtime.js";

View File

@@ -0,0 +1 @@
export { requireApiKey, resolveApiKeyForProvider } from "./openclaw-runtime.js";

View File

@@ -0,0 +1,17 @@
export {
colorize,
defaultRuntime,
formatDocsLink,
formatErrorMessage,
formatHelpExamples,
isRich,
isVerbose,
resolveCommandSecretRefsViaGateway,
setVerbose,
shortenHomeInString,
shortenHomePath,
theme,
withManager,
withProgress,
withProgressTotals,
} from "./openclaw-runtime.js";

View File

@@ -0,0 +1,22 @@
export {
getRuntimeConfig,
hasConfiguredSecretInput,
loadConfig,
normalizeResolvedSecretInputString,
parseDurationMs,
parseNonNegativeByteSize,
resolveSessionTranscriptsDirForAgent,
resolveStateDir,
} from "./openclaw-runtime.js";
export type {
MemoryBackend,
MemoryCitationsMode,
MemoryQmdConfig,
MemoryQmdIndexPath,
MemoryQmdMcporterConfig,
MemoryQmdSearchMode,
MemorySearchConfig,
OpenClawConfig,
SecretInput,
SessionSendPolicyConfig,
} from "./openclaw-runtime.js";

View File

@@ -0,0 +1,15 @@
export {
CHARS_PER_TOKEN_ESTIMATE,
createSubsystemLogger,
detectMime,
estimateStringChars,
redactSensitiveText,
resolveGlobalSingleton,
resolveUserPath,
runTasksWithConcurrency,
shortenHomeInString,
shortenHomePath,
splitShellArgs,
truncateUtf16Safe,
writeFileWithinRoot,
} from "./openclaw-runtime.js";

View File

@@ -0,0 +1,29 @@
export {
buildActiveMemoryPromptSection,
emptyPluginConfigSchema,
getMemoryCapabilityRegistration,
getMemoryEmbeddingProvider,
listActiveMemoryPublicArtifacts,
listMemoryEmbeddingProviders,
listRegisteredMemoryEmbeddingProviderAdapters,
listRegisteredMemoryEmbeddingProviders,
resolveCanonicalRootMemoryFile,
shouldSkipRootMemoryAuxiliaryPath,
} from "./openclaw-runtime.js";
export type {
MemoryEmbeddingBatchChunk,
MemoryEmbeddingBatchOptions,
MemoryEmbeddingProvider,
MemoryEmbeddingProviderAdapter,
MemoryEmbeddingProviderCreateOptions,
MemoryEmbeddingProviderCreateResult,
MemoryEmbeddingProviderRuntime,
MemoryFlushPlan,
MemoryFlushPlanResolver,
MemoryPluginCapability,
MemoryPluginPublicArtifact,
MemoryPluginPublicArtifactsProvider,
MemoryPluginRuntime,
MemoryPromptSectionBuilder,
OpenClawPluginApi,
} from "./openclaw-runtime.js";

View File

@@ -0,0 +1,5 @@
export {
fetchWithSsrFGuard,
shouldUseEnvHttpProxyForUrl,
ssrfPolicyFromHttpBaseUrlAllowedHostname,
} from "./openclaw-runtime.js";

View File

@@ -0,0 +1,18 @@
export {
HEARTBEAT_PROMPT,
HEARTBEAT_TOKEN,
SILENT_REPLY_TOKEN,
hasInterSessionUserProvenance,
isCompactionCheckpointTranscriptFileName,
isCronRunSessionKey,
isExecCompletionEvent,
isHeartbeatUserMessage,
isSessionArchiveArtifactName,
isSilentReplyPayloadText,
isUsageCountedSessionTranscriptFileName,
onSessionTranscriptUpdate,
parseUsageCountedSessionIdFromFileName,
resolveSessionTranscriptsDirForAgent,
stripInboundMetadata,
stripInternalRuntimeContext,
} from "./openclaw-runtime.js";

View File

@@ -1,3 +1,4 @@
// Agent/runtime helpers.
export { resolveCronStyleNow } from "../../../../src/agents/current-time.js";
export {
resolveAgentContextLimits,
@@ -22,6 +23,8 @@ export {
type ResolvedMemorySearchConfig,
type ResolvedMemorySearchSyncConfig,
} from "../../../../src/agents/memory-search.js";
// Session and reply helpers.
export { isHeartbeatUserMessage } from "../../../../src/auto-reply/heartbeat-filter.js";
export { HEARTBEAT_PROMPT } from "../../../../src/auto-reply/heartbeat.js";
export { stripInboundMetadata } from "../../../../src/auto-reply/reply/strip-inbound-meta.js";
@@ -30,6 +33,8 @@ export {
SILENT_REPLY_TOKEN,
isSilentReplyPayloadText,
} from "../../../../src/auto-reply/tokens.js";
// CLI/runtime/config helpers.
export { formatErrorMessage, withManager } from "../../../../src/cli/cli-utils.js";
export { resolveCommandSecretRefsViaGateway } from "../../../../src/cli/command-secret-gateway.js";
export { formatHelpExamples } from "../../../../src/cli/help-format.js";
@@ -66,6 +71,8 @@ export {
export type { SecretInput } from "../../../../src/config/types.secrets.js";
export type { MemorySearchConfig } from "../../../../src/config/types.tools.js";
export { isVerbose, setVerbose } from "../../../../src/globals.js";
// IO, network, and logging helpers.
export { isExecCompletionEvent } from "../../../../src/infra/heartbeat-events-filter.js";
export { writeFileWithinRoot } from "../../../../src/infra/fs-safe.js";
export { fetchWithSsrFGuard } from "../../../../src/infra/net/fetch-guard.js";
@@ -74,6 +81,8 @@ export { ssrfPolicyFromHttpBaseUrlAllowedHostname } from "../../../../src/infra/
export { redactSensitiveText } from "../../../../src/logging/redact.js";
export { createSubsystemLogger } from "../../../../src/logging/subsystem.js";
export { detectMime } from "../../../../src/media/mime.js";
// Memory plugin helpers.
export {
resolveCanonicalRootMemoryFile,
shouldSkipRootMemoryAuxiliaryPath,
@@ -109,6 +118,8 @@ export type {
MemoryPromptSectionBuilder,
} from "../../../../src/plugins/memory-state.js";
export type { OpenClawPluginApi } from "../../../../src/plugins/types.js";
// Shared session/text utilities.
export { defaultRuntime } from "../../../../src/runtime.js";
export { parseAgentSessionKey } from "../../../../src/routing/session-key.js";
export { hasInterSessionUserProvenance } from "../../../../src/sessions/input-provenance.js";

View File

@@ -2,7 +2,7 @@ import {
fetchWithSsrFGuard,
shouldUseEnvHttpProxyForUrl,
ssrfPolicyFromHttpBaseUrlAllowedHostname,
} from "./openclaw-runtime.js";
} from "./openclaw-runtime-network.js";
import type { SsrFPolicy } from "./ssrf-policy.js";
export const MEMORY_REMOTE_TRUSTED_ENV_PROXY_MODE = "trusted_env_proxy";

View File

@@ -2,8 +2,8 @@ import fsSync from "node:fs";
import fs from "node:fs/promises";
import path from "node:path";
import { hashText } from "./hash.js";
import { createSubsystemLogger, redactSensitiveText } from "./openclaw-runtime-io.js";
import {
createSubsystemLogger,
HEARTBEAT_PROMPT,
HEARTBEAT_TOKEN,
hasInterSessionUserProvenance,
@@ -14,11 +14,10 @@ import {
isSessionArchiveArtifactName,
isSilentReplyPayloadText,
isUsageCountedSessionTranscriptFileName,
redactSensitiveText,
resolveSessionTranscriptsDirForAgent,
stripInboundMetadata,
stripInternalRuntimeContext,
} from "./openclaw-runtime.js";
} from "./openclaw-runtime-session.js";
const DREAMING_NARRATIVE_RUN_PREFIX = "dreaming-narrative-";
// Keep the historical one-line-per-message export shape for normal turns, but

View File

@@ -1,11 +1,11 @@
// Focused runtime contract for memory CLI/UI helpers.
export { formatErrorMessage, withManager } from "./host/openclaw-runtime.js";
export { formatHelpExamples } from "./host/openclaw-runtime.js";
export { resolveCommandSecretRefsViaGateway } from "./host/openclaw-runtime.js";
export { withProgress, withProgressTotals } from "./host/openclaw-runtime.js";
export { defaultRuntime } from "./host/openclaw-runtime.js";
export { formatDocsLink } from "./host/openclaw-runtime.js";
export { colorize, isRich, theme } from "./host/openclaw-runtime.js";
export { isVerbose, setVerbose } from "./host/openclaw-runtime.js";
export { shortenHomeInString, shortenHomePath } from "./host/openclaw-runtime.js";
export { formatErrorMessage, withManager } from "./host/openclaw-runtime-cli.js";
export { formatHelpExamples } from "./host/openclaw-runtime-cli.js";
export { resolveCommandSecretRefsViaGateway } from "./host/openclaw-runtime-cli.js";
export { withProgress, withProgressTotals } from "./host/openclaw-runtime-cli.js";
export { defaultRuntime } from "./host/openclaw-runtime-cli.js";
export { formatDocsLink } from "./host/openclaw-runtime-cli.js";
export { colorize, isRich, theme } from "./host/openclaw-runtime-cli.js";
export { isVerbose, setVerbose } from "./host/openclaw-runtime-cli.js";
export { shortenHomeInString, shortenHomePath } from "./host/openclaw-runtime-cli.js";

View File

@@ -1,34 +1,34 @@
// Focused runtime contract for memory plugin config/state/helpers.
export type { AnyAgentTool } from "./host/openclaw-runtime.js";
export { resolveCronStyleNow } from "./host/openclaw-runtime.js";
export { DEFAULT_PI_COMPACTION_RESERVE_TOKENS_FLOOR } from "./host/openclaw-runtime.js";
export { resolveDefaultAgentId, resolveSessionAgentId } from "./host/openclaw-runtime.js";
export { resolveMemorySearchConfig } from "./host/openclaw-runtime.js";
export type { AnyAgentTool } from "./host/openclaw-runtime-agent.js";
export { resolveCronStyleNow } from "./host/openclaw-runtime-agent.js";
export { DEFAULT_PI_COMPACTION_RESERVE_TOKENS_FLOOR } from "./host/openclaw-runtime-agent.js";
export { resolveDefaultAgentId, resolveSessionAgentId } from "./host/openclaw-runtime-agent.js";
export { resolveMemorySearchConfig } from "./host/openclaw-runtime-agent.js";
export {
asToolParamsRecord,
jsonResult,
readNumberParam,
readStringParam,
} from "./host/openclaw-runtime.js";
export { SILENT_REPLY_TOKEN } from "./host/openclaw-runtime.js";
export { parseNonNegativeByteSize } from "./host/openclaw-runtime.js";
} from "./host/openclaw-runtime-agent.js";
export { SILENT_REPLY_TOKEN } from "./host/openclaw-runtime-session.js";
export { parseNonNegativeByteSize } from "./host/openclaw-runtime-config.js";
export {
getRuntimeConfig,
/** @deprecated Use getRuntimeConfig(), or pass the already loaded config through the call path. */
loadConfig,
} from "./host/openclaw-runtime.js";
export { resolveStateDir } from "./host/openclaw-runtime.js";
export { resolveSessionTranscriptsDirForAgent } from "./host/openclaw-runtime.js";
export { emptyPluginConfigSchema } from "./host/openclaw-runtime.js";
} from "./host/openclaw-runtime-config.js";
export { resolveStateDir } from "./host/openclaw-runtime-config.js";
export { resolveSessionTranscriptsDirForAgent } from "./host/openclaw-runtime-config.js";
export { emptyPluginConfigSchema } from "./host/openclaw-runtime-memory.js";
export {
buildActiveMemoryPromptSection,
getMemoryCapabilityRegistration,
listActiveMemoryPublicArtifacts,
} from "./host/openclaw-runtime.js";
export { parseAgentSessionKey } from "./host/openclaw-runtime.js";
export type { OpenClawConfig } from "./host/openclaw-runtime.js";
export type { MemoryCitationsMode } from "./host/openclaw-runtime.js";
} from "./host/openclaw-runtime-memory.js";
export { parseAgentSessionKey } from "./host/openclaw-runtime-agent.js";
export type { OpenClawConfig } from "./host/openclaw-runtime-config.js";
export type { MemoryCitationsMode } from "./host/openclaw-runtime-config.js";
export type {
MemoryFlushPlan,
MemoryFlushPlanResolver,
@@ -37,5 +37,5 @@ export type {
MemoryPluginPublicArtifactsProvider,
MemoryPluginRuntime,
MemoryPromptSectionBuilder,
} from "./host/openclaw-runtime.js";
export type { OpenClawPluginApi } from "./host/openclaw-runtime.js";
} from "./host/openclaw-runtime-memory.js";
export type { OpenClawPluginApi } from "./host/openclaw-runtime-memory.js";

View File

@@ -58,6 +58,16 @@ const MEMORY_HOST_SDK_EXPORTS = [
const MEMORY_HOST_SDK_ALLOWED_CORE_BRIDGE_FILES = [
"packages/memory-host-sdk/src/host/openclaw-runtime.ts",
] as const;
const MEMORY_HOST_SDK_RUNTIME_ADAPTER_FILES = [
"packages/memory-host-sdk/src/host/openclaw-runtime-agent.ts",
"packages/memory-host-sdk/src/host/openclaw-runtime-auth.ts",
"packages/memory-host-sdk/src/host/openclaw-runtime-cli.ts",
"packages/memory-host-sdk/src/host/openclaw-runtime-config.ts",
"packages/memory-host-sdk/src/host/openclaw-runtime-io.ts",
"packages/memory-host-sdk/src/host/openclaw-runtime-memory.ts",
"packages/memory-host-sdk/src/host/openclaw-runtime-network.ts",
"packages/memory-host-sdk/src/host/openclaw-runtime-session.ts",
] as const;
// oxlint-disable-next-line typescript/no-unnecessary-type-parameters -- Test helper lets assertions ascribe JSON file shape.
function readJsonFile<T>(relativePath: string): T {
@@ -87,6 +97,13 @@ function collectCoreReferenceFiles(relativeDir: string): string[] {
});
}
function collectOpenClawRuntimeDirectImportFiles(relativeDir: string): string[] {
return collectCodeFiles(relativeDir).filter((file) => {
const source = readFileSync(resolve(REPO_ROOT, file), "utf8");
return source.includes('"./openclaw-runtime.js"');
});
}
describe("opt-in extension package boundaries", () => {
it("keeps path aliases in a dedicated shared config", () => {
const pathsConfig = readJsonFile<TsConfigJson>(EXTENSION_PACKAGE_BOUNDARY_PATHS_CONFIG);
@@ -239,6 +256,9 @@ describe("opt-in extension package boundaries", () => {
expect(collectCoreReferenceFiles("packages/memory-host-sdk/src")).toEqual([
...MEMORY_HOST_SDK_ALLOWED_CORE_BRIDGE_FILES,
]);
expect(collectOpenClawRuntimeDirectImportFiles("packages/memory-host-sdk/src")).toEqual([
...MEMORY_HOST_SDK_RUNTIME_ADAPTER_FILES,
]);
});
it("keeps plugin-package-contract independent from core internals", () => {