File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 } ) ;
Original file line number Diff line number Diff 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 ( ) ;
You can’t perform that action at this time.
0 commit comments