dsh-rp-card 1.7.12 → 1.7.13

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # 更新记录
2
2
 
3
+ ## 1.7.13
4
+
5
+ 新增头像与图像呈现工具 `card_avatar`。
6
+
7
+ - 新工具 `card_avatar`(`guide` / `css` / `check`):用户要求换头像、头像自定义、头像切换或多角色头像时启动;`guide` 输出纯净操作指南,`css` 生成覆盖平台头像位的 CSS,`check` 检查卡的 `built_in_css` / `pre_prompt` 是否实现覆盖与 `data-c` 切换。
8
+ - 新增 `lib/avatar.js`(纯函数,不调模型)与 `docs/supplements/头像呈现.md`(操作指南)。
9
+ - 系统提示词新增「头像与图像呈现」段:固定头像用 CSS 覆盖(不依赖 AI);多角色用 `data-who` 标记 + `:has([data-c])` 切换;玩家自定义复制到「自定义配置里的内置 CSS」;覆盖头像位需同时让内部 `img` 透明。
10
+ - 新增 `tests/avatar.test.mjs`(10 项);`inject.test.mjs` 工具清单同步;测试总数 137。
11
+
3
12
  ## 1.7.12
4
13
 
5
14
  档案页补平台容器与沙箱环境约束。
@@ -0,0 +1,91 @@
1
+ # 头像与图像呈现(card_avatar)
2
+
3
+ > 工具触发:用户要求「换头像 / 头像自定义 / 头像切换 / 多角色头像」。
4
+ > 动作:`guide`(操作指南)、`css`(生成覆盖 CSS)、`check`(自检卡的实现)。
5
+
6
+ ---
7
+
8
+ ## 一、先判断需求属于哪类
9
+
10
+ | 需求 | 做法 | 依赖 AI |
11
+ |---|---|---|
12
+ | 固定玩家头像 / 单角色 AI 头像 | CSS 直接覆盖平台头像位 | 否 |
13
+ | 多角色随说话人切换 | AI 输出 `data-who` 标记 + CSS `:has` 查表 | 是 |
14
+ | 玩家自己换图 | 生成 CSS,复制到「自定义配置里的内置 CSS」 | 否 |
15
+
16
+ **原则**:能固定的不交给 AI;只有「当前是谁」才用标记。
17
+
18
+ ---
19
+
20
+ ## 二、固定头像(最可靠,首选)
21
+
22
+ ```css
23
+ /* 玩家头像 */
24
+ #customized-question-avatar{
25
+ background-image:url("玩家头像.png") !important;
26
+ background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;
27
+ }
28
+ #customized-question-avatar img{opacity:0 !important;}
29
+
30
+ /* AI 头像(单角色) */
31
+ #customized-answer-avatar{
32
+ background-image:url("AI头像.png") !important;
33
+ background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;
34
+ }
35
+ #customized-answer-avatar img{opacity:0 !important;}
36
+ ```
37
+
38
+ 要点:容器设背景图,内部 `img` 透明;只改其一会出现旧图透出或布局跳动。
39
+
40
+ ---
41
+
42
+ ## 三、多角色头像切换
43
+
44
+ 1. 输出格式里要求 AI 每条消息前输出隐藏标记:
45
+
46
+ ```html
47
+ <span data-who data-c="角色标准名"></span>
48
+ ```
49
+
50
+ 2. CSS 隐藏标记并按角色切换:
51
+
52
+ ```css
53
+ #customized-answer [data-who]{ display:none !important; }
54
+
55
+ #customized-answer:has([data-c="角色A"]) #customized-answer-avatar{
56
+ background-image:url("A.png") !important;
57
+ background-size:cover !important;background-position:center !important;
58
+ }
59
+ #customized-answer:has([data-c="角色B"]) #customized-answer-avatar{
60
+ background-image:url("B.png") !important;
61
+ background-size:cover !important;background-position:center !important;
62
+ }
63
+ ```
64
+
65
+ 规则:
66
+
67
+ - `data-c` 必须与角色档案、状态栏、世界书角色名**逐字一致**;
68
+ - 必须保留默认头像(未命中标记时回落);
69
+ - 玩家自己的消息不输出标记;
70
+ - 一条消息只有一个头像位:同一轮出现多个角色时,拆成多条消息分别输出标记。
71
+
72
+ ---
73
+
74
+ ## 四、玩家自定义换图
75
+
76
+ 1. 玩家把图片上传到图床,拿到直链;
77
+ 2. 用 `card_avatar`(action=css)或卡前端生成 CSS;
78
+ 3. 复制 CSS,粘贴到平台的「**自定义配置里的内置 CSS**」,保存;
79
+ 4. 回到聊天页刷新查看。
80
+
81
+ 前端选图只能本地预览,无法上传;不要在卡里承诺自动上传。
82
+
83
+ ---
84
+
85
+ ## 五、验收清单
86
+
87
+ - 玩家头像打开即显示,AI 漏写不受影响;
88
+ - 单角色 AI 头像固定显示;
89
+ - 多角色消息头像各自切换,未命中时回落默认;
90
+ - `data-who` 标记在正文里不可见;
91
+ - 覆盖后平台其它 UI(按钮、输入框)未受影响。
package/index.js CHANGED
@@ -13,6 +13,7 @@ import { keyStatus } from './lib/image-setup.js';
13
13
  import { loadManifest } from './lib/assets.js';
