Bug Description
The stripTagPrefix function in packages/plugin/src/hooks/magic-context/tag-content-primitives.ts only strips a single tag prefix, but the transform pipeline can process the same content multiple times (e.g., during compartment compaction, message replay, or transform re-runs). This causes tags to accumulate, leading to unreadable messages with excessive §N§ symbols like:
§4687§ §4687§ §4687§ §4687§ ... §4687§ actual content
Root Cause
const TAG_PREFIX_REGEX = /^§\d+§\s*/; // No global flag, only matches ONE tag
export function stripTagPrefix(value: string): string {
return value.replace(TAG_PREFIX_REGEX, ""); // Only strips first tag!
}
export function prependTag(tagId: number, value: string): string {
const stripped = stripTagPrefix(value); // Still has old tags
return `§${tagId}§ ${stripped}`; // Prepends new tag to remaining tags
}
Each transform pass:
- Calls
prependTag() which strips only the outermost tag
- Leaves previously accumulated tags intact
- Prepends a new tag on top
- Result: tag stack grows unbounded
Proposed Fix
Change the regex to match all consecutive tags at the start:
const TAG_PREFIX_REGEX = /^(?:§\d+§\s*)+/; // Match one or more tags
export function stripTagPrefix(value: string): string {
return value.replace(TAG_PREFIX_REGEX, "");
}
This ensures stripTagPrefix removes all accumulated tags, so prependTag always results in exactly one tag as intended.
Impact
- Messages become increasingly difficult to read as tags accumulate
- Affects long-running sessions or those with frequent compartment operations
- No data loss, but severe UX degradation
Bug Description
The
stripTagPrefixfunction inpackages/plugin/src/hooks/magic-context/tag-content-primitives.tsonly strips a single tag prefix, but the transform pipeline can process the same content multiple times (e.g., during compartment compaction, message replay, or transform re-runs). This causes tags to accumulate, leading to unreadable messages with excessive §N§ symbols like:Root Cause
Each transform pass:
prependTag()which strips only the outermost tagProposed Fix
Change the regex to match all consecutive tags at the start:
This ensures
stripTagPrefixremoves all accumulated tags, soprependTagalways results in exactly one tag as intended.Impact