Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

chore(openclaw-plugin): remove unused code and redundant guards (#2050)

AutoCoder5271baff1be9
diff --git a/examples/openclaw-plugin/context-engine.ts b/examples/openclaw-plugin/context-engine.ts
index d0bcc62c9..d69450a85 100644
--- a/examples/openclaw-plugin/context-engine.ts
+++ b/examples/openclaw-plugin/context-engine.ts
@@ -153,10 +153,6 @@ function allocateContextBudget(totalBudget: number, instructionTokens = 0): Cont
return { archiveMemory, sessionContext, reserved };
}
-function estimateTokens(messages: AgentMessage[]): number {
- return Math.max(1, messages.length * 80);
-}
-
function roughEstimate(messages: AgentMessage[]): number {
return Math.ceil(JSON.stringify(messages).length / 4);
}
@@ -1387,15 +1383,13 @@ export function createMemoryOpenVikingContextEngine(params: {
`openviking: Phase2 memory extraction runs asynchronously on the server (task_id=${commitResult.task_id}). ` +
"memories_extracted appears only after that task completes — not in this immediate response.",
);
- if (cfg.logFindRequests) {
- void pollPhase2ExtractionOutcome(
- getClient,
- commitResult.task_id,
- agentId,
- logger,
- OVSessionId,
- );
- }
+ void pollPhase2ExtractionOutcome(
+ getClient,
+ commitResult.task_id,
+ agentId,
+ logger,
+ OVSessionId,
+ );
}
} catch (err) {
logger.warn?.(`openviking: afterTurn failed: ${String(err)}`);
diff --git a/examples/openclaw-plugin/process-manager.ts b/examples/openclaw-plugin/process-manager.ts
index 8bd5aac0d..d2b4fc8a0 100644
--- a/examples/openclaw-plugin/process-manager.ts
+++ b/examples/openclaw-plugin/process-manager.ts
@@ -1,98 +1,3 @@
-import { Socket } from "node:net";
-
-type ChildLike = {
- killed?: boolean;
- exitCode?: number | null;
- signalCode?: string | null;
- off?: (event: string, listener: (...args: any[]) => void) => void;
- once: (event: string, listener: (...args: any[]) => void) => void;
-};
-
-export function waitForHealth(baseUrl: string, timeoutMs: number, intervalMs: number): Promise<void> {
- const deadline = Date.now() + timeoutMs;
- return new Promise((resolve, reject) => {
- const tick = () => {
- if (Date.now() > deadline) {
- reject(new Error(`OpenViking health check timeout at ${baseUrl}`));
- return;
- }
- fetch(`${baseUrl}/health`)
- .then((r) => r.json())
- .then((body: { status?: string }) => {
- if (body?.status === "ok") {
- resolve();
- return;
- }
- setTimeout(tick, intervalMs);
- })
- .catch(() => setTimeout(tick, intervalMs));
- };
- tick();
- });
-}
-
-export function waitForHealthOrExit(
- baseUrl: string,
- timeoutMs: number,
- intervalMs: number,
- child: ChildLike,
-): Promise<void> {
- const exited =
- child.killed || child.exitCode !== null || child.signalCode !== null;
- if (exited) {
- return Promise.reject(
- new Error(
- `OpenViking subprocess exited before health check ` +
- `(code=${child.exitCode}, signal=${child.signalCode})`,
- ),
- );
- }
-
- return new Promise((resolve, reject) => {
- let settled = false;
-
- const cleanup = () => {
- child.off?.("error", onError);
- child.off?.("exit", onExit);
- };
-
- const finishResolve = () => {
- if (settled) {
- return;
- }
- settled = true;
- cleanup();
- resolve();
- };
-
- const finishReject = (err: unknown) => {
- if (settled) {
- return;
- }
- settled = true;
- cleanup();
- reject(err instanceof Error ? err : new Error(String(err)));
- };
-
- const onError = (err: Error) => {
- finishReject(err);
- };
-
- const onExit = (code: number | null, signal: string | null) => {
- finishReject(
- new Error(
- `OpenViking subprocess exited before health check ` +
- `(code=${code}, signal=${signal})`,
- ),
- );
- };
-
- child.once("error", onError);
- child.once("exit", onExit);
- waitForHealth(baseUrl, timeoutMs, intervalMs).then(finishResolve, finishReject);
- });
-}
-
export function withTimeout<T>(promise: Promise<T>, timeoutMs: number, timeoutMessage: string): Promise<T> {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => reject(new Error(timeoutMessage)), timeoutMs);
@@ -109,30 +14,6 @@ export function withTimeout<T>(promise: Promise<T>, timeoutMs: number, timeoutMe
});
}
-export function quickTcpProbe(host: string, port: number, timeoutMs: number): Promise<boolean> {
- return new Promise((resolve) => {
- const socket = new Socket();
- let done = false;
- const finish = (ok: boolean) => {
- if (done) {
- return;
- }
- done = true;
- socket.destroy();
- resolve(ok);
- };
- socket.setTimeout(timeoutMs);
- socket.once("connect", () => finish(true));
- socket.once("timeout", () => finish(false));
- socket.once("error", () => finish(false));
- try {
- socket.connect(port, host);
- } catch {
- finish(false);
- }
- });
-}
-
export async function quickHealthCheck(baseUrl: string, timeoutMs: number): Promise<boolean> {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), timeoutMs);
@@ -162,8 +43,3 @@ export async function quickRecallPrecheck(
}
return { ok: false, reason: "health check failed" };
}
-
-export interface ProcessLogger {
- info?: (msg: string) => void;
- warn?: (msg: string) => void;
-}
diff --git a/examples/openclaw-plugin/runtime-utils.ts b/examples/openclaw-plugin/runtime-utils.ts
index 630b8b110..12303d79e 100644
--- a/examples/openclaw-plugin/runtime-utils.ts
+++ b/examples/openclaw-plugin/runtime-utils.ts
@@ -1,7 +1,4 @@
const _env = globalThis["process"];
-export function sysEnv(): NodeJS.ProcessEnv {
- return _env.env;
-}
export function getEnv(key: string): string | undefined {
return _env.env[key];
diff --git a/examples/openclaw-plugin/text-utils.ts b/examples/openclaw-plugin/text-utils.ts
index b83fe340a..7b7d39784 100644
--- a/examples/openclaw-plugin/text-utils.ts
+++ b/examples/openclaw-plugin/text-utils.ts
@@ -27,8 +27,6 @@ const SUBAGENT_CONTEXT_RE = /^\s*\[Subagent Context\]/i;
const MEMORY_INTENT_RE = /记住|记下|remember|save|store|偏好|preference|规则|rule|事实|fact/i;
const QUESTION_CUE_RE =
/[??]|\b(?:what|when|where|who|why|how|which|can|could|would|did|does|is|are)\b|^(?:请问|能否|可否|怎么|如何|什么时候|谁|什么|哪|是否)/i;
-export const CAPTURE_LIMIT = 3;
-
function resolveCaptureMinLength(text: string): number {
return CJK_CHAR_REGEX.test(text) ? 4 : 10;
}
@@ -274,21 +272,6 @@ export function extractTextsFromUserMessages(messages: unknown[]): string[] {
return texts;
}
-function formatToolUseBlock(b: Record<string, unknown>): string {
- const name = typeof b.name === "string" ? b.name : "unknown";
- let inputStr = "";
- if (b.input !== undefined && b.input !== null) {
- try {
- inputStr = typeof b.input === "string" ? b.input : JSON.stringify(b.input);
- } catch {
- inputStr = String(b.input);
- }
- }
- return inputStr
- ? `[toolUse: ${name}]\n${inputStr}`
- : `[toolUse: ${name}]`;
-}
-
function formatToolResultContent(content: unknown): string {
if (typeof content === "string") return content.trim();
if (Array.isArray(content)) {
@@ -311,39 +294,6 @@ function formatToolResultContent(content: unknown): string {
return "";
}
-/**
- * Extract text from a single message without a `[role]:` prefix.
- * Used by afterTurn to send messages with their actual role.
- */
-export function extractSingleMessageText(msg: unknown): string {
- if (!msg || typeof msg !== "object") return "";
- const m = msg as Record<string, unknown>;
- const role = m.role as string;
- if (!role || role === "system") return "";
-
- if (role === "toolResult") {
- const toolName = typeof m.toolName === "string" ? m.toolName : "tool";
- const resultText = formatToolResultContent(m.content);
- return resultText ? `[${toolName} result]: ${resultText}` : "";
- }
-
- const content = m.content;
- if (typeof content === "string") return content.trim();
- if (Array.isArray(content)) {
- const parts: string[] = [];
- for (const block of content) {
- const b = block as Record<string, unknown>;
- if (b?.type === "text" && typeof b.text === "string") {
- parts.push((b.text as string).trim());
- } else if (b?.type === "toolUse") {
- parts.push(formatToolUseBlock(b));
- }
- }
- return parts.join("\n");
- }
- return "";
-}
-
/**
* 提取消息中的一个 part 的文本内容,并清理时间戳等噪音
*/
@@ -367,7 +317,7 @@ function extractPartText(content: unknown): string {
/**
* 结构化消息类型 - 用于 afterTurn 发送到 OpenViking
*/
-export type ExtractedMessage = {
+type ExtractedMessage = {
role: "user" | "assistant";
parts: Array<{
type: "text";
@@ -459,7 +409,6 @@ export function extractNewTurnMessages(
}
// user/assistant -> type: "text"
- // 统一 role 为 user
const content = msg.content;
const text = extractPartText(content);