14
14
  import { evaluateAction } from './lib/evaluate.js';
15
15
  import { reviewAction, REVIEW_ACTIONS } from './lib/review.js';
16
+ import { avatarAction, AVATAR_ACTIONS } from './lib/avatar.js';
16
17
  import { resolveVisionDelegate } from './lib/vision.js';
17
18
 
18
19
  // 视觉检查委托目标:环境变量 > profile 的 subagent 允许列表首个 DeepSeek 项 > 兜底。
@@ -1151,6 +1152,55 @@ export function apply(ctx) {
1151
1152
  }));
1152
1153
  });
1153
1154
 
1155
+ bindService(ctx, 'tools', (c, tools) => {
1156
+ c.effect(() => tools.register({
1157
+ name: 'card_avatar',
1158
+ description: '头像与图像呈现工具:用户要求「换头像 / 头像自定义 / 头像切换 / 多角色头像」时使用。动作:guide(纯净操作指南:固定头像、多角色切换、玩家自定义三步)→ css(根据玩家与 NPC 图片地址生成覆盖平台头像位的 CSS)→ check(检查卡的 built_in_css / pre_prompt 是否已实现头像覆盖与 data-c 切换)。工具不调模型,不改卡。',
1159
+ parameters: {
1160
+ type: 'object',
1161
+ properties: {
1162
+ action: { type: 'string', enum: AVATAR_ACTIONS, description: '动作:guide / css / check' },
1163
+ player_url: { type: 'string', description: 'css:玩家头像图片直链' },
1164
+ npc: {
1165
+ type: 'array',
1166
+ description: 'css:NPC 头像列表 [{ name: 角色标准名, url: 图片直链 }]',
1167
+ items: {
1168
+ type: 'object',
1169
+ properties: { name: { type: 'string' }, url: { type: 'string' } },
1170
+ required: ['name', 'url'],
1171
+ },
1172
+ },
1173
+ built_in_css: { type: 'string', description: 'check:卡的 built_in_css' },
1174
+ pre_prompt: { type: 'string', description: 'check:卡的 pre_prompt(输出格式)' },
1175
+ },
1176
+ required: ['action'],
1177
+ },
1178
+ output: {
1179
+ schema: {
1180
+ type: 'object',
1181
+ properties: { ok: { type: 'boolean' }, action: { type: 'string' }, output: { type: 'string' } },
1182
+ required: ['ok', 'action', 'output'],
1183
+ },
1184
+ render: (_args, value) => [
1185
+ { type: 'text', text: value && typeof value.output === 'string' ? value.output : JSON.stringify(value, null, 2) },
1186
+ ],
1187
+ },
1188
+ execute: async (args) => {
1189
+ const act = args && args.action ? String(args.action) : 'guide';
1190
+ try {
1191
+ const result = avatarAction({ ...(args || {}) });
1192
+ return {
1193
+ ok: true,
1194
+ action: act,
1195
+ output: result.guide ? result.guide : JSON.stringify(result, null, 2),
1196
+ };
1197
+ } catch (e) {
1198
+ return { ok: false, action: act, output: `错误:${e && e.message ? e.message : String(e)}` };
1199
+ }
1200
+ },
1201
+ }));
1202
+ });
1203
+
1154
1204
  bindService(ctx, 'tools', (c, tools) => {
1155
1205
  c.effect(() => tools.register({
1156
1206
  name: 'card_library',
@@ -1418,6 +1468,14 @@ export function apply(ctx) {
1418
1468
  '- 只做本次要求的事,不顺手重做整卡;改完回归主奴线三栏 / 自由人两栏 / 奴隶表 / 背包 / 声望块 / 折叠。',
1419
1469
  '- 用户只要评估不要改 → 走上传卡评估流程;不要为了改功能先跑完整 audit。',
1420
1470
  '',
1471
+ '## 头像与图像呈现(工具 card_avatar)',
1472
+ '触发:用户要求「换头像 / 头像自定义 / 头像切换 / 多角色头像」时,先调用 `card_avatar`(action=guide)拿操作指南,再按指南实现;实现后用 action=check 自检。',
1473
+ '- 固定头像(玩家 / 单角色 AI):CSS 覆盖 `#customized-question-avatar` / `#customized-answer-avatar`(容器背景图 + 内部 `img{opacity:0}`),**不依赖 AI**;',
1474
+ '- 多角色切换:输出格式要求每条消息前输出 `<span data-who data-c="角色标准名"></span>`,CSS 用 `:has([data-c="名字"])` 切换该条消息的头像位,并保留默认头像兜底;',
1475
+ '- 玩家自定义:用 `card_avatar`(action=css)生成覆盖 CSS,让玩家复制到平台的「**自定义配置里的内置 CSS**」——不要写成「自定义 CSS」;',
1476
+ '- `data-c` 必须与角色档案、状态栏、世界书的角色名逐字一致;一条消息只有一个头像位,多角色同屏时拆成多条消息;',
1477
+ '- 前端选图只能本地预览、无法上传;不要在卡里承诺自动上传或自动写入 CSS。',
1478
+ '',
1421
1479
  '## 教学模式(默认关闭)',
1422
1480
  '默认按正常节奏干活,不讲解原理。',
1423
1481
  '- 当用户说「我想学」「讲一下原理」「为什么这么做」「教我」时,开启教学模式:每一步多做三件事——这步在干什么、为什么这么做、换个做法会怎样;不改变实现,只增加解释。',
package/lib/avatar.js ADDED
@@ -0,0 +1,156 @@
1
+ /**
2
+ * 头像与图像呈现(card_avatar)
3
+ * 纯函数模块:不调模型、不读写卡;产出操作指南、CSS 片段与检查结论。
4
+ */
5
+
6
+ export const AVATAR_ACTIONS = ['guide', 'css', 'check'];
7
+
8
+ const cleanUrl = (s) => String(s || '').trim().replace(/["\\)\s]/g, '');
9
+
10
+ /** 生成「覆盖平台头像位」的 CSS 片段 */
11
+ export function buildAvatarCss({ player = '', npc = [] } = {}) {
12
+ const rules = [];
13
+ const p = cleanUrl(player);
14
+ if (p) {
15
+ rules.push(
16
+ '#customized-question-avatar{\n' +
17
+ ' background-image:url("' + p + '") !important;\n' +
18
+ ' background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;\n' +
19
+ '}\n' +
20
+ '#customized-question-avatar img{opacity:0 !important;}'
21
+ );
22
+ }
23
+ for (const item of Array.isArray(npc) ? npc : []) {
24
+ const url = cleanUrl(item && item.url);
25
+ const name = String((item && item.name) || '').trim();
26
+ if (!url || !name) continue;
27
+ rules.push(
28
+ '#customized-answer:has([data-c="' + name + '"]) #customized-answer-avatar{\n' +
29
+ ' background-image:url("' + url + '") !important;\n' +
30
+ ' background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;\n' +
31
+ '}'
32
+ );
33
+ }
34
+ return rules.join('\n\n');
35
+ }
36
+
37
+ /** 检查卡内头像实现状态 */
38
+ export function checkAvatarCard({ built_in_css = '', pre_prompt = '' } = {}) {
39
+ const css = String(built_in_css || '');
40
+ const ppt = String(pre_prompt || '');
41
+ const findings = [];
42
+ const suggestions = [];
43
+
44
+ const hasPlayer = css.includes('#customized-question-avatar');
45
+ const hasAnswer = css.includes('#customized-answer-avatar');
46
+ const hasSwitch = /:has\(\s*\[data-c=/i.test(css);
47
+ const hasMark = /data-who/i.test(css) || /data-who/i.test(ppt);
48
+ const hasImgTransparent = /#customized-(question|answer)-avatar\s+img\s*\{[^}]*opacity\s*:\s*0/i.test(css);
49
+
50
+ if (hasPlayer) findings.push('已覆盖玩家头像位');
51
+ if (hasAnswer) findings.push('已覆盖 AI 头像位');
52
+ if (hasSwitch) findings.push('已使用 :has([data-c]) 多角色切换');
53
+ if (hasMark) findings.push('已输出或隐藏 data-who 标记');
54
+ if (hasImgTransparent) findings.push('头像位内部 img 已透明');
55
+
56
+ if (!hasPlayer) suggestions.push('玩家头像固定:用 #customized-question-avatar 背景图覆盖,不依赖 AI');
57
+ if (!hasAnswer) suggestions.push('单角色 AI 头像固定:用 #customized-answer-avatar 背景图覆盖');
58
+ if (!hasSwitch && hasMark) suggestions.push('已有 data-who 标记,但缺少 :has([data-c]) 切换规则');
59
+ if (hasSwitch && !hasMark) suggestions.push('已有切换规则,但提示词里缺少 data-who 标记输出要求');
60
+ if ((hasPlayer || hasAnswer) && !hasImgTransparent) suggestions.push('覆盖头像位时需同时让内部 img 透明(opacity:0),否则旧头像会透出');
61
+ if (!suggestions.length && (hasPlayer || hasAnswer)) suggestions.push('实现符合规范:固定头像不依赖 AI,多角色切换用 data-c');
62
+
63
+ return { findings, suggestions, flags: { hasPlayer, hasAnswer, hasSwitch, hasMark, hasImgTransparent } };
64
+ }
65
+
66
+ /** 纯净操作指南(面向玩家/写卡者,不含测试内容) */
67
+ export function avatarGuide() {
68
+ return [
69
+ '# 头像与图像呈现 · 操作指南',
70
+ '',
71
+ '## 适用场景',
72
+ '用户要求「换头像 / 头像自定义 / 头像切换 / 多角色头像」时使用本指南。',
73
+ '',
74
+ '## 一、先判断需求属于哪类',
75
+ '',
76
+ '| 需求 | 做法 | 依赖 AI |',
77
+ '|---|---|---|',
78
+ '| 固定玩家头像 / 单角色 AI 头像 | CSS 直接覆盖平台头像位 | 否 |',
79
+ '| 多角色随说话人切换 | AI 输出 data-who 标记 + CSS :has 查表 | 是 |',
80
+ '| 玩家自己换图 | 生成 CSS,复制到「自定义配置里的内置 CSS」 | 否 |',
81
+ '',
82
+ '## 二、固定头像(最可靠,首选)',
83
+ '',
84
+ '```css',
85
+ '/* 玩家头像 */',
86
+ '#customized-question-avatar{',
87
+ ' background-image:url("玩家头像.png") !important;',
88
+ ' background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;',
89
+ '}',
90
+ '#customized-question-avatar img{opacity:0 !important;}',
91
+ '',
92
+ '/* AI 头像(单角色) */',
93
+ '#customized-answer-avatar{',
94
+ ' background-image:url("AI头像.png") !important;',
95
+ ' background-size:cover !important;background-position:center !important;background-repeat:no-repeat !important;',
96
+ '}',
97
+ '#customized-answer-avatar img{opacity:0 !important;}',
98
+ '```',
99
+ '',
100
+ '要点:容器设背景图,内部 img 透明;只改其一会出现旧图透出或布局跳动。',
101
+ '',
102
+ '## 三、多角色头像切换',
103
+ '',
104
+ '1. 在输出格式里要求 AI 每条消息前输出隐藏标记:',
105
+ '',
106
+ '```html',
107
+ '<span data-who data-c="角色标准名"></span>',
108
+ '```',
109
+ '',
110
+ '2. CSS 里隐藏标记并按角色切换:',
111
+ '',
112
+ '```css',
113
+ '#customized-answer [data-who]{ display:none !important; }',
114
+ '#customized-answer:has([data-c="角色A"]) #customized-answer-avatar{ background-image:url("A.png") !important; }',
115
+ '#customized-answer:has([data-c="角色B"]) #customized-answer-avatar{ background-image:url("B.png") !important; }',
116
+ '```',
117
+ '',
118
+ '规则:',
119
+ '- data-c 必须与角色档案、状态栏、世界书的角色名逐字一致;',
120
+ '- 必须保留默认头像(未命中标记时回落);',
121
+ '- 玩家自己的消息不输出标记;',
122
+ '- 一条消息只有一个头像位:同一轮出现多个角色时,拆成多条消息分别输出标记。',
123
+ '',
124
+ '## 四、玩家自定义换图',
125
+ '',
126
+ '1. 玩家把图片上传到图床,拿到直链;',
127
+ '2. 在卡前端或本工具生成 CSS;',
128
+ '3. 复制 CSS,粘贴到平台的「**自定义配置里的内置 CSS**」,保存;',
129
+ '4. 回到聊天页刷新查看。',
130
+ '',
131
+ '前端选图只能本地预览,无法上传;不要在卡里承诺自动上传。',
132
+ '',
133
+ '## 五、验收清单',
134
+ '',
135
+ '- 玩家头像打开即显示,AI 漏写不受影响;',
136
+ '- 单角色 AI 头像固定显示;',
137
+ '- 多角色消息头像各自切换,未命中时回落默认;',
138
+ '- data-who 标记在正文里不可见;',
139
+ '- 覆盖后平台其它 UI(按钮、输入框)未受影响。',
140
+ ].join('\n');
141
+ }
142
+
143
+ /** 工具动作分发 */
144
+ export function avatarAction(args = {}) {
145
+ const action = String(args.action || 'guide');
146
+ if (action === 'guide') return { action, guide: avatarGuide() };
147
+ if (action === 'css') {
148
+ const css = buildAvatarCss({ player: args.player_url || '', npc: args.npc || [] });
149
+ return { action, css, note: css ? '复制到「自定义配置里的内置 CSS」' : '未提供图片地址' };
150
+ }
151
+ if (action === 'check') {
152
+ const result = checkAvatarCard({ built_in_css: args.built_in_css || '', pre_prompt: args.pre_prompt || '' });
153
+ return { action, ...result };
154
+ }
155
+ throw new Error(`未知动作:${action}(可用:${AVATAR_ACTIONS.join(' / ')})`);
156
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-rp-card",
3
- "version": "1.7.12",
3
+ "version": "1.7.13",
4
4
  "type": "module",
5
5
  "description": "DeepSeek Harness 插件:按四部分流程创作 RP 卡,含世界书规则层、人工门禁、图像能力设置、上传卡评估与平台组装。",
6
6
  "main": "index.js",