Files
memind/wechat/intent/channel-prefix.mjs
T
john 8f88eec2bd
Memind CI / Test, build, and release guards (push) Successful in 4m40s
Separate WeChat chat, page refine, and task flows with explicit routing.
Add channel prefixes, pin edit targets in Cursor prompts, and force fresh sessions for page refine URLs so DeepSeek/Goose chat history does not pollute page tasks.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-31 14:10:02 +08:00

50 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** Explicit WeChat channel prefixes so users can separate chat, page, and scheduled tasks. */
export const WECHAT_CHANNEL_PREFIX = Object.freeze({
CHAT: 'chat',
PAGE: 'page',
SCHEDULED_TASK: 'scheduled_task',
});
const PREFIX_ENTRIES = Object.freeze([
{
channel: WECHAT_CHANNEL_PREFIX.CHAT,
pattern: /^【?\s*聊天\s*】?[:\s]*/iu,
},
{
channel: WECHAT_CHANNEL_PREFIX.PAGE,
pattern: /^【?\s*(?:改页|做页|页面)\s*】?[:\s]*/iu,
},
{
channel: WECHAT_CHANNEL_PREFIX.SCHEDULED_TASK,
pattern: /^【?\s*定时任务\s*】?[:\s]*/iu,
},
]);
/**
* @returns {{ channel: string|null, body: string, hadPrefix: boolean }}
*/
export function parseWechatChannelPrefix(text) {
const normalized = String(text ?? '').trim();
if (!normalized) {
return { channel: null, body: '', hadPrefix: false };
}
for (const entry of PREFIX_ENTRIES) {
if (!entry.pattern.test(normalized)) continue;
return {
channel: entry.channel,
body: normalized.replace(entry.pattern, '').trim(),
hadPrefix: true,
};
}
return { channel: null, body: normalized, hadPrefix: false };
}
export function stripWechatChannelPrefix(text) {
return parseWechatChannelPrefix(text).body;
}
export function hasWechatPageChannelPrefix(text) {
return parseWechatChannelPrefix(text).channel === WECHAT_CHANNEL_PREFIX.PAGE;
}