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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
Jina AI
Jina AI
WordPress大学
WordPress大学
Recent Announcements
Recent Announcements
G
Google Developers Blog
I
InfoQ
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
M
MIT News - Artificial intelligence
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
C
Check Point Blog
J
Java Code Geeks
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
MongoDB | Blog
MongoDB | Blog
V
Visual Studio Blog
人人都是产品经理
人人都是产品经理
量子位
A
About on SuperTechFans
D
DataBreaches.Net
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

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
fix: cache stable system prompt prep · openclaw/openclaw@...
steipete · 2026-05-02 · via Recent Commits to openclaw:main

@@ -4,20 +4,21 @@ import { buildBootstrapInjectionStats } from "./bootstrap-budget.js";

44

import type { EmbeddedContextFile } from "./pi-embedded-helpers.js";

55

import type { WorkspaceBootstrapFile } from "./workspace.js";

667-

function extractBetween(

8-

input: string,

9-

startMarker: string,

10-

endMarker: string,

11-

): { text: string; found: boolean } {

7+

type ToolReportEntry = SessionSystemPromptReport["tools"]["entries"][number];

8+9+

const toolReportEntryCache = new WeakMap<AgentTool, ToolReportEntry>();

10+

const toolSchemaStatsCache = new WeakMap<

11+

object,

12+

Pick<ToolReportEntry, "propertiesCount" | "schemaChars">

13+

>();

14+15+

function extractBetween(input: string, startMarker: string, endMarker: string): string {

1216

const start = input.indexOf(startMarker);

1317

if (start === -1) {

14-

return { text: "", found: false };

18+

return "";

1519

}

1620

const end = input.indexOf(endMarker, start + startMarker.length);

17-

if (end === -1) {

18-

return { text: input.slice(start), found: true };

19-

}

20-

return { text: input.slice(start, end), found: true };

21+

return end === -1 ? input.slice(start) : input.slice(start, end);

2122

}

22232324

function parseSkillBlocks(skillsPrompt: string): Array<{ name: string; blockChars: number }> {

@@ -36,36 +37,57 @@ function parseSkillBlocks(skillsPrompt: string): Array<{ name: string; blockChar

3637

.filter((b) => b.blockChars > 0);

3738

}

383939-

function buildToolsEntries(tools: AgentTool[]): SessionSystemPromptReport["tools"]["entries"] {

40-

return tools.map((tool) => {

41-

const name = tool.name;

42-

const summary = tool.description?.trim() || tool.label?.trim() || "";

43-

const summaryChars = summary.length;

44-

const schemaChars = (() => {

45-

if (!tool.parameters || typeof tool.parameters !== "object") {

46-

return 0;

47-

}

40+

function buildToolSchemaStats(

41+

parameters: AgentTool["parameters"],

42+

): Pick<ToolReportEntry, "propertiesCount" | "schemaChars"> {

43+

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

44+

return { schemaChars: 0, propertiesCount: null };

45+

}

46+

const cached = toolSchemaStatsCache.get(parameters);

47+

if (cached) {

48+

return cached;

49+

}

50+

const stats = {

51+

schemaChars: (() => {

4852

try {

49-

return JSON.stringify(tool.parameters).length;

53+

return JSON.stringify(parameters).length;

5054

} catch {

5155

return 0;

5256

}

53-

})();

54-

const propertiesCount = (() => {

55-

const schema =

56-

tool.parameters && typeof tool.parameters === "object"

57-

? (tool.parameters as Record<string, unknown>)

58-

: null;

59-

const props = schema && typeof schema.properties === "object" ? schema.properties : null;

57+

})(),

58+

propertiesCount: (() => {

59+

const schema = parameters as Record<string, unknown>;

60+

const props = typeof schema.properties === "object" ? schema.properties : null;

6061

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

6162

return null;

6263

}

6364

return Object.keys(props as Record<string, unknown>).length;

64-

})();

65-

return { name, summaryChars, schemaChars, propertiesCount };

65+

})(),

66+

};

67+

toolSchemaStatsCache.set(parameters, stats);

68+

return stats;

69+

}

70+71+

function buildToolsEntries(tools: AgentTool[]): SessionSystemPromptReport["tools"]["entries"] {

72+

return tools.map((tool) => {

73+

const cached = toolReportEntryCache.get(tool);

74+

if (cached) {

75+

return cached;

76+

}

77+

const name = tool.name;

78+

const summary = tool.description?.trim() || tool.label?.trim() || "";

79+

const summaryChars = summary.length;

80+

const schemaStats = buildToolSchemaStats(tool.parameters);

81+

const entry = { name, summaryChars, ...schemaStats };

82+

toolReportEntryCache.set(tool, entry);

83+

return entry;

6684

});

6785

}

688687+

function measureRenderedProjectContextChars(systemPrompt: string): number {

88+

return extractBetween(systemPrompt, "\n# Project Context\n", "\n## Silent Replies\n").length;

89+

}

90+6991

export function buildSystemPromptReport(params: {

7092

source: SessionSystemPromptReport["source"];

7193

generatedAt: number;

@@ -84,13 +106,8 @@ export function buildSystemPromptReport(params: {

84106

skillsPrompt: string;

85107

tools: AgentTool[];

86108

}): SessionSystemPromptReport {

87-

const systemPrompt = params.systemPrompt.trim();

88-

const projectContext = extractBetween(

89-

systemPrompt,

90-

"\n# Project Context\n",

91-

"\n## Silent Replies\n",

92-

);

93-

const projectContextChars = projectContext.text.length;

109+

const systemPromptChars = params.systemPrompt.length;

110+

const projectContextChars = measureRenderedProjectContextChars(params.systemPrompt);

94111

const toolsEntries = buildToolsEntries(params.tools);

95112

const toolsSchemaChars = toolsEntries.reduce((sum, t) => sum + (t.schemaChars ?? 0), 0);

96113

const skillsEntries = parseSkillBlocks(params.skillsPrompt);

@@ -108,9 +125,9 @@ export function buildSystemPromptReport(params: {

108125

...(params.bootstrapTruncation ? { bootstrapTruncation: params.bootstrapTruncation } : {}),

109126

sandbox: params.sandbox,

110127

systemPrompt: {

111-

chars: systemPrompt.length,

128+

chars: systemPromptChars,

112129

projectContextChars,

113-

nonProjectContextChars: Math.max(0, systemPrompt.length - projectContextChars),

130+

nonProjectContextChars: Math.max(0, systemPromptChars - projectContextChars),

114131

},

115132

injectedWorkspaceFiles: buildBootstrapInjectionStats({

116133

bootstrapFiles: params.bootstrapFiles,