Files
memind/wechat/page-refine-target.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

70 lines
2.6 KiB
JavaScript

import {
PAGE_MINDSPACE_PUBLIC_URL_PATTERN,
PAGE_REFINE_DETAIL_PATTERN,
} from './intent/patterns.mjs';
/** MindSpace public HTML path inside a full URL (userId or username slug). */
export const MINDSPACE_PUBLIC_HTML_PATH_PATTERN =
/(?:https?:\/\/[^\s/]+)?\/?mindspace\/[^/\s"'<>]+?\/(public\/[\w.-]+\.html)/iu;
export function extractMindSpacePublicHtmlPath(text) {
const normalized = String(text ?? '').trim();
if (!normalized) return null;
const match = normalized.match(MINDSPACE_PUBLIC_HTML_PATH_PATTERN);
const relativePath = match?.[1]?.replace(/\\/g, '/').trim();
return relativePath || null;
}
export function isWechatPageRefineRequestText(text) {
const normalized = String(text ?? '').trim();
if (!normalized) return false;
if (PAGE_REFINE_DETAIL_PATTERN.test(normalized)) return true;
return (
PAGE_MINDSPACE_PUBLIC_URL_PATTERN.test(normalized)
&& /(?:页面|网页|更新|详细|改|完善|补充)/iu.test(normalized)
);
}
/**
* Extra Cursor/Goose page prompt block: pin edit target file when URL or refine intent is present.
*/
export function buildPageRefineTargetPromptBlock(text) {
const normalized = String(text ?? '').trim();
if (!normalized || !isWechatPageRefineRequestText(normalized)) return '';
const relativePath = extractMindSpacePublicHtmlPath(normalized);
if (relativePath) {
return [
'【改页目标文件(从用户消息解析,必须优先改此文件)】',
`- 相对路径:${relativePath}`,
'- 用 edit_file 更新该 HTML;禁止新建无关页面或只回复文字说明。',
'- 按用户要求补充/修改内容,保留其余仍有效的结构与样式。',
'',
].join('\n');
}
return [
'【改页任务】用户要求细化或更新已有页面。',
'- 在工作区查找最相关的 public/*.html,用 edit_file 更新原文件,不要新建无关页面。',
'- 禁止只回复文字说明而不落盘。',
'',
].join('\n');
}
/** Copy-paste WeChat message template for page refine (e.g. Tang). */
export function buildWechatPageRefineUserMessageTemplate({
publicHtmlPath = 'public/your-page.html',
requirements = '请把页面改更详细(示例:行程细化到每个时间节点)',
publicUrl = '',
} = {}) {
const pathLine = String(publicHtmlPath ?? '').trim();
const reqLine = String(requirements ?? '').trim();
const urlLine = String(publicUrl ?? '').trim();
return [
'改页任务(请直接改原文件,不要新建页面)',
pathLine ? `文件:${pathLine}` : '',
reqLine ? `要求:${reqLine}` : '',
urlLine ? `链接:${urlLine}` : '',
].filter(Boolean).join('\n');
}