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

推荐订阅源

N
Netflix TechBlog - Medium
I
InfoQ
Engineering at Meta
Engineering at Meta
Jina AI
Jina AI
Recent Announcements
Recent Announcements
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
D
Docker
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
博客园 - Franky
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog RSS Feed
WordPress大学
WordPress大学
MyScale Blog
MyScale Blog
月光博客
月光博客
罗磊的独立博客

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: restore user turn persistence checks · openclaw/open...
shakkernerd · 2026-05-27 · via Recent Commits to openclaw:main

@@ -1,14 +1,18 @@

11

import path from "node:path";

22

import type { AgentMessage } from "@earendil-works/pi-agent-core";

3-

import { runAgentHarnessBeforeMessageWriteHook } from "../agents/harness/hook-helpers.js";

43

import { appendSessionTranscriptMessage } from "../config/sessions/transcript-append.js";

5-

import { resolveSessionTranscriptFile } from "../config/sessions/transcript.js";

6-

import type { SessionEntry } from "../config/sessions/types.js";

7-

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

8-

import { logVerbose } from "../globals.js";

94

import { mimeTypeFromFilePath } from "../media/mime.js";

105

import { emitSessionTranscriptUpdate } from "./transcript-events.js";

1167+

type TranscriptAppendConfig = Parameters<typeof appendSessionTranscriptMessage>[0]["config"];

8+9+

type UserTurnSessionEntry = {

10+

sessionId: string;

11+

updatedAt: number;

12+

sessionFile?: string;

13+

threadId?: string | number;

14+

} & Record<string, unknown>;

15+1216

type PersistedUserTurnMediaInput = {

1317

path?: string | null;

1418

url?: string | null;

@@ -35,6 +39,12 @@ export type UserTurnInput = {

35393640

type UserTurnTranscriptUpdateMode = "inline" | "none";

374142+

export type UserTurnBeforeMessageWrite = (params: {

43+

message: PersistedUserTurnMessage;

44+

agentId?: string;

45+

sessionKey?: string;

46+

}) => AgentMessage | null;

47+3848

type AppendUserTurnTranscriptMessageParams = {

3949

transcriptPath: string;

4050

input?: UserTurnInput;

@@ -43,23 +53,25 @@ type AppendUserTurnTranscriptMessageParams = {

4353

agentId?: string;

4454

sessionKey?: string;

4555

cwd?: string;

46-

config?: OpenClawConfig;

56+

config?: TranscriptAppendConfig;

4757

updateMode?: UserTurnTranscriptUpdateMode;

58+

beforeMessageWrite?: UserTurnBeforeMessageWrite;

4859

};

49605061

type PersistUserTurnTranscriptParams = {

5162

input?: UserTurnInput;

5263

message?: PersistedUserTurnMessage;

5364

sessionId: string;

5465

sessionKey: string;

55-

sessionEntry: SessionEntry | undefined;

56-

sessionStore?: Record<string, SessionEntry>;

66+

sessionEntry: UserTurnSessionEntry | undefined;

67+

sessionStore?: Record<string, UserTurnSessionEntry>;

5768

storePath?: string;

5869

agentId: string;

5970

threadId?: string | number;

6071

cwd?: string;

61-

config?: OpenClawConfig;

72+

config?: TranscriptAppendConfig;

6273

updateMode?: UserTurnTranscriptUpdateMode;

74+

beforeMessageWrite?: UserTurnBeforeMessageWrite;

6375

};

64766577

type UserTurnTranscriptPersistenceTarget = Omit<

@@ -73,14 +85,14 @@ type UserTurnTranscriptFileTarget = {

7385

agentId?: string;

7486

sessionKey?: string;

7587

cwd?: string;

76-

config?: OpenClawConfig;

88+

config?: TranscriptAppendConfig;

7789

};

78907991

type UserTurnTranscriptTarget = UserTurnTranscriptPersistenceTarget | UserTurnTranscriptFileTarget;

80928193

type UserTurnTranscriptPersistResult = {

8294

sessionFile: string;

83-

sessionEntry: SessionEntry | undefined;

95+

sessionEntry: UserTurnSessionEntry | undefined;

8496

messageId: string;

8597

message: PersistedUserTurnMessage;

8698

};

@@ -113,6 +125,7 @@ type CreateUserTurnTranscriptRecorderParams = {

113125

message?: PersistedUserTurnMessage;

114126

target: UserTurnTranscriptTargetResolver;

115127

updateMode?: UserTurnTranscriptUpdateMode;

128+

beforeMessageWrite?: UserTurnBeforeMessageWrite;

116129

errorContext?: string;

117130

onPersistenceError?: (error: unknown) => void;

118131

};

@@ -351,12 +364,18 @@ export function mergePreparedUserTurnMessageForRuntime(params: {

351364352365

function applyBeforeMessageWriteToUserTurn(

353366

message: PersistedUserTurnMessage,

354-

params: Pick<AppendUserTurnTranscriptMessageParams, "agentId" | "sessionKey">,

367+

params: Pick<

368+

AppendUserTurnTranscriptMessageParams,

369+

"agentId" | "sessionKey" | "beforeMessageWrite"

370+

>,

355371

): PersistedUserTurnMessage | undefined {

372+

if (!params.beforeMessageWrite) {

373+

return message;

374+

}

356375

const originalMessage = message as unknown as { idempotencyKey?: unknown };

357376

const idempotencyKey =

358377

typeof originalMessage.idempotencyKey === "string" ? originalMessage.idempotencyKey : undefined;

359-

const nextMessage = runAgentHarnessBeforeMessageWriteHook({

378+

const nextMessage = params.beforeMessageWrite({

360379

message,

361380

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

362381

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

@@ -429,6 +448,7 @@ export async function persistUserTurnTranscript(

429448

return undefined;

430449

}

431450451+

const { resolveSessionTranscriptFile } = await import("../config/sessions/transcript.js");

432452

const { sessionFile, sessionEntry } = await resolveSessionTranscriptFile({

433453

sessionId: params.sessionId,

434454

sessionKey: params.sessionKey,

@@ -448,6 +468,7 @@ export async function persistUserTurnTranscript(

448468

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

449469

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

450470

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

471+

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

451472

});

452473

if (!appended) {

453474

return undefined;

@@ -486,9 +507,13 @@ export function createUserTurnTranscriptRecorder(

486507

params.onPersistenceError(error);

487508

return;

488509

}

489-

logVerbose(

490-

`failed to persist ${params.errorContext ?? "user turn transcript"}: ${String(error)}`,

491-

);

510+

void import("../globals.js")

511+

.then(({ logVerbose }) => {

512+

logVerbose(

513+

`failed to persist ${params.errorContext ?? "user turn transcript"}: ${String(error)}`,

514+

);

515+

})

516+

.catch(() => undefined);

492517

};

493518494519

const waitForRuntimePersistence = async () => {

@@ -537,6 +562,7 @@ export function createUserTurnTranscriptRecorder(

537562

...target,

538563

message,

539564

updateMode,

565+

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

540566

}).then((appended) =>

541567

appended

542568

? {

@@ -549,6 +575,7 @@ export function createUserTurnTranscriptRecorder(

549575

...target,

550576

message,

551577

updateMode,

578+

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

552579

});

553580

if (result) {

554581

persisted = true;