refactor: consolidate coercion contracts (#122458)

* refactor: consolidate coercion contracts

Centralize exact string, record, numeric, date, Boolean, argument, and structured-error coercions while preserving call-site semantics.

Migrate canonical-name collisions and deprecated internal SDK bypasses, deleting 55 net production/tooling lines. Expand declaration ownership enforcement to 101 allowed helpers and add a narrow export-completeness audit.

* fix: preserve standalone script coercions

Keep copied Control UI tooling self-contained and retain the trusted release harness module-relative source seam when the harness runs against an old target cwd.
This commit is contained in:
Peter Steinberger
2026-08-11 23:26:37 -07:00
committed by GitHub
parent 66fe424590
commit b080dd1e76
276 changed files with 1685 additions and 1663 deletions
+2 -4
View File
@@ -1,4 +1,5 @@
/** Dependency-light normalization helpers for stored cron run diagnostics. */
import { asFiniteNumber } from "@openclaw/normalization-core/number-coercion";
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
import { sliceUtf16Safe, truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
@@ -76,10 +77,7 @@ export function normalizeDiagnosticToolName(value: unknown): string | undefined
}
export function normalizeExitCode(value: unknown): number | null | undefined {
if (typeof value === "number" && Number.isFinite(value)) {
return value;
}
return value === null ? null : undefined;
return asFiniteNumber(value) ?? (value === null ? null : undefined);
}
export function tailText(value: string, maxChars: number): string {
+9 -12
View File
@@ -1,5 +1,8 @@
/** Resolves and emits cron failure-alert notifications. */
import { normalizeOptionalLowercaseString } from "@openclaw/normalization-core/string-coerce";
import {
normalizeOptionalLowercaseString,
normalizeOptionalString,
} from "@openclaw/normalization-core/string-coerce";
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
import { classifyOAuthRefreshFailure } from "../../agents/auth-profiles/oauth-refresh-failure.js";
import type { FailoverReason } from "../../agents/failover/signal.js";
@@ -62,14 +65,6 @@ function normalizeFailureAlertRecipient(channel: CronMessageChannel, to: string)
}
}
function normalizeTo(input: unknown): string | undefined {
if (typeof input !== "string") {
return undefined;
}
const to = input.trim();
return to ? to : undefined;
}
function clampPositiveInt(value: unknown, fallback: number): number {
if (typeof value !== "number" || !Number.isFinite(value)) {
return fallback;
@@ -104,9 +99,11 @@ export function resolveFailureAlert(
const mode = jobConfig?.mode ?? globalConfig?.mode;
const inheritsGlobalMode =
!jobConfig?.mode || jobConfig.mode === (globalConfig?.mode ?? "announce");
const jobTo = normalizeTo(jobConfig?.to);
const jobTo = normalizeOptionalString(jobConfig?.to);
const jobChannel = resolveFailureAlertChannel(jobConfig?.channel, jobTo);
const configuredGlobalTo = inheritsGlobalMode ? normalizeTo(globalConfig?.to) : undefined;
const configuredGlobalTo = inheritsGlobalMode
? normalizeOptionalString(globalConfig?.to)
: undefined;
const globalChannel = inheritsGlobalMode
? resolveFailureAlertChannel(globalConfig?.channel, configuredGlobalTo)
: undefined;
@@ -115,7 +112,7 @@ export function resolveFailureAlert(
const inheritsGlobalRoute =
inheritsGlobalMode && (mode === "webhook" || !jobChannel || jobChannel === globalChannel);
const globalTo = inheritsGlobalRoute ? configuredGlobalTo : undefined;
const deliveryTo = normalizeTo(job.delivery?.to);
const deliveryTo = normalizeOptionalString(job.delivery?.to);
const deliveryChannel = resolveFailureAlertChannel(job.delivery?.channel, deliveryTo);
const channel = jobChannel ?? globalChannel ?? deliveryChannel ?? "last";
const inheritsDeliveryChannel =