Skip to content

Commit eef860d

Browse files
authored
feat(ui): unify system notices in chat with a minimal line family (#122144)
* feat(ui): unify system notices in chat with a minimal line family Class A (model-facing system turns: restart recovery, gateway restarted, generic internal_system fallback) and class B (lifecycle facts: compaction) now share one hairline+icon+label rendering; known kinds show operator summaries instead of raw injected prompts. Core producers share one formatSystemTurnPrompt owner for the [System] prefix; subagent resume copy unified from "gateway reload" to "gateway restart". No protocol, channel, or marker changes. * fix(ui): keep system-turn prompt helper out of the plugin SDK surface Relocate formatSystemTurnPrompt to src/sessions/system-turn-prompt.ts so the core-internal [System] convention does not widen the SDK API baseline; drop the unused prefix/type exports; use var(--cursor-action) per cursor policy.
1 parent 1fb7158 commit eef860d

19 files changed

Lines changed: 299 additions & 78 deletions

‎src/agents/main-session-recovery/main-session-restart-dispatch.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { createSubsystemLogger } from "../../logging/subsystem.js";
1919
import { CommandLane } from "../../process/lanes.js";
2020
import { MAIN_SESSION_RESTART_RECOVERY_SOURCE_TOOL } from "../../sessions/input-provenance.js";
2121
import { resolveSendPolicy } from "../../sessions/send-policy.js";
22+
import { formatSystemTurnPrompt } from "../../sessions/system-turn-prompt.js";
2223
import {
2324
deliveryContextFromSession,
2425
normalizeDeliveryContext,
@@ -41,10 +42,11 @@ import { commitMainSessionRecovery } from "./main-session-recovery-store.js";
4142
import { normalizeFiniteTimestamp } from "./main-session-restart-recovery-shared.js";
4243

4344
const log = createSubsystemLogger("main-session-restart-recovery");
44-
const RESTART_RECOVERY_RESUME_MESSAGE =
45-
"[System] Your previous turn was interrupted by a gateway restart while " +
46-
"OpenClaw was waiting on tool/model work. Continue from the existing " +
47-
"transcript and finish the interrupted response.";
45+
const RESTART_RECOVERY_RESUME_MESSAGE = formatSystemTurnPrompt(
46+
"Your previous turn was interrupted by a gateway restart while " +
47+
"OpenClaw was waiting on tool/model work. Continue from the existing " +
48+
"transcript and finish the interrupted response.",
49+
);
4850

4951
type RestartRecoveryTerminalStatus = "error" | "ok" | "timeout";
5052

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { describe, expect, it } from "vitest";
2+
import { buildRestartRecoveryResumeMessage } from "./subagent-registry-restart-recovery-helpers.js";
3+
4+
describe("buildRestartRecoveryResumeMessage", () => {
5+
it("uses the canonical system prefix and gateway restart wording", () => {
6+
expect(buildRestartRecoveryResumeMessage("Finish the report", "Use the latest figures")).toBe(
7+
"[System] Your previous turn was interrupted by a gateway restart. " +
8+
"Your original task was:\n\nFinish the report\n\n" +
9+
"The last message from the user before the interruption was:\n\n" +
10+
"Use the latest figures\n\nPlease continue where you left off.",
11+
);
12+
});
13+
});

‎src/agents/subagents/registry/subagent-registry-restart-recovery-helpers.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createHash } from "node:crypto";
22
import { loadSessionEntry } from "../../../config/sessions/session-accessor.js";
33
import * as agentEvents from "../../../infra/agent-events.js";
4+
import { formatSystemTurnPrompt } from "../../../sessions/system-turn-prompt.js";
45
import { truncateUtf16Safe } from "../../../utils.js";
56
import type {
67
SubagentRestartRecoveryReceipt,
@@ -29,13 +30,13 @@ export function isRestartRecoveryLifecycleCurrent(
2930

3031
export function buildRestartRecoveryResumeMessage(task: string, lastHumanMessage?: string): string {
3132
const original = task.length > 2_000 ? `${truncateUtf16Safe(task, 2_000)}...` : task;
32-
return (
33-
`[System] Your previous turn was interrupted by a gateway reload. ` +
34-
`Your original task was:\n\n${original}\n\n` +
35-
(lastHumanMessage
36-
? `The last message from the user before the interruption was:\n\n${lastHumanMessage}\n\n`
37-
: "") +
38-
`Please continue where you left off.`
33+
return formatSystemTurnPrompt(
34+
`Your previous turn was interrupted by a gateway restart. ` +
35+
`Your original task was:\n\n${original}\n\n` +
36+
(lastHumanMessage
37+
? `The last message from the user before the interruption was:\n\n${lastHumanMessage}\n\n`
38+
: "") +
39+
`Please continue where you left off.`,
3940
);
4041
}
4142

‎src/auto-reply/reply/stranded-reply-recovery.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ describe("resolveStrandedReplyRecovery", () => {
8282
if (recovery.kind === "retry") {
8383
expect(recovery.run.strandedReplyRetry).toBe(true);
8484
expect(recovery.run.disableCollectBatching).toBe(true);
85+
expect(recovery.run.prompt).toBe(
86+
`[System] Your previous reply was not delivered to the conversation because ` +
87+
`you did not call message(action=send). Your reply text was:\n\n` +
88+
`"${substantiveFinal}"\n\n` +
89+
`Please deliver this reply now by calling message(action=send). ` +
90+
`Do not add any extra commentary; just deliver the original reply.`,
91+
);
8592
}
8693
});
8794

‎src/auto-reply/reply/stranded-reply-recovery.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { formatSystemTurnPrompt } from "../../sessions/system-turn-prompt.js";
12
import type { SourceReplyDeliveryMode } from "../get-reply-options.types.js";
23
import { markReplyPayloadForSourceSuppressionDelivery } from "../reply-payload.js";
34
import type { ReplyPayload } from "../types.js";
@@ -58,12 +59,12 @@ export function resolveStrandedReplyRecovery(params: {
5859
}
5960

6061
function buildStrandedReplyRetryPrompt(finalText: string): string {
61-
return (
62-
`[System] Your previous reply was not delivered to the conversation because ` +
63-
`you did not call message(action=send). Your reply text was:\n\n` +
64-
`"${finalText}"\n\n` +
65-
`Please deliver this reply now by calling message(action=send). ` +
66-
`Do not add any extra commentary; just deliver the original reply.`
62+
return formatSystemTurnPrompt(
63+
`Your previous reply was not delivered to the conversation because ` +
64+
`you did not call message(action=send). Your reply text was:\n\n` +
65+
`"${finalText}"\n\n` +
66+
`Please deliver this reply now by calling message(action=send). ` +
67+
`Do not add any extra commentary; just deliver the original reply.`,
6768
);
6869
}
6970

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, it } from "vitest";
2+
import { formatSystemTurnPrompt } from "./system-turn-prompt.js";
3+
4+
describe("formatSystemTurnPrompt", () => {
5+
it.each([
6+
["resume the turn", "[System] resume the turn"],
7+
[" resume the turn ", "[System] resume the turn"],
8+
[" [System] resume the turn ", "[System] resume the turn"],
9+
])("formats %j without duplicating the system prefix", (body, expected) => {
10+
expect(formatSystemTurnPrompt(body)).toBe(expected);
11+
});
12+
});

‎src/sessions/system-turn-prompt.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Canonical prefix for model-facing internal system turns (restart recovery,
2+
// stranded-reply retry, subagent resume). Lives outside input-provenance so the
3+
// helper stays core-internal instead of widening the plugin SDK API surface.
4+
const SYSTEM_TURN_PROMPT_PREFIX = "[System]";
5+
6+
export function formatSystemTurnPrompt(body: string): string {
7+
const trimmedBody = body.trim();
8+
return trimmedBody.startsWith(SYSTEM_TURN_PROMPT_PREFIX)
9+
? trimmedBody
10+
: `${SYSTEM_TURN_PROMPT_PREFIX} ${trimmedBody}`;
11+
}

‎ui/src/components/icons-tools.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ export function strokeIcon(body: SVGTemplateResult): TemplateResult {
2222
}
2323

2424
export const toolIcons = {
25+
cpu: strokeIcon(svg` <rect width="16" height="16" x="4" y="4" rx="2" />
26+
<rect width="6" height="6" x="9" y="9" rx="1" />
27+
<path d="M15 2v2" />
28+
<path d="M15 20v2" />
29+
<path d="M2 15h2" />
30+
<path d="M2 9h2" />
31+
<path d="M20 15h2" />
32+
<path d="M20 9h2" />
33+
<path d="M9 2v2" />
34+
<path d="M9 20v2" />`),
35+
foldVertical: strokeIcon(svg` <path d="M12 22v-6" />
36+
<path d="M12 8V2" />
37+
<path d="M4 12H2" />
38+
<path d="M10 12H8" />
39+
<path d="M16 12h-2" />
40+
<path d="M22 12h-2" />
41+
<path d="m19 9-3 3 3 3" />
42+
<path d="m5 15 3-3-3-3" />`),
2543
wrench: strokeIcon(svg` <path
2644
d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"
2745
/>`),

‎ui/src/i18n/locales/en.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4767,10 +4767,19 @@ export const en: TranslationMap = {
47674767
compaction: {
47684768
label: "Compacted history",
47694769
savedTokens: "saved {count} tokens",
4770-
description:
4771-
"The compacted transcript is preserved as a checkpoint. Open session checkpoints to branch or restore from that compacted view.",
4770+
description: "The compacted transcript is preserved as a checkpoint.",
47724771
openCheckpoints: "Open checkpoints",
47734772
},
4773+
systemNotice: {
4774+
restartRecovery: {
4775+
label: "System · restart recovery",
4776+
summary:
4777+
"Turn interrupted by a gateway restart — asked the agent to resume and finish the response.",
4778+
},
4779+
gatewayRestarted: {
4780+
label: "System · gateway restarted",
4781+
},
4782+
},
47744783
progressLabels: {
47754784
shelling: "Shelling",
47764785
scuttling: "Scuttling",

‎ui/src/lib/chat/chat-types.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import type { MediaKind } from "@openclaw/media-core/constants";
6+
import type { toolIcons } from "../../components/icons-tools.ts";
67
import type { SenderIdentity } from "./sender-label.ts";
78

89
export type BrowserAnnotationAttachment = {
@@ -89,13 +90,15 @@ export type ChatItem =
8990
key: string;
9091
text: string;
9192
timestamp: number;
93+
icon?: keyof typeof toolIcons;
9294
label?: string;
9395
startsTurn?: true;
9496
}
9597
| {
9698
kind: "divider";
9799
key: string;
98100
label: string;
101+
icon?: keyof typeof toolIcons;
99102
metric?: string;
100103
description?: string;
101104
action?: { kind: "session-checkpoints"; label: string };

0 commit comments

Comments
 (0)