Files
openclaw/src/auto-reply/reply/reply-inline.ts
Peter Steinberger 00d8d7ead0 refactor: extract normalization core package
Extract shared normalization/coercion helpers into private @openclaw/normalization-core workspace package while preserving existing plugin SDK helper subpaths.\n\nAlso keeps direct normalization-core imports internal, wires UI/build/loader resolution, and replaces the slow PR network CodeQL lane with a fast added-line boundary scan while retaining full CodeQL for scheduled/manual runs.\n\nVerification: local moved tests, plugin SDK boundary tests, extension loader tests, agents-support shard, UI build/test, build artifacts, lint, workflow guards, autoreview, and GitHub CI passed on PR head 963d893715.
2026-05-31 01:33:00 +01:00

47 lines
1.5 KiB
TypeScript

import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
import { collapseInlineHorizontalWhitespace } from "./reply-inline-whitespace.js";
const INLINE_SIMPLE_COMMAND_ALIASES = new Map<string, string>([
["/help", "/help"],
["/commands", "/commands"],
["/whoami", "/whoami"],
["/id", "/whoami"],
]);
const INLINE_SIMPLE_COMMAND_RE = /(?:^|\s)\/(help|commands|whoami|id)(?=$|\s|:)/i;
const INLINE_STATUS_RE = /(?:^|\s)\/status(?=$|\s|:)(?:\s*:\s*)?/gi;
export function extractInlineSimpleCommand(body?: string): {
command: string;
cleaned: string;
} | null {
if (!body) {
return null;
}
const match = body.match(INLINE_SIMPLE_COMMAND_RE);
if (!match || match.index === undefined) {
return null;
}
const alias = `/${normalizeLowercaseStringOrEmpty(match[1])}`;
const command = INLINE_SIMPLE_COMMAND_ALIASES.get(alias);
if (!command) {
return null;
}
const cleaned = collapseInlineHorizontalWhitespace(body.replace(match[0], " ")).trim();
return { command, cleaned };
}
export function stripInlineStatus(body: string): {
cleaned: string;
didStrip: boolean;
} {
const trimmed = body.trim();
if (!trimmed) {
return { cleaned: "", didStrip: false };
}
// Use [^\S\n]+ instead of \s+ to only collapse horizontal whitespace,
// preserving newlines so multi-line messages keep their paragraph structure.
const cleaned = collapseInlineHorizontalWhitespace(trimmed.replace(INLINE_STATUS_RE, " ")).trim();
return { cleaned, didStrip: cleaned !== trimmed };
}