docs: document shared helpers

This commit is contained in:
Peter Steinberger
2026-06-04 20:02:33 -04:00
parent 5b53cddc75
commit 87d053c0cb
85 changed files with 85 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
// Agent run status tests cover status normalization for agent run records.
import { describe, expect, it } from "vitest";
import { isNonTerminalAgentRunStatus } from "./agent-run-status.js";

View File

@@ -1,3 +1,4 @@
// Assistant error formatting helpers normalize assistant-visible error payloads.
const ERROR_PAYLOAD_PREFIX_RE =
/^(?:error|(?:[a-z][\w-]*\s+)?api\s*error|apierror|openai\s*error|anthropic\s*error|gateway\s*error|codex\s*error)(?:\s+\d{3})?[:\s-]+/i;
const HTTP_STATUS_DELIMITER_RE = /(?:\s*:\s*|\s+)/;

View File

@@ -1,3 +1,4 @@
// Assistant identity tests cover normalized assistant names and metadata values.
import { describe, expect, it } from "vitest";
import { coerceIdentityValue } from "./assistant-identity-values.js";

View File

@@ -1,3 +1,4 @@
// Assistant identity helpers normalize assistant identity labels and metadata.
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
/** Normalizes optional assistant identity fields and truncates them to the caller's limit. */

View File

