Skip to content

Commit c430b97

Browse files
chenjwclaude
andauthored
Fix/openclaw addmsg (#1391)
* fix(ragfs): localfs write should respect WriteFlag to truncate file The localfs write implementation was ignoring the WriteFlag parameter and not truncating the file when WriteFlag::Create or WriteFlag::Truncate was specified. This caused files to be appended instead of overwritten when writing empty content. Root cause: The _flags parameter was declared but never used. When opening an existing file, .truncate(true) was not called. Fix: Use OpenOptions::new().truncate(should_truncate) based on the flags. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(session): clear messages.jsonl after commit and improve memory extraction - Add workaround to delete messages.jsonl before writing to work around RAGFS localfs not truncating files (now fixed in ragfs) - Add _get_latest_archive_last_msg_time to filter messages for memory extraction by timestamp - Fix memory extraction to only process new messages after last archive Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * update * fix(openclaw): add HEARTBEAT filtering in sanitizeUserTextForCapture 过滤 HEARTBEAT 健康检查消息,避免 HEARTBEAT.md 和 HEARTBEAT_OK 进入 session 存档。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * revert: restore logger.warn instead of warnOrInfo Reverting to use logger.warn directly. The warnOrInfo wrapper was unnecessary as logger always has warn method. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore(session): remove RAGFS truncate workaround The ragfs localfs write now respects WriteFlag to truncate files, so the workaround to delete messages.jsonl before writing is no longer needed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor(openclaw): unify addSessionMessage with parts API - Remove old addSessionMessage (string content) - Keep addSessionMessage but accept parts array - Update index.ts and context-engine.ts to use new format - Update tests to check parts structure Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(openclaw): use optional chaining for logger.warn TypeScript strict mode requires handling possibly undefined warn method. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat(openclaw): log trace_id from commit results Add trace_id to CommitSessionResult type and log it for all commitSession calls (afterTurn, commitOVSession, compact). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(openclaw): add tool_input to tool parts - Add toolInput field to ExtractedMessage type - Extract tool_input from msg.toolInput in extractNewTurnMessages - Pass tool_input when constructing tool parts for addSessionMessage Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(openclaw): lookup toolInput from preceding toolUse messages When extracting toolResult messages, look up the corresponding toolInput from the preceding assistant messages' toolUse blocks using toolCallId/ toolUseId as the key. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(openclaw): add more field name variations for toolInput/toolCallId Support additional field names: arguments, toolInput, tool_call_id Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(openclaw): lookup toolInput from preceding toolCall messages - Scan all messages to find toolCall/toolUse/tool_call blocks - Extract tool input from arguments/input/toolInput fields - Match toolResult with toolCall using toolCallId/toolUseId Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 13673ac commit c430b97

File tree

10 files changed

+590
-260
lines changed

10 files changed

+590
-260
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# 安装本地 OpenClaw OpenViking 插件
5+
# 用法: ./install_local_openclaw_plugin.sh [--rebuild]
6+
#
7+
# 选项:
8+
# --rebuild 只重新编译,不重新复制文件
9+
10+
REBUILD=false
11+
if [[ "$1" == "--rebuild" ]]; then
12+
REBUILD=true
13+
fi
14+
15+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
16+
17+
# 源目录:openviking 根目录下的 examples/openclaw-plugin
18+
OPENCLAW_PLUGIN_SOURCE="$(dirname "$SCRIPT_DIR")/../examples/openclaw-plugin"
19+
OPENCLAW_PLUGIN_DIR="$HOME/.openclaw/extensions/openviking"
20+
21+
echo "=== 安装本地 OpenClaw OpenViking 插件 ==="
22+
echo "源目录: $OPENCLAW_PLUGIN_SOURCE"
23+
echo "目标目录: $OPENCLAW_PLUGIN_DIR"
24+
25+
# 检查源目录是否存在
26+
if [[ ! -d "$OPENCLAW_PLUGIN_SOURCE" ]]; then
27+
echo "错误: 源目录不存在: $OPENCLAW_PLUGIN_SOURCE"
28+
exit 1
29+
fi
30+
31+
# 删除旧的插件目录
32+
if [[ "$REBUILD" == "false" ]]; then
33+
echo "删除旧插件目录..."
34+
rm -rf "$OPENCLAW_PLUGIN_DIR"
35+
36+
# 复制源文件到插件目录
37+
echo "复制源文件..."
38+
cp -r "$OPENCLAW_PLUGIN_SOURCE" "$OPENCLAW_PLUGIN_DIR"
39+
40+
# 复制 tsconfig.json
41+
echo "复制 tsconfig.json..."
42+
cp "$OPENCLAW_PLUGIN_SOURCE/tsconfig.json" "$OPENCLAW_PLUGIN_DIR/"
43+
44+
# 安装依赖
45+
echo "安装依赖..."
46+
cd "$OPENCLAW_PLUGIN_DIR"
47+
npm install --include=dev
48+
fi
49+
50+
# 编译 TypeScript
51+
echo "编译 TypeScript..."
52+
cd "$OPENCLAW_PLUGIN_DIR"
53+
npx -p typescript tsc -p tsconfig.json
54+
55+
# 重启 OpenClaw
56+
echo "重启 OpenClaw..."
57+
if command -v openclaw &> /dev/null; then
58+
openclaw gateway restart
59+
sleep 2
60+
echo ""
61+
echo "=== 等待插件加载,按 Ctrl+C 退出日志 ==="
62+
openclaw logs --follow | grep -E "openviking|context-engine|error.*plugin" | head -10
63+
else
64+
echo "警告: openclaw 命令未找到,请手动重启 OpenClaw"
65+
fi

crates/ragfs/src/plugins/localfs/mod.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl FileSystem for LocalFileSystem {
180180
}
181181
}
182182

183-
async fn write(&self, path: &str, data: &[u8], offset: u64, _flags: WriteFlag) -> Result<u64> {
183+
async fn write(&self, path: &str, data: &[u8], offset: u64, flags: WriteFlag) -> Result<u64> {
184184
let local_path = self.resolve_path(path);
185185

186186
// Check if it's a directory
@@ -195,19 +195,16 @@ impl FileSystem for LocalFileSystem {
195195
}
196196
}
197197

198-
// Open or create file
199-
let mut file = if local_path.exists() {
200-
fs::OpenOptions::new()
201-
.write(true)
202-
.open(&local_path)
203-
.map_err(|e| Error::plugin(format!("failed to open file: {}", e)))?
204-
} else {
205-
fs::OpenOptions::new()
206-
.write(true)
207-
.create(true)
208-
.open(&local_path)
209-
.map_err(|e| Error::plugin(format!("failed to create file: {}", e)))?
210-
};
198+
// Determine if we should truncate based on flags
199+
let should_truncate = matches!(flags, WriteFlag::Create | WriteFlag::Truncate);
200+
201+
// Open or create file with truncate support
202+
let mut file = fs::OpenOptions::new()
203+
.write(true)
204+
.create(true)
205+
.truncate(should_truncate)
206+
.open(&local_path)
207+
.map_err(|e| Error::plugin(format!("failed to open file: {}", e)))?;
211208

212209
// Write data
213210
use std::io::{Seek, SeekFrom, Write};

examples/openclaw-plugin/client.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export type CommitSessionResult = {
5252
/** Present when wait=true and extraction completed. Keyed by category. */
5353
memories_extracted?: Record<string, number>;
5454
error?: string;
55+
trace_id?: string;
5556
};
5657

5758
export type TaskResult = {
@@ -630,25 +631,36 @@ export class OpenVikingClient {
630631
async addSessionMessage(
631632
sessionId: string,
632633
role: string,
633-
content: string,
634+
parts: Array<{
635+
type: "text" | "tool" | "context";
636+
text?: string;
637+
tool_name?: string;
638+
tool_output?: string;
639+
tool_status?: string;
640+
tool_input?: Record<string, unknown>;
641+
tool_id?: string;
642+
uri?: string;
643+
abstract?: string;
644+
context_type?: "memory" | "resource" | "skill";
645+
}>,
634646
agentId?: string,
635647
createdAt?: string,
636648
): Promise<void> {
637649
const body: {
638650
role: string;
639-
content: string;
651+
parts: typeof parts;
640652
created_at?: string;
641-
} = { role, content };
653+
} = { role, parts };
642654
if (createdAt) {
643655
body.created_at = createdAt;
644656
}
645657
await this.emitRoutingDebug(
646-
"session message POST",
658+
"session message POST (with parts)",
647659
{
648660
path: `/api/v1/sessions/${encodeURIComponent(sessionId)}/messages`,
649661
sessionId,
650662
role,
651-
contentChars: content.length,
663+
partCount: parts.length,
652664
created_at: createdAt ?? null,
653665
},
654666
agentId,

0 commit comments

Comments
 (0)