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:
john
2026-07-04 14:15:42 +08:00
parent cd81c4b2bb
commit b5a88d9746
8 changed files with 79 additions and 14 deletions
+9 -3
View File
@@ -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',
};
}
+8 -2
View File
@@ -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 与摘要),所以我先不发链接。',
+6
View File
@@ -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 };
}
+27 -8
View File
@@ -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');