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

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
F
Fortinet All Blogs
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
The Cloudflare Blog
量子位
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
D
DataBreaches.Net
V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
U
Unit 42
博客园 - 聂微东
有赞技术团队
有赞技术团队
A
About on SuperTechFans

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
refactor: centralize bootstrap system prompt assembly · o...
steipete · 2026-05-04 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -15,7 +15,8 @@ export type AttemptBootstrapRoutingInput = {

1515
1616

export type AttemptBootstrapRouting = {

1717

bootstrapMode: BootstrapMode;

18-

shouldStripBootstrapFromContext: boolean;

18+

includeBootstrapInSystemContext: boolean;

19+

includeBootstrapInRuntimeContext: boolean;

1920

};

2021
2122

export type AttemptWorkspaceBootstrapRoutingInput = Omit<

@@ -25,10 +26,16 @@ export type AttemptWorkspaceBootstrapRoutingInput = Omit<

2526

isWorkspaceBootstrapPending: (workspaceDir: string) => Promise<boolean>;

2627

};

2728
28-

export function shouldStripBootstrapFromEmbeddedContext(_params: {

29+

export function resolveBootstrapContextTargets(params: {

2930

bootstrapMode: BootstrapMode;

30-

}): boolean {

31-

return _params.bootstrapMode !== "full";

31+

}): Pick<

32+

AttemptBootstrapRouting,

33+

"includeBootstrapInSystemContext" | "includeBootstrapInRuntimeContext"

34+

> {

35+

return {

36+

includeBootstrapInSystemContext: params.bootstrapMode === "full",

37+

includeBootstrapInRuntimeContext: false,

38+

};

3239

}

3340
3441

function resolveAttemptBootstrapRouting(

@@ -47,9 +54,7 @@ function resolveAttemptBootstrapRouting(

4754
4855

return {

4956

bootstrapMode,

50-

shouldStripBootstrapFromContext: shouldStripBootstrapFromEmbeddedContext({

51-

bootstrapMode,

52-

}),

57+

...resolveBootstrapContextTargets({ bootstrapMode }),

5358

};

5459

}

5560
Original file line numberDiff line numberDiff line change

@@ -0,0 +1,90 @@

1+

import { describe, expect, it } from "vitest";

2+

import { buildAttemptSystemPrompt } from "./attempt-system-prompt.js";

3+
4+

const baseProviderTransform = {

5+

provider: "openai",

6+

workspaceDir: "/tmp/openclaw",

7+

context: {

8+

provider: "openai",

9+

modelId: "gpt-5.5",

10+

promptMode: "full" as const,

11+

},

12+

};

13+
14+

describe("buildAttemptSystemPrompt", () => {

15+

it("preserves bootstrap Project Context when a system prompt override is configured", () => {

16+

const result = buildAttemptSystemPrompt({

17+

isRawModelRun: false,

18+

systemPromptOverrideText: "Custom override prompt.",

19+

embeddedSystemPrompt: {

20+

workspaceDir: "/tmp/openclaw",

21+

reasoningTagHint: false,

22+

runtimeInfo: {

23+

host: "test-host",

24+

os: "Darwin",

25+

arch: "arm64",

26+

node: "v22.0.0",

27+

model: "openai/gpt-5.5",

28+

},

29+

tools: [],

30+

modelAliasLines: [],

31+

userTimezone: "UTC",

32+

bootstrapMode: "full",

33+

bootstrapTruncationNotice: "Bootstrap context was truncated.",

34+

contextFiles: [

35+

{

36+

path: "/tmp/openclaw/BOOTSTRAP.md",

37+

content: "Reply with BOOTSTRAP_OK.",

38+

},

39+

{

40+

path: "/tmp/openclaw/USER.md",

41+

content: "User profile should stay in normal prompt context only.",

42+

},

43+

],

44+

},

45+

providerTransform: baseProviderTransform,

46+

});

47+
48+

expect(result.systemPrompt).toContain("Custom override prompt.");

49+

expect(result.systemPrompt).toContain("## Bootstrap Pending");

50+

expect(result.systemPrompt).toContain("BOOTSTRAP.md is included below in Project Context");

51+

expect(result.systemPrompt).toContain("## Bootstrap Context Notice");

52+

expect(result.systemPrompt).toContain("Bootstrap context was truncated.");

53+

expect(result.systemPrompt).toContain("# Project Context");

54+

expect(result.systemPrompt).toContain("## /tmp/openclaw/BOOTSTRAP.md");

55+

expect(result.systemPrompt).toContain("Reply with BOOTSTRAP_OK.");

56+

expect(result.systemPrompt).not.toContain("USER.md");

57+

});

58+
59+

it("omits system prompts for raw model probes", () => {

60+

const result = buildAttemptSystemPrompt({

61+

isRawModelRun: true,

62+

embeddedSystemPrompt: {

63+

workspaceDir: "/tmp/openclaw",

64+

reasoningTagHint: false,

65+

runtimeInfo: {

66+

host: "test-host",

67+

os: "Darwin",

68+

arch: "arm64",

69+

node: "v22.0.0",

70+

model: "openai/gpt-5.5",

71+

},

72+

tools: [],

73+

modelAliasLines: [],

74+

userTimezone: "UTC",

75+

bootstrapMode: "full",

76+

contextFiles: [

77+

{

78+

path: "/tmp/openclaw/BOOTSTRAP.md",

79+

content: "Reply with BOOTSTRAP_OK.",

80+

},

81+

],

82+

},

83+

providerTransform: baseProviderTransform,

84+

});

85+
86+

expect(result.baseSystemPrompt).toContain("BOOTSTRAP.md is included below in Project Context");

87+

expect(result.systemPrompt).toBe("");

88+

expect(result.systemPromptOverride()).toBe("");

89+

});

90+

});

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,56 @@

1+

import type { OpenClawConfig } from "../../../config/types.openclaw.js";

2+

import { transformProviderSystemPrompt } from "../../../plugins/provider-runtime.js";

3+

import type { ProviderTransformSystemPromptContext } from "../../../plugins/types.js";

4+

import { appendAgentBootstrapSystemPromptSupplement } from "../../system-prompt.js";

5+

import { buildEmbeddedSystemPrompt, createSystemPromptOverride } from "../system-prompt.js";

6+
7+

type EmbeddedSystemPromptParams = Parameters<typeof buildEmbeddedSystemPrompt>[0];

8+
9+

export type BuildAttemptSystemPromptParams = {

10+

isRawModelRun: boolean;

11+

systemPromptOverrideText?: string;

12+

embeddedSystemPrompt: EmbeddedSystemPromptParams;

13+

providerTransform: {

14+

provider: string;

15+

config?: OpenClawConfig;

16+

workspaceDir: string;

17+

context: Omit<ProviderTransformSystemPromptContext, "systemPrompt">;

18+

};

19+

};

20+
21+

export type AttemptSystemPrompt = {

22+

baseSystemPrompt: string;

23+

systemPrompt: string;

24+

systemPromptOverride: (defaultPrompt?: string) => string;

25+

};

26+
27+

export function buildAttemptSystemPrompt(

28+

params: BuildAttemptSystemPromptParams,

29+

): AttemptSystemPrompt {

30+

const baseSystemPrompt = params.systemPromptOverrideText

31+

? appendAgentBootstrapSystemPromptSupplement({

32+

systemPrompt: params.systemPromptOverrideText,

33+

bootstrapMode: params.embeddedSystemPrompt.bootstrapMode,

34+

bootstrapTruncationNotice: params.embeddedSystemPrompt.bootstrapTruncationNotice,

35+

contextFiles: params.embeddedSystemPrompt.contextFiles,

36+

})

37+

: buildEmbeddedSystemPrompt(params.embeddedSystemPrompt);

38+
39+

const systemPrompt = params.isRawModelRun

40+

? ""

41+

: transformProviderSystemPrompt({

42+

provider: params.providerTransform.provider,

43+

config: params.providerTransform.config,

44+

workspaceDir: params.providerTransform.workspaceDir,

45+

context: {

46+

...params.providerTransform.context,

47+

systemPrompt: baseSystemPrompt,

48+

},

49+

});

50+
51+

return {

52+

baseSystemPrompt,

53+

systemPrompt,

54+

systemPromptOverride: createSystemPromptOverride(systemPrompt),

55+

};

56+

}

Original file line numberDiff line numberDiff line change

@@ -1,7 +1,7 @@

11

import { describe, expect, it, vi } from "vitest";

22

import {

3+

resolveBootstrapContextTargets,

34

resolveAttemptWorkspaceBootstrapRouting,

4-

shouldStripBootstrapFromEmbeddedContext,

55

} from "./attempt-bootstrap-routing.js";

66
77

describe("runEmbeddedAttempt bootstrap routing", () => {

@@ -26,7 +26,8 @@ describe("runEmbeddedAttempt bootstrap routing", () => {

2626

expect(isWorkspaceBootstrapPending).toHaveBeenCalledWith(canonicalWorkspace);

2727

expect(isWorkspaceBootstrapPending).not.toHaveBeenCalledWith(sandboxWorkspace);

2828

expect(routing.bootstrapMode).toBe("none");

29-

expect(routing.shouldStripBootstrapFromContext).toBe(true);

29+

expect(routing.includeBootstrapInSystemContext).toBe(false);

30+

expect(routing.includeBootstrapInRuntimeContext).toBe(false);

3031

});

3132
3233

it("falls back to limited bootstrap wording when a primary run cannot read files", async () => {

@@ -41,15 +42,25 @@ describe("runEmbeddedAttempt bootstrap routing", () => {

4142

});

4243
4344

expect(routing.bootstrapMode).toBe("limited");

44-

expect(routing.shouldStripBootstrapFromContext).toBe(true);

45+

expect(routing.includeBootstrapInSystemContext).toBe(false);

46+

expect(routing.includeBootstrapInRuntimeContext).toBe(false);

4547

});

4648
4749

it("keeps BOOTSTRAP.md in Project Context for full bootstrap turns", () => {

48-

expect(shouldStripBootstrapFromEmbeddedContext({ bootstrapMode: "full" })).toBe(false);

50+

expect(resolveBootstrapContextTargets({ bootstrapMode: "full" })).toEqual({

51+

includeBootstrapInSystemContext: true,

52+

includeBootstrapInRuntimeContext: false,

53+

});

4954

});

5055
51-

it("strips BOOTSTRAP.md from Project Context outside full bootstrap turns", () => {

52-

expect(shouldStripBootstrapFromEmbeddedContext({ bootstrapMode: "limited" })).toBe(true);

53-

expect(shouldStripBootstrapFromEmbeddedContext({ bootstrapMode: "none" })).toBe(true);

56+

it("excludes BOOTSTRAP.md from every context outside full bootstrap turns", () => {

57+

expect(resolveBootstrapContextTargets({ bootstrapMode: "limited" })).toEqual({

58+

includeBootstrapInSystemContext: false,

59+

includeBootstrapInRuntimeContext: false,

60+

});

61+

expect(resolveBootstrapContextTargets({ bootstrapMode: "none" })).toEqual({

62+

includeBootstrapInSystemContext: false,

63+

includeBootstrapInRuntimeContext: false,

64+

});

5465

});

5566

});

Original file line numberDiff line numberDiff line change

@@ -3,6 +3,7 @@ import { describe, expect, it, vi } from "vitest";

33

import type { OpenClawConfig } from "../../../config/config.js";

44

import { SYSTEM_PROMPT_CACHE_BOUNDARY } from "../../system-prompt-cache-boundary.js";

55

import { buildAgentSystemPrompt } from "../../system-prompt.js";

6+

import { resolveBootstrapContextTargets } from "./attempt-bootstrap-routing.js";

67

import {

78

buildContextEnginePromptCacheInfo,

89

buildAfterTurnRuntimeContext,

@@ -24,7 +25,6 @@ import {

2425

resolveAttemptToolPolicyMessageProvider,

2526

resolvePromptBuildHookResult,

2627

resolvePromptModeForSession,

27-

shouldStripBootstrapFromEmbeddedContext,

2828

shouldWarnOnOrphanedUserRepair,

2929

wrapStreamFnRepairMalformedToolCallArguments,

3030

wrapStreamFnSanitizeMalformedToolCalls,

@@ -404,11 +404,20 @@ describe("resolvePromptModeForSession", () => {

404404

});

405405

});

406406
407-

describe("shouldStripBootstrapFromEmbeddedContext", () => {

407+

describe("resolveBootstrapContextTargets", () => {

408408

it("keeps BOOTSTRAP.md in system Project Context only for full bootstrap turns", () => {

409-

expect(shouldStripBootstrapFromEmbeddedContext({ bootstrapMode: "full" })).toBe(false);

410-

expect(shouldStripBootstrapFromEmbeddedContext({ bootstrapMode: "limited" })).toBe(true);

411-

expect(shouldStripBootstrapFromEmbeddedContext({ bootstrapMode: "none" })).toBe(true);

409+

expect(resolveBootstrapContextTargets({ bootstrapMode: "full" })).toEqual({

410+

includeBootstrapInSystemContext: true,

411+

includeBootstrapInRuntimeContext: false,

412+

});

413+

expect(resolveBootstrapContextTargets({ bootstrapMode: "limited" })).toEqual({

414+

includeBootstrapInSystemContext: false,

415+

includeBootstrapInRuntimeContext: false,

416+

});

417+

expect(resolveBootstrapContextTargets({ bootstrapMode: "none" })).toEqual({

418+

includeBootstrapInSystemContext: false,

419+

includeBootstrapInRuntimeContext: false,

420+

});

412421

});

413422

});

414423