Skip to content

Commit 43901be

Browse files
authored
refactor(agents): trim embedded helper dead exports (#105815)
* refactor(agents): trim embedded helper exports * chore(deadcode): refresh export baseline * chore(deadcode): sync export baseline * chore(deadcode): reconcile export baseline
1 parent 3613b83 commit 43901be

12 files changed

Lines changed: 41 additions & 234 deletions

‎scripts/deadcode-exports.baseline.mjs‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,34 +1975,6 @@ export const KNIP_UNUSED_EXPORT_BASELINE = [
19751975
"src/agents/conversation-capability-profile.ts: ConversationCapabilityProfileParams",
19761976
"src/agents/conversation-capability-profile.ts: ConversationCapabilityScope",
19771977
"src/agents/core-tool-factory-descriptors.ts: CORE_TOOL_FACTORY_DESCRIPTORS",
1978-
"src/agents/embedded-agent-helpers.ts: classifyFailoverReasonFromHttpStatus",
1979-
"src/agents/embedded-agent-helpers.ts: DEFAULT_BOOTSTRAP_MAX_CHARS",
1980-
"src/agents/embedded-agent-helpers.ts: DEFAULT_BOOTSTRAP_PROMPT_TRUNCATION_WARNING_MODE",
1981-
"src/agents/embedded-agent-helpers.ts: DEFAULT_BOOTSTRAP_TOTAL_MAX_CHARS",
1982-
"src/agents/embedded-agent-helpers.ts: isAuthPermanentErrorMessage",
1983-
"src/agents/embedded-agent-helpers.ts: isCloudflareOrHtmlErrorPage",
1984-
"src/agents/embedded-agent-helpers.ts: isGoogleModelApi",
1985-
"src/agents/embedded-agent-helpers.ts: isImageDimensionErrorMessage",
1986-
"src/agents/embedded-agent-helpers.ts: isImageSizeError",
1987-
"src/agents/embedded-agent-helpers.ts: isModelNotFoundErrorMessage",
1988-
"src/agents/embedded-agent-helpers.ts: isValidCloudCodeAssistToolId",
1989-
"src/agents/embedded-agent-helpers.ts: mergeConsecutiveUserTurns",
1990-
"src/agents/embedded-agent-helpers.ts: sanitizeToolCallId",
1991-
"src/agents/embedded-agent-helpers.ts: sanitizeUserFacingText",
1992-
"src/agents/embedded-agent-helpers.ts: stripThoughtSignatures",
1993-
"src/agents/embedded-agent-helpers.ts: ToolCallIdMode",
1994-
"src/agents/embedded-agent-helpers/bootstrap.ts: DEFAULT_BOOTSTRAP_MAX_CHARS",
1995-
"src/agents/embedded-agent-helpers/bootstrap.ts: DEFAULT_BOOTSTRAP_PROMPT_TRUNCATION_WARNING_MODE",
1996-
"src/agents/embedded-agent-helpers/bootstrap.ts: DEFAULT_BOOTSTRAP_TOTAL_MAX_CHARS",
1997-
"src/agents/embedded-agent-helpers/errors.ts: classifyFailoverReasonFromHttpStatus",
1998-
"src/agents/embedded-agent-helpers/errors.ts: extractLeadingHttpStatus",
1999-
"src/agents/embedded-agent-helpers/errors.ts: isAuthPermanentErrorMessage",
2000-
"src/agents/embedded-agent-helpers/errors.ts: isCloudflareOrHtmlErrorPage",
2001-
"src/agents/embedded-agent-helpers/errors.ts: isGenericProviderInternalError",
2002-
"src/agents/embedded-agent-helpers/errors.ts: isImageDimensionErrorMessage",
2003-
"src/agents/embedded-agent-helpers/errors.ts: isImageSizeError",
2004-
"src/agents/embedded-agent-helpers/errors.ts: isServerErrorMessage",
2005-
"src/agents/embedded-agent-helpers/errors.ts: sanitizeUserFacingText",
20061978
"src/agents/embedded-agent-helpers/turns.ts: mergeConsecutiveUserTurns",
20071979
"src/agents/embedded-agent-runner.ts: applyExtraParamsToAgent",
20081980
"src/agents/embedded-agent-runner.ts: buildEmbeddedSandboxInfo",

‎src/agents/embedded-agent-helpers.buildbootstrapcontextfiles.test.ts‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import { describe, expect, it } from "vitest";
66
import type { OpenClawConfig } from "../config/config.js";
77
import {
88
buildBootstrapContextFiles,
9-
DEFAULT_BOOTSTRAP_MAX_CHARS,
10-
DEFAULT_BOOTSTRAP_PROMPT_TRUNCATION_WARNING_MODE,
11-
DEFAULT_BOOTSTRAP_TOTAL_MAX_CHARS,
129
ensureSessionHeader,
1310
resolveBootstrapMaxChars,
1411
resolveBootstrapPromptTruncationWarningMode,
@@ -17,6 +14,10 @@ import {
1714
import type { WorkspaceBootstrapFile } from "./workspace.js";
1815
import { DEFAULT_AGENTS_FILENAME } from "./workspace.js";
1916

17+
const EXPECTED_DEFAULT_BOOTSTRAP_MAX_CHARS = 20_000;
18+
const EXPECTED_DEFAULT_BOOTSTRAP_TOTAL_MAX_CHARS = 60_000;
19+
const EXPECTED_DEFAULT_BOOTSTRAP_PROMPT_TRUNCATION_WARNING_MODE = "always";
20+
2021
const makeFile = (overrides: Partial<WorkspaceBootstrapFile>): WorkspaceBootstrapFile => ({
2122
name: DEFAULT_AGENTS_FILENAME,
2223
path: "/tmp/AGENTS.md",
@@ -124,7 +125,7 @@ describe("buildBootstrapContextFiles", () => {
124125
}
125126
});
126127
it("fits the rendered truncation marker inside the per-file budget", () => {
127-
const maxChars = DEFAULT_BOOTSTRAP_MAX_CHARS;
128+
const maxChars = EXPECTED_DEFAULT_BOOTSTRAP_MAX_CHARS;
128129
const files = [
129130
makeFile({
130131
name: "HEARTBEAT.md",
@@ -190,7 +191,7 @@ describe("buildBootstrapContextFiles", () => {
190191
expect(result?.content).toContain("H");
191192
});
192193
it("keeps content under the default limit", () => {
193-
const long = "a".repeat(DEFAULT_BOOTSTRAP_MAX_CHARS - 10);
194+
const long = "a".repeat(EXPECTED_DEFAULT_BOOTSTRAP_MAX_CHARS - 10);
194195
const files = [makeFile({ content: long })];
195196
const [result] = buildBootstrapContextFiles(files);
196197
expect(result?.content).toBe(long);
@@ -203,7 +204,7 @@ describe("buildBootstrapContextFiles", () => {
203204
const files = createLargeBootstrapFiles();
204205
const result = buildBootstrapContextFiles(files);
205206
const totalChars = result.reduce((sum, entry) => sum + entry.content.length, 0);
206-
expect(totalChars).toBeLessThanOrEqual(DEFAULT_BOOTSTRAP_TOTAL_MAX_CHARS);
207+
expect(totalChars).toBeLessThanOrEqual(EXPECTED_DEFAULT_BOOTSTRAP_TOTAL_MAX_CHARS);
207208
expect(result).toHaveLength(3);
208209
expect(result[2]?.content).toBe("c".repeat(10_000));
209210
});
@@ -311,12 +312,12 @@ const BOOTSTRAP_LIMIT_RESOLVERS: BootstrapLimitResolverCase[] = [
311312
{
312313
name: "bootstrapMaxChars",
313314
resolve: resolveBootstrapMaxChars,
314-
defaultValue: DEFAULT_BOOTSTRAP_MAX_CHARS,
315+
defaultValue: EXPECTED_DEFAULT_BOOTSTRAP_MAX_CHARS,
315316
},
316317
{
317318
name: "bootstrapTotalMaxChars",
318319
resolve: resolveBootstrapTotalMaxChars,
319-
defaultValue: DEFAULT_BOOTSTRAP_TOTAL_MAX_CHARS,
320+
defaultValue: EXPECTED_DEFAULT_BOOTSTRAP_TOTAL_MAX_CHARS,
320321
},
321322
];
322323

@@ -373,7 +374,7 @@ describe("bootstrap limit resolvers", () => {
373374
describe("resolveBootstrapPromptTruncationWarningMode", () => {
374375
it("defaults to always", () => {
375376
expect(resolveBootstrapPromptTruncationWarningMode()).toBe("always");
376-
expect(DEFAULT_BOOTSTRAP_PROMPT_TRUNCATION_WARNING_MODE).toBe("always");
377+
expect(EXPECTED_DEFAULT_BOOTSTRAP_PROMPT_TRUNCATION_WARNING_MODE).toBe("always");
377378
});
378379

379380
it("accepts explicit valid modes", () => {
@@ -399,6 +400,6 @@ describe("resolveBootstrapPromptTruncationWarningMode", () => {
399400
resolveBootstrapPromptTruncationWarningMode({
400401
agents: { defaults: { bootstrapPromptTruncationWarning: "invalid" } },
401402
} as unknown as OpenClawConfig),
402-
).toBe(DEFAULT_BOOTSTRAP_PROMPT_TRUNCATION_WARNING_MODE);
403+
).toBe(EXPECTED_DEFAULT_BOOTSTRAP_PROMPT_TRUNCATION_WARNING_MODE);
403404
});
404405
});

‎src/agents/embedded-agent-helpers.formatassistanterrortext.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
getApiErrorPayloadFingerprint,
1212
formatRawAssistantErrorForUi,
1313
isRawApiErrorPayload,
14-
sanitizeUserFacingText,
1514
} from "./embedded-agent-helpers.js";
15+
import { sanitizeUserFacingText } from "./embedded-agent-helpers/sanitize-user-facing-text.js";
1616
import { makeAssistantMessageFixture } from "./test-helpers/assistant-message-fixtures.js";
1717

1818
describe("formatAssistantErrorText", () => {

‎src/agents/embedded-agent-helpers.isbillingerrormessage.test.ts‎

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
// Covers provider error classifiers and failover reason mapping.
22
import { describe, expect, it } from "vitest";
3+
import { isCloudflareOrHtmlErrorPage } from "../shared/assistant-error-format.js";
34
import {
45
classifyAssistantFailoverReason,
56
classifyProviderRuntimeFailureKind,
67
classifyFailoverReason,
7-
classifyFailoverReasonFromHttpStatus,
88
extractObservedOverflowTokenCount,
99
isAuthErrorMessage,
10-
isAuthPermanentErrorMessage,
1110
isBillingErrorMessage,
1211
isCloudCodeAssistFormatError,
13-
isCloudflareOrHtmlErrorPage,
1412
isCompactionFailureError,
1513
isContextOverflowError,
1614
isFailoverErrorMessage,
17-
isImageDimensionErrorMessage,
1815
isLikelyContextOverflowError,
1916
isTimeoutErrorMessage,
2017
isTransientHttpError,
2118
parseImageDimensionError,
2219
parseImageSizeError,
2320
} from "./embedded-agent-helpers.js";
21+
import { isAuthPermanentErrorMessage } from "./embedded-agent-helpers/failover-matches.js";
2422

2523
// OpenAI 429 example shape: https://help.openai.com/en/articles/5955604-how-can-i-solve-429-too-many-requests-errors
2624
const OPENAI_RATE_LIMIT_MESSAGE =
@@ -80,6 +78,18 @@ function expectNotFailoverSample(sample: string) {
8078
expect(isFailoverErrorMessage(sample)).toBe(false);
8179
}
8280

81+
function classifyFailoverReasonFromHttpStatus(
82+
status: number | undefined,
83+
message?: string,
84+
opts?: { provider?: string },
85+
) {
86+
if (status === undefined) {
87+
return null;
88+
}
89+
const statusText = `HTTP ${status}`;
90+
return classifyFailoverReason(message ? `${statusText}: ${message}` : statusText, opts);
91+
}
92+
8393
describe("isAuthPermanentErrorMessage", () => {
8494
it.each([
8595
{
@@ -639,20 +649,6 @@ describe("classifyFailoverReasonFromHttpStatus", () => {
639649
expect(classifyFailoverReasonFromHttpStatus(401, "invalid_api_key")).toBe("auth");
640650
});
641651

642-
it("treats body-less HTTP 422 as unknown instead of format", () => {
643-
expect(classifyFailoverReasonFromHttpStatus(422)).toBeNull();
644-
});
645-
646-
it("treats no-body HTTP 400/422 wrappers as unknown instead of format", () => {
647-
expect(classifyFailoverReasonFromHttpStatus(400, "No body response")).toBeNull();
648-
expect(classifyFailoverReasonFromHttpStatus(400, "400 status code (no body)")).toBeNull();
649-
expect(classifyFailoverReasonFromHttpStatus(422, "HTTP 422: No body")).toBeNull();
650-
expect(classifyFailoverReasonFromHttpStatus(422, "HTTP 422: No response body")).toBeNull();
651-
expect(
652-
classifyFailoverReasonFromHttpStatus(422, "Error: HTTP 422: No response body"),
653-
).toBeNull();
654-
});
655-
656652
it("treats HTTP 422 with an unclassifiable body as format error", () => {
657653
expect(classifyFailoverReasonFromHttpStatus(422, "check open ai req parameter error")).toBe(
658654
"format",
@@ -1040,7 +1036,6 @@ describe("image dimension errors", () => {
10401036
contentIndex: 1,
10411037
raw,
10421038
});
1043-
expect(isImageDimensionErrorMessage(raw)).toBe(true);
10441039
});
10451040
});
10461041

‎src/agents/embedded-agent-helpers.sanitizeuserfacingtext.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import {
1010
downgradeOpenAIReasoningBlocks,
1111
isMessagingToolDuplicate,
1212
normalizeTextForComparison,
13-
sanitizeToolCallId,
14-
sanitizeUserFacingText,
15-
stripThoughtSignatures,
1613
} from "./embedded-agent-helpers.js";
14+
import { stripThoughtSignatures } from "./embedded-agent-helpers/bootstrap.js";
15+
import { sanitizeUserFacingText } from "./embedded-agent-helpers/sanitize-user-facing-text.js";
1716
import {
1817
formatAgentInternalEventsForPrompt,
1918
INTERNAL_RUNTIME_CONTEXT_BEGIN,
2019
INTERNAL_RUNTIME_CONTEXT_END,
2120
} from "./internal-events.js";
21+
import { sanitizeToolCallId } from "./tool-call-id.js";
2222

2323
describe("sanitizeUserFacingText", () => {
2424
it("strips final tags", () => {
Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
/** Embedded-agent helper barrel for bootstrap, provider error, media, and turn sanitizers. */
2-
export { isModelNotFoundErrorMessage } from "./live-model-errors.js";
32

43
export {
54
buildBootstrapContextFiles,
6-
DEFAULT_BOOTSTRAP_MAX_CHARS,
7-
DEFAULT_BOOTSTRAP_PROMPT_TRUNCATION_WARNING_MODE,
8-
DEFAULT_BOOTSTRAP_TOTAL_MAX_CHARS,
95
ensureSessionHeader,
106
resolveBootstrapMaxChars,
117
resolveBootstrapPromptTruncationWarningMode,
128
resolveBootstrapTotalMaxChars,
13-
stripThoughtSignatures,
149
} from "./embedded-agent-helpers/bootstrap.js";
1510
export {
1611
BILLING_ERROR_USER_MESSAGE,
@@ -19,29 +14,24 @@ export {
1914
formatBillingErrorMessage,
2015
formatRateLimitOrOverloadedErrorCopy,
2116
classifyFailoverReason,
22-
classifyFailoverReasonFromHttpStatus,
2317
formatRawAssistantErrorForUi,
2418
formatAssistantErrorText,
2519
formatUserFacingAssistantErrorText,
2620
GENERIC_ASSISTANT_ERROR_TEXT,
2721
getApiErrorPayloadFingerprint,
2822
isAuthAssistantError,
2923
isAuthErrorMessage,
30-
isAuthPermanentErrorMessage,
3124
isBillingAssistantError,
3225
extractObservedOverflowTokenCount,
3326
parseApiErrorInfo,
3427
isBillingErrorMessage,
35-
isCloudflareOrHtmlErrorPage,
3628
isCloudCodeAssistFormatError,
3729
isCompactionFailureError,
3830
isContextOverflowError,
3931
isLikelyContextOverflowError,
4032
isFailoverAssistantError,
4133
isFailoverErrorMessage,
4234
isGenericUnknownStreamErrorMessage,
43-
isImageDimensionErrorMessage,
44-
isImageSizeError,
4535
isOverloadedErrorMessage,
4636
isRawApiErrorPayload,
4737
isRateLimitAssistantError,
@@ -52,8 +42,7 @@ export {
5242
parseImageSizeError,
5343
} from "./embedded-agent-helpers/errors.js";
5444
export type { ProviderRuntimeFailureKind } from "./embedded-agent-helpers/errors.js";
55-
export { sanitizeUserFacingText } from "./embedded-agent-helpers/sanitize-user-facing-text.js";
56-
export { isGoogleModelApi, sanitizeGoogleTurnOrdering } from "./embedded-agent-helpers/google.js";
45+
export { sanitizeGoogleTurnOrdering } from "./embedded-agent-helpers/google.js";
5746

5847
export {
5948
downgradeOpenAIFunctionCallReasoningPairs,
@@ -69,12 +58,5 @@ export {
6958

7059
export { pickFallbackThinkingLevel } from "./embedded-agent-helpers/thinking.js";
7160

72-
export {
73-
mergeConsecutiveUserTurns,
74-
validateAnthropicTurns,
75-
validateGeminiTurns,
76-
} from "./embedded-agent-helpers/turns.js";
61+
export { validateAnthropicTurns, validateGeminiTurns } from "./embedded-agent-helpers/turns.js";
7762
export type { EmbeddedContextFile, FailoverReason } from "./embedded-agent-helpers/types.js";
78-
79-
export type { ToolCallIdMode } from "./tool-call-id.js";
80-
export { isValidCloudCodeAssistToolId, sanitizeToolCallId } from "./tool-call-id.js";

‎src/agents/embedded-agent-helpers.validate-turns.test.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
import { expectDefined } from "@openclaw/normalization-core";
44
import type { AgentMessage } from "openclaw/plugin-sdk/agent-core";
55
import { describe, expect, it } from "vitest";
6-
import {
7-
mergeConsecutiveUserTurns,
8-
validateAnthropicTurns,
9-
validateGeminiTurns,
10-
} from "./embedded-agent-helpers.js";
6+
import { validateAnthropicTurns, validateGeminiTurns } from "./embedded-agent-helpers.js";
7+
import { mergeConsecutiveUserTurns } from "./embedded-agent-helpers/turns.js";
118

129
function asMessages(messages: unknown[]): AgentMessage[] {
1310
return messages as AgentMessage[];

‎src/agents/embedded-agent-helpers/bootstrap.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ export function stripThoughtSignatures<T>(
8888
}) as T;
8989
}
9090

91-
export const DEFAULT_BOOTSTRAP_MAX_CHARS = 20_000;
92-
export const DEFAULT_BOOTSTRAP_TOTAL_MAX_CHARS = 60_000;
93-
export const DEFAULT_BOOTSTRAP_PROMPT_TRUNCATION_WARNING_MODE = "always";
91+
const DEFAULT_BOOTSTRAP_MAX_CHARS = 20_000;
92+
const DEFAULT_BOOTSTRAP_TOTAL_MAX_CHARS = 60_000;
93+
const DEFAULT_BOOTSTRAP_PROMPT_TRUNCATION_WARNING_MODE = "always";
9494
const MIN_BOOTSTRAP_FILE_BUDGET_CHARS = 64;
9595
// Ratios split `contentBudget` (= maxChars − marker.length − join separators), not `maxChars`.
9696
// The marker and "\n" separators are already reserved before this split runs; these ratios

0 commit comments

Comments
 (0)