refactor: extract shared sandbox and gateway plumbing

This commit is contained in:
Peter Steinberger
2026-03-02 23:16:02 +00:00
parent 350d041eaf
commit 7066d5e192
21 changed files with 870 additions and 675 deletions

View File

@@ -0,0 +1,9 @@
import { describe, expect, it } from "vitest";
import { collapseInlineHorizontalWhitespace } from "./reply-inline-whitespace.js";
describe("collapseInlineHorizontalWhitespace", () => {
it("collapses spaces and tabs but preserves newlines", () => {
const value = "hello\t\tworld\n next\tline";
expect(collapseInlineHorizontalWhitespace(value)).toBe("hello world\n next line");
});
});

View File

@@ -0,0 +1,5 @@
const INLINE_HORIZONTAL_WHITESPACE_RE = /[^\S\n]+/g;
export function collapseInlineHorizontalWhitespace(value: string): string {
return value.replace(INLINE_HORIZONTAL_WHITESPACE_RE, " ");
}

View File

@@ -1,3 +1,5 @@
import { collapseInlineHorizontalWhitespace } from "./reply-inline-whitespace.js";
const INLINE_SIMPLE_COMMAND_ALIASES = new Map<string, string>([
["/help", "/help"],
["/commands", "/commands"],
@@ -24,10 +26,7 @@ export function extractInlineSimpleCommand(body?: string): {
if (!command) {
return null;
}
const cleaned = body
.replace(match[0], " ")
.replace(/[^\S\n]+/g, " ")
.trim();
const cleaned = collapseInlineHorizontalWhitespace(body.replace(match[0], " ")).trim();
return { command, cleaned };
}
@@ -41,9 +40,6 @@ export function stripInlineStatus(body: string): {
}
// Use [^\S\n]+ instead of \s+ to only collapse horizontal whitespace,
// preserving newlines so multi-line messages keep their paragraph structure.
const cleaned = trimmed
.replace(INLINE_STATUS_RE, " ")
.replace(/[^\S\n]+/g, " ")
.trim();
const cleaned = collapseInlineHorizontalWhitespace(trimmed.replace(INLINE_STATUS_RE, " ")).trim();
return { cleaned, didStrip: cleaned !== trimmed };
}