fix(brand): require TKMind platform marker on wechat page delivery
Backfill missing platform-brand footer at serve time and block service- account links when the HTML file omits data-mindspace-page-tag. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -31,6 +31,24 @@ export function ensurePlatformBrandPageTags(html) {
|
||||
});
|
||||
}
|
||||
|
||||
export function hasPlatformBrandMarker(html) {
|
||||
return new RegExp(
|
||||
`${MINDSPACE_PAGE_TAG_ATTR}\\s*=\\s*["']${MINDSPACE_PAGE_TAG_PLATFORM_BRAND}["']`,
|
||||
'i',
|
||||
).test(String(html ?? ''));
|
||||
}
|
||||
|
||||
/** Append the platform brand footer when authors omitted data-mindspace-page-tag. */
|
||||
export function ensurePlatformBrandFooter(html) {
|
||||
const normalized = ensurePlatformBrandPageTags(html);
|
||||
if (hasPlatformBrandMarker(normalized)) return normalized;
|
||||
const footer = `<p ${MINDSPACE_PAGE_TAG_ATTR}="${MINDSPACE_PAGE_TAG_PLATFORM_BRAND}">${PLATFORM_BRAND_TEXT}</p>`;
|
||||
if (/<\/body>/i.test(normalized)) {
|
||||
return normalized.replace(/<\/body>/i, `${footer}\n</body>`);
|
||||
}
|
||||
return `${normalized}\n${footer}`;
|
||||
}
|
||||
|
||||
export function prepareHtmlPageBrandMarkers(html) {
|
||||
return ensurePlatformBrandPageTags(html);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import test from 'node:test';
|
||||
import {
|
||||
MINDSPACE_PAGE_TAG_ATTR,
|
||||
MINDSPACE_PAGE_TAG_PLATFORM_BRAND,
|
||||
ensurePlatformBrandFooter,
|
||||
ensurePlatformBrandPageTags,
|
||||
normalizePlatformBrandHtml,
|
||||
prepareHtmlPageBrandMarkers,
|
||||
@@ -28,3 +29,10 @@ test('prepareHtmlPageBrandMarkers keeps existing marker', () => {
|
||||
const result = prepareHtmlPageBrandMarkers(html);
|
||||
assert.equal(result.match(new RegExp(MINDSPACE_PAGE_TAG_ATTR, 'g'))?.length, 1);
|
||||
});
|
||||
|
||||
test('ensurePlatformBrandFooter appends brand line when marker is missing', () => {
|
||||
const html = '<html><body><main>content</main></body></html>';
|
||||
const result = ensurePlatformBrandFooter(html);
|
||||
assert.match(result, /data-mindspace-page-tag="platform-brand"/);
|
||||
assert.match(result, /TKMind · 智趣/);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import crypto from 'node:crypto';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { ensurePlatformBrandFooter } from './mindspace-page-tag.mjs';
|
||||
|
||||
const INLINE_SCRIPT_PATTERN = /<script\b(?![^>]*\bsrc\b)[^>]*>([\s\S]*?)<\/script>/gi;
|
||||
|
||||
@@ -67,6 +68,7 @@ export function decorateMindSpacePublishedHtml({
|
||||
}
|
||||
|
||||
try {
|
||||
nextHtml = ensurePlatformBrandFooter(nextHtml);
|
||||
nextHtml = injectOgTags(nextHtml, {
|
||||
origin: context.origin,
|
||||
pageUrl: context.pageUrl,
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ function inboundXml({
|
||||
}
|
||||
|
||||
function previewReadyPageHtml({ title = 'Page', subtitle = '测试页面' } = {}) {
|
||||
return `<!doctype html><html><head><meta name="description" content="${subtitle}"><meta name="mindspace-cover" content='{"tag":"页面","accent":"#3366cc","accent2":"#112233","subtitle":"${subtitle}"}'><title>${title}</title></head><body><main>${'x'.repeat(600)}</main></body></html>`;
|
||||
return `<!doctype html><html><head><meta name="description" content="${subtitle}"><meta name="mindspace-cover" content='{"tag":"页面","accent":"#3366cc","accent2":"#112233","subtitle":"${subtitle}"}'><title>${title}</title></head><body><main>${'x'.repeat(600)}</main><p data-mindspace-page-tag="platform-brand">TKMind · 智趣</p></body></html>`;
|
||||
}
|
||||
|
||||
function jsonEscapedPreviewReadyPageHtml(options = {}) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { buildPagePublishFailureText } from '../prompts/page-generate.mjs';
|
||||
import { selectSendableHtmlArtifacts, verifyPageArtifactContent } from '../verify/page-artifact.mjs';
|
||||
import { filterSharePreviewReadyArtifacts } from '../verify/share-preview.mjs';
|
||||
import { filterSharePreviewReadyArtifacts, verifyArtifactSharePreview } from '../verify/share-preview.mjs';
|
||||
|
||||
export function evaluatePageGenerateSendableArtifacts({ verifiedArtifacts = [], confirmedArtifacts = [] } = {}) {
|
||||
const sendable = selectSendableHtmlArtifacts({ verifiedArtifacts, confirmedArtifacts });
|
||||
@@ -48,10 +48,16 @@ export function resolvePageGenerateOutcome({
|
||||
selectSendableHtmlArtifacts({ verifiedArtifacts, confirmedArtifacts }),
|
||||
);
|
||||
if (previewCandidates.length === 0 && confirmedArtifacts.length > 0) {
|
||||
const previewIssue = verifyArtifactSharePreview(
|
||||
selectSendableHtmlArtifacts({ verifiedArtifacts, confirmedArtifacts })[0] ?? confirmedArtifacts[0],
|
||||
);
|
||||
return {
|
||||
action: 'fail',
|
||||
failureText: buildPagePublishFailureText({ missingSharePreview: true }),
|
||||
reason: 'missing_share_preview',
|
||||
failureText: buildPagePublishFailureText({
|
||||
missingPlatformBrand: previewIssue.reason === 'missing_platform_brand',
|
||||
missingSharePreview: previewIssue.reason !== 'missing_platform_brand',
|
||||
}),
|
||||
reason: previewIssue.reason ?? 'missing_share_preview',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ export function buildPageGenerateAgentPrompt(intent, { wantsDocx = false } = {})
|
||||
' - `<meta name="description" content="一句话摘要">`',
|
||||
' - `<meta name="mindspace-cover" content=\'{"tag":"主题","accent":"#主色","accent2":"#辅色","subtitle":"卖点","cover":"assets/hero.jpg"}\'>`',
|
||||
' tag/accent/subtitle 必须与页面主题一致;有 hero 图时 cover 指向同目录 raster 图(jpg/png)。',
|
||||
'6. 页脚加 `<footer data-mindspace-page-tag="platform-brand">` 以显示 TKMind 智趣 品牌。',
|
||||
'6. 页脚加 `<p data-mindspace-page-tag="platform-brand">TKMind · 智趣</p>`(必须,禁止省略或用邮箱/tkmind.ai 代替)。',
|
||||
'7. 回复里只给一个正式域名链接;没有落盘或缺少上述元数据就不要发链接。',
|
||||
'',
|
||||
buildCurrentTimeAgentPrefix({ timezone: scheduleTimezone }),
|
||||
@@ -38,7 +38,13 @@ export function buildPageGenerateAgentPrompt(intent, { wantsDocx = false } = {})
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
export function buildPagePublishFailureText({ missingSharePreview = false } = {}) {
|
||||
export function buildPagePublishFailureText({ missingSharePreview = false, missingPlatformBrand = false } = {}) {
|
||||
if (missingPlatformBrand) {
|
||||
return [
|
||||
'这次页面已落盘,但缺少页脚平台品牌标记(data-mindspace-page-tag="platform-brand"),所以我先不发链接。',
|
||||
'请直接重发一次完整页面需求,我会重新按 static-page-publish 技能生成带 TKMind · 智趣 品牌页脚的页面。',
|
||||
].join('\n');
|
||||
}
|
||||
if (missingSharePreview) {
|
||||
return [
|
||||
'这次页面已落盘,但缺少微信分享卡片所需的预览元数据(mindspace-cover 与摘要),所以我先不发链接。',
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import fs from 'node:fs';
|
||||
import { artifactFileExists } from './page-artifact.mjs';
|
||||
import { hasPlatformBrandMarker } from '../../mindspace-page-tag.mjs';
|
||||
|
||||
export { hasPlatformBrandMarker };
|
||||
|
||||
const RASTER_IMAGE_PATTERN = /\.(png|jpe?g|webp|gif)(?:[?#]|$)/i;
|
||||
|
||||
@@ -48,6 +51,9 @@ export function verifySharePreviewMeta(html) {
|
||||
if (!hasShareDescription(html)) {
|
||||
return { ok: false, reason: 'missing_description' };
|
||||
}
|
||||
if (!hasPlatformBrandMarker(html)) {
|
||||
return { ok: false, reason: 'missing_platform_brand' };
|
||||
}
|
||||
return { ok: true, reason: null };
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import { buildGreetingText, resolveSyncReply } from './handlers/sync-replies.mjs
|
||||
import { buildWechatAgentPrompt } from './prompts/chat-general.mjs';
|
||||
import {
|
||||
hasMindspaceCoverMeta,
|
||||
hasPlatformBrandMarker,
|
||||
hasShareDescription,
|
||||
verifyArtifactSharePreview,
|
||||
verifySharePreviewMeta,
|
||||
@@ -120,26 +121,31 @@ test('verifyPageArtifactContent rejects small stub files', () => {
|
||||
assert.equal(filterSendableHtmlArtifacts([artifact]).length, 0);
|
||||
});
|
||||
|
||||
function writePreviewReadyHtml(file, { withCover = true } = {}) {
|
||||
function writePreviewReadyHtml(file, { withCover = true, withBrand = true } = {}) {
|
||||
const coverMeta = withCover
|
||||
? '<meta name="mindspace-cover" content=\'{"tag":"旅行","accent":"#ff6b35","accent2":"#24243e","subtitle":"测试页面"}\'>'
|
||||
: '';
|
||||
const brandMeta = withBrand
|
||||
? '<p data-mindspace-page-tag="platform-brand">TKMind · 智趣</p>'
|
||||
: '';
|
||||
fs.writeFileSync(
|
||||
file,
|
||||
`<!doctype html><html><head>
|
||||
<meta name="description" content="一句话摘要">
|
||||
${coverMeta}
|
||||
</head><body><main>${'x'.repeat(600)}</main></body></html>`,
|
||||
</head><body><main>${'x'.repeat(600)}</main>${brandMeta}</body></html>`,
|
||||
'utf8',
|
||||
);
|
||||
}
|
||||
|
||||
test('verifySharePreviewMeta requires mindspace-cover and description', () => {
|
||||
const withBoth = '<meta name="description" content="摘要"><meta name="mindspace-cover" content=\'{"tag":"旅行"}\'>';
|
||||
assert.equal(verifySharePreviewMeta(withBoth).ok, true);
|
||||
test('verifySharePreviewMeta requires mindspace-cover, description, and platform brand', () => {
|
||||
const withAll =
|
||||
'<meta name="description" content="摘要"><meta name="mindspace-cover" content=\'{"tag":"旅行"}\'><p data-mindspace-page-tag="platform-brand">TKMind · 智趣</p>';
|
||||
assert.equal(verifySharePreviewMeta(withAll).ok, true);
|
||||
assert.equal(verifySharePreviewMeta('<meta name="description" content="摘要">').ok, false);
|
||||
assert.equal(hasMindspaceCoverMeta(withBoth), true);
|
||||
assert.equal(hasShareDescription(withBoth), true);
|
||||
assert.equal(hasMindspaceCoverMeta(withAll), true);
|
||||
assert.equal(hasShareDescription(withAll), true);
|
||||
assert.equal(hasPlatformBrandMarker(withAll), true);
|
||||
});
|
||||
|
||||
test('resolvePageGenerateOutcome fails when html lacks share preview meta', () => {
|
||||
@@ -151,10 +157,23 @@ test('resolvePageGenerateOutcome fails when html lacks share preview meta', () =
|
||||
confirmedArtifacts: [{ localPath: file, relativePath: 'public/page.html' }],
|
||||
});
|
||||
assert.equal(outcome.action, 'fail');
|
||||
assert.equal(outcome.reason, 'missing_share_preview');
|
||||
assert.equal(outcome.reason, 'missing_mindspace_cover');
|
||||
assert.match(outcome.failureText, /预览元数据/);
|
||||
});
|
||||
|
||||
test('resolvePageGenerateOutcome fails when html lacks platform brand marker', () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'wechat-brand-'));
|
||||
const file = path.join(dir, 'page.html');
|
||||
writePreviewReadyHtml(file, { withBrand: false });
|
||||
const outcome = resolvePageGenerateOutcome({
|
||||
reply: { text: '页面已生成' },
|
||||
confirmedArtifacts: [{ localPath: file, relativePath: 'public/page.html' }],
|
||||
});
|
||||
assert.equal(outcome.action, 'fail');
|
||||
assert.equal(outcome.reason, 'missing_platform_brand');
|
||||
assert.match(outcome.failureText, /平台品牌/);
|
||||
});
|
||||
|
||||
test('resolvePageGenerateOutcome sends when share preview meta is present', () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'wechat-preview-ok-'));
|
||||
const file = path.join(dir, 'page.html');
|
||||
|
||||
Reference in New Issue
Block a user