Skip to content

Commit 07a425a

Browse files
committed
fix: preserve colon slash commands
1 parent db5bb1c commit 07a425a

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/auto-reply/reply/mentions.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ describe("stripStructuralPrefixes", () => {
1616

1717
it("preserves colon-delimited slash commands", () => {
1818
expect(stripStructuralPrefixes("/config:json")).toBe("/config:json");
19+
expect(stripStructuralPrefixes("/reset: soft")).toBe("/reset: soft");
20+
expect(stripStructuralPrefixes("/compact: focus on decisions")).toBe(
21+
"/compact: focus on decisions",
22+
);
1923
});
2024

2125
it("strips direct envelope display labels with handles", () => {
@@ -29,6 +33,10 @@ describe("stripStructuralPrefixes", () => {
2933
expect(stripStructuralPrefixes("[Telegram 山田] 山田: /status")).toBe("/status");
3034
});
3135

36+
it("strips slash-like display labels only after an envelope", () => {
37+
expect(stripStructuralPrefixes("[Telegram /reset id:123] /reset: hello")).toBe("hello");
38+
});
39+
3240
it("passes through plain text", () => {
3341
expect(stripStructuralPrefixes("just a message")).toBe("just a message");
3442
});

src/auto-reply/reply/mentions.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,14 @@ export function stripStructuralPrefixes(text: string): string {
184184
const afterMarker = text.includes(CURRENT_MESSAGE_MARKER)
185185
? text.slice(text.indexOf(CURRENT_MESSAGE_MARKER) + CURRENT_MESSAGE_MARKER.length).trimStart()
186186
: text;
187-
188-
return afterMarker
189-
.replace(/\[[^\]]+\]\s*/g, "")
190-
.replace(/^[ \t]*[^\n:]{1,120}:\s+/gm, "")
187+
const afterEnvelope = afterMarker.replace(/\[[^\]]+\]\s*/g, "");
188+
const senderPrefixPattern =
189+
afterEnvelope === afterMarker
190+
? /^[ \t]*(?!\/)[^\n:]{1,120}:\s+/gm
191+
: /^[ \t]*[^\n:]{1,120}:\s+/gm;
192+
193+
return afterEnvelope
194+
.replace(senderPrefixPattern, "")
191195
.replace(/\\n/g, " ")
192196
.replace(/\s+/g, " ")
193197
.trim();

0 commit comments

Comments
 (0)