@@ -1,3 +1,4 @@
// Avatar policy tests cover avatar source resolution and fallback behavior.
import path from "node:path";
import { describe, expect, it } from "vitest";
import {

View File

@@ -1,3 +1,4 @@
// Avatar policy helpers resolve avatar paths and provider fallback rules.
import path from "node:path";
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
import { isPathInside } from "../infra/path-guards.js";

View File

@@ -1,3 +1,4 @@
// Chat content tests cover message content normalization for chat surfaces.
import { describe, expect, it } from "vitest";
import { extractTextFromChatContent } from "./chat-content.js";

View File

@@ -1,3 +1,4 @@
// Chat envelope tests cover parsing and formatting channel-prefixed chat text.
import { describe, expect, it } from "vitest";
import { stripEnvelope, stripMessageIdHints } from "./chat-envelope.js";

View File

@@ -1,3 +1,4 @@
// Chat envelope helpers parse and format channel prefixes in chat text.
const ENVELOPE_PREFIX = /^\[([^\]]+)\]\s*/;
const ENVELOPE_CHANNELS = [
"WebChat",

View File

@@ -1,3 +1,4 @@
// Chat message content tests cover visible text extraction from message parts.
import { describe, expect, it } from "vitest";
import {
extractAssistantTextForPhase,

View File

@@ -1,3 +1,4 @@
// Chat message content helpers extract user-visible text from mixed message parts.
import { readStringValue } from "@openclaw/normalization-core/string-coerce";
/** Returns inline string content or the first array text block without scanning later blocks. */

View File

@@ -1,3 +1,4 @@
// Config eval tests cover dynamic config loading and evaluation guards.
import fs from "node:fs";
import path from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";

View File

@@ -1,3 +1,4 @@
// Config evaluation helpers load dynamic config modules with guarded evaluation.
import fs from "node:fs";
import path from "node:path";

View File

@@ -1,3 +1,4 @@
// Custom command config helpers normalize command configuration records.
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
/** Raw custom slash-command entry from config. */

View File

@@ -1,3 +1,4 @@
// Device auth store tests cover persisted paired-device auth state.
import { describe, expect, it, vi } from "vitest";
import {
clearDeviceAuthTokenFromStore,

View File

@@ -1,3 +1,4 @@
// Device auth store helpers persist and normalize paired device auth records.
import { isRecord } from "@openclaw/normalization-core/record-coerce";
import {
type DeviceAuthEntry,

View File

@@ -1,3 +1,4 @@
// Device auth tests cover role and scope normalization for paired devices.
import { describe, expect, it } from "vitest";
import { normalizeDeviceAuthRole, normalizeDeviceAuthScopes } from "./device-auth.js";

View File

@@ -1,3 +1,4 @@
// Device bootstrap profile tests cover profile normalization for paired devices.
import { describe, expect, test } from "vitest";
import {
BOOTSTRAP_HANDOFF_OPERATOR_SCOPES,

View File

@@ -1,3 +1,4 @@
// Device bootstrap profile helpers build profile claims for device onboarding.
import { normalizeDeviceAuthRole, normalizeDeviceAuthScopes } from "./device-auth.js";
/** Normalized roles/scopes carried by a bootstrap token during device handoff. */

View File

@@ -1,3 +1,4 @@
// Device pairing access tests cover role and scope checks for pairing requests.
import { describe, expect, it } from "vitest";
import { resolvePendingDeviceApprovalState } from "./device-pairing-access.js";

View File

@@ -1,3 +1,4 @@
// Device pairing access helpers evaluate pairing scopes and role permissions.
import { normalizeDeviceAuthScopes } from "./device-auth.js";
export type DevicePairingAccessSummary = {

View File

@@ -1,3 +1,4 @@
// Entry metadata tests cover display metadata resolution for agents and jobs.
import { describe, expect, it } from "vitest";
import { resolveEmojiAndHomepage } from "./entry-metadata.js";

View File

@@ -1,3 +1,4 @@
// Entry metadata helpers resolve display names, emojis, and homepage links.
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
/** Resolves entry emoji/homepage with metadata taking precedence over frontmatter aliases. */

View File

@@ -1,3 +1,4 @@
// Entry status tests cover normalized status labels and terminal-state behavior.
import { afterEach, describe, expect, it, vi } from "vitest";
import { mockProcessPlatform } from "../test-utils/vitest-spies.js";
import {

View File

@@ -1,3 +1,4 @@
// Entry status helpers resolve display metadata for run and queue entries.
import { resolveEmojiAndHomepage } from "./entry-metadata.js";
import {
evaluateRequirementsFromMetadataWithRemote,

View File

@@ -1,3 +1,4 @@
// Frontmatter tests cover shared Markdown frontmatter parsing helpers.
import { describe, expect, it, test } from "vitest";
import {
applyOpenClawManifestInstallCommonFields,

View File

@@ -1,3 +1,4 @@
// Shared frontmatter helpers parse Markdown frontmatter blocks and body text.
import {
normalizeOptionalLowercaseString,
readStringValue,

View File

@@ -1,3 +1,4 @@
// Gateway bind URL tests cover host and port normalization for gateway listeners.
import { describe, expect, it, vi } from "vitest";
import { resolveGatewayBindUrl } from "./gateway-bind-url.js";

View File

@@ -1,3 +1,4 @@
// Gateway bind URL helpers compute listener URLs from host and port settings.
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
export type GatewayBindUrlResult =

View File

@@ -1,3 +1,4 @@
// Gateway method policy helpers classify reserved and operator-only gateway methods.
const RESERVED_ADMIN_GATEWAY_METHOD_PREFIXES = [
"exec.approvals.",
"config.",

View File

@@ -1,3 +1,4 @@
// Gateway Tailscale auth policy helpers describe auth requirements for Tailscale modes.
import type { GatewayAuthMode, GatewayTailscaleMode } from "../config/types.gateway.js";
/** True when Tailscale exposure is configured without gateway authentication. */

View File

@@ -1,3 +1,4 @@
// Global singleton tests cover process-wide singleton creation and reset behavior.
import { afterEach, describe, expect, it, vi } from "vitest";
import { resolveGlobalMap, resolveGlobalSingleton } from "./global-singleton.js";

View File

@@ -1,3 +1,4 @@
// Google model helpers normalize Google model identifiers and aliases.
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
/** Return true when a model id/name refers to the Gemma 4 family. */

View File

@@ -1,3 +1,4 @@
// Google turn ordering helpers keep Google model conversations in supported order.
import type { AgentMessage } from "../agents/runtime/index.js";
const GOOGLE_TURN_ORDER_BOOTSTRAP_TEXT = "(session bootstrap)";

View File

@@ -1,3 +1,4 @@
// Import specifier helpers convert paths to stable ESM import specifiers.
import path from "node:path";
import { pathToFileURL } from "node:url";

View File

@@ -1,3 +1,4 @@
// JSON schema default helpers fill object values from TypeBox schema defaults.
import { Compile } from "typebox/compile";
import type { JsonSchemaObject } from "./json-schema.types.js";
import { parseConfigPathArrayIndex } from "./path-array-index.js";

View File

@@ -1,3 +1,4 @@
// JSON schema shared types keep TypeBox schema aliases consistent across callers.
import type { TSchema } from "typebox";
/** TypeBox schema value widened for generic JSON-schema object transforms. */

View File

@@ -1,3 +1,4 @@
// Lazy promise tests cover single-flight loading and error reuse behavior.
import { describe, expect, it, vi } from "vitest";
import { createLazyImportLoader, createLazyPromiseLoader } from "./lazy-promise.js";

View File

@@ -1,3 +1,4 @@
// Lazy runtime helpers expose dynamic imports through cached runtime surfaces.
export function createLazyRuntimeSurface<TModule, TSurface>(
importer: () => Promise<TModule>,
select: (module: TModule) => TSurface,

View File

@@ -1,3 +1,4 @@
// Model parameter B tests cover reasoning budget normalization and aliases.
import { describe, expect, it } from "vitest";
import { inferParamBFromIdOrName } from "./model-param-b.js";

View File

@@ -1,3 +1,4 @@
// Model parameter B helpers normalize provider-specific reasoning budget values.
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
/** Infers the largest `<number>b` parameter-size token from a model id or display name. */

View File

@@ -1,3 +1,4 @@
// Node list parsing tests cover normalized node inventory records.
import { describe, expect, it } from "vitest";
import { parseNodeList, parsePairingList } from "./node-list-parse.js";

View File

@@ -1,3 +1,4 @@
// Node list parsing helpers normalize node inventory records from CLI output.
import { asRecord } from "@openclaw/normalization-core/record-coerce";
import type { NodeListNode, PairedNode, PairingList, PendingRequest } from "./node-list-types.js";

View File

@@ -1,3 +1,4 @@
// Node match tests cover node selection from names, ids, and address hints.
import { describe, expect, it } from "vitest";
import { normalizeNodeKey, resolveNodeIdFromCandidates, resolveNodeMatches } from "./node-match.js";

View File

@@ -1,3 +1,4 @@
// Node match helpers score and select nodes from names, ids, and addresses.
import {
normalizeLowercaseStringOrEmpty,
normalizeOptionalLowercaseString,

View File

@@ -1,3 +1,4 @@
// Node presence helpers normalize live node presence and heartbeat metadata.
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
/** Gateway event name used by node hosts to refresh their last-seen presence. */

View File

@@ -1,3 +1,4 @@
// Node resolve tests cover node identity and address resolution helpers.
import { describe, expect, it } from "vitest";
import { resolveNodeFromNodeList, resolveNodeIdFromNodeList } from "./node-resolve.js";

View File

@@ -1,3 +1,4 @@
// Node resolution helpers resolve node references from names, ids, and URLs.
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
import { type NodeMatchCandidate, resolveNodeIdFromCandidates } from "./node-match.js";

View File

@@ -1,3 +1,4 @@
// Operator scope compatibility tests cover legacy operator scope normalization.
import { describe, expect, it } from "vitest";
import {
resolveMissingRequestedScope,

View File

@@ -1,3 +1,4 @@
// Operator scope compatibility helpers normalize legacy operator role names.
const OPERATOR_ROLE = "operator";
const OPERATOR_ADMIN_SCOPE = "operator.admin";
const OPERATOR_READ_SCOPE = "operator.read";

View File

@@ -1,3 +1,4 @@
// PID liveness tests cover process existence checks across platforms.
import fsSync from "node:fs";
import { afterEach, describe, expect, it, vi } from "vitest";
import { withMockedPlatform } from "../test-utils/vitest-spies.js";

View File

@@ -1,3 +1,4 @@
// PID liveness helpers check whether process ids still refer to active processes.
import fsSync from "node:fs";
function isValidPid(pid: number): boolean {

View File

@@ -1,3 +1,4 @@
// Requirement tests cover merging and formatting runtime requirements.
import { describe, expect, it } from "vitest";
import {
buildConfigChecks,

View File

@@ -1,3 +1,4 @@
// Requirement types describe runtime requirements advertised by shared surfaces.
export type Requirements = {
bins: string[];
anyBins: string[];

View File

@@ -1,3 +1,4 @@
// Runtime import tests cover lazy runtime import caching and failure handling.
import { afterEach, describe, expect, it, vi } from "vitest";
import {
importRuntimeModule,

View File

@@ -1,3 +1,4 @@
// Scoped expiring id cache tests cover TTL and scope isolation behavior.
import { describe, expect, it } from "vitest";
import { createScopedExpiringIdCache } from "./scoped-expiring-id-cache.js";

View File

@@ -1,3 +1,4 @@
// Silent reply policy tests cover reply suppression decision rules.
import { describe, expect, it } from "vitest";
import {
DEFAULT_SILENT_REPLY_POLICY,

View File

@@ -1,3 +1,4 @@
// Silent reply policy helpers decide when automated replies should be suppressed.
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
export type SilentReplyPolicy = "allow" | "disallow";

View File

@@ -1,3 +1,4 @@
// String sample tests cover compact string sampling and truncation behavior.
import { describe, expect, it } from "vitest";
import { summarizeStringEntries } from "./string-sample.js";

View File

@@ -1,3 +1,4 @@
// Subagent format tests cover concise subagent status and duration formatting.
import { describe, expect, it } from "vitest";
import {
formatDurationCompact,

View File

@@ -1,3 +1,4 @@
// Subagent formatting helpers expose compact durations and status text.
export { formatDurationCompact } from "../infra/format-time/format-duration.ts";
/** Formats token counts using compact k/m suffixes for subagent summaries. */

View File

@@ -1,3 +1,4 @@
// Tailscale status tests cover status parsing and validation.
import { describe, expect, it, vi } from "vitest";
import { resolveTailnetHostWithRunner } from "./tailscale-status.js";

View File

@@ -1,3 +1,4 @@
// Tailscale status helpers parse and validate status payloads from Tailscale.
import { z } from "zod";
import { safeParseJsonWithSchema } from "../utils/zod-parse.js";

View File

@@ -1,3 +1,4 @@
// Text chunking tests cover splitting text into bounded model-safe chunks.
import { describe, expect, it } from "vitest";
import { chunkTextByBreakResolver } from "./text-chunking.js";

View File

@@ -1,3 +1,4 @@
// Assistant visible text tests cover extracting user-visible assistant output.
import { describe, expect, it } from "vitest";
import {
sanitizeAssistantVisibleText,

View File

@@ -1,3 +1,4 @@
// Assistant visible text helpers strip hidden reasoning and control marker text.
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
import { findCodeRegions, isInsideCode } from "./code-regions.js";
import { stripModelSpecialTokens } from "./model-special-tokens.js";

View File

@@ -1,3 +1,4 @@
// Auto-linked file ref helpers detect file references that can be linked in UI text.
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
const FILE_REF_EXTENSIONS = ["md", "go", "py", "pl", "sh", "am", "at", "be", "cc"] as const;

View File

@@ -1,3 +1,4 @@
// Citation control marker tests cover stripping unsupported citation markers.
import { describe, expect, it } from "vitest";
import { stripUnsupportedCitationControlMarkers } from "./citation-control-markers.js";

View File

@@ -1,3 +1,4 @@
// Citation control marker helpers remove unsupported citation control tokens.
const UNSUPPORTED_CITATION_CONTROL_MARKER_RE = /cite(?:[^]*)?/g;
const TRAILING_UNSUPPORTED_CITATION_CONTROL_MARKER_RE = /[ \t]*cite(?:[^]*)?(?=\r?\n|$)/g;

View File

@@ -1,3 +1,4 @@
// Code region tests cover Markdown code span and fence detection.
import { describe, expect, it } from "vitest";
import { findCodeRegions, isInsideCode } from "./code-regions.js";

View File

@@ -1,3 +1,4 @@
// Code region helpers find fenced and inline code spans in Markdown text.
export interface CodeRegion {
start: number;
end: number;

View File

@@ -1,3 +1,4 @@
// Final tag helpers detect final-answer tag regions in assistant text.
export type FinalTagMatch = {
index: number;
text: string;

View File

@@ -1,3 +1,4 @@
// Formatted reasoning message helpers remove reasoning tags before display.
import { stripReasoningTagsFromText } from "./reasoning-tags.js";
/** Strip provider-formatted Reasoning/Thinking preambles from visible text. */

View File

@@ -1,3 +1,4 @@
// Join segment tests cover stable text segment recombination.
import { describe, expect, it } from "vitest";
import { concatOptionalTextSegments, joinPresentTextSegments } from "./join-segments.js";

View File

@@ -1,3 +1,4 @@
// Model special token helpers strip model control tokens outside code regions.
import { findCodeRegions, isInsideCode } from "./code-regions.js";
// Match both ASCII pipe <|...|> and full-width pipe <...> (U+FF5C) variants.

View File

@@ -1,3 +1,4 @@
// Reasoning tag partitioner tests cover splitting reasoning and visible text segments.
import { describe, expect, it } from "vitest";
import { createReasoningTagTextPartitioner } from "./reasoning-tag-text-partitioner.js";

View File

@@ -1,3 +1,4 @@
// Reasoning tag partitioner helpers split text around reasoning tag regions.
import {
buildCodeSpanIndex,
createInlineCodeState,

View File

@@ -1,3 +1,4 @@
// Reasoning tag tests cover parsing and stripping reasoning tag blocks.
import { describe, expect, it } from "vitest";
import { stripReasoningTagsFromText } from "./reasoning-tags.js";

View File

@@ -1,3 +1,4 @@
// Reasoning tag helpers find and remove model reasoning tag blocks from text.
import { findCodeRegions, isInsideCode } from "./code-regions.js";
import { findFinalTagMatches } from "./final-tags.js";
export type ReasoningTagMode = "strict" | "preserve";

View File

@@ -1,3 +1,4 @@
// Tool-call shaped text tests cover detection of text that resembles tool calls.
import { describe, expect, it } from "vitest";
import { detectToolCallShapedText } from "./tool-call-shaped-text.js";

View File

@@ -1,3 +1,4 @@
// Tool-call shaped text helpers detect malformed text that resembles tool calls.
import { asOptionalRecord } from "@openclaw/normalization-core/record-coerce";
import { normalizeOptionalString as readTrimmedString } from "@openclaw/normalization-core/string-coerce";

View File

@@ -1,3 +1,4 @@
// Thread binding lifecycle tests cover binding states across channel threads.
import { describe, expect, it } from "vitest";
import { resolveThreadBindingLifecycle } from "./thread-binding-lifecycle.js";

View File

@@ -1,3 +1,4 @@
// Usage aggregate tests cover token, cost, and latency accumulation.
import { describe, expect, it } from "vitest";
import {
buildUsageAggregateTail,

View File

@@ -1,3 +1,4 @@
// Usage aggregate helpers accumulate token, cost, and latency usage totals.
type LatencyTotalsLike = {
count: number;
sum: number;

View File

@@ -1,3 +1,4 @@
// Usage types define shared usage accounting structures for sessions and runs.
import type { SessionSystemPromptReport } from "../config/sessions/types.js";
import type {
CostUsageSummary,