惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
J
Java Code Geeks
月光博客
月光博客
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
Jina AI
Jina AI
小众软件
小众软件
U
Unit 42
云风的 BLOG
云风的 BLOG
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
宝玉的分享
宝玉的分享
B
Blog
C
Check Point Blog
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
量子位
阮一峰的网络日志
阮一峰的网络日志
Vercel News
Vercel News
酷 壳 – CoolShell
酷 壳 – CoolShell

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
perf(reply): compact chat window context · openclaw/openc...
obviyus · 2026-05-09 · via Recent Commits to openclaw:main

@@ -11,6 +11,7 @@ import type { TemplateContext } from "../templating.js";

11111212

const MAX_UNTRUSTED_JSON_STRING_CHARS = 2_000;

1313

const MAX_UNTRUSTED_HISTORY_ENTRIES = 20;

14+

const MAX_UNTRUSTED_TRANSCRIPT_FIELD_CHARS = 500;

14151516

function stripNullBytes(value: string): string {

1617

return value.replaceAll("\u0000", "");

@@ -59,6 +60,30 @@ function sanitizeUntrustedJsonValue(value: unknown): unknown {

5960

);

6061

}

616263+

function isRecord(value: unknown): value is Record<string, unknown> {

64+

return typeof value === "object" && value !== null && !Array.isArray(value);

65+

}

66+67+

function truncateUntrustedTranscriptField(value: string): string {

68+

if (value.length <= MAX_UNTRUSTED_TRANSCRIPT_FIELD_CHARS) {

69+

return value;

70+

}

71+

return `${truncateUtf16Safe(

72+

value,

73+

Math.max(0, MAX_UNTRUSTED_TRANSCRIPT_FIELD_CHARS - 14),

74+

).trimEnd()}…[truncated]`;

75+

}

76+77+

function sanitizeTranscriptField(value: unknown): string | undefined {

78+

const body = sanitizePromptBody(value);

79+

if (!body) {

80+

return undefined;

81+

}

82+

return neutralizeMarkdownFences(truncateUntrustedTranscriptField(body))

83+

.replace(/\s+/g, " ")

84+

.trim();

85+

}

86+6287

function formatUntrustedStructuredContextLabel(label: unknown): string {

6388

const normalized = normalizePromptMetadataString(label);

6489

return normalized

@@ -75,6 +100,67 @@ function formatUntrustedJsonBlock(label: string, payload: unknown): string {

75100

].join("\n");

76101

}

77102103+

function formatStructuredContextRelation(value: unknown): string | undefined {

104+

const relation = normalizePromptMetadataString(value);

105+

if (relation === "before_current_message") {

106+

return "before current message";

107+

}

108+

if (relation === "around_reply_target") {

109+

return "around replied-to message";

110+

}

111+

return relation?.replaceAll("_", " ");

112+

}

113+114+

function formatChatWindowMessage(

115+

value: unknown,

116+

envelope?: EnvelopeFormatOptions,

117+

): string | undefined {

118+

if (!isRecord(value)) {

119+

return undefined;

120+

}

121+

const messageId = normalizePromptMetadataString(value["message_id"]);

122+

const sender = normalizePromptMetadataString(value["sender"]) ?? "unknown sender";

123+

const timestamp = formatConversationTimestamp(value["timestamp_ms"], envelope);

124+

const replyToId = normalizePromptMetadataString(value["reply_to_id"]);

125+

const mediaType = normalizePromptMetadataString(value["media_type"]);

126+

const mediaRef = normalizePromptMetadataString(value["media_ref"]);

127+

const body = sanitizeTranscriptField(value["body"]);

128+

const details = [

129+

messageId ? `#${messageId}` : undefined,

130+

timestamp,

131+

value["is_reply_target"] === true ? "[reply target]" : undefined,

132+

replyToId ? `->#${replyToId}` : undefined,

133+

].filter(Boolean);

134+

const media = mediaType ? `[${mediaType}${mediaRef ? ` ${mediaRef}` : ""}]` : undefined;

135+

const content = [body, media].filter(Boolean).join(" ");

136+

if (!content) {

137+

return undefined;

138+

}

139+

return `${details.length > 0 ? `${details.join(" ")} ` : ""}${sender}: ${content}`;

140+

}

141+142+

function formatChatWindowStructuredContext(

143+

entry: NonNullable<TemplateContext["UntrustedStructuredContext"]>[number],

144+

envelope?: EnvelopeFormatOptions,

145+

): string | undefined {

146+

if (normalizePromptMetadataString(entry.type) !== "chat_window" || !isRecord(entry.payload)) {

147+

return undefined;

148+

}

149+

const messages = Array.isArray(entry.payload["messages"]) ? entry.payload["messages"] : [];

150+

const lines = messages.flatMap((message) => {

151+

const line = formatChatWindowMessage(message, envelope);

152+

return line ? [line] : [];

153+

});

154+

if (lines.length === 0) {

155+

return undefined;

156+

}

157+

const label = normalizePromptMetadataString(entry.label) ?? "Chat window";

158+

const relation = formatStructuredContextRelation(entry.payload["relation"]);

159+

const order = normalizePromptMetadataString(entry.payload["order"]);

160+

const qualifiers = ["untrusted", order, relation].filter(Boolean).join(", ");

161+

return [`${label} (${qualifiers}):`, ...lines].join("\n");

162+

}

163+78164

function buildLocationContextPayload(ctx: TemplateContext): Record<string, unknown> | undefined {

79165

const payload = {

80166

latitude: typeof ctx.LocationLat === "number" ? ctx.LocationLat : undefined,

@@ -350,6 +436,11 @@ export function buildInboundUserContextPrefix(

350436

if (!entry || typeof entry !== "object") {

351437

continue;

352438

}

439+

const chatWindow = formatChatWindowStructuredContext(entry, envelope);

440+

if (chatWindow) {

441+

blocks.push(chatWindow);

442+

continue;

443+

}

353444

blocks.push(

354445

formatUntrustedJsonBlock(formatUntrustedStructuredContextLabel(entry.label), {

355446

source: normalizePromptMetadataString(entry.source),