From d17bb9c3e933afcfc56bddba35cf81c8d6c047f8 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 22 Jun 2026 09:59:31 +0800 Subject: [PATCH] chore(deadcode): collapse session helper barrels --- src/agents/subagent-announce-output.ts | 2 +- src/agents/tools/assistant-phase-text.test.ts | 39 +++++++------------ src/agents/tools/session-message-text.ts | 7 ---- src/agents/tools/sessions-helpers.ts | 5 --- src/agents/tools/sessions-history-tool.ts | 2 +- src/agents/tools/sessions-list-tool.ts | 2 +- src/agents/tools/sessions.test.ts | 2 +- .../reply/commands-subagents/action-agents.ts | 9 +---- .../reply/commands-subagents/action-log.ts | 2 +- .../reply/commands-subagents/shared.ts | 4 -- 10 files changed, 22 insertions(+), 52 deletions(-) delete mode 100644 src/agents/tools/session-message-text.ts diff --git a/src/agents/subagent-announce-output.ts b/src/agents/subagent-announce-output.ts index 12dca9afb341..d46c533b6fdd 100644 --- a/src/agents/subagent-announce-output.ts +++ b/src/agents/subagent-announce-output.ts @@ -20,7 +20,7 @@ import { resolveStorePath, } from "./subagent-announce.runtime.js"; import { assistantCallsSessionsYield, isSessionsYieldToolResult } from "./subagent-yield-output.js"; -import { extractAssistantText, sanitizeTextContent } from "./tools/session-message-text.js"; +import { extractAssistantText, sanitizeTextContent } from "./tools/chat-history-text.js"; import { isAnnounceSkip } from "./tools/sessions-send-tokens.js"; const FAST_TEST_RETRY_INTERVAL_MS = 8; diff --git a/src/agents/tools/assistant-phase-text.test.ts b/src/agents/tools/assistant-phase-text.test.ts index 921045f1b231..09cdb26e78a1 100644 --- a/src/agents/tools/assistant-phase-text.test.ts +++ b/src/agents/tools/assistant-phase-text.test.ts @@ -2,7 +2,6 @@ // assistant message phases. import { describe, expect, it } from "vitest"; import { extractAssistantText as extractChatHistoryAssistantText } from "./chat-history-text.js"; -import { extractAssistantText as extractSessionAssistantText } from "./session-message-text.js"; function assistantTextPart(id: string, phase: string, text: string) { return { @@ -19,39 +18,31 @@ function assistantMessage(...content: ReturnType[]) { }; } -const assistantTextExtractors = [ - ["chat history", extractChatHistoryAssistantText], - ["session message", extractSessionAssistantText], -] as const; - describe("phase-aware assistant text helpers", () => { it("fails soft for malformed inputs", () => { for (const message of [null, 42, "broken history entry"]) { expect(extractChatHistoryAssistantText(message)).toBeUndefined(); - expect(extractSessionAssistantText(message)).toBeUndefined(); } }); - for (const [label, extractAssistantText] of assistantTextExtractors) { - it(`prefers final_answer text over commentary in ${label} helpers`, () => { - const message = assistantMessage( - assistantTextPart("commentary", "commentary", "Need verify healthy."), - assistantTextPart("final", "final_answer", "Health check completed successfully."), - ); + it("prefers final_answer text over commentary", () => { + const message = assistantMessage( + assistantTextPart("commentary", "commentary", "Need verify healthy."), + assistantTextPart("final", "final_answer", "Health check completed successfully."), + ); - expect(extractAssistantText(message)).toBe("Health check completed successfully."); - }); + expect(extractChatHistoryAssistantText(message)).toBe("Health check completed successfully."); + }); - it(`preserves spaces across split final_answer blocks in ${label} helpers`, () => { - const message = assistantMessage( - assistantTextPart("commentary", "commentary", "Need verify healthy."), - assistantTextPart("final_1", "final_answer", "Hi "), - assistantTextPart("final_2", "final_answer", "secretthere"), - ); + it("preserves spaces across split final_answer blocks", () => { + const message = assistantMessage( + assistantTextPart("commentary", "commentary", "Need verify healthy."), + assistantTextPart("final_1", "final_answer", "Hi "), + assistantTextPart("final_2", "final_answer", "secretthere"), + ); - expect(extractAssistantText(message)).toBe("Hi there"); - }); - } + expect(extractChatHistoryAssistantText(message)).toBe("Hi there"); + }); it("does not fall back to commentary when an explicit final_answer is empty", () => { // An explicit empty final answer means there is no publishable response; diff --git a/src/agents/tools/session-message-text.ts b/src/agents/tools/session-message-text.ts deleted file mode 100644 index d815ce4b82e2..000000000000 --- a/src/agents/tools/session-message-text.ts +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Session message text extraction barrel. - * - * Session tools import this narrow surface for assistant/user text extraction - * without reaching into chat-history helper internals. - */ -export { extractAssistantText, sanitizeTextContent } from "./chat-history-text.js"; diff --git a/src/agents/tools/sessions-helpers.ts b/src/agents/tools/sessions-helpers.ts index 841496a33642..bdab0d552b9a 100644 --- a/src/agents/tools/sessions-helpers.ts +++ b/src/agents/tools/sessions-helpers.ts @@ -20,11 +20,6 @@ export { resolveVisibleSessionReference, shouldResolveSessionIdInput, } from "./sessions-resolution.js"; -export { - extractAssistantText, - sanitizeTextContent, - stripToolMessages, -} from "./chat-history-text.js"; import { normalizeOptionalString, type FastMode } from "@openclaw/normalization-core/string-coerce"; import { getRuntimeConfig } from "../../config/config.js"; import type { OpenClawConfig } from "../../config/types.openclaw.js"; diff --git a/src/agents/tools/sessions-history-tool.ts b/src/agents/tools/sessions-history-tool.ts index 00442b3cc99e..0a2ff3b15239 100644 --- a/src/agents/tools/sessions-history-tool.ts +++ b/src/agents/tools/sessions-history-tool.ts @@ -17,6 +17,7 @@ import { describeSessionsHistoryTool, SESSIONS_HISTORY_TOOL_DISPLAY_SUMMARY, } from "../tool-description-presets.js"; +import { stripToolMessages } from "./chat-history-text.js"; import type { AnyAgentTool } from "./common.js"; import { jsonResult, readPositiveIntegerParam, readStringParam } from "./common.js"; import { @@ -26,7 +27,6 @@ import { resolveSessionReference, resolveSandboxedSessionToolContext, resolveVisibleSessionReference, - stripToolMessages, } from "./sessions-helpers.js"; const SessionsHistoryToolSchema = Type.Object({ diff --git a/src/agents/tools/sessions-list-tool.ts b/src/agents/tools/sessions-list-tool.ts index e7a6f87cebd9..0a596590601c 100644 --- a/src/agents/tools/sessions-list-tool.ts +++ b/src/agents/tools/sessions-list-tool.ts @@ -32,6 +32,7 @@ import { describeSessionsListTool, SESSIONS_LIST_TOOL_DISPLAY_SUMMARY, } from "../tool-description-presets.js"; +import { stripToolMessages } from "./chat-history-text.js"; import type { AnyAgentTool } from "./common.js"; import { jsonResult, @@ -51,7 +52,6 @@ import { resolveSandboxedSessionToolContext, type SessionListRow, type SessionRunStatus, - stripToolMessages, } from "./sessions-helpers.js"; const SessionsListToolSchema = Type.Object({ diff --git a/src/agents/tools/sessions.test.ts b/src/agents/tools/sessions.test.ts index d070473caff1..fcaee43300ba 100644 --- a/src/agents/tools/sessions.test.ts +++ b/src/agents/tools/sessions.test.ts @@ -7,7 +7,7 @@ import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import type { ChannelMessagingAdapter } from "../../channels/plugins/types.js"; import { createTestRegistry } from "../../test-utils/channel-plugins.js"; import { withEnvAsync } from "../../test-utils/env.js"; -import { extractAssistantText, sanitizeTextContent } from "./sessions-helpers.js"; +import { extractAssistantText, sanitizeTextContent } from "./chat-history-text.js"; const callGatewayMock = vi.fn(); vi.mock("../../gateway/call.js", () => ({ diff --git a/src/auto-reply/reply/commands-subagents/action-agents.ts b/src/auto-reply/reply/commands-subagents/action-agents.ts index 0fbe605d06da..cb4ccf2d6d8e 100644 --- a/src/auto-reply/reply/commands-subagents/action-agents.ts +++ b/src/auto-reply/reply/commands-subagents/action-agents.ts @@ -5,15 +5,10 @@ import { countPendingDescendantRunsFromRuns } from "../../../agents/subagent-reg import { getSubagentRunsSnapshotForRead } from "../../../agents/subagent-registry-state.js"; import { getChannelPlugin, normalizeChannelId } from "../../../channels/plugins/index.js"; import { getSessionBindingService } from "../../../infra/outbound/session-binding-service.js"; +import { resolveChannelAccountId, resolveCommandSurfaceChannel } from "../channel-context.js"; import type { CommandHandlerResult } from "../commands-types.js"; import { formatRunLabel, sortSubagentRuns } from "../subagents-utils.js"; -import { - RECENT_WINDOW_MINUTES, - type SubagentsCommandContext, - resolveChannelAccountId, - resolveCommandSurfaceChannel, - stopWithText, -} from "./shared.js"; +import { RECENT_WINDOW_MINUTES, type SubagentsCommandContext, stopWithText } from "./shared.js"; function formatConversationBindingText(params: { conversationId: string }): string { return `binding:${params.conversationId}`; diff --git a/src/auto-reply/reply/commands-subagents/action-log.ts b/src/auto-reply/reply/commands-subagents/action-log.ts index 626dd096b5a9..4ecf50e2518c 100644 --- a/src/auto-reply/reply/commands-subagents/action-log.ts +++ b/src/auto-reply/reply/commands-subagents/action-log.ts @@ -1,6 +1,7 @@ // Implements subagent log retrieval and pagination. import { parseStrictNonNegativeInteger } from "@openclaw/normalization-core/number-coercion"; import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce"; +import { stripToolMessages } from "../../../agents/tools/chat-history-text.js"; import { callGateway } from "../../../gateway/call.js"; import type { CommandHandlerResult } from "../commands-types.js"; import { formatRunLabel } from "../subagents-utils.js"; @@ -10,7 +11,6 @@ import { formatLogLines, resolveSubagentEntryForToken, stopWithText, - stripToolMessages, } from "./shared.js"; export async function handleSubagentsLogAction( diff --git a/src/auto-reply/reply/commands-subagents/shared.ts b/src/auto-reply/reply/commands-subagents/shared.ts index 3de51b507d2a..e9ed3102cca7 100644 --- a/src/auto-reply/reply/commands-subagents/shared.ts +++ b/src/auto-reply/reply/commands-subagents/shared.ts @@ -12,14 +12,12 @@ import type { SubagentRunRecord } from "../../../agents/subagent-registry.types. import { resolveInternalSessionKey, resolveMainSessionAlias, - stripToolMessages, } from "../../../agents/tools/sessions-helpers.js"; import { callGateway } from "../../../gateway/call.js"; import { parseAgentSessionKey } from "../../../routing/session-key.js"; import { isSubagentSessionKey } from "../../../routing/session-key.js"; import { looksLikeSessionId } from "../../../sessions/session-id.js"; import { isNativeCommandTurn, resolveCommandTurnContext } from "../../command-turn-context.js"; -import { resolveCommandSurfaceChannel, resolveChannelAccountId } from "../channel-context.js"; import { extractMessageText, type ChatMessage } from "../commands-subagents-text.js"; import type { CommandHandler, CommandHandlerResult } from "../commands-types.js"; import { @@ -28,8 +26,6 @@ import { type SubagentTargetResolution, } from "../subagents-utils.js"; -export { stripToolMessages }; -export { resolveCommandSurfaceChannel, resolveChannelAccountId }; export type { ChatMessage } from "../commands-subagents-text.js"; export const COMMAND = "/subagents";