8f88eec2bd
Memind CI / Test, build, and release guards (push) Successful in 4m40s
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>
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
/** 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;
|
||
}
|