mirror of
https://github.com/thedotmack/claude-mem
synced 2026-04-25 17:15:04 +02:00
fix: walk back to UTF-8 boundary on prompt truncation (Greptile P2)
Plain Buffer.subarray at MAX_USER_PROMPT_BYTES can land mid-codepoint, which the utf8 decoder silently rewrites to U+FFFD. Walk back over any continuation bytes (0b10xxxxxx) before decoding so the truncated prompt ends on a valid sequence boundary instead of a replacement character.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -944,7 +944,10 @@ export class SessionRoutes extends BaseRouteHandler {
|
||||
maxBytes: MAX_USER_PROMPT_BYTES,
|
||||
preview: prompt.slice(0, 200)
|
||||
});
|
||||
prompt = Buffer.from(prompt).subarray(0, MAX_USER_PROMPT_BYTES).toString('utf8');
|
||||
const buf = Buffer.from(prompt, 'utf8');
|
||||
let end = MAX_USER_PROMPT_BYTES;
|
||||
while (end > 0 && (buf[end] & 0xc0) === 0x80) end--;
|
||||
prompt = buf.subarray(0, end).toString('utf8');
|
||||
}
|
||||
|
||||
logger.info('HTTP', 'SessionRoutes: handleSessionInitByClaudeId called', {
|
||||
|
||||
Reference in New Issue
Block a user