fix: remove opinionated filters from OpenClaw plugin
Remove arbitrary TOOL_RESULT_MAX_LENGTH truncation, capture all content blocks instead of only the first, observe all tool uses including memory_ tools, and filter context injection by workspace directory instead of hardcoded project name. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+10
-11
@@ -1,5 +1,5 @@
|
|||||||
import { writeFile } from "fs/promises";
|
import { writeFile } from "fs/promises";
|
||||||
import { join } from "path";
|
import { basename, join } from "path";
|
||||||
|
|
||||||
// Minimal type declarations for the OpenClaw Plugin SDK.
|
// Minimal type declarations for the OpenClaw Plugin SDK.
|
||||||
// These match the real OpenClawPluginApi provided by the gateway at runtime.
|
// These match the real OpenClawPluginApi provided by the gateway at runtime.
|
||||||
@@ -173,7 +173,6 @@ interface ClaudeMemPluginConfig {
|
|||||||
|
|
||||||
const MAX_SSE_BUFFER_SIZE = 1024 * 1024; // 1MB
|
const MAX_SSE_BUFFER_SIZE = 1024 * 1024; // 1MB
|
||||||
const DEFAULT_WORKER_PORT = 37777;
|
const DEFAULT_WORKER_PORT = 37777;
|
||||||
const TOOL_RESULT_MAX_LENGTH = 1000;
|
|
||||||
|
|
||||||
// Agent emoji map for observation feed messages.
|
// Agent emoji map for observation feed messages.
|
||||||
// When creating a new OpenClaw agent, add its agentId and emoji here.
|
// When creating a new OpenClaw agent, add its agentId and emoji here.
|
||||||
@@ -466,9 +465,11 @@ export default function claudeMemPlugin(api: OpenClawPluginApi): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function syncMemoryToWorkspace(workspaceDir: string): Promise<void> {
|
async function syncMemoryToWorkspace(workspaceDir: string): Promise<void> {
|
||||||
|
// Derive project name from workspace directory (matches Claude Code's getProjectName logic)
|
||||||
|
const workspaceProject = basename(workspaceDir) || baseProjectName;
|
||||||
const contextText = await workerGetText(
|
const contextText = await workerGetText(
|
||||||
workerPort,
|
workerPort,
|
||||||
`/api/context/inject?projects=${encodeURIComponent(baseProjectName)}`,
|
`/api/context/inject?projects=${encodeURIComponent(workspaceProject)}`,
|
||||||
api.logger
|
api.logger
|
||||||
);
|
);
|
||||||
if (contextText && contextText.trim().length > 0) {
|
if (contextText && contextText.trim().length > 0) {
|
||||||
@@ -556,20 +557,18 @@ export default function claudeMemPlugin(api: OpenClawPluginApi): void {
|
|||||||
api.on("tool_result_persist", (event, ctx) => {
|
api.on("tool_result_persist", (event, ctx) => {
|
||||||
api.logger.info(`[claude-mem] tool_result_persist fired: tool=${event.toolName ?? "unknown"} agent=${ctx.agentId ?? "none"} session=${ctx.sessionKey ?? "none"}`);
|
api.logger.info(`[claude-mem] tool_result_persist fired: tool=${event.toolName ?? "unknown"} agent=${ctx.agentId ?? "none"} session=${ctx.sessionKey ?? "none"}`);
|
||||||
const toolName = event.toolName;
|
const toolName = event.toolName;
|
||||||
if (!toolName || toolName.startsWith("memory_")) return;
|
if (!toolName) return;
|
||||||
|
|
||||||
const contentSessionId = getContentSessionId(ctx.sessionKey);
|
const contentSessionId = getContentSessionId(ctx.sessionKey);
|
||||||
|
|
||||||
// Extract result text from message content
|
// Extract result text from all content blocks
|
||||||
let toolResponseText = "";
|
let toolResponseText = "";
|
||||||
const content = event.message?.content;
|
const content = event.message?.content;
|
||||||
if (Array.isArray(content)) {
|
if (Array.isArray(content)) {
|
||||||
const textBlock = content.find(
|
toolResponseText = content
|
||||||
(block) => block.type === "tool_result" || block.type === "text"
|
.filter((block) => (block.type === "tool_result" || block.type === "text") && "text" in block)
|
||||||
);
|
.map((block) => String(block.text))
|
||||||
if (textBlock && "text" in textBlock) {
|
.join("\n");
|
||||||
toolResponseText = String(textBlock.text).slice(0, TOOL_RESULT_MAX_LENGTH);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fire-and-forget: send observation + sync MEMORY.md in parallel
|
// Fire-and-forget: send observation + sync MEMORY.md in parallel
|
||||||
|
|||||||
Reference in New Issue
Block a user