@open-dy/interest-card-cli 0.1.0-beta.31 → 0.1.0-beta.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser-runtime/scripts/capture-feed-card.sh +23 -18
- package/browser-runtime/scripts/preview-session.mjs +9 -0
- package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-aiuser-profile.md +6 -4
- package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-aiuser-profile.md +6 -4
- package/card-skills/douyin-interest-card-capability/scripts/search-capabilities.mjs +7 -4
- package/card-skills/douyin-interest-card-cli/SKILL.md +10 -4
- package/card-skills/douyin-interest-card-generate/references/common/post-card-differences.md +29 -3
- package/card-skills/douyin-interest-card-generate/references/common/upgrade-to-post.md +28 -5
- package/card-skills/douyin-interest-card-generate/scripts/inspect-post-upgrade.mjs +630 -0
- package/dist/src/upgrade.js +37 -5
- package/package.json +1 -1
|
@@ -134,23 +134,6 @@ if [[ -z "$PROJECT_ROOT" ]]; then
|
|
|
134
134
|
PROJECT_ROOT="$(cd "$(dirname "$FEED_FILE")/.." && pwd)"
|
|
135
135
|
fi
|
|
136
136
|
|
|
137
|
-
if [[ ! "$CONVERSATION_ID" =~ ^conv_[A-Za-z0-9-]+(_ext)?$ ]]; then
|
|
138
|
-
printf 'CONVERSATION_ID is missing or invalid; expected conv_<id> or conv_<id>_ext.\n' >&2
|
|
139
|
-
exit 6
|
|
140
|
-
fi
|
|
141
|
-
if [[ -z "$PROJECT_CONVERSATION_ID" ]]; then
|
|
142
|
-
PROJECT_CONVERSATION_ID="$CONVERSATION_ID"
|
|
143
|
-
fi
|
|
144
|
-
if [[ ! "$PROJECT_CONVERSATION_ID" =~ ^conv_[A-Za-z0-9-]+(_ext)?$ ]]; then
|
|
145
|
-
printf 'Project ConversationId is invalid.\n' >&2
|
|
146
|
-
exit 6
|
|
147
|
-
fi
|
|
148
|
-
|
|
149
|
-
if [[ -z "$OUTPUT" ]]; then
|
|
150
|
-
OUTPUT="$PROJECT_ROOT/artifacts/feed-card-${CONVERSATION_ID}.png"
|
|
151
|
-
fi
|
|
152
|
-
mkdir -p "$(dirname "$OUTPUT")"
|
|
153
|
-
|
|
154
137
|
if [[ -n "$SESSION_NAME" && ! "$SESSION_NAME" =~ ^[A-Za-z0-9._-]+$ ]]; then
|
|
155
138
|
printf 'Session name may contain only letters, digits, dot, underscore and hyphen.\n' >&2
|
|
156
139
|
exit 2
|
|
@@ -170,7 +153,8 @@ cleanup() {
|
|
|
170
153
|
fi
|
|
171
154
|
[[ -z "$DATA_PREFLIGHT_FILE" ]] || rm -f "$DATA_PREFLIGHT_FILE"
|
|
172
155
|
COMMAND_TIMEOUT_MS="1500"
|
|
173
|
-
if [[ "$
|
|
156
|
+
if [[ "$STAGE" != "readiness" && "$CONTROL_FAILED" != "true" &&
|
|
157
|
+
( "$KEEP_OPEN" != "true" || "$CAPTURE_SUCCEEDED" != "true" ) ]]; then
|
|
174
158
|
if [[ -n "$owned_tab_id" ]]; then
|
|
175
159
|
agent-browser --session "$SESSION_NAME" tab close "$owned_tab_id" >/dev/null 2>&1 || true
|
|
176
160
|
fi
|
|
@@ -290,11 +274,32 @@ inspect_current() {
|
|
|
290
274
|
|
|
291
275
|
STAGE="readiness"
|
|
292
276
|
dev_status="$(cd "$PROJECT_ROOT" && node "$SCRIPT_DIR/wait-dev-status.mjs")"
|
|
277
|
+
initial_conversation_id="$CONVERSATION_ID"
|
|
293
278
|
runtime_conversation_id="$(printf '%s' "$dev_status" | jq -r '.runtimeConversationId // ""')"
|
|
294
279
|
if [[ "$CONVERSATION_ID_SOURCE" == "environment" && -n "$runtime_conversation_id" ]]; then
|
|
295
280
|
CONVERSATION_ID="$runtime_conversation_id"
|
|
296
281
|
CONVERSATION_ID_SOURCE="dev/status or runtime meta"
|
|
297
282
|
fi
|
|
283
|
+
|
|
284
|
+
conversation_id_pattern='^conv_[A-Za-z0-9-]+(_ext)?$'
|
|
285
|
+
if [[ ! "$CONVERSATION_ID" =~ $conversation_id_pattern ]]; then
|
|
286
|
+
ERROR_SUMMARY='CONVERSATION_ID is missing or invalid; expected conv_<id> or conv_<id>_ext.'
|
|
287
|
+
printf '%s\n' "$ERROR_SUMMARY" >&2
|
|
288
|
+
exit 6
|
|
289
|
+
fi
|
|
290
|
+
# Keep a valid caller CID for audit metadata and the default output name.
|
|
291
|
+
if [[ ! "$initial_conversation_id" =~ $conversation_id_pattern ]]; then
|
|
292
|
+
initial_conversation_id="$CONVERSATION_ID"
|
|
293
|
+
fi
|
|
294
|
+
PROJECT_CONVERSATION_ID="${PROJECT_CONVERSATION_ID:-$initial_conversation_id}"
|
|
295
|
+
if [[ ! "$PROJECT_CONVERSATION_ID" =~ $conversation_id_pattern ]]; then
|
|
296
|
+
ERROR_SUMMARY='Project ConversationId is invalid.'
|
|
297
|
+
printf '%s\n' "$ERROR_SUMMARY" >&2
|
|
298
|
+
exit 6
|
|
299
|
+
fi
|
|
300
|
+
OUTPUT="${OUTPUT:-$PROJECT_ROOT/artifacts/feed-card-${initial_conversation_id}.png}"
|
|
301
|
+
mkdir -p "$(dirname "$OUTPUT")"
|
|
302
|
+
|
|
298
303
|
if [[ "$CONVERSATION_ID" == *_ext ]]; then
|
|
299
304
|
PREVIEW_HOST="aihub.douyin.com"
|
|
300
305
|
else
|
|
@@ -14,6 +14,7 @@ import { SESSION_FLAGS, readJsonInput, readSessionFile, requireCdpUrl, resolveBr
|
|
|
14
14
|
export const SESSION_HELP = `Usage: preview-session.mjs <command> [arguments]
|
|
15
15
|
landing-url <preview-url> <registered-pages-route-with-optional-query>
|
|
16
16
|
inject <cdp-url> <feed-url> <feed.json> [--reload]
|
|
17
|
+
inject --session-file state.json [<feed.json>] [--reload]
|
|
17
18
|
wait <cdp-url> <url> <interest-card|landing-page> [readiness-json-or-file]
|
|
18
19
|
observe <cdp-url> <url> <interest-card|landing-page> <absolute-output.json> <fields-json-or-file>
|
|
19
20
|
capture <cdp-url> <url> <output.png> [options-json-or-file]
|
|
@@ -22,6 +23,7 @@ Preferred: replace <cdp-url> <url> with --session-file <capture state.json> [--s
|
|
|
22
23
|
wait --session-file state.json landing-page readiness.json
|
|
23
24
|
capture --session-file state.json --scope landing-page out.png options.json
|
|
24
25
|
The session file supplies cdpUrl and previewUrl (landingPreviewUrl for landing-page); --url overrides the URL.
|
|
26
|
+
inject uses the session's feedFile when no Feed JSON path is supplied.
|
|
25
27
|
|
|
26
28
|
readiness: {"expectedRoute":"pages/detail/index","textPresent":["TA 的主页"],"stablePasses":2,"timeoutMs":10000}
|
|
27
29
|
fields: {"quantity":{"type":"number","pattern":"数量:[ ]*([0-9]+)","group":1}}
|
|
@@ -413,6 +415,13 @@ if (isMain) {
|
|
|
413
415
|
const scoped = ['wait', 'observe'].includes(operation);
|
|
414
416
|
const target = named ? resolveBrowserTarget(flags, positional, { defaultScope: scoped ? '' : 'interest-card' })
|
|
415
417
|
: { cdpUrl: positional[0], expectedUrl: positional[1], rest: positional.slice(2) };
|
|
418
|
+
if (operation === 'inject') {
|
|
419
|
+
const feedFile = target.rest[0] ?? target.browserSession?.feedFile;
|
|
420
|
+
if (typeof feedFile !== 'string' || !feedFile.trim()) {
|
|
421
|
+
throw new Error('inject requires a Feed JSON path or a --session-file containing feedFile');
|
|
422
|
+
}
|
|
423
|
+
target.rest[0] = feedFile;
|
|
424
|
+
}
|
|
416
425
|
if (named && scoped) target.rest.unshift(target.scope);
|
|
417
426
|
args = { ...target, named, cdpUrl: requireCdpUrl(target.cdpUrl), reload: Boolean(flags['--reload']),
|
|
418
427
|
sessionFile: flags['--session-file'] };
|
|
@@ -37,7 +37,8 @@ getAIUserProfile(params: AIUserProfileParams, options?: CallOptions): Promise<Op
|
|
|
37
37
|
|
|
38
38
|
## 能力使用规则
|
|
39
39
|
|
|
40
|
-
-
|
|
40
|
+
- `const response = await getAIUserProfile(params, options)` 得到 SDK 已规范化的 `{ err_no, err_msg, data: { UserInfo } }`。直接从 `response.data.UserInfo` 取资料,业务状态码在 `response.err_no`。`response.data` 的下一层是 `UserInfo`。
|
|
41
|
+
- 保留 SDK 推断的返回类型。性别读 `response.data.UserInfo.gender`,未知值不归为男性或女性。生日读 `response.data.UserInfo.birthday`,有效完整出生日期按生日是否已过计算周岁,不把账号注册天数当作年龄。
|
|
41
42
|
- 生日缺失、不完整或无效时,不能推测年龄或填入固定画像;明确展示资料不可用,并保留不依赖该字段的业务内容。不得因一次检索为空就要求用户改为手填年龄或性别。
|
|
42
43
|
- 账号资料及其派生年龄在封闭域服务中处理,遵守数据流限制;不得记录原始生日、身份或凭证。
|
|
43
44
|
|
|
@@ -61,8 +62,9 @@ export async function callGetAIUserProfile(input: {
|
|
|
61
62
|
params,
|
|
62
63
|
{ ...options, delegateToken },
|
|
63
64
|
);
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
const profile = result.data.UserInfo;
|
|
66
|
+
console.log('getAIUserProfile success', { errNo: result.err_no });
|
|
67
|
+
return profile;
|
|
66
68
|
} catch (error) {
|
|
67
69
|
console.error('getAIUserProfile fail', error);
|
|
68
70
|
throw error;
|
|
@@ -72,4 +74,4 @@ export async function callGetAIUserProfile(input: {
|
|
|
72
74
|
|
|
73
75
|
## 验证
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
核对 `result.err_no` 和 `result.data.UserInfo`。仅记录业务状态码,不输出资料内容;SDK 调用失败时保留错误处理。
|
|
@@ -40,7 +40,8 @@ getAIUserProfile(params: AIUserProfileParams, options?: CallOptions): Promise<Op
|
|
|
40
40
|
|
|
41
41
|
## 能力使用规则
|
|
42
42
|
|
|
43
|
-
-
|
|
43
|
+
- `const response = await getAIUserProfile(params, options)` 得到 SDK 已规范化的 `{ err_no, err_msg, data: { UserInfo } }`。直接从 `response.data.UserInfo` 取资料,业务状态码在 `response.err_no`。`response.data` 的下一层是 `UserInfo`。
|
|
44
|
+
- 保留 SDK 推断的返回类型。性别读 `response.data.UserInfo.gender`,未知值不归为男性或女性。生日读 `response.data.UserInfo.birthday`,有效完整出生日期按生日是否已过计算周岁,不把账号注册天数当作年龄。
|
|
44
45
|
- 生日缺失、不完整或无效时,不能推测年龄或填入固定画像;明确展示资料不可用,并保留不依赖该字段的业务内容。不得因一次检索为空就要求用户改为手填年龄或性别。
|
|
45
46
|
- 账号资料及其派生年龄在封闭域服务中处理,遵守数据流限制;不得记录原始生日、身份或凭证。
|
|
46
47
|
|
|
@@ -64,8 +65,9 @@ export async function callGetAIUserProfile(input: {
|
|
|
64
65
|
params,
|
|
65
66
|
{ ...options, delegateToken },
|
|
66
67
|
);
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
const profile = result.data.UserInfo;
|
|
69
|
+
console.log('getAIUserProfile success', { errNo: result.err_no });
|
|
70
|
+
return profile;
|
|
69
71
|
} catch (error) {
|
|
70
72
|
console.error('getAIUserProfile fail', error);
|
|
71
73
|
throw error;
|
|
@@ -75,4 +77,4 @@ export async function callGetAIUserProfile(input: {
|
|
|
75
77
|
|
|
76
78
|
## 验证
|
|
77
79
|
|
|
78
|
-
|
|
80
|
+
核对 `result.err_no` 和 `result.data.UserInfo`。仅记录业务状态码,不输出资料内容;SDK 调用失败时保留错误处理。
|
|
@@ -125,7 +125,10 @@ function scoreRecord(record, query) {
|
|
|
125
125
|
if (!normalizedField) continue
|
|
126
126
|
if (normalizedField === normalizedQuery) score = Math.max(score, 100)
|
|
127
127
|
else if (normalizedField.includes(normalizedQuery)) score = Math.max(score, 70)
|
|
128
|
-
else if (
|
|
128
|
+
else if (
|
|
129
|
+
normalizedQuery.includes(normalizedField)
|
|
130
|
+
&& (normalizedField.length >= 3 || /^\p{Script=Han}{2}$/u.test(normalizedField))
|
|
131
|
+
) {
|
|
129
132
|
score = Math.max(score, 55)
|
|
130
133
|
}
|
|
131
134
|
score = Math.max(score, Math.round(similarity(field, query) * 40))
|
|
@@ -137,7 +140,7 @@ function includesAny(value, terms) {
|
|
|
137
140
|
return terms.some((term) => value.includes(normalize(term)))
|
|
138
141
|
}
|
|
139
142
|
|
|
140
|
-
function detectIntent(query) {
|
|
143
|
+
function detectIntent(query, scene) {
|
|
141
144
|
const rawQuery = String(query ?? '').toLowerCase()
|
|
142
145
|
const normalizedQuery = normalize(query)
|
|
143
146
|
const explicitOpenAPI = rawQuery.includes('user_profile') || includesAny(normalizedQuery, [
|
|
@@ -167,7 +170,7 @@ function detectIntent(query) {
|
|
|
167
170
|
])
|
|
168
171
|
return {
|
|
169
172
|
explicitOpenAPI,
|
|
170
|
-
localUserProfile,
|
|
173
|
+
localUserProfile: scene === 'microapp' && localUserProfile,
|
|
171
174
|
displayOnly: includesAny(normalizedQuery, ['展示', '显示', '渲染', '只展示']),
|
|
172
175
|
needsPhone: includesAny(normalizedQuery, ['手机号', '手机号码', 'phoneNumber']),
|
|
173
176
|
}
|
|
@@ -308,7 +311,7 @@ function search(args) {
|
|
|
308
311
|
flow.capability_ids.every((id) => capabilityIds.has(id)),
|
|
309
312
|
)
|
|
310
313
|
|
|
311
|
-
const intent = detectIntent(args.query)
|
|
314
|
+
const intent = detectIntent(args.query, args.scene)
|
|
312
315
|
const score = (records) => records
|
|
313
316
|
.map((record) => ({
|
|
314
317
|
record,
|
|
@@ -9,24 +9,30 @@ description: 用 interest-card-cli 新建、拉取或在本地修改抖音兴趣
|
|
|
9
9
|
|
|
10
10
|
## 先判断主题能不能做
|
|
11
11
|
|
|
12
|
-
兴趣卡主题、功能、引导或落地页涉及下列任一类服务 → 立即拒绝,不调用 Skill、不初始化(不执行 `create`、`pull`、`push`、`reply
|
|
12
|
+
兴趣卡主题、功能、引导或落地页涉及下列任一类服务 → 立即拒绝,不调用 Skill、不初始化(不执行 `create`、`pull`、`push`、`reply`),不生产任何产物;禁止部分生成、擦边或改头换面继续做。同义、变体、隐晦话术同样拦截。不得为受限服务提供跳转、报名、下单、咨询、导流等可交互能力。看服务实质,不看表面措辞;规避性、拆分式、包装式表达同样拒绝。棋牌类按下方玩法规则判断;无法明确判断是否涉及受限服务时,按下方澄清流程处理。已拉取的工程在修改中途出现这类需求时同样处理。输出话术(【类别】换成命中的一类):
|
|
13
13
|
|
|
14
14
|
> 该内容涉及【金融/公益/医疗/号卡/教育K12/社交/东方玄学/军事/新闻时政/法律/棋牌赌博/负面内容/广告营销/三方引流】类服务,暂不支持在兴趣卡中生成,请调整创作方向。
|
|
15
15
|
|
|
16
|
+
- **判断与澄清**:主题既可能涉及受限服务,也可能是不受限内容,而请求缺少足以区分的事实时,视为无法判定;不得凭默认假设或擅自改成不受限方向认定已准入。
|
|
17
|
+
- 先只询问决定是否受限的关键事实,例如目标人群、用途、具体功能或服务方式;不得用玩法、风格确认代替准入澄清。若提供选项,选项仅用于确认事实,不预设都可生成。
|
|
18
|
+
- 等待答复后重新逐项校验;确认前不执行 `create`、`pull`、`push`、`reply`,不读模板,也不输出玩法方案或其他产物。已明确不涉及受限服务时,继续判断其他准入项,无需因此追问。
|
|
16
19
|
- 金融:贷款、理财、投资、股票、基金、保险、信用卡、借贷、征信、数字货币、外汇等
|
|
17
20
|
- 公益:募捐、慈善、公益筹款、志愿服务招募、捐赠倡导等
|
|
18
21
|
- 医疗:诊断、问诊、用药建议、疾病治疗、医美、体检、健康干预、医疗器械等
|
|
19
22
|
- 号卡:手机号卡、电话卡、流量卡、SIM 卡、宽带号卡办理与推销等
|
|
20
23
|
- 教育K12:面向学龄前至高中的学科培训、课程、辅导、招生、提分服务等
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
+
- 社交:陌生人交友、相亲、婚恋、约会、社交匹配、聊天陪伴、社交论坛,以及用户上传内容(文字/图片等)生成相关产物、产物体现在卡面/落地页,并在兴趣卡后续分发(私域/公域)时被其他用户看见的 UGC 社区场景等
|
|
25
|
+
- 仅调用抖音开放接口展示用户授权后的主页、互关、收藏等数据,且不提供交友匹配、聊天陪伴或内容生产分享能力的,不按社交类服务拦截。
|
|
26
|
+
- 东方玄学:算命、占卜、看相、测八字、风水、辟邪、改运、符咒、大仙、神药等封建迷信内容(塔罗牌、星座、抽签可准入;答案之书等若仅作娱乐或灵感参考,且不宣称预测、占卜或改运,也可准入)
|
|
27
|
+
- 棋牌赌博:博彩式棋牌、捕鱼及其他赌博玩法,包括押注财物或可充值、可交易、可兑换的筹码,按输赢结算财物、提供博彩导流等。玩法已明确为纯策略、益智或休闲对局,且没有上述机制的,可通过本项校验,继续判断其他准入项。仅用于计分、排名且不可交易、不可兑换的积分按游戏计分处理。
|
|
28
|
+
- 只提“棋牌”等宽泛方向,关键玩法不足以判断是否命中本项时,先用一句话确认具体玩法及是否涉及押注或兑换。等待答复后重新做准入校验,确认前不初始化、不生成。玩法已明确时直接判定。
|
|
24
29
|
- 军事:军事装备、作战推演、征兵、军情分析等
|
|
25
30
|
- 新闻时政:社会时政、时事新闻、政策解读、政治人物等
|
|
26
31
|
- 法律:法律咨询、案件分析、诉讼指导、法规解读建议等
|
|
27
32
|
- 负面内容:白事、殡葬、社会恶劣事件(烧/杀/暴力等)等易引发用户负面情绪的内容
|
|
28
33
|
- 广告营销:商品推荐/预定/下单、站外站内购物、引导留资,以及酒店机票预定、租房买房、挂号预约等直接服务;兴趣卡只做内容展示与兴趣引导,不提供具体服务
|
|
29
34
|
- 三方引流:引导到外部网站、下载其他 APP、关注站外账号、加入站外群
|
|
35
|
+
- 仅个别文案提及上述领域、但非主体经营内容且不提供相关服务能力的,可准入。
|
|
30
36
|
|
|
31
37
|
## 找到或新建工程
|
|
32
38
|
|
package/card-skills/douyin-interest-card-generate/references/common/post-card-differences.md
CHANGED
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
|
|
30
30
|
作品 Feed 里,宿主会在屏幕右侧固定悬浮一列操作按钮(头像、关注、点赞、评论、收藏、分享),直接盖在卡片上面。卡片内容分两类,处理方式不同:
|
|
31
31
|
|
|
32
|
-
-
|
|
33
|
-
-
|
|
32
|
+
- **视觉主体**:背景图、主视觉、底板、色块、装饰元素。铺满整个画布,允许被右侧操作列重叠,重叠处须保证宿主图标和计数清楚可辨。
|
|
33
|
+
- **交互元素**:按钮、答题选项、上一题/下一题、抽取、提交等可点元素,连同其完整外框和点击热区。这是功能可用性的零容忍硬约束、不是视觉建议:必须整体完整落在安全区内,一律不得被右侧操作列盖住或与其热区贴边冲突;只要任一部分越过安全区边界即判不通过,与遮挡面积大小、按钮主体看起来是否仍可识别无关。
|
|
34
34
|
|
|
35
35
|
安全区是画布右侧扣除操作列后的区域。边界分两层:外层 `.widget-root` 保留模板自带的 `4.3vw` 内边距,内层在内容侧再留 `60rpx`,两层一起覆盖右侧操作列。
|
|
36
36
|
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
|
|
39
39
|
- 交互元素以整张卡片的中心为轴,和视觉主体共用同一套对齐基准;不要用单向 `padding-right` 或给整排加固定左偏移,那会让内容整体偏左、和铺满的主体错位。
|
|
40
40
|
- 把右侧留白当成一条**边界**:居中排布后,若交互元素的右边缘越过边界,就围绕卡片中心等比缩放或重排,让它在保持居中的同时完整落进安全区,左右留白自然对称。
|
|
41
|
-
-
|
|
41
|
+
- 不接受“只盖住一小部分”,擦边、极限贴近同样不通过:被盖住的部分点不到,靠近边缘还容易误触宿主的点赞、评论、收藏。截图验收禁止以“基本通过”“没有明显重叠”“不影响主体识别”“可选优化”“保持现状”等说法放行;出现遮挡或临界一律判不通过,围绕卡片中心等比缩放或重排,待其完整落进安全区后重新截图复验,不得把这项硬伤记为可选项。
|
|
42
42
|
|
|
43
43
|
其他:
|
|
44
44
|
|
|
@@ -48,6 +48,32 @@
|
|
|
48
48
|
|
|
49
49
|
仅适用于作品 Feed 中的 OpenCard,普通兴趣卡和落地页不用留这个白。改完在真实作品宿主核对各状态与热区,确认交互元素没被盖住、整体居中没有偏左;lint 和 H5 看不出遮挡,没验证就如实说明。
|
|
50
50
|
|
|
51
|
+
## 右侧宿主操作列的对比度
|
|
52
|
+
|
|
53
|
+
这是视觉可读性问题,不影响点击等交互功能,与上一条交互避让分开判断、互不替代。宿主操作列的图标和计数在未交互态固定为白色,卡片改不了宿主颜色;当它们落在纯白或浅色实心底板、背景渐变或高光上时对比度不足,白色图标、计数会和底色融在一起看不清。逐状态查看带宿主外壳的截图原图,按每个图标和计数各自的实际落点底色判断,不按整列明暗一概而论;计数字号小、最先看不清,以计数完整可读为准。
|
|
54
|
+
|
|
55
|
+
白色图标或计数叠在浅色底上读不出,该状态截图的对比度项即不通过。只在卡片侧修复、不动宿主控件:在操作列对应的纵向条带叠一层向内容侧渐隐的深色压暗渐变(scrim/蒙层)垫底,或让浅色实心底板右缘避让该条带(背景图、主视觉仍可铺满),且不破坏交互安全区与居中布局,然后复跑该状态、重看原图确认。
|
|
56
|
+
|
|
57
|
+
## 卡片内容饱满、避免大块空白
|
|
58
|
+
|
|
59
|
+
作品卡片内容要与卡位匹配、排版饱满,不出现与内容无关的大块空白或空面板。内容偏少、余高较多时,用图片或图表自适应伸缩、删减可选项或分页承接,不增加空占位 View、不靠重复加 padding 或硬造内容填高,短文字的自然留白允许。截图逐状态核对有无异常空洞、核心内容是否完整可读,排版口径按 `${SKILL_DIR}/references/opencard/opencard.md`。
|
|
60
|
+
|
|
61
|
+
## 作品截图的固定看图提示词
|
|
62
|
+
|
|
63
|
+
新建、续改和升级后的个人页作品,每次使用 `read_img` 检查 `post` 场景截图时,都将下方文本原样传给 `prompt`,包括首检、手动检查和修复后的最终复验。每次调用只换图片路径,保持提示词全文一致。按原图实际出现的元素验收,无需填写玩法、页面状态或控件名单。
|
|
64
|
+
|
|
65
|
+
```text
|
|
66
|
+
这是个人页作品宿主截图。按画面实际出现的元素检查以下各项,逐项给出「通过」「不通过」或「待核实」,并说明看到的证据。
|
|
67
|
+
|
|
68
|
+
1. 交互安全区。检查可识别的可点击控件,其完整外框及可见点击区域是否全部落在安全区内。被右侧宿主操作列遮挡、越过安全区边界或与宿主操作列贴边均不通过。截图无法确认的实际点击热区标为待核实。
|
|
69
|
+
2. 水平居中。检查交互元素是否以整张卡片的中心为轴对齐,有无整体偏左。
|
|
70
|
+
3. 宿主操作列可读性。分别看右侧图标和计数实际落点的卡面或背景,检查图标轮廓是否清楚、计数是否完整可读。图标融入底色或计数读不清均不通过。
|
|
71
|
+
4. 内容饱满度。检查卡片是否出现异常大块空白或空面板。短内容的自然留白允许。
|
|
72
|
+
5. 内容完整性。检查图文和控件是否完整可读,有无重叠或裁切。
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
任一项不通过,整张作品截图按不通过处理。存在待核实项时,补齐对应证据后再登记验收结论。
|
|
76
|
+
|
|
51
77
|
## OpenCard 交互仅使用点击
|
|
52
78
|
|
|
53
79
|
- 点击使用 SDK 支持的 `onClick`、`onTap` 及相应 Catch 写法;阻止点击冒泡仍遵循 Taro DSL 事件规则。
|
|
@@ -5,9 +5,17 @@
|
|
|
5
5
|
## 先读取规范并确认工程
|
|
6
6
|
|
|
7
7
|
1. 从当前 Skill 的真实绝对路径确定 `SKILL_DIR`,先读取 `${SKILL_DIR}/references/common/post-card-differences.md`,再读取 `${SKILL_DIR}/references/common/legacy-project-compatibility.md`。
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
|
|
9
|
+
2. 迁移前先运行只读预检。
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
node "${SKILL_DIR}/scripts/inspect-post-upgrade.mjs" --project /workspace/project/card-app
|
|
13
|
+
```
|
|
14
|
+
该脚本会快速检查当前项目需要升级的项,并在涉及依赖、配置或启动脚本迁移时提示对应的重启服务步骤。
|
|
15
|
+
|
|
16
|
+
3. 检查现有 `package.json`、小程序与 OpenCard 源码、构建及 ESLint 配置、网络层和卡片服务端接口。已有这些文件即为续改,禁止执行 `init.sh` 覆盖工程。
|
|
17
|
+
4. 读取现有 `config/card-routing.json`,记录 `cardType` 原值及字段是否存在。缺少文件或 `cardType` 时,形态按 `interest` 兼容;服务域仍须由实际接口和工程证据确认,不能因配置缺失默认 `open`。已有 `isCardTypeUpdating: true` 时按未完成的升级继续检查,不重新初始化;已有 `post` 且无升级中标记时继续检查个人页作品兼容性,不重复迁移。
|
|
18
|
+
5. 记录用户已有改动和本次拟调整的文件。必要文档无法读取、依赖来源不完整或服务域不明时,停止依赖该信息的改动并说明缺失项。
|
|
11
19
|
|
|
12
20
|
## 开始适配前标记升级中
|
|
13
21
|
|
|
@@ -28,6 +36,19 @@
|
|
|
28
36
|
- 沿用已写入 `"isCardTypeUpdating": true` 的现有配置,完成必要适配后按下文统一写入最终形态。不执行初始化或重新安装整份模板。
|
|
29
37
|
- 已调用 `@open-dy/vibecoding-sdk-taro` / `@open-dy/vibecoding-sdk-opencard` 配置工厂的 `eslint.config.mjs` 保持原样。`@open-dy/vibecoding-cli` 读取宿主配置后通过子进程环境传递形态,这两个包内部选择规则;直接运行 ESLint 时,这两个包根据待检查文件定位工程并读取同一配置。只有尚未接入这两个包的旧配置才需要局部合并入口。
|
|
30
38
|
|
|
39
|
+
## 依赖或配置迁移后立即重启开发服务(必做)
|
|
40
|
+
|
|
41
|
+
只要本轮改动了根工程或 `opencard/` 的工具链依赖(`@open-dy/vibecoding-cli`、`@open-dy/vibecoding-sdk-taro`、`@open-dy/vibecoding-sdk-opencard`、`@open-dy/opencard-taro`)、构建或 ESLint 配置(`config/*`、`turbo.json`、`eslint.config.*`、`tsconfig.json` 等)、`package.json` 的 `scripts` 或 `scripts/dev_run.sh`,在完成这些配置迁移并执行完依赖安装(根工程及涉及改动的 `opencard/`)后,**必须立刻通过容器开发服务接口重启一次开发预览服务**(未改动上述依赖、配置或启动脚本的较新工程无需额外重启):
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
curl -fsS -X POST http://127.0.0.1:7983/dev/run \
|
|
45
|
+
-H 'Content-Type: application/json' \
|
|
46
|
+
-d '{"projectKey":"card-app"}'
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- **由容器服务统一托管,禁止在终端直接运行 `pnpm dev` / `pnpm run dev`**:该接口由容器常驻服务拉起 `scripts/dev_run.sh` 并同步维护 `/dev/status` 状态与日志,请求会立即返回;触发后**不要 `sleep` 等待或手动轮询端口**,直接继续后续业务改造、切换 `"cardType": "post"`,待全部代码完成后统一执行 `pnpm verify` 与截图检查。
|
|
50
|
+
- **严禁单独运行 `opencard` 的 `pnpm run dev:tt`**:根工程开发服务运行期间,**禁止**单独在 `opencard/` 下执行 `pnpm run dev:tt` 或编写脚本刷新 `dist-tt`;并发写入 `opencard/dist-tt` 会导致 `rspuck` 异常退出并使预览端口残留旧内存包。
|
|
51
|
+
|
|
31
52
|
## 修复与验收
|
|
32
53
|
|
|
33
54
|
按差异文档移除底部页面切换导航形态(平台 TabBar 与自绘底部导航均需移除),改用顶部标签、内容筛选或入口跳转,并改造 OpenCard 非点击交互,保留可用的页面导航与业务操作。
|
|
@@ -43,7 +64,7 @@
|
|
|
43
64
|
|
|
44
65
|
随后以 `post` 形态执行小程序及 OpenCard 全量 lint、类型检查、构建和必要业务验收。形态及规则缓存由 `@open-dy/vibecoding-cli` 管理,不删除字段或关闭规则来通过检查。最终校验失败或无法完成时,恢复 `"isCardTypeUpdating": true` 及开始适配前的 `cardType`(原先缺省则删除该字段),保留已完成的代码适配及其他配置改动,并报告升级尚未完成;不能改按兴趣卡规则校验后宣称升级完成。
|
|
45
66
|
|
|
46
|
-
|
|
67
|
+
确认已完成上文开发服务重启后,核对开发产物 `opencard/dist-tt/app.json`、正式产物 `opencard/dist/app.json` 都满足 `meta.cardType === "post"`。仅 lint 通过不能证明编译器已经支持该字段;产物缺少字段时先通过 `curl -fsS 'http://127.0.0.1:7983/dev/status?projectKey=card-app'` 确认开发服务已重启就绪(未运行或仍为旧进程时再次按上文调用 `/dev/run` 重启,不要在终端直接执行 `pnpm dev` / `pnpm run dev`),并检查依赖和实际构建入口,不要单独执行 `opencard` 的 `pnpm run dev:tt` 或手工修改产物。后续通过 `@open-dy/vibecoding-cli` 开发预览入口切换形态会自动重启编译。
|
|
47
68
|
|
|
48
69
|
同一工程继续使用现有产物结构,不引入两种构建目标。包内实现、实际启动入口及网络请求均需验证;静态检查不替代作品宿主中的手势、导航和返回行为验收。仅写入字段不代表升级完成,明确报告已完成、失败和未验证项;用户要求回退时只撤销本轮升级改动,保留用户原有修改。
|
|
49
70
|
|
|
@@ -52,7 +73,9 @@
|
|
|
52
73
|
升级完成后,使用 `douyin-interest-card-browser` 分别对兴趣卡和个人页作品两个场景截图,截图均须包含 Feed 宿主外壳,并按本 Skill 的“截图检查”执行检查、修复和证据保留,不能只截个人页作品:
|
|
53
74
|
|
|
54
75
|
- **兴趣卡(默认场景或 `--preview-scene feed`)**:只校验布局合理性——主体内容沿卡片垂直中轴线水平居中,视觉重心落在卡片中心、左右留白均衡,无明显偏左或偏右的单侧偏移;对照 `DESIGN.md` 确认内容无裁切、重叠,文字与按钮完整可读,可点击元素未被宿主控件遮挡。
|
|
55
|
-
- **个人页作品(`--preview-scene post
|
|
76
|
+
- **个人页作品(`--preview-scene post`)**:逐状态检查按钮、答题选项等交互元素完整落在安全区内,并以卡片中心为轴保持居中。同时逐个确认右侧宿主图标轮廓清楚、计数在其实际落点的卡面或背景上完整可读,白色图标或计数叠在纯白、浅色底板上即不通过;并核对卡片内容饱满、无异常大块空白或空面板,短内容的自然留白不算问题。按 `post-card-differences.md`「主交互避让右侧宿主操作区」「右侧宿主操作列的对比度」「卡片内容饱满、避免大块空白」执行。
|
|
77
|
+
|
|
78
|
+
每次通过 `read_img` 检查作品截图时,原样使用 `post-card-differences.md`「作品截图的固定看图提示词」中的正文。
|
|
56
79
|
|
|
57
80
|
任一场景发现问题都需修复业务代码后按原验收流程复验并重新截图,两个场景均通过后才能进入封面与交付环节。
|
|
58
81
|
|
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync, readdirSync, realpathSync, statSync } from 'node:fs';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { isDeepStrictEqual, parseArgs } from 'node:util';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
const templates = fileURLToPath(new URL('../templates/', import.meta.url));
|
|
9
|
+
const configFile = /^(?:\.npmrc|(?:babel|eslint|postcss)\.config\.[a-z]+|(?:turbo|tsconfig|project)(?:\.[\w-]+)*\.json)$/u;
|
|
10
|
+
const entryPoint = /^(?:(?:build|dev|lint|pack|verify)(?::|$)|check-routes$|validate-feed-card$)/u;
|
|
11
|
+
const toolchain = /^(?:@open-dy\/(?:vibecoding-cli|vibecoding-sdk-(?:taro|opencard)|opencard-taro)|@tarojs\/.+|turbo|eslint|typescript)$/u;
|
|
12
|
+
const dependencyFields = ['dependencies', 'devDependencies', 'optionalDependencies'];
|
|
13
|
+
const workspaceName = 'pnpm-workspace.yaml';
|
|
14
|
+
const schemaName = 'custom-card-schema.json';
|
|
15
|
+
const routingFile = 'config/card-routing.json';
|
|
16
|
+
const devRestartTriggerIds = new Set([
|
|
17
|
+
'DEPENDENCY_DECLARATION', 'PARENT_DEPENDENCY', 'DEPENDENCY_UNRESOLVED', 'MANIFEST_SETTING',
|
|
18
|
+
'PATCH_MISSING', 'LOCAL_REFERENCE_REVIEW', 'ROOT_WORKSPACE_REVIEW', 'OPENCARD_WORKSPACE_REVIEW',
|
|
19
|
+
'SCRIPT_ENTRY_DIFFERS', 'SCRIPT_TARGET_MISSING', 'FILE_DIFFERS',
|
|
20
|
+
]);
|
|
21
|
+
const legacyLucideGuidance = '存在旧图标别名 `paths["lucide-taro"]`(指向本地 `icons`):在 `package.json` 声明 `@open-dy/lucide-taro` 后,将 `src/` 中的 `lucide-taro` 导入改为 `@open-dy/lucide-taro`,并删除该 `paths` 别名。';
|
|
22
|
+
const help = 'Usage: node inspect-post-upgrade.mjs --project <card-app root> [--format markdown|json]\nDefault format: markdown';
|
|
23
|
+
const isMissingRouting = item => item.id === 'FILE_MISSING' && item.file === routingFile;
|
|
24
|
+
|
|
25
|
+
function inside(root, file) {
|
|
26
|
+
const relative = path.relative(root, file);
|
|
27
|
+
return relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Restrict reads to explicit engineering files, including when a file is a symlink.
|
|
31
|
+
function localFile(root, relative) {
|
|
32
|
+
const file = path.resolve(root, relative);
|
|
33
|
+
const allowed = value => inside(root, value) && !path.relative(root, value).split(path.sep).includes('src');
|
|
34
|
+
if (!allowed(file)) throw new Error('path is outside the supported inspection scope');
|
|
35
|
+
try {
|
|
36
|
+
const real = realpathSync(file);
|
|
37
|
+
if (!allowed(real)) throw new Error('symlink is outside the supported inspection scope');
|
|
38
|
+
if (!statSync(real).isFile()) throw new Error('expected a file');
|
|
39
|
+
return real;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if (error.code === 'ENOENT' || error.code === 'ENOTDIR') return null;
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function workspacePatterns(text) {
|
|
47
|
+
// Recognize simple pnpm package lists. Leave YAML aliases and complex values for review.
|
|
48
|
+
const lines = text.split(/\r?\n/u);
|
|
49
|
+
const start = lines.findIndex(line => /^packages\s*:/u.test(line));
|
|
50
|
+
if (start < 0) return null;
|
|
51
|
+
const tail = lines[start].replace(/^packages\s*:\s*/u, '').replace(/\s+#.*$|^#.*$/u, '').trim();
|
|
52
|
+
let values = [];
|
|
53
|
+
if (tail) {
|
|
54
|
+
if (!tail.startsWith('[') || !tail.endsWith(']')) return null;
|
|
55
|
+
values = tail.slice(1, -1).split(',').map(value => value.trim()).filter(Boolean);
|
|
56
|
+
} else {
|
|
57
|
+
for (const line of lines.slice(start + 1)) {
|
|
58
|
+
if (/^\s*(?:#.*)?$/u.test(line)) continue;
|
|
59
|
+
if (/^[\w-]+\s*:/u.test(line)) break;
|
|
60
|
+
const item = line.match(/^\s*-\s+(.+?)\s*$/u);
|
|
61
|
+
if (!item) return null;
|
|
62
|
+
values.push(item[1].replace(/\s+#.*$/u, ''));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const patterns = values.map(value => value.replace(/^(['"])(.*?)\1$/u, '$2'));
|
|
66
|
+
return patterns.every(value => /^!?[\w./*?@+-]+$/u.test(value)) ? patterns : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function findWorkspace(root) {
|
|
70
|
+
for (let dir = root; ; dir = path.dirname(dir)) {
|
|
71
|
+
const file = localFile(dir, workspaceName);
|
|
72
|
+
if (file) return { file: path.join(dir, workspaceName), root: dir, patterns: workspacePatterns(readFileSync(file, 'utf8')) };
|
|
73
|
+
if (path.dirname(dir) === dir) return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function workspaceMembership(workspace, root) {
|
|
78
|
+
if (!workspace) return false;
|
|
79
|
+
if (workspace.root === root) return true;
|
|
80
|
+
if (!workspace.patterns || typeof path.posix.matchesGlob !== 'function') return null;
|
|
81
|
+
const relative = path.relative(workspace.root, root).split(path.sep).join('/');
|
|
82
|
+
return workspace.patterns.some(pattern => !pattern.startsWith('!') && path.posix.matchesGlob(relative, pattern)) &&
|
|
83
|
+
!workspace.patterns.some(pattern => pattern.startsWith('!') && path.posix.matchesGlob(relative, pattern.slice(1)));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function declarations(manifest) {
|
|
87
|
+
return Object.assign({}, ...dependencyFields.map(field => manifest[field]));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function dependencySource(value) {
|
|
91
|
+
if (typeof value !== 'string') return null;
|
|
92
|
+
return /^[\w@./:^~*+ -]+$/u.test(value) && !value.includes('://') ? value : 'custom source';
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function installedPackage(root, name) {
|
|
96
|
+
const fromProject = createRequire(path.join(root, 'package.json'));
|
|
97
|
+
try {
|
|
98
|
+
let manifest;
|
|
99
|
+
try {
|
|
100
|
+
manifest = fromProject.resolve(`${name}/package.json`);
|
|
101
|
+
} catch {
|
|
102
|
+
// Some SDKs export their public entry but do not export package.json.
|
|
103
|
+
const entry = fromProject.resolve(name);
|
|
104
|
+
for (let dir = path.dirname(entry); path.dirname(dir) !== dir; dir = path.dirname(dir)) {
|
|
105
|
+
const file = localFile(dir, 'package.json');
|
|
106
|
+
if (!file) continue;
|
|
107
|
+
const metadata = JSON.parse(readFileSync(file, 'utf8'));
|
|
108
|
+
if (metadata.name && metadata.version) {
|
|
109
|
+
manifest = file;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!manifest) return null;
|
|
115
|
+
const { name: installedName, version } = JSON.parse(readFileSync(manifest, 'utf8'));
|
|
116
|
+
const direct = fromProject.resolve.paths(name)?.find(dir => {
|
|
117
|
+
try {
|
|
118
|
+
return realpathSync(path.join(dir, name)) === realpathSync(path.dirname(manifest));
|
|
119
|
+
} catch {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return { name: installedName, version, manifest, fromParent: Boolean(direct && !inside(root, direct)) };
|
|
124
|
+
} catch {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function scriptReferences(command = '') {
|
|
130
|
+
// Trace literal repo script paths and simple local pnpm / Turbo calls. Never evaluate shell.
|
|
131
|
+
const files = [...command.matchAll(/(?:^|[\s'"=&|;])(?:\.\/)?(scripts\/[\w./-]+\.(?:[cm]?js|[cm]?ts|sh))(?=$|[\s'";&|])/gu)]
|
|
132
|
+
.map(match => match[1]).filter(file => !file.split('/').includes('..'));
|
|
133
|
+
const localCalls = [...command.matchAll(/(?:^|[;&|]\s*)pnpm\s+(?:run\s+)?([\w:-]+)\b|\bturbo\s+[^;&|]*?\brun\s+([\w:-]+)/gu)]
|
|
134
|
+
.map(match => match[1] ?? match[2])
|
|
135
|
+
.filter(name => entryPoint.test(name));
|
|
136
|
+
return { files: [...new Set(files)], scripts: [...new Set(localCalls)] };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function hasLegacyLucideAlias(text) {
|
|
140
|
+
// tsconfig.json allows JSON comments and trailing commas. Preserve quoted strings in both passes.
|
|
141
|
+
const withoutComments = text.replace(/"(?:[^"\\]|\\.)*"|\/\*[\s\S]*?\*\/|\/\/[^\r\n]*/gu,
|
|
142
|
+
token => token.startsWith('"') ? token : ' ');
|
|
143
|
+
const json = withoutComments.replace(/"(?:[^"\\]|\\.)*"|,\s*(?=[}\]])/gu,
|
|
144
|
+
token => token.startsWith('"') ? token : '');
|
|
145
|
+
try {
|
|
146
|
+
const aliases = JSON.parse(json.replace(/^\uFEFF/u, ''))?.compilerOptions?.paths?.['lucide-taro'];
|
|
147
|
+
return Array.isArray(aliases) && aliases.includes('icons');
|
|
148
|
+
} catch {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function inspect(root) {
|
|
154
|
+
const findings = [];
|
|
155
|
+
const add = (id, file, message, details = {}) => findings.push({ id, file, message, ...details });
|
|
156
|
+
const taroTemplate = path.join(templates, 'taro');
|
|
157
|
+
const openCardTemplate = path.join(templates, 'fragments/opencard');
|
|
158
|
+
const taroManifest = JSON.parse(readFileSync(path.join(taroTemplate, 'package.json'), 'utf8'));
|
|
159
|
+
const openCardManifest = JSON.parse(readFileSync(path.join(openCardTemplate, 'package.json'), 'utf8'));
|
|
160
|
+
const templateSchema = JSON.parse(readFileSync(path.join(taroTemplate, 'feed', schemaName), 'utf8'));
|
|
161
|
+
const postTemplateInputs = [
|
|
162
|
+
['templates/taro/package.json', declarations(taroManifest), ['@open-dy/vibecoding-sdk-taro', '@open-dy/vibecoding-cli']],
|
|
163
|
+
['templates/fragments/opencard/package.json', declarations(openCardManifest), ['@open-dy/vibecoding-sdk-opencard', '@open-dy/vibecoding-cli']],
|
|
164
|
+
[`templates/taro/feed/${schemaName}`, templateSchema.properties ?? {}, ['BgMusicUrl']],
|
|
165
|
+
];
|
|
166
|
+
for (const [file, entries, keys] of postTemplateInputs) {
|
|
167
|
+
const missing = keys.filter(key => !entries[key]);
|
|
168
|
+
if (missing.length) add('TEMPLATE_POST_CAPABILITY_MISSING', file, 'The bundled template lacks a required post upgrade capability.', { missing });
|
|
169
|
+
}
|
|
170
|
+
const postSupported = findings.length === 0;
|
|
171
|
+
const projectPath = (dir, name) => path.relative(root, path.join(dir, name)).split(path.sep).join('/');
|
|
172
|
+
const locate = (dir, name) => {
|
|
173
|
+
try {
|
|
174
|
+
return localFile(dir, name);
|
|
175
|
+
} catch (error) {
|
|
176
|
+
add('FILE_UNREADABLE', projectPath(dir, name), error.code ?? error.message);
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
const read = (dir, name, { json = false, required = false, file = locate(dir, name) } = {}) => {
|
|
181
|
+
const location = projectPath(dir, name);
|
|
182
|
+
try {
|
|
183
|
+
if (!file) {
|
|
184
|
+
if (file === null && required) add('FILE_MISSING', location, 'Required project file is missing.');
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
const text = readFileSync(file, 'utf8');
|
|
188
|
+
if (!json) return text;
|
|
189
|
+
const data = JSON.parse(text);
|
|
190
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) throw new Error('expected a JSON object');
|
|
191
|
+
return data;
|
|
192
|
+
} catch (error) {
|
|
193
|
+
add('FILE_UNREADABLE', location, error instanceof SyntaxError ? 'Invalid JSON.' : (error.code ?? error.message));
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
function checkFiles(dir, template, scriptFiles) {
|
|
199
|
+
const config = path.join(template, 'config');
|
|
200
|
+
const names = readdirSync(template, { withFileTypes: true })
|
|
201
|
+
.filter(entry => entry.isFile() && configFile.test(entry.name)).map(entry => entry.name);
|
|
202
|
+
names.push(...readdirSync(config, { withFileTypes: true })
|
|
203
|
+
.filter(entry => entry.isFile() && entry.name !== 'card-routing.json').map(entry => `config/${entry.name}`));
|
|
204
|
+
for (const name of [...new Set([...names, ...scriptFiles])].sort()) {
|
|
205
|
+
if (name.split('/').includes('src')) continue;
|
|
206
|
+
const templateFile = localFile(template, name);
|
|
207
|
+
const actual = read(dir, name, { required: true });
|
|
208
|
+
if (actual === null || !templateFile) continue;
|
|
209
|
+
const expected = readFileSync(templateFile, 'utf8');
|
|
210
|
+
const differs = name === '.npmrc'
|
|
211
|
+
? expected.split(/\r?\n/u).map(line => line.trim())
|
|
212
|
+
.filter(line => /^(?:registry|@[^:]+:registry|node-linker|public-hoist-pattern|shamefully-hoist)\s*=/u.test(line))
|
|
213
|
+
.some(line => !actual.split(/\r?\n/u).map(item => item.trim()).includes(line))
|
|
214
|
+
: actual.trim() !== expected.trim();
|
|
215
|
+
if (differs) add('FILE_DIFFERS', projectPath(dir, name), 'Review this engineering file against the matching Skill template.', {
|
|
216
|
+
template: path.relative(templates, templateFile).split(path.sep).join('/'),
|
|
217
|
+
...(dir === root && name === 'tsconfig.json' && hasLegacyLucideAlias(actual) ? { guidance: legacyLucideGuidance } : {}),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function checkProject(dir, template, target, scope) {
|
|
223
|
+
const manifest = read(dir, 'package.json', { json: true, required: true });
|
|
224
|
+
if (!manifest) return null;
|
|
225
|
+
const manifestPath = projectPath(dir, 'package.json');
|
|
226
|
+
const ownDeps = declarations(manifest);
|
|
227
|
+
const targetDeps = declarations(target);
|
|
228
|
+
const installed = {};
|
|
229
|
+
const deps = new Set([...Object.keys(ownDeps), ...Object.keys(targetDeps)].filter(name => toolchain.test(name)));
|
|
230
|
+
for (const name of [...deps].sort()) {
|
|
231
|
+
if (ownDeps[name] !== targetDeps[name]) {
|
|
232
|
+
add('DEPENDENCY_DECLARATION', manifestPath, 'Review the toolchain dependency against the matching template.', {
|
|
233
|
+
dependency: name, declared: dependencySource(ownDeps[name]), expected: dependencySource(targetDeps[name]),
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
installed[name] = installedPackage(dir, name);
|
|
237
|
+
if (installed[name]?.fromParent && scope === 'opencard' && Object.hasOwn(targetDeps, name)) {
|
|
238
|
+
add('PARENT_DEPENDENCY', manifestPath, 'OpenCard resolves this dependency from an ancestor installation.', {
|
|
239
|
+
dependency: name, resolved: installed[name],
|
|
240
|
+
});
|
|
241
|
+
} else if (!installed[name] && Object.hasOwn(ownDeps, name) && /^@open-dy\//u.test(name)) {
|
|
242
|
+
add('DEPENDENCY_UNRESOLVED', manifestPath, 'This SDK or CLI cannot be resolved from the project directory.', { dependency: name });
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
for (const name of ['packageManager', 'pnpm']) {
|
|
246
|
+
if (!isDeepStrictEqual(manifest[name], target[name])) {
|
|
247
|
+
const keys = name === 'pnpm' ? [...new Set([...Object.keys(manifest.pnpm ?? {}), ...Object.keys(target.pnpm ?? {})])]
|
|
248
|
+
.filter(key => !isDeepStrictEqual(manifest.pnpm?.[key], target.pnpm?.[key])).sort() : undefined;
|
|
249
|
+
add('MANIFEST_SETTING', manifestPath, 'Review this package manager setting against the template.', { key: name, keys });
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const localRefs = Object.entries(manifest.pnpm?.patchedDependencies ?? {});
|
|
253
|
+
for (const map of [ownDeps, manifest.pnpm?.overrides ?? {}]) {
|
|
254
|
+
for (const [name, value] of Object.entries(map)) {
|
|
255
|
+
if (typeof value === 'string' && value.startsWith('file:')) localRefs.push([name, value.slice(5)]);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
for (const [name, relative] of localRefs) {
|
|
259
|
+
try {
|
|
260
|
+
if (typeof relative !== 'string' || !localFile(dir, relative)) {
|
|
261
|
+
add('PATCH_MISSING', manifestPath, 'A referenced local dependency or patch file is missing.', { dependency: name, reference: relative });
|
|
262
|
+
}
|
|
263
|
+
} catch {
|
|
264
|
+
add('LOCAL_REFERENCE_REVIEW', manifestPath, 'Check this local dependency or patch reference manually.', { dependency: name });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const scripts = {};
|
|
269
|
+
const scriptFiles = new Set(scope === 'root' ? ['scripts/dev_run.sh', 'scripts/pack.sh'] : []);
|
|
270
|
+
const scriptKeys = new Set([...Object.keys(target.scripts ?? {}), ...Object.keys(manifest.scripts ?? {})].filter(key => entryPoint.test(key)));
|
|
271
|
+
for (const key of scriptKeys) {
|
|
272
|
+
const actual = manifest.scripts?.[key];
|
|
273
|
+
const refs = scriptReferences(typeof actual === 'string' ? actual : '');
|
|
274
|
+
scripts[key] = refs;
|
|
275
|
+
refs.files.forEach(file => scriptFiles.add(file));
|
|
276
|
+
if (actual !== target.scripts?.[key]) {
|
|
277
|
+
add('SCRIPT_ENTRY_DIFFERS', manifestPath, 'Review the actual command chain before changing this script.', {
|
|
278
|
+
key: `scripts.${key}`, present: typeof actual === 'string', references: refs, templateCommand: target.scripts?.[key] ?? null,
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
for (const called of refs.scripts) {
|
|
282
|
+
if (typeof manifest.scripts?.[called] !== 'string') {
|
|
283
|
+
add('SCRIPT_TARGET_MISSING', manifestPath, 'This entry calls another project script that is missing.', { key, called });
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
checkFiles(dir, template, scriptFiles);
|
|
288
|
+
let workspace = null;
|
|
289
|
+
let member = null;
|
|
290
|
+
try {
|
|
291
|
+
workspace = findWorkspace(dir);
|
|
292
|
+
member = workspaceMembership(workspace, dir);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
add('WORKSPACE_UNREADABLE', projectPath(dir, workspaceName), error.code ?? error.message);
|
|
295
|
+
}
|
|
296
|
+
if (scope === 'root' && workspace?.root !== dir) {
|
|
297
|
+
add('ROOT_WORKSPACE_REVIEW', workspaceName, 'The template declares the service workspace in the app root.');
|
|
298
|
+
}
|
|
299
|
+
if (scope === 'opencard' && workspace && workspace.root !== dir && member !== false) {
|
|
300
|
+
add('OPENCARD_WORKSPACE_REVIEW', workspace.file, member
|
|
301
|
+
? 'OpenCard belongs to an ancestor workspace. The current Skill template installs it independently.'
|
|
302
|
+
: 'Cannot determine OpenCard workspace membership from this packages declaration.');
|
|
303
|
+
}
|
|
304
|
+
return { workspace: workspace?.file ?? null, workspaceMember: member,
|
|
305
|
+
hasLockfile: Boolean(locate(dir, 'pnpm-lock.yaml')), installed, scripts };
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const app = checkProject(root, taroTemplate, taroManifest, 'root');
|
|
309
|
+
const openCard = checkProject(path.join(root, 'opencard'), openCardTemplate, openCardManifest, 'opencard');
|
|
310
|
+
const routing = read(root, routingFile, { json: true, required: true });
|
|
311
|
+
const serviceDomain = routing?.cardData?.serviceDomain ?? null;
|
|
312
|
+
if (routing && !['open', 'closed'].includes(serviceDomain)) {
|
|
313
|
+
add('SERVICE_DOMAIN_REVIEW', 'config/card-routing.json', 'Confirm the current service domain using project route evidence.', { serviceDomain });
|
|
314
|
+
}
|
|
315
|
+
if (routing && Object.hasOwn(routing, 'cardType') && !['interest', 'post'].includes(routing.cardType)) {
|
|
316
|
+
add('CARD_TYPE_INVALID', 'config/card-routing.json', 'cardType must be interest or post when present.');
|
|
317
|
+
}
|
|
318
|
+
if (routing && (routing.version !== 1 || routing.cardData?.path !== '/api/dy_card/data' ||
|
|
319
|
+
(routing.cardData?.routes !== undefined && (!Array.isArray(routing.cardData.routes) ||
|
|
320
|
+
routing.cardData.routes.some(route => typeof route !== 'string' || !route.trim()))))) {
|
|
321
|
+
add('CARD_ROUTING_SHAPE', 'config/card-routing.json', 'Review version, cardData.path and cardData.routes against the routing contract.');
|
|
322
|
+
}
|
|
323
|
+
for (const service of serviceDomain === 'closed' ? ['server', 'closed-domain-server'] : ['server']) {
|
|
324
|
+
const manifest = read(root, `${service}/package.json`, { json: true, required: true });
|
|
325
|
+
if (manifest && manifest.name !== service) {
|
|
326
|
+
add('SERVER_PACKAGE_NAME', `${service}/package.json`, 'Confirm that the package name matches the pnpm filter used by the project scripts.', {
|
|
327
|
+
expected: service,
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const schemas = [`scripts/schemas/${schemaName}`, `feed/${schemaName}`];
|
|
333
|
+
const schemaFiles = schemas.map(name => [name, locate(root, name)]);
|
|
334
|
+
const candidate = schemaFiles.find(([, file]) => file)?.[0] ?? null;
|
|
335
|
+
let supportsBgMusicUrl = null;
|
|
336
|
+
for (const [name, file] of schemaFiles) {
|
|
337
|
+
const schema = read(root, name, { json: true, required: name.startsWith('feed/'), file });
|
|
338
|
+
if (name === candidate && schema) supportsBgMusicUrl = Object.hasOwn(schema.properties ?? {}, 'BgMusicUrl');
|
|
339
|
+
if (schema && !isDeepStrictEqual(schema, templateSchema)) {
|
|
340
|
+
add('FEED_SCHEMA_DIFFERS', name, 'Review this project Feed Schema against the template.', { effectiveCandidate: name === candidate });
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (supportsBgMusicUrl === false) {
|
|
344
|
+
add('POST_SCHEMA_BGM_UNSUPPORTED', candidate, 'The selected project Feed Schema does not declare BgMusicUrl.');
|
|
345
|
+
}
|
|
346
|
+
const feed = read(root, 'feed/feed-card.json', { json: true, required: true });
|
|
347
|
+
if (feed && (typeof feed.BgMusicUrl !== 'string' || !/^https:\/\/[^\s]+$/iu.test(feed.BgMusicUrl.trim()))) {
|
|
348
|
+
add('POST_BGM_REVIEW', 'feed/feed-card.json', 'A post needs a valid HTTPS BgMusicUrl.');
|
|
349
|
+
}
|
|
350
|
+
const missingRouting = findings.findIndex(isMissingRouting);
|
|
351
|
+
if (missingRouting > 0) findings.unshift(...findings.splice(missingRouting, 1));
|
|
352
|
+
return {
|
|
353
|
+
status: findings.length ? 'review' : 'no-findings', project: root,
|
|
354
|
+
template: { postSupported },
|
|
355
|
+
projects: { root: app, opencard: openCard },
|
|
356
|
+
routing: { cardType: routing ? (Object.hasOwn(routing, 'cardType') ? routing.cardType : 'interest') : null,
|
|
357
|
+
isCardTypeUpdating: routing?.isCardTypeUpdating ?? null, serviceDomain,
|
|
358
|
+
route: routing?.cardData?.path ?? null },
|
|
359
|
+
feedSchema: { candidate, fallback: candidate ? null : 'cli', supportsBgMusicUrl, eligible: ['open', 'closed'].includes(serviceDomain) },
|
|
360
|
+
findings,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const code = value => `\`${String(value).replace(/[`\r\n]/gu, ' ')}\``;
|
|
365
|
+
const codeList = values => values.map(code).join('、');
|
|
366
|
+
|
|
367
|
+
function findingText(item) {
|
|
368
|
+
const { id, file, key, dependency, declared, expected, references, resolved } = item;
|
|
369
|
+
const location = code(file);
|
|
370
|
+
switch (id) {
|
|
371
|
+
case 'TEMPLATE_POST_CAPABILITY_MISSING':
|
|
372
|
+
return `${location} 缺少 ${codeList(item.missing)}。`;
|
|
373
|
+
case 'SERVICE_DOMAIN_REVIEW':
|
|
374
|
+
return `${location} 的服务域是 ${code(item.serviceDomain ?? '缺失')}。先核实现有卡片接口注册在哪个服务,再处理服务域配置。`;
|
|
375
|
+
case 'CARD_TYPE_INVALID':
|
|
376
|
+
return `${location} 的形态值无效。按现有升级状态核实 \`cardType\`,允许值为 \`interest\` 或 \`post\`。`;
|
|
377
|
+
case 'CARD_ROUTING_SHAPE':
|
|
378
|
+
return `${location} 的路由结构与契约不符。核对 \`version\`、\`cardData.path\` 和 \`cardData.routes\`。`;
|
|
379
|
+
case 'SERVER_PACKAGE_NAME':
|
|
380
|
+
return `${location} 的包名与模板中的 ${code(expected)} 不一致。先核对工程实际使用的 pnpm filter。`;
|
|
381
|
+
case 'DEPENDENCY_DECLARATION':
|
|
382
|
+
return `${location} 的 ${code(dependency)} 当前 ${declared === null ? '未声明' : code(declared)},模板${expected === null ? '未声明' : `是 ${code(expected)}`}。`;
|
|
383
|
+
case 'PARENT_DEPENDENCY':
|
|
384
|
+
return `${location} 的 ${code(dependency)} 实际解析到了父级安装 ${code(resolved.version)},位置在 ${code(resolved.manifest)}。`;
|
|
385
|
+
case 'DEPENDENCY_UNRESOLVED':
|
|
386
|
+
return `${location} 已声明 ${code(dependency)},但从该工程目录解析不到它。`;
|
|
387
|
+
case 'MANIFEST_SETTING':
|
|
388
|
+
return `${location} 的 ${code(key)} 与模板有差异${item.keys?.length ? `,涉及 ${codeList(item.keys)}` : ''}。`;
|
|
389
|
+
case 'PATCH_MISSING':
|
|
390
|
+
return `${location} 引用的 ${code(dependency)} 本地文件不存在,路径是 ${code(item.reference ?? '无效路径')}。`;
|
|
391
|
+
case 'LOCAL_REFERENCE_REVIEW':
|
|
392
|
+
return `${location} 的 ${code(dependency)} 是无法静态核实的本地引用,需确认实际文件位置。`;
|
|
393
|
+
case 'ROOT_WORKSPACE_REVIEW':
|
|
394
|
+
return `${location} 未在项目根生效。核实服务端包实际归属的 workspace。`;
|
|
395
|
+
case 'OPENCARD_WORKSPACE_REVIEW':
|
|
396
|
+
return `${location} 的 OpenCard 安装边界需要核实,当前作品模板按独立项目安装 OpenCard。`;
|
|
397
|
+
case 'WORKSPACE_UNREADABLE':
|
|
398
|
+
return `${location} 无法读取,需核实 workspace 路径和文件权限。`;
|
|
399
|
+
case 'SCRIPT_ENTRY_DIFFERS': {
|
|
400
|
+
const chain = [...references.scripts, ...references.files];
|
|
401
|
+
const actual = !item.present ? '项目未定义' : chain.length ? `项目当前引用 ${codeList(chain)}` : '项目当前命令与模板不同';
|
|
402
|
+
return `${location} 的 ${code(key)},${actual}。模板${item.templateCommand ? `使用 ${code(item.templateCommand)}` : '未定义这一项'}。`;
|
|
403
|
+
}
|
|
404
|
+
case 'SCRIPT_TARGET_MISSING':
|
|
405
|
+
return `${location} 的 ${code(key)} 调用了未定义的脚本 ${code(item.called)}。`;
|
|
406
|
+
case 'FILE_DIFFERS':
|
|
407
|
+
return `${location} 和 ${code(item.template)} 不同。对照实际入口核对是否需要合并模板改动。${item.guidance ? ` ${item.guidance}` : ''}`;
|
|
408
|
+
case 'FILE_MISSING':
|
|
409
|
+
if (isMissingRouting(item)) return `缺少 ${location}:先核实现有卡片接口归属,再补路由配置。`;
|
|
410
|
+
return `缺少 ${location},核实是否为当前入口所需。`;
|
|
411
|
+
case 'FILE_UNREADABLE':
|
|
412
|
+
return `${location} 无法读取,检查文件内容或路径(${code(item.message)})。`;
|
|
413
|
+
case 'FEED_SCHEMA_DIFFERS':
|
|
414
|
+
return `Feed Schema:${location}${item.effectiveCandidate ? ' 是实际优先使用的 Schema 且' : ' '}与模板不同,先处理后再用项目 Feed 校验入口复验。`;
|
|
415
|
+
case 'POST_SCHEMA_BGM_UNSUPPORTED':
|
|
416
|
+
return `Feed Schema:优先使用的 ${location} 缺少 \`BgMusicUrl\`,先同步支持该字段的 Schema,再用项目 Feed 校验入口复验。`;
|
|
417
|
+
case 'POST_BGM_REVIEW':
|
|
418
|
+
return `作品配乐:${location} 的 \`BgMusicUrl\` 缺失或格式无效,按作品配乐规则补齐有效 HTTPS 地址。`;
|
|
419
|
+
default:
|
|
420
|
+
return `${location} — ${item.message}`;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function extraDependencyGroupKey(dependency, declared) {
|
|
425
|
+
const scoped = dependency.match(/^@([^/]+)\/(.+)$/u);
|
|
426
|
+
if (scoped && typeof declared === 'string' && declared.startsWith('file:')) {
|
|
427
|
+
const [, scope, pkg] = scoped;
|
|
428
|
+
const slug = `${scope}-${pkg}`;
|
|
429
|
+
if (declared.includes(slug)) return declared.replace(slug, `${scope}-*`);
|
|
430
|
+
}
|
|
431
|
+
return declared;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function groupBy(items, getKey) {
|
|
435
|
+
const groups = new Map();
|
|
436
|
+
for (const item of items) {
|
|
437
|
+
const key = getKey(item);
|
|
438
|
+
if (!groups.has(key)) groups.set(key, []);
|
|
439
|
+
groups.get(key).push(item);
|
|
440
|
+
}
|
|
441
|
+
return groups;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function renderDependencySection(items) {
|
|
445
|
+
const lines = [];
|
|
446
|
+
const directIds = new Set([
|
|
447
|
+
'PATCH_MISSING', 'LOCAL_REFERENCE_REVIEW', 'OPENCARD_WORKSPACE_REVIEW',
|
|
448
|
+
'ROOT_WORKSPACE_REVIEW', 'WORKSPACE_UNREADABLE', 'PARENT_DEPENDENCY', 'DEPENDENCY_UNRESOLVED',
|
|
449
|
+
]);
|
|
450
|
+
for (const item of items.filter(entry => directIds.has(entry.id))) {
|
|
451
|
+
lines.push(`- ${findingText(item)}`);
|
|
452
|
+
}
|
|
453
|
+
const byFile = groupBy(items.filter(entry => !directIds.has(entry.id)), entry => entry.file);
|
|
454
|
+
for (const [file, fileItems] of byFile) {
|
|
455
|
+
const missing = [];
|
|
456
|
+
const mismatch = [];
|
|
457
|
+
const extra = [];
|
|
458
|
+
const settings = [];
|
|
459
|
+
for (const item of fileItems) {
|
|
460
|
+
if (item.id === 'MANIFEST_SETTING') {
|
|
461
|
+
settings.push(item.keys?.length ? `${code(item.key)} 差异:${codeList(item.keys)}` : `${code(item.key)} 与模板不同`);
|
|
462
|
+
} else if (item.declared === null) {
|
|
463
|
+
missing.push(`${code(item.dependency)} (${code(item.expected)})`);
|
|
464
|
+
} else if (item.expected === null) {
|
|
465
|
+
extra.push(item);
|
|
466
|
+
} else {
|
|
467
|
+
mismatch.push(`${code(item.dependency)} (${code(item.declared)} -> ${code(item.expected)})`);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
const settingSuffix = settings.length ? `;${settings.join(';')}` : '';
|
|
471
|
+
if (missing.length) {
|
|
472
|
+
lines.push(`- ${code(file)} 缺失:${missing.join('、')}${mismatch.length ? '' : settingSuffix}`);
|
|
473
|
+
}
|
|
474
|
+
if (mismatch.length) {
|
|
475
|
+
lines.push(`- ${code(file)} 版本差异:${mismatch.join('、')}${settingSuffix}`);
|
|
476
|
+
} else if (!missing.length && settings.length) {
|
|
477
|
+
lines.push(`- ${code(file)} 配置差异:${settings.join(';')}`);
|
|
478
|
+
}
|
|
479
|
+
if (extra.length) {
|
|
480
|
+
const extraGroups = groupBy(extra, item => extraDependencyGroupKey(item.dependency, item.declared));
|
|
481
|
+
const formatted = [...extraGroups.entries()].map(([pattern, entries]) => [
|
|
482
|
+
entries.length === 1 ? entries[0].declared : pattern,
|
|
483
|
+
entries.map(entry => entry.dependency),
|
|
484
|
+
]);
|
|
485
|
+
if (formatted.length === 1) {
|
|
486
|
+
lines.push(`- ${code(file)} 模板未声明(${code(formatted[0][0])}):${codeList(formatted[0][1])}`);
|
|
487
|
+
} else {
|
|
488
|
+
lines.push(`- ${code(file)} 模板未声明:`);
|
|
489
|
+
for (const [label, deps] of formatted) {
|
|
490
|
+
lines.push(` - ${code(label)}:${codeList(deps)}`);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return lines;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function renderConfigSection(items) {
|
|
499
|
+
const lines = [];
|
|
500
|
+
const diffs = items.filter(item => item.id === 'FILE_DIFFERS');
|
|
501
|
+
const buckets = [
|
|
502
|
+
['根工程(对比 `taro/*`)', item => !item.file.startsWith('opencard/') && item.template.startsWith('taro/')],
|
|
503
|
+
['OpenCard(对比 `fragments/opencard/*`)', item => item.file.startsWith('opencard/') && item.template.startsWith('fragments/opencard/')],
|
|
504
|
+
];
|
|
505
|
+
const handled = new Set();
|
|
506
|
+
for (const [label, match] of buckets) {
|
|
507
|
+
const matched = diffs.filter(match);
|
|
508
|
+
if (!matched.length) continue;
|
|
509
|
+
matched.forEach(item => handled.add(item));
|
|
510
|
+
lines.push(`- ${label}:${codeList(matched.map(item => item.file))}`);
|
|
511
|
+
for (const item of matched.filter(entry => entry.guidance)) {
|
|
512
|
+
lines.push(` - ${code(item.file)} ${item.guidance}`);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
for (const item of diffs.filter(entry => !handled.has(entry))) {
|
|
516
|
+
lines.push(`- ${code(item.file)}(对比 ${code(item.template)})`);
|
|
517
|
+
if (item.guidance) lines.push(` - ${code(item.file)} ${item.guidance}`);
|
|
518
|
+
}
|
|
519
|
+
const missingFiles = items.filter(entry => entry.id === 'FILE_MISSING');
|
|
520
|
+
if (missingFiles.length) {
|
|
521
|
+
lines.push(`- 缺失文件(核实是否为当前入口所需):${codeList(missingFiles.map(entry => entry.file))}`);
|
|
522
|
+
}
|
|
523
|
+
for (const item of items.filter(entry => entry.id !== 'FILE_DIFFERS' && entry.id !== 'FILE_MISSING')) {
|
|
524
|
+
lines.push(`- ${findingText(item)}`);
|
|
525
|
+
}
|
|
526
|
+
return lines;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
function renderScriptSection(items) {
|
|
530
|
+
const lines = [];
|
|
531
|
+
for (const item of items.filter(entry => entry.id === 'SCRIPT_TARGET_MISSING')) {
|
|
532
|
+
lines.push(`- ${findingText(item)}`);
|
|
533
|
+
}
|
|
534
|
+
const byFile = groupBy(items.filter(entry => entry.id === 'SCRIPT_ENTRY_DIFFERS'), entry => entry.file);
|
|
535
|
+
for (const [file, entries] of byFile) {
|
|
536
|
+
lines.push(`- ${code(file)}:`);
|
|
537
|
+
for (const item of entries) {
|
|
538
|
+
const name = item.key.replace(/^scripts\./u, '');
|
|
539
|
+
const chain = [...item.references.scripts, ...item.references.files];
|
|
540
|
+
const actual = !item.present ? '未定义' : chain.length ? `引用 ${codeList(chain)}` : '命令不同';
|
|
541
|
+
const expected = item.templateCommand ? code(item.templateCommand) : '模板未定义';
|
|
542
|
+
lines.push(` - ${code(name)}: ${actual} -> ${expected}`);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return lines;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function markdownReport(report) {
|
|
549
|
+
const { project, template, routing, feedSchema, findings } = report;
|
|
550
|
+
const schemaLabel = feedSchema.candidate ? code(feedSchema.candidate) : 'CLI 内置 Schema(需核对 CLI 版本)';
|
|
551
|
+
const lines = [
|
|
552
|
+
'# 个人页作品升级预检',
|
|
553
|
+
`工程 ${code(project)} | 形态 ${code(routing.cardType ?? '未知')} | 服务域 ${code(routing.serviceDomain ?? '未知')} | Feed Schema ${schemaLabel}`,
|
|
554
|
+
];
|
|
555
|
+
const templateFindings = findings.filter(item => item.id === 'TEMPLATE_POST_CAPABILITY_MISSING');
|
|
556
|
+
if (!template.postSupported) {
|
|
557
|
+
lines.push('', '**先更新 Skill 模板,再复跑预检。** 当前模板缺少作品升级所需能力,下面只列能直接确认的工程问题。', '');
|
|
558
|
+
lines.push(...templateFindings.map(item => `- ${findingText(item)}`), '');
|
|
559
|
+
} else if (!findings.length) {
|
|
560
|
+
lines.push('', '预检范围内未发现问题。可以继续按升级流程适配和验收。');
|
|
561
|
+
return lines.join('\n');
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
const templateComparisons = new Set(['DEPENDENCY_DECLARATION', 'MANIFEST_SETTING', 'SCRIPT_ENTRY_DIFFERS',
|
|
565
|
+
'FILE_DIFFERS', 'FEED_SCHEMA_DIFFERS', 'ROOT_WORKSPACE_REVIEW', 'OPENCARD_WORKSPACE_REVIEW']);
|
|
566
|
+
const remaining = findings.filter(item => !isMissingRouting(item) && item.id !== 'TEMPLATE_POST_CAPABILITY_MISSING' &&
|
|
567
|
+
(template.postSupported || item.guidance || !templateComparisons.has(item.id)));
|
|
568
|
+
|
|
569
|
+
const priorityItems = [];
|
|
570
|
+
const missingRouting = findings.find(isMissingRouting);
|
|
571
|
+
if (missingRouting) priorityItems.push(findingText(missingRouting));
|
|
572
|
+
const priorityIds = new Set([
|
|
573
|
+
'SERVICE_DOMAIN_REVIEW', 'CARD_TYPE_INVALID', 'CARD_ROUTING_SHAPE', 'SERVER_PACKAGE_NAME',
|
|
574
|
+
'POST_SCHEMA_BGM_UNSUPPORTED', 'FEED_SCHEMA_DIFFERS', 'POST_BGM_REVIEW',
|
|
575
|
+
]);
|
|
576
|
+
for (const item of remaining.filter(entry => priorityIds.has(entry.id))) {
|
|
577
|
+
priorityItems.push(findingText(item));
|
|
578
|
+
}
|
|
579
|
+
const needsDevRestart = template.postSupported && remaining.some(item => devRestartTriggerIds.has(item.id)
|
|
580
|
+
|| (item.id === 'FILE_MISSING' && !item.file.startsWith('feed/')));
|
|
581
|
+
if (needsDevRestart) {
|
|
582
|
+
priorityItems.push('迁移后重启:完成下述依赖、配置或启动脚本迁移并安装完依赖后,调用 `curl -fsS -X POST http://127.0.0.1:7983/dev/run -H \'Content-Type: application/json\' -d \'{"projectKey":"card-app"}\'` 重启一次开发服务(不要直接在终端运行 `pnpm dev` / `pnpm run dev`)。');
|
|
583
|
+
}
|
|
584
|
+
if (priorityItems.length) {
|
|
585
|
+
lines.push('**阻塞与必做**:', ...priorityItems.map((text, index) => `${index + 1}. ${text}`));
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const depIds = new Set([
|
|
589
|
+
'PATCH_MISSING', 'LOCAL_REFERENCE_REVIEW', 'OPENCARD_WORKSPACE_REVIEW', 'ROOT_WORKSPACE_REVIEW',
|
|
590
|
+
'WORKSPACE_UNREADABLE', 'PARENT_DEPENDENCY', 'DEPENDENCY_UNRESOLVED', 'DEPENDENCY_DECLARATION', 'MANIFEST_SETTING',
|
|
591
|
+
]);
|
|
592
|
+
const configIds = new Set(['FILE_DIFFERS', 'FILE_MISSING', 'FILE_UNREADABLE']);
|
|
593
|
+
const scriptIds = new Set(['SCRIPT_TARGET_MISSING', 'SCRIPT_ENTRY_DIFFERS']);
|
|
594
|
+
|
|
595
|
+
const sections = [
|
|
596
|
+
['依赖与安装边界(修正后复跑预检核对包解析位置)', renderDependencySection(remaining.filter(item => depIds.has(item.id)))],
|
|
597
|
+
['配置文件差异(对照实际入口核对是否合并模板改动)', renderConfigSection(remaining.filter(item => configIds.has(item.id)))],
|
|
598
|
+
['脚本入口差异(格式:`script`: 当前 -> 模板;沿实际脚本适配并保留必要自定义步骤)', renderScriptSection(remaining.filter(item => scriptIds.has(item.id)))],
|
|
599
|
+
];
|
|
600
|
+
for (const [title, body] of sections) {
|
|
601
|
+
if (!body.length) continue;
|
|
602
|
+
lines.push('', `## ${title}`, ...body);
|
|
603
|
+
}
|
|
604
|
+
return lines.join('\n').trimEnd();
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
let format = 'markdown';
|
|
608
|
+
try {
|
|
609
|
+
const { values } = parseArgs({ options: {
|
|
610
|
+
project: { type: 'string' },
|
|
611
|
+
format: { type: 'string', default: format },
|
|
612
|
+
help: { type: 'boolean', short: 'h' },
|
|
613
|
+
} });
|
|
614
|
+
if (values.help) {
|
|
615
|
+
console.log(help);
|
|
616
|
+
} else {
|
|
617
|
+
format = values.format;
|
|
618
|
+
if (!values.project?.trim() || !['json', 'markdown'].includes(values.format)) throw new Error(help);
|
|
619
|
+
const root = realpathSync(values.project);
|
|
620
|
+
if (!statSync(root).isDirectory()) throw new Error('--project must be the root directory of the card app.');
|
|
621
|
+
const result = inspect(root);
|
|
622
|
+
console.log(values.format === 'markdown' ? markdownReport(result) : JSON.stringify(result, null, 2));
|
|
623
|
+
if (result.findings.length) process.exitCode = 1;
|
|
624
|
+
}
|
|
625
|
+
} catch (error) {
|
|
626
|
+
console.log(format === 'json'
|
|
627
|
+
? JSON.stringify({ status: 'error', error: error.message })
|
|
628
|
+
: `# 个人页作品升级预检失败\n\n${error.message}`);
|
|
629
|
+
process.exitCode = 2;
|
|
630
|
+
}
|
package/dist/src/upgrade.js
CHANGED
|
@@ -161,16 +161,38 @@ export async function installGlobalPackage(version, json) {
|
|
|
161
161
|
'--registry',
|
|
162
162
|
registry,
|
|
163
163
|
scopeRegistryArg(registry),
|
|
164
|
-
], json);
|
|
164
|
+
], json, true);
|
|
165
165
|
}
|
|
166
166
|
catch (error) {
|
|
167
167
|
const cause = failureCause(error);
|
|
168
|
+
const stderr = capturedStderr(error);
|
|
168
169
|
throw new CliError(`Could not install ${CLI_PACKAGE_NAME}@${version}.`, 'CARD_UPGRADE_FAILED', {
|
|
169
170
|
cause,
|
|
170
171
|
installCommand: installCommand(version, registry),
|
|
172
|
+
...(stderr ? { stderr } : {}),
|
|
173
|
+
hint: installFailureHint(stderr),
|
|
171
174
|
});
|
|
172
175
|
}
|
|
173
176
|
}
|
|
177
|
+
const NPM_PERMISSION_ERROR = /\b(EACCES|EPERM|EROFS)\b|permission denied|operation not permitted|read-only file system/i;
|
|
178
|
+
const NPM_NETWORK_ERROR = /\b(ENOTFOUND|ETIMEDOUT|ECONNREFUSED|ECONNRESET|EAI_AGAIN|ENETUNREACH|ERR_SOCKET_TIMEOUT)\b|network (request|error|timeout)|socket hang up/i;
|
|
179
|
+
/** What to do next after `npm install -g` failed, judged from what npm printed. */
|
|
180
|
+
export function installFailureHint(stderr) {
|
|
181
|
+
const text = stderr ?? '';
|
|
182
|
+
if (NPM_PERMISSION_ERROR.test(text)) {
|
|
183
|
+
return 'npm could not write to its global directory. Agents in a sandbox: rerun this command with write access outside the sandbox. Otherwise fix the permissions of the npm global prefix, or run installCommand yourself.';
|
|
184
|
+
}
|
|
185
|
+
if (NPM_NETWORK_ERROR.test(text)) {
|
|
186
|
+
return 'npm could not reach the registry. Agents in a sandbox: rerun this command with network access. Otherwise check the network or npm proxy settings.';
|
|
187
|
+
}
|
|
188
|
+
return 'See stderr for what npm reported. Agents in a sandbox: rerun this command with network access and write access outside the sandbox. Otherwise run installCommand yourself.';
|
|
189
|
+
}
|
|
190
|
+
const STDERR_TAIL_CHARS = 2000;
|
|
191
|
+
/** The end of what a failed child printed to stderr, when it was captured. */
|
|
192
|
+
function capturedStderr(error) {
|
|
193
|
+
const stderr = error instanceof CliError ? error.details?.stderr : undefined;
|
|
194
|
+
return typeof stderr === 'string' && stderr.trim() ? stderr.trim() : undefined;
|
|
195
|
+
}
|
|
174
196
|
async function refreshProjectSkills(parsed, useInstalledCli = false, json = false) {
|
|
175
197
|
const root = await findProjectRoot(getString(parsed, 'dir') || process.cwd()).catch(() => undefined);
|
|
176
198
|
if (!root) {
|
|
@@ -208,13 +230,23 @@ function runCapture(command, args) {
|
|
|
208
230
|
});
|
|
209
231
|
});
|
|
210
232
|
}
|
|
211
|
-
/**
|
|
212
|
-
|
|
233
|
+
/**
|
|
234
|
+
* With --json, child output goes to stderr so stdout stays one JSON document.
|
|
235
|
+
* With captureStderr, the child's stderr is still shown as it arrives, and its tail is kept
|
|
236
|
+
* on the error (details.stderr) so a failure can say what the child reported.
|
|
237
|
+
*/
|
|
238
|
+
export function runInherit(command, args, json = false, captureStderr = false) {
|
|
213
239
|
return new Promise((resolve, reject) => {
|
|
214
240
|
const run = commandInvocation(command, args);
|
|
241
|
+
const stderrTarget = captureStderr ? 'pipe' : json ? 2 : 'inherit';
|
|
215
242
|
const child = spawn(run.command, run.args, {
|
|
216
243
|
...run.options,
|
|
217
|
-
stdio: json ? ['ignore', 2,
|
|
244
|
+
stdio: json ? ['ignore', 2, stderrTarget] : ['inherit', 'inherit', stderrTarget],
|
|
245
|
+
});
|
|
246
|
+
let stderrTail = '';
|
|
247
|
+
child.stderr?.on('data', chunk => {
|
|
248
|
+
process.stderr.write(chunk);
|
|
249
|
+
stderrTail = (stderrTail + String(chunk)).slice(-STDERR_TAIL_CHARS);
|
|
218
250
|
});
|
|
219
251
|
child.on('error', error => {
|
|
220
252
|
reject(new CliError(`Failed to run ${command}.`, 'CARD_UPGRADE_FAILED', {
|
|
@@ -226,7 +258,7 @@ function runInherit(command, args, json = false) {
|
|
|
226
258
|
resolve();
|
|
227
259
|
return;
|
|
228
260
|
}
|
|
229
|
-
reject(new CliError(`${command} exited with ${code}.`, 'CARD_UPGRADE_FAILED'));
|
|
261
|
+
reject(new CliError(`${command} exited with ${code}.`, 'CARD_UPGRADE_FAILED', stderrTail.trim() ? { stderr: stderrTail } : undefined));
|
|
230
262
|
});
|
|
231
263
|
});
|
|
232
264
|
}
|