@oxmumu3/dsh-plugin-finder 0.13.1 → 0.13.3

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.
@@ -1,6 +1,5 @@
1
- // 创造模式进度条:挂在创造模式会话输入框上方(conversation.input.dock),只在 cordis 会话、且经验开启时出现。
2
- // 数据来自 Host 的阶段记录(创造会话里的 finder_creator_step 工具),不轮询:工具调用或一轮结束时刷新。
3
- // 外观按 v8 设计稿的陪做条(SPEC 5.11):三种状态、五步一行、颜色之外每步都写着名字。
1
+ // 创造模式向导条 v2:挂在创造模式会话输入框上方(conversation.input.dock),只在 cordis 会话、且经验开启时出现。
2
+ // 数据来自 Host 的阶段记录(finder_creator_step 工具)与实时事件流,不轮询;默认收成单行引导条,展开后显示阶段轨迹与人读锦囊。
4
3
  const STAGES = [
5
4
  { id: 'search', label: '查现成' },
6
5
  { id: 'design', label: '定设计' },
@@ -10,12 +9,131 @@ const STAGES = [
10
9
  ];
11
10
  const ORDER = Object.fromEntries(STAGES.map((stage, index) => [stage.id, index]));
12
11
  const LABEL = { ...Object.fromEntries(STAGES.map(stage => [stage.id, stage.label])), blocked: '卡住了' };
13
- // What a user reads. The internal labels are shorthand for logs and handoff text.
14
12
  const PLAIN = {
15
- search: '先看看有没有现成的', design: '说清怎么做', skeleton: '先搭个能打开的',
16
- feature: '一次加一个功能', verify: '跑一遍确认', blocked: '卡住了',
13
+ search: '先看看有没有现成的',
14
+ design: '先对齐 3 句话方案',
15
+ skeleton: '先搭能点开的空架子',
16
+ feature: '一次只加一个核心功能',
17
+ verify: '按提示刷新核对实效',
18
+ blocked: '卡住了',
17
19
  };
18
- const BRICK = 'M3 7H3.4V5.3a1.1 1.1 0 0 1 1.1-1.1h3a1.1 1.1 0 0 1 1.1 1.1V7h2.8V5.3a1.1 1.1 0 0 1 1.1-1.1h3a1.1 1.1 0 0 1 1.1 1.1V7H17a3 3 0 0 1 3 3v7a3 3 0 0 1-3 3H3a3 3 0 0 1-3-3v-7a3 3 0 0 1 3-3Z';
20
+ const STAGE_SHORT = Object.freeze({
21
+ search: '查现成',
22
+ design: '定方案',
23
+ skeleton: '搭架子',
24
+ feature: '加功能',
25
+ verify: '待验收',
26
+ });
27
+ const STAGE_HINTS = Object.freeze({
28
+ search: '有现成插件优先复用,确实没有再自己造',
29
+ design: '先确认挂在哪、平时怎么用,再让它写代码',
30
+ skeleton: '先点开看位置和入口没白屏,先不管细节',
31
+ feature: '看一眼刚加的功能顺不顺手,一次只改一处',
32
+ verify: '按 ⌘R 刷新看实效(改了后台或工具需退出重开 DSH)',
33
+ });
34
+
35
+ // 给「人类用户」看的分步锦囊(不放给 AI 看的 SDK 内部实现细节)
36
+ const STAGE_LESSONS = Object.freeze({
37
+ search: [
38
+ '先搜社区现成插件能省掉大量重复造轮子;真没有现成的,也可挑最接近的让 AI 照着改。',
39
+ '聊完发现现成的就能用时,直接装现成插件最稳。',
40
+ ],
41
+ design: [
42
+ '动手前只对齐三件事:入口挂在哪(侧栏、顶部标签还是悬浮窗)、占多大空间、数据存哪。',
43
+ '首版砍掉锦上添花的功能,越聚焦越容易一次做成。',
44
+ ],
45
+ skeleton: [
46
+ '第一版只要能点开、不白屏、位置顺眼就算过关,别一口气塞满所有功能。',
47
+ '入口位置如果不顺手,趁现在还没堆逻辑时换位置最轻松。',
48
+ ],
49
+ feature: [
50
+ '每次只提 1–2 个具体调整(如“压小字号”“只留三项指标”),比一次改十处稳得多。',
51
+ '每加完一块都顺手点一下,确认没把上一版做好的地方改坏。',
52
+ ],
53
+ verify: [
54
+ '只改界面样式按 ⌘R 即可生效;新加了工具、后台接口或重装同名插件,需 ⌘Q 退出重开 DSH。',
55
+ '顺手切一下深色/浅色和窄窗口,看有没有挤爆、遮挡或看不清的字。',
56
+ ],
57
+ blocked: [
58
+ '同一问题连改三轮没好,继续在长对话里硬磨只会越改越乱、越花越多 Token;带进展换干净窗口最划算。',
59
+ ],
60
+ });
61
+
62
+ const STARTER_CHIPS = Object.freeze([
63
+ {
64
+ label: '先查有没有现成的',
65
+ prompt: '我想做一个功能:___。先别急着写代码,请先用 finder_search 查查社区有没有现成或相近的插件。',
66
+ },
67
+ {
68
+ label: '先对齐 3 句话方案',
69
+ prompt: '我想自己做一个小插件:___。先别写代码,请用三五句大白话跟我确认入口挂在哪、怎么交互、数据存哪。',
70
+ },
71
+ {
72
+ label: '搭最小可点开初版',
73
+ prompt: '我想做:___。第一版请只搭一个最小能点开、不白屏的空架子,我确认位置顺眼后再逐个加功能。',
74
+ },
75
+ ]);
76
+
77
+ const STAGE_CHIPS = Object.freeze({
78
+ search: {
79
+ primary: {
80
+ label: '自己造 · 先定 3 句方案',
81
+ prompt: '现成插件不完全合适,我们自己做一个轻量版。先别写代码,请用三五句大白话跟我确认入口挂在哪、平时怎么用、数据存哪。',
82
+ },
83
+ secondary: {
84
+ label: '挑最接近的照着改',
85
+ prompt: '请挑一个结构最接近的现成插件参考它的挂载方式,按我的需求精简重做一版。',
86
+ },
87
+ },
88
+ design: {
89
+ primary: {
90
+ label: '方案可以 · 先搭空架子',
91
+ prompt: '这个方案可以,第一版请先搭一个最小能点开、不白屏的空架子,先不塞复杂逻辑。',
92
+ },
93
+ secondary: {
94
+ label: '再压精简一点',
95
+ prompt: '首版还可以再精简一点,只保留最核心的一项能力:',
96
+ },
97
+ },
98
+ skeleton: {
99
+ primary: {
100
+ label: '架子 OK · 加核心功能',
101
+ prompt: '入口我已经点开确认正常了,现在请只加上最核心的第一个功能:',
102
+ },
103
+ secondary: {
104
+ label: '怎么刷新看效果?',
105
+ prompt: '请告诉我这一步只需要按 Cmd+R 刷新界面,还是需要彻底退出重开 DSH?',
106
+ },
107
+ },
108
+ feature: {
109
+ primary: {
110
+ label: '自查深浅色与窄窗口',
111
+ prompt: '请帮我检查一下当前界面在深色/浅色主题和窄窗口下的排版、对比度与溢出情况。',
112
+ },
113
+ secondary: {
114
+ label: '微调交互与细节',
115
+ prompt: '刚加的功能我看了一眼,想微调一处细节:',
116
+ },
117
+ },
118
+ verify: {
119
+ primary: {
120
+ label: '微调样式与精简度',
121
+ prompt: '我看了一眼当前效果,想微调一下视觉样式和信息精简度:',
122
+ },
123
+ secondary: {
124
+ label: '把踩坑记入经验库',
125
+ prompt: '请把这次制作过程中值得复用的避坑点调用 finder_creator_note 记入插件经验。',
126
+ },
127
+ },
128
+ blocked: {
129
+ primary: {
130
+ label: '先总结试过什么与卡点',
131
+ prompt: '先停一下别改代码了:请用三句话总结刚才试过了什么、具体卡在哪个现象,方便我判断或换新窗口继续。',
132
+ },
133
+ },
134
+ });
135
+
136
+ const SPARK_PATH = 'M10 2.25 11.9 7.1l4.85 1.9-4.85 1.9L10 15.75l-1.9-4.85-4.85-1.9 4.85-1.9L10 2.25Z';
19
137
  const text = value => typeof value === 'string' ? value : '';
20
138
  export const CREATOR_PRESET = 'cordis';
21
139
 
@@ -31,12 +149,16 @@ export function creatorProgress(steps) {
31
149
  const last = rows.at(-1) ?? null;
32
150
  // Only a recorded stage counts as done; an earlier stage with no record is shown as skipped, not completed.
33
151
  return {
34
- stages: STAGES.map((stage, index) => ({ ...stage, plain: PLAIN[stage.id], state: index === furthest ? 'current' : index > furthest ? 'todo' : recorded.has(stage.id) ? 'done' : 'skipped' })),
152
+ stages: STAGES.map((stage, index) => ({
153
+ ...stage,
154
+ plain: PLAIN[stage.id],
155
+ state: index === furthest ? 'current' : index > furthest ? 'todo' : recorded.has(stage.id) ? 'done' : 'skipped',
156
+ })),
35
157
  last: last ? { stage: last.stage, label: LABEL[last.stage], summary: text(last.summary) } : null,
36
158
  blocked: last?.stage === 'blocked',
37
159
  blockedStep: recordedStep,
38
160
  count: rows.length,
39
- reached: Math.max(0, STAGES.filter((stage, index) => index <= furthest).length),
161
+ reached: Math.max(0, STAGES.filter((_, index) => index <= furthest).length),
40
162
  };
41
163
  }
42
164
 
@@ -52,191 +174,520 @@ export function creatorHandoffPrompt(steps) {
52
174
  ].join('\n');
53
175
  }
54
176
 
55
- const STAGE_LESSONS = Object.freeze({
56
- search: [
57
- '写代码前先用 cordis_inspect 查展位和接口,找结构相近的已跑通插件照着改。',
58
- '只读宿主包里的 api-catalog 和 slots 定义,不凭记忆猜接口。',
59
- ],
60
- design: [
61
- '动手前用三五句大白话对齐:挂在哪、几个文件、数据存哪。',
62
- '可选服务写进 inject,状态收在一个地方,写接口拒绝跨站请求。',
63
- ],
64
- skeleton: [
65
- '第一版只做能点开、不白屏的空架子,所有注册放进 ctx.effect。',
66
- 'main 面板用 flex 撑满并自己当滚动口;React 用宿主那份,不引宿主 UI 包。',
67
- ],
68
- feature: [
69
- '一轮只加一个功能;@container 量自身宽度,颜色只用 --dsw-alias-* 变量。',
70
- '按钮和模型工具走同一套实现;客户端入口包进 window.__ModuleLoader__.load。',
71
- ],
72
- verify: [
73
- '先打包并在浅色/深色/窄屏下量真实渲染,再进隔离宿主真点开验。',
74
- '弹窗和列表行必须有状态文字,不单靠颜色;换包后彻底退出桌面端重开。',
75
- ],
76
- blocked: [
77
- '同一问题连改三轮没好就停下来写清尝试和卡点,开干净窗口接着做。',
78
- ],
79
- });
177
+ /** 将向导引导语安全填入或追加到当前输入框草稿中,绝不覆盖用户未发文字,必要时回退剪贴板。 */
178
+ export async function applyCreatorPrompt({ ctx, sessionId, inputActions } = {}, prompt) {
179
+ const value = text(prompt).trim();
180
+ if (!value) return 'noop';
181
+ if (typeof inputActions?.captureInsertion === 'function' && typeof inputActions?.insertText === 'function') {
182
+ try {
183
+ const span = inputActions.captureInsertion();
184
+ const prefix = span && Number.isInteger(span.start) && span.start > 0 && span.start === span.end ? '\n' : '';
185
+ if (inputActions.insertText(prefix + value, span)) {
186
+ try {
187
+ const editor = globalThis.document?.querySelector?.('[data-composer-seat] [contenteditable="true"], [data-composer-seat] textarea');
188
+ editor?.focus?.();
189
+ } catch { /* 聚焦为尽善体验,失败不影响已写入的草稿 */ }
190
+ return 'inserted';
191
+ }
192
+ } catch { /* 回退到底层会话草稿或剪贴板 */ }
193
+ }
194
+ try {
195
+ const binding = sessionId ? ctx?.sessions?.binding?.(sessionId) : null;
196
+ const convInput = binding?.ctx?.get?.('conversation', false)?.input;
197
+ if (typeof convInput?.requestDraftInitialization === 'function') {
198
+ const status = convInput.requestDraftInitialization(binding, {
199
+ prompt: value,
200
+ whenDraftExists: 'append',
201
+ clearPreviousDraft: false,
202
+ });
203
+ if (status === 'applied') return 'inserted';
204
+ }
205
+ } catch { /* 回退到剪贴板 */ }
206
+ try {
207
+ if (typeof globalThis.navigator?.clipboard?.writeText === 'function') {
208
+ await globalThis.navigator.clipboard.writeText(value);
209
+ return 'copied';
210
+ }
211
+ } catch { /* 无剪贴板权限 */ }
212
+ return 'unavailable';
213
+ }
80
214
 
81
215
  const css = `
82
- .pfc_dock, .pfc_closed { box-sizing: border-box; color-scheme: light dark;
216
+ .pfc_dock, .pfc_closed {
217
+ box-sizing: border-box;
218
+ container-type: inline-size;
219
+ container-name: pfc-dock;
220
+ color-scheme: light dark;
83
221
  --pfc_ink: var(--dsw-alias-label-primary, #191b1f);
84
222
  --pfc_ink2: var(--dsw-alias-label-secondary, #4b5058);
85
223
  --pfc_ink3: var(--dsw-alias-label-tertiary, #868c95);
86
- --pfc_card: var(--dsw-alias-bg-layer-2, #ffffff);
87
- --pfc_line: var(--dsw-alias-border-l2, #e7e7e2);
88
- --pfc_line2: var(--dsw-alias-border-l4, #d0d0c9);
89
- --pfc_build: var(--dsw-alias-state-warn-primary, #dd8500);
224
+ --pfc_card: var(--dsw-specific-menu, var(--dsw-alias-bg-layer-2, #ffffff));
225
+ --pfc_chip_bg: var(--dsw-alias-fill-l2, rgba(25, 27, 31, 0.05));
226
+ --pfc_chip_hover: var(--dsw-alias-fill-l3, rgba(25, 27, 31, 0.09));
227
+ --pfc_line: var(--dsw-alias-border-l1, rgba(25, 27, 31, 0.08));
228
+ --pfc_line2: var(--dsw-alias-border-l3, rgba(25, 27, 31, 0.16));
229
+ --pfc_accent: var(--dsw-alias-brand-primary, #4b83f0);
230
+ --pfc_build: var(--dsw-alias-state-warn-primary, #d97706);
90
231
  --pfc_ok: var(--dsw-alias-state-success-primary, #2fa36b);
91
232
  --pfc_primary: var(--dsw-alias-button-primary-fill, #191b1f);
92
233
  --pfc_on_primary: var(--dsw-alias-label-primary-inverted, #ffffff);
93
- --pfc_serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", Georgia, serif;
94
234
  --pfc_sans: var(--dsw-font-family, -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif);
95
- font-family: var(--pfc_sans); color: var(--pfc_ink); }
235
+ width: calc(100% - var(--dsh-composer-side-clearance, 0px) - var(--dsh-composer-side-clearance, 0px) - var(--dsh-composer-dock-inset, 0px) - var(--dsh-composer-dock-inset, 0px) - var(--dsh-composer-dock-inset, 0px) - var(--dsh-composer-dock-inset, 0px));
236
+ max-width: calc(var(--dsh-composer-card-max-width, 768px) - var(--dsh-composer-dock-inset, 0px) - var(--dsh-composer-dock-inset, 0px) - var(--dsh-composer-dock-inset, 0px) - var(--dsh-composer-dock-inset, 0px));
237
+ margin: 0 auto 6px;
238
+ border-radius: var(--dsw-radius-lg, 12px);
239
+ border: 1px solid var(--pfc_line);
240
+ background: var(--pfc_card);
241
+ backdrop-filter: var(--dsw-menu-backdrop-filter, blur(16px));
242
+ box-shadow: var(--dsw-elevation-panel, 0 2px 8px rgba(0, 0, 0, 0.06));
243
+ font-family: var(--pfc_sans);
244
+ color: var(--pfc_ink);
245
+ overflow: hidden;
246
+ }
96
247
  :where(.pfc_dock, .pfc_closed)[data-theme="dark"], .dark :where(.pfc_dock, .pfc_closed) {
97
248
  --pfc_ink: var(--dsw-alias-label-primary, #eceded);
98
249
  --pfc_ink2: var(--dsw-alias-label-secondary, #b5b9bf);
99
250
  --pfc_ink3: var(--dsw-alias-label-tertiary, #7e848d);
100
- --pfc_card: var(--dsw-alias-bg-layer-2, #1d1f22);
101
- --pfc_line: var(--dsw-alias-border-l2, #2a2c30);
102
- --pfc_line2: var(--dsw-alias-border-l4, #3b3e43);
251
+ --pfc_card: var(--dsw-specific-menu, var(--dsw-alias-bg-layer-2, rgba(31, 33, 38, 0.92)));
252
+ --pfc_chip_bg: var(--dsw-alias-fill-l2, rgba(255, 255, 255, 0.07));
253
+ --pfc_chip_hover: var(--dsw-alias-fill-l3, rgba(255, 255, 255, 0.12));
254
+ --pfc_line: var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.08));
255
+ --pfc_line2: var(--dsw-alias-border-l3, rgba(255, 255, 255, 0.16));
256
+ --pfc_accent: var(--dsw-alias-brand-primary, #6c9ef8);
103
257
  --pfc_build: var(--dsw-alias-state-warn-primary, #f0a530);
104
258
  --pfc_ok: var(--dsw-alias-state-success-primary, #4cc38a);
105
259
  --pfc_primary: var(--dsw-alias-button-primary-fill, #eceded);
106
260
  --pfc_on_primary: var(--dsw-alias-label-primary-inverted, #141517);
261
+ box-shadow: var(--dsw-elevation-panel, 0 2px 10px rgba(0, 0, 0, 0.28));
107
262
  }
108
263
  @media (prefers-color-scheme: dark) {
109
264
  :where(.pfc_dock, .pfc_closed):not([data-theme="light"]) {
110
265
  --pfc_ink: var(--dsw-alias-label-primary, #eceded);
111
266
  --pfc_ink2: var(--dsw-alias-label-secondary, #b5b9bf);
112
267
  --pfc_ink3: var(--dsw-alias-label-tertiary, #7e848d);
113
- --pfc_card: var(--dsw-alias-bg-layer-2, #1d1f22);
114
- --pfc_line: var(--dsw-alias-border-l2, #2a2c30);
115
- --pfc_line2: var(--dsw-alias-border-l4, #3b3e43);
268
+ --pfc_card: var(--dsw-specific-menu, var(--dsw-alias-bg-layer-2, rgba(31, 33, 38, 0.92)));
269
+ --pfc_chip_bg: var(--dsw-alias-fill-l2, rgba(255, 255, 255, 0.07));
270
+ --pfc_chip_hover: var(--dsw-alias-fill-l3, rgba(255, 255, 255, 0.12));
271
+ --pfc_line: var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.08));
272
+ --pfc_line2: var(--dsw-alias-border-l3, rgba(255, 255, 255, 0.16));
273
+ --pfc_accent: var(--dsw-alias-brand-primary, #6c9ef8);
116
274
  --pfc_build: var(--dsw-alias-state-warn-primary, #f0a530);
117
275
  --pfc_ok: var(--dsw-alias-state-success-primary, #4cc38a);
118
276
  --pfc_primary: var(--dsw-alias-button-primary-fill, #eceded);
119
277
  --pfc_on_primary: var(--dsw-alias-label-primary-inverted, #141517);
120
278
  }
121
279
  }
122
- .pfc_dock { width: 100%; margin: 0 0 8px; padding: 16px 20px 18px; border: 1px solid var(--pfc_line2); border-radius: 20px; background: var(--pfc_card); }
123
- .pfc_dock[data-stuck="true"] { border-color: var(--pfc_build); }
124
- .pfc_hd { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
125
- .pfc_hd b { font: 400 18px/1.4 var(--pfc_serif); }
126
- .pfc_brick { width: 24px; height: 24px; flex: none; margin: -2px 0 -2px -2px; overflow: visible; }
127
- .pfc_brick path { fill: color-mix(in srgb, var(--pfc_build) 9%, transparent); stroke: var(--pfc_build); stroke-width: 1.3; stroke-dasharray: 2.6 2.3; stroke-linecap: round; stroke-linejoin: round; }
128
- .pfc_hd .pfc_steps_link { margin-left: auto; }
129
- .pfc_dock p { margin: 6px 0 0; font-size: 14px; line-height: 1.7; color: var(--pfc_ink2); }
130
- .pfc_dock p b { color: var(--pfc_ink); font-weight: 500; }
131
- .pfc_five { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 3px; margin-top: 14px; }
132
- .pfc_five div { min-width: 0; padding-right: 8px; }
133
- .pfc_five i { display: block; height: 5px; border-radius: 3px; background: var(--pfc_line); }
280
+
281
+ .pfc_dock[data-compact="true"] { padding: 5px 10px; }
282
+ .pfc_dock:not([data-compact="true"]) { padding: 10px 14px; }
283
+ .pfc_dock[data-stuck="true"] { border-color: color-mix(in srgb, var(--pfc_build) 52%, var(--pfc_line)); }
284
+
285
+ .pfc_bar { display: flex; align-items: center; gap: 8px; min-height: 26px; }
286
+ .pfc_bar_toggle {
287
+ flex: 1 1 0;
288
+ min-width: 0;
289
+ display: flex;
290
+ align-items: center;
291
+ gap: 8px;
292
+ padding: 2px 4px;
293
+ border: 0;
294
+ border-radius: 7px;
295
+ background: transparent;
296
+ color: inherit;
297
+ font: inherit;
298
+ text-align: left;
299
+ cursor: pointer;
300
+ }
301
+ .pfc_bar_toggle:hover:not(:disabled) { background: var(--pfc_chip_bg); }
302
+
303
+ .pfc_mini_steps { display: inline-flex; align-items: center; gap: 3px; flex: none; }
304
+ .pfc_mini_steps i { display: block; width: 14px; height: 4px; border-radius: 999px; background: var(--pfc_line2); }
305
+ .pfc_mini_steps .is_done { background: var(--pfc_ok); }
306
+ .pfc_mini_steps .is_skipped { background: color-mix(in srgb, var(--pfc_ok) 36%, var(--pfc_line2)); }
307
+ .pfc_mini_steps .is_current { background: var(--pfc_accent); }
308
+ .pfc_dock[data-stage="verify"][data-running="false"] .pfc_mini_steps .is_current { background: var(--pfc_ok); }
309
+ .pfc_dock[data-stuck="true"] .pfc_mini_steps .is_current { background: var(--pfc_build); }
310
+ .pfc_mini_steps .is_current.is_running { background: var(--pfc_accent); }
311
+
312
+ .pfc_badge { font-size: 12px; font-weight: 600; line-height: 18px; color: var(--pfc_ink); white-space: nowrap; flex: none; }
313
+ .pfc_hint {
314
+ min-width: 0;
315
+ flex: 1 1 auto;
316
+ font-size: 12.5px;
317
+ line-height: 18px;
318
+ color: var(--pfc_ink2);
319
+ overflow: hidden;
320
+ text-overflow: ellipsis;
321
+ white-space: nowrap;
322
+ }
323
+ .pfc_bar_actions { display: flex; align-items: center; gap: 4px; flex: none; }
324
+
325
+ .pfc_chip {
326
+ box-sizing: border-box;
327
+ height: 26px;
328
+ padding: 0 10px;
329
+ border-radius: 999px;
330
+ border: 1px solid var(--pfc_line);
331
+ background: var(--pfc_chip_bg);
332
+ color: var(--pfc_ink);
333
+ font: inherit;
334
+ font-size: 12px;
335
+ font-weight: 500;
336
+ line-height: 24px;
337
+ white-space: nowrap;
338
+ cursor: pointer;
339
+ }
340
+ .pfc_chip:hover:not(:disabled) { background: var(--pfc_chip_hover); border-color: var(--pfc_line2); }
341
+ .pfc_chip:disabled { opacity: 0.45; cursor: default; }
342
+
343
+ .pfc_icon_btn {
344
+ box-sizing: border-box;
345
+ width: 24px;
346
+ height: 24px;
347
+ padding: 0;
348
+ border: 0;
349
+ border-radius: 6px;
350
+ background: transparent;
351
+ color: var(--pfc_ink3);
352
+ display: inline-flex;
353
+ align-items: center;
354
+ justify-content: center;
355
+ cursor: pointer;
356
+ flex: none;
357
+ }
358
+ .pfc_icon_btn:hover:not(:disabled) { background: var(--pfc_chip_bg); color: var(--pfc_ink); }
359
+ .pfc_icon_btn:disabled { opacity: 0.45; cursor: default; }
360
+
361
+ .pfc_hd { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 24px; }
362
+ .pfc_hd b { font-size: 13px; font-weight: 600; line-height: 20px; color: var(--pfc_ink); }
363
+ .pfc_sub { font-size: 12.5px; line-height: 18px; color: var(--pfc_ink2); flex: 1 1 200px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
364
+ .pfc_hd_tools { display: flex; align-items: center; gap: 6px; margin-left: auto; flex: none; }
365
+ .pfc_spark { width: 15px; height: 15px; flex: none; color: var(--pfc_accent); }
366
+ .pfc_stuck_dot { width: 7px; height: 7px; border-radius: 50%; background: var(--pfc_build); flex: none; }
367
+
368
+ .pfc_chip_row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
369
+ .pfc_stuck_note { margin: 6px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--pfc_ink2); }
370
+
371
+ .pfc_dock .pfc_button, .pfc_closed .pfc_button {
372
+ box-sizing: border-box;
373
+ height: 28px;
374
+ padding: 0 12px;
375
+ border-radius: 999px;
376
+ border: 1px solid var(--pfc_line2);
377
+ background: transparent;
378
+ color: var(--pfc_ink);
379
+ font: inherit;
380
+ font-size: 12.5px;
381
+ font-weight: 500;
382
+ cursor: pointer;
383
+ }
384
+ .pfc_dock .pfc_button:hover:not(:disabled), .pfc_closed .pfc_button:hover:not(:disabled) { background: var(--pfc_chip_bg); }
385
+ .pfc_dock .pfc_button[data-primary="true"] { border-color: var(--pfc_primary); background: var(--pfc_primary); color: var(--pfc_on_primary); }
386
+ .pfc_dock .pfc_button[data-primary="true"]:hover:not(:disabled) { opacity: 0.9; background: var(--pfc_primary); }
387
+ .pfc_dock .pfc_button:disabled, .pfc_closed .pfc_button:disabled { opacity: 0.45; cursor: default; }
388
+
389
+ .pfc_dock .pfc_ghost, .pfc_closed .pfc_ghost {
390
+ box-sizing: border-box;
391
+ height: 24px;
392
+ padding: 0 8px;
393
+ border: 0;
394
+ border-radius: 6px;
395
+ background: transparent;
396
+ color: var(--pfc_ink3);
397
+ font: inherit;
398
+ font-size: 12px;
399
+ line-height: 24px;
400
+ text-decoration: none;
401
+ cursor: pointer;
402
+ white-space: nowrap;
403
+ }
404
+ .pfc_dock .pfc_ghost:hover:not(:disabled), .pfc_closed .pfc_ghost:hover:not(:disabled) { background: var(--pfc_chip_bg); color: var(--pfc_ink); }
405
+ .pfc_dock .pfc_ghost:disabled, .pfc_closed .pfc_ghost:disabled { opacity: 0.45; cursor: default; }
406
+
407
+ .pfc_drawer { margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--pfc_line); display: flex; flex-direction: column; gap: 10px; }
408
+ .pfc_five { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
409
+ .pfc_five div { min-width: 0; }
410
+ .pfc_five i { display: block; height: 4px; border-radius: 999px; background: var(--pfc_line2); }
134
411
  .pfc_five .is_done i { background: var(--pfc_ok); }
135
- .pfc_five .is_current i { background: var(--pfc_build); }
136
- .pfc_five span { display: block; margin-top: 6px; font-size: 12px; line-height: 1.45; color: var(--pfc_ink3); }
412
+ .pfc_five .is_skipped i { background: color-mix(in srgb, var(--pfc_ok) 36%, var(--pfc_line2)); }
413
+ .pfc_five .is_current i { background: var(--pfc_accent); }
414
+ .pfc_dock[data-stage="verify"][data-running="false"] .pfc_five .is_current i { background: var(--pfc_ok); }
415
+ .pfc_dock[data-stuck="true"] .pfc_five .is_current i { background: var(--pfc_build); }
416
+ .pfc_five span { display: block; margin-top: 5px; font-size: 11.5px; line-height: 1.35; color: var(--pfc_ink3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
137
417
  .pfc_five .is_done span { color: var(--pfc_ink2); }
418
+ .pfc_five .is_skipped span { color: var(--pfc_ink3); }
138
419
  .pfc_five .is_current span { color: var(--pfc_ink); font-weight: 600; }
139
- .pfc_acts { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 16px; }
140
- .pfc_dock .pfc_button, .pfc_closed .pfc_button { box-sizing: border-box; font: inherit; font-size: 13px; height: 32px; padding: 0 16px; border-radius: 16px; border: 1px solid var(--pfc_line2);
141
- background: transparent; color: var(--pfc_ink); cursor: pointer; }
142
- .pfc_dock .pfc_button:hover:not(:disabled), .pfc_closed .pfc_button:hover:not(:disabled) { background: color-mix(in srgb, var(--pfc_ink) 5%, transparent); }
143
- .pfc_dock .pfc_button[data-primary="true"], .pfc_closed .pfc_button[data-primary="true"] { border-color: var(--pfc_primary); background: var(--pfc_primary); color: var(--pfc_on_primary); }
144
- .pfc_dock .pfc_button[data-primary="true"]:hover:not(:disabled), .pfc_closed .pfc_button[data-primary="true"]:hover:not(:disabled) { opacity: .9; background: var(--pfc_primary); }
145
- .pfc_dock .pfc_button:disabled, .pfc_closed .pfc_button:disabled { opacity: .45; cursor: default; }
146
- .pfc_dock .pfc_link, .pfc_closed .pfc_link { box-sizing: border-box; font: inherit; font-size: 12.5px; padding: 0; border: 0; background: none; color: var(--pfc_ink3); cursor: pointer;
147
- border-bottom: 1px solid var(--pfc_line2); line-height: 1.5; }
148
- .pfc_dock .pfc_link:hover, .pfc_closed .pfc_link:hover { color: var(--pfc_ink); }
149
- .pfc_notice { font-size: 12.5px; color: var(--pfc_ink3); }
150
- .pfc_closed { width: 100%; margin: 0 0 8px; padding: 10px 14px; border: 1px solid var(--pfc_line); border-radius: 14px;
151
- display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--pfc_ink3); background: var(--pfc_card); }
152
- .pfc_button:focus-visible, .pfc_link:focus-visible { outline: 2px solid var(--pfc_ink); outline-offset: 2px; border-radius: 6px; }
153
- .pfc_lessons { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--pfc_line); }
154
- .pfc_lessons > summary { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; list-style: none; font-size: 12.5px; color: var(--pfc_ink2); }
155
- .pfc_lessons > summary::-webkit-details-marker { display: none; }
156
- .pfc_lessons > summary::before { content: ""; display: inline-block; width: 0; height: 0; border-left: 4.5px solid currentColor; border-top: 3.5px solid transparent; border-bottom: 3.5px solid transparent; }
157
- .pfc_lessons[open] > summary::before { border-left: 3.5px solid transparent; border-right: 3.5px solid transparent; border-top: 4.5px solid currentColor; border-bottom: 0; }
158
- .pfc_lessons > summary:hover { color: var(--pfc_ink); }
159
- .pfc_lessons_list { margin: 8px 0 0; padding-left: 18px; list-style: disc; font-size: 12.5px; line-height: 1.65; color: var(--pfc_ink2); }
160
- .pfc_lessons_list li + li { margin-top: 4px; }
161
- @media (max-width: 560px) {
162
- .pfc_dock { padding: 14px 16px 16px; }
420
+ .pfc_meta_note { margin: -2px 0 0; font-size: 11.5px; line-height: 1.45; color: var(--pfc_ink3); }
421
+
422
+ .pfc_summary { margin: 0; padding: 8px 0 0; border-top: 1px solid var(--pfc_line); font-size: 12.5px; line-height: 1.55; color: var(--pfc_ink2); }
423
+ .pfc_lessons { padding-top: 8px; border-top: 1px solid var(--pfc_line); }
424
+ .pfc_lessons_hd { font-size: 12px; font-weight: 600; line-height: 18px; color: var(--pfc_ink); }
425
+ .pfc_lessons_list { margin: 4px 0 0; padding-left: 16px; list-style: disc; font-size: 12px; line-height: 1.6; color: var(--pfc_ink2); }
426
+ .pfc_lessons_list li + li { margin-top: 2px; }
427
+
428
+ .pfc_drawer_foot {
429
+ padding-top: 8px;
430
+ border-top: 1px solid var(--pfc_line);
431
+ display: flex;
432
+ align-items: center;
433
+ justify-content: space-between;
434
+ gap: 8px;
435
+ flex-wrap: wrap;
436
+ }
437
+ .pfc_drawer_left, .pfc_drawer_right { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
438
+
439
+ .pfc_notice_row { margin-top: 6px; font-size: 12px; line-height: 1.4; color: var(--pfc_ok); }
440
+ .pfc_closed {
441
+ padding: 6px 12px;
442
+ display: flex;
443
+ align-items: center;
444
+ gap: 10px;
445
+ flex-wrap: wrap;
446
+ font-size: 12.5px;
447
+ color: var(--pfc_ink2);
448
+ }
449
+ .pfc_closed .pfc_ghost { margin-left: auto; color: var(--pfc_ink); font-weight: 500; }
450
+ .pfc_bar_toggle:focus-visible, .pfc_chip:focus-visible, .pfc_icon_btn:focus-visible, .pfc_button:focus-visible, .pfc_ghost:focus-visible {
451
+ outline: 2px solid var(--pfc_accent);
452
+ outline-offset: 2px;
453
+ }
454
+
455
+ @container pfc-dock (max-width: 560px) {
456
+ .pfc_hint { display: none; }
457
+ .pfc_five { gap: 4px; }
163
458
  .pfc_five span { font-size: 11px; }
164
459
  }
165
- @media (prefers-reduced-motion: no-preference) { .pfc_five i { transition: background-color .2s; } }
460
+ @media (prefers-reduced-motion: no-preference) {
461
+ @keyframes pfc-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.38; } }
462
+ .pfc_mini_steps .is_current.is_running { animation: pfc-pulse 1.4s ease-in-out infinite; }
463
+ .pfc_mini_steps i, .pfc_five i { transition: background-color 0.2s ease; }
464
+ }
166
465
  `;
167
466
  export const creatorStripCss = css;
168
467
 
169
- /** 纯展示:三种状态都只是排版,行为和文字沿用 preview.21。 */
468
+ /** 纯展示:v2 精简引导条,保持完全无状态以便 SSR 与单元测试直接驱动。 */
170
469
  export function createCreatorDock(React) {
171
470
  const h = React.createElement;
172
- const brick = () => h('svg', { className: 'pfc_brick', viewBox: '-3 0.6 26 22.6', role: 'img', 'aria-label': '还没做完,要一起做' },
173
- h('path', { d: BRICK }));
471
+ const sparkIcon = () => h('svg', { className: 'pfc_spark', viewBox: '0 0 20 20', fill: 'none', 'aria-hidden': 'true' },
472
+ h('path', { d: SPARK_PATH, stroke: 'currentColor', strokeWidth: '1.5', strokeLinejoin: 'round' }));
473
+ const chevronIcon = open => h('svg', { width: 14, height: 14, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': 'true' },
474
+ h('path', { d: open ? 'M4 10l4-4 4 4' : 'M4 6l4 4 4-4', stroke: 'currentColor', strokeWidth: '1.5', strokeLinecap: 'round', strokeLinejoin: 'round' }));
475
+ const closeIcon = () => h('svg', { width: 13, height: 13, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': 'true' },
476
+ h('path', { d: 'M4.5 4.5l7 7m0-7l-7 7', stroke: 'currentColor', strokeWidth: '1.5', strokeLinecap: 'round' }));
174
477
 
175
478
  return function CreatorDock({
176
- mode = 'intro', progress = null, busy = '', notice = '',
177
- onKnow, onSkip, onReopen, onOpenNext, onClose, onSettings, onShowSteps, onEnable, onDismiss,
479
+ mode = 'intro',
480
+ progress = null,
481
+ expanded = false,
482
+ running = false,
483
+ busy = '',
484
+ notice = '',
485
+ onKnow,
486
+ onSkip,
487
+ onToggleExpand,
488
+ onPrompt,
489
+ onOpenNext,
490
+ onClose,
491
+ onSettings,
492
+ onShowSteps,
493
+ onEnable,
494
+ onDismiss,
178
495
  }) {
179
496
  if (mode === 'closed') {
180
497
  return h('div', { className: 'pfc_closed', role: 'status' },
181
- h('span', null, '已关闭「发现好插件」的创造经验,之后新开的创造模式会话不再带上。'),
182
- h('button', { type: 'button', className: 'pfc_link', disabled: busy !== '', onClick: onEnable }, '撤销'),
183
- notice ? h('span', { className: 'pfc_notice', role: 'status' }, notice) : null);
498
+ h('span', null, '已全局关闭创造向导与后台省 Token 经验,新开创造会话不再启用。'),
499
+ notice ? h('span', { className: 'pfc_notice_row', role: 'status' }, notice) : null,
500
+ h('button', { type: 'button', className: 'pfc_ghost', disabled: busy !== '', onClick: onEnable }, '撤销'));
184
501
  }
502
+
185
503
  const stages = progress?.stages ?? [];
186
504
  const reached = progress?.reached ?? 0;
187
505
  const last = progress?.last ?? null;
188
- const five = () => h('div', { className: 'pfc_five', role: 'img', 'aria-label': `五步:${stages.map((stage, index) => `${index + 1} ${stage.plain ?? stage.label}`).join(',')}` },
189
- ...stages.map((stage, index) => h('div', { key: stage.id, className: stage.state === 'done' ? 'is_done' : stage.state === 'current' ? 'is_current' : '' },
190
- h('i', null), h('span', null, `${index + 1} ${stage.plain ?? stage.label}`))));
191
- const links = (showSteps = false) => h(React.Fragment, null,
192
- showSteps ? h('button', { type: 'button', className: 'pfc_link pfc_steps_link', onClick: onShowSteps, title: '这几步是什么' }, '这几步是什么') : null,
193
- typeof onSettings === 'function' ? h('button', { type: 'button', className: 'pfc_link', onClick: onSettings }, '经验') : null,
194
- h('button', { type: 'button', className: 'pfc_link', disabled: busy !== '', onClick: onClose }, '关闭'));
506
+ const current = stages.find(stage => stage.state === 'current') ?? stages[Math.min(Math.max(reached - 1, 0), (stages.length || 1) - 1)] ?? STAGES[0];
507
+ const currentId = current?.id || 'search';
508
+ const isExpanded = Boolean(expanded);
509
+ const hasSkipped = stages.some(stage => stage.state === 'skipped');
510
+ const stageTip = (stage, index, isRunning) => {
511
+ const shortLabel = STAGE_SHORT[stage.id] ?? stage.label;
512
+ const stateLabel = stage.state === 'done'
513
+ ? '已完成'
514
+ : stage.state === 'skipped'
515
+ ? '本轮免走(如继续迭代已有插件),无需补做'
516
+ : stage.state === 'current'
517
+ ? (isRunning ? 'AI 正在改动' : '当前步骤')
518
+ : '待进行';
519
+ return `${index + 1}. ${shortLabel} · ${stateLabel}`;
520
+ };
521
+ const metaNote = () => h('p', { className: 'pfc_meta_note' },
522
+ hasSkipped
523
+ ? '来自「发现好插件」· 后台省 Token 引导生效中(点 × 仅收起浮条)· 标「免走」代表老项目迭代或直奔主题,无需回头补做'
524
+ : '来自「发现好插件」· 找现成没合适的就陪你造 · 后台省 Token 引导生效中(点 × 仅收起浮条)');
195
525
 
196
- if (mode === 'intro') {
197
- return h('div', { className: 'pfc_dock', role: 'region', 'aria-label': '发现好插件 · 陪你做插件的做法' },
198
- h('div', { className: 'pfc_hd' }, brick(), h('b', null, '这一块,我陪你做')),
199
- h('p', null, '做插件的时候我按下面五步来,每一步先问你。不用设置;聊别的事我不出声。'),
200
- five(),
201
- h('div', { className: 'pfc_acts' },
202
- h('button', { type: 'button', className: 'pfc_button', 'data-primary': 'true', onClick: onKnow }, '知道了'),
203
- h('button', { type: 'button', className: 'pfc_link', onClick: onSkip }, '这个对话不用陪')));
204
- }
526
+ const five = () => h('div', {
527
+ className: 'pfc_five',
528
+ role: 'img',
529
+ 'aria-label': `五步流程:${stages.map((stage, index) => `${index + 1} ${STAGE_SHORT[stage.id] ?? stage.label}`).join(',')}`,
530
+ }, ...stages.map((stage, index) => {
531
+ const shortLabel = STAGE_SHORT[stage.id] ?? stage.label;
532
+ const tip = stageTip(stage, index, running);
533
+ return h('div', {
534
+ key: stage.id,
535
+ title: tip,
536
+ className: stage.state === 'done' ? 'is_done' : stage.state === 'skipped' ? 'is_skipped' : stage.state === 'current' ? 'is_current' : '',
537
+ }, h('i', null), h('span', { title: tip }, `${index + 1} ${shortLabel}${stage.state === 'skipped' ? ' · 免走' : ''}`));
538
+ }));
205
539
 
206
540
  const lessonList = (stageId, label) => {
207
541
  const items = STAGE_LESSONS[stageId] ?? STAGE_LESSONS.search;
208
- return h('details', { className: 'pfc_lessons' },
209
- h('summary', { className: 'pfc_lessons_sum' }, h('span', null, label ? `本步避坑铁律 · ${label}` : '本步避坑铁律')),
542
+ return h('div', { className: 'pfc_lessons' },
543
+ h('div', { className: 'pfc_lessons_hd' }, label ? `这一步注意什么 · ${label}` : '这一步注意什么'),
210
544
  h('ul', { className: 'pfc_lessons_list' }, ...items.map((item, idx) => h('li', { key: idx }, item))));
211
545
  };
212
546
 
547
+ const noticeEl = notice ? h('div', { className: 'pfc_notice_row', role: 'status' }, notice) : null;
548
+
549
+ if (mode === 'intro') {
550
+ return h('div', { className: 'pfc_dock', 'data-mode': 'intro', role: 'region', 'aria-label': '发现好插件 · 创造向导' },
551
+ h('div', { className: 'pfc_hd' },
552
+ sparkIcon(),
553
+ h('b', null, '发现好插件 · 创造向导'),
554
+ h('span', { className: 'pfc_sub' }, '没现成插件时陪你按 5 步稳造 · 后台已自动给 AI 开启省 Token 规矩'),
555
+ h('div', { className: 'pfc_hd_tools' },
556
+ typeof onSkip === 'function' ? h('button', { type: 'button', className: 'pfc_ghost', title: '仅隐藏本次起步卡,后台省 Token 引导继续生效', onClick: onSkip }, '这回不用') : null,
557
+ typeof onClose === 'function' ? h('button', { type: 'button', className: 'pfc_ghost', title: '在所有创造会话中同时关闭向导浮条与后台省 Token 经验', disabled: busy !== '', onClick: onClose }, '全局关闭') : null)),
558
+ h('div', { className: 'pfc_chip_row' },
559
+ ...STARTER_CHIPS.map(chip => h('button', {
560
+ key: chip.label,
561
+ type: 'button',
562
+ className: 'pfc_chip',
563
+ title: chip.prompt,
564
+ onClick: () => (onPrompt ? onPrompt(chip.prompt, { fromIntro: true }) : onKnow?.()),
565
+ }, chip.label)),
566
+ !onPrompt && typeof onKnow === 'function' ? h('button', { type: 'button', className: 'pfc_ghost', onClick: onKnow }, '知道了') : null),
567
+ noticeEl);
568
+ }
569
+
213
570
  if (mode === 'stuck') {
214
571
  const blockedStep = progress?.blockedStep;
215
- const heading = blockedStep
216
- ? `卡在第 ${blockedStep} 步${last?.summary ? `:${last.summary}` : ''}`
217
- : `卡住了${last?.summary ? `:${last.summary}` : ''}`;
218
- return h('div', { className: 'pfc_dock', 'data-stuck': 'true', role: 'region', 'aria-label': '发现好插件 · 创造进度' },
219
- h('div', { className: 'pfc_hd' }, brick(),
220
- h('b', null, heading)),
221
- h('p', null, '同一个问题在一个对话里反复改,只会越改越贵。开个新窗口,把试过什么、卡在哪一起带过去。'),
222
- five(),
223
- lessonList('blocked', '止损换窗'),
224
- h('div', { className: 'pfc_acts' },
225
- h('button', { type: 'button', className: 'pfc_button', 'data-primary': 'true', disabled: busy !== '', onClick: onOpenNext, title: '新建一个干净的创造模式窗口,把这里记下的进展带过去' }, '开新窗口接着做'),
226
- h('button', { type: 'button', className: 'pfc_link', onClick: onDismiss }, '先不用'),
227
- links()),
228
- notice ? h('span', { className: 'pfc_notice', role: 'status' }, notice) : null);
572
+ const heading = blockedStep ? `卡在第 ${blockedStep} 步` : '这里卡住了';
573
+ const stuckChip = STAGE_CHIPS.blocked.primary;
574
+ return h('div', { className: 'pfc_dock', 'data-mode': 'stuck', 'data-stuck': 'true', 'data-stage': currentId, 'data-running': running ? 'true' : 'false', role: 'region', 'aria-label': '发现好插件 · 卡点止损' },
575
+ h('div', { className: 'pfc_hd' },
576
+ h('i', { className: 'pfc_stuck_dot', 'aria-hidden': 'true' }),
577
+ h('b', null, heading),
578
+ last?.summary ? h('span', { className: 'pfc_sub', title: last.summary }, last.summary) : null,
579
+ h('div', { className: 'pfc_hd_tools' },
580
+ typeof onToggleExpand === 'function' ? h('button', { type: 'button', className: 'pfc_ghost', 'aria-expanded': isExpanded, onClick: onToggleExpand }, isExpanded ? '收起' : '详情') : null,
581
+ h('button', { type: 'button', className: 'pfc_ghost', title: '本次先收起提示,后台省 Token 引导继续生效', onClick: onDismiss }, '先不用'))),
582
+ h('p', { className: 'pfc_stuck_note' }, '同一个问题在长对话里反复改只会越改越乱;把进展和卡点带去新窗口接着做最稳。'),
583
+ h('div', { className: 'pfc_chip_row' },
584
+ h('button', {
585
+ type: 'button',
586
+ className: 'pfc_button',
587
+ 'data-primary': 'true',
588
+ disabled: busy !== '',
589
+ onClick: onOpenNext,
590
+ title: '新建一个干净的创造模式窗口,把这里记下的进展带过去',
591
+ }, '开新窗口接着做'),
592
+ h('button', {
593
+ type: 'button',
594
+ className: 'pfc_chip',
595
+ title: stuckChip.prompt,
596
+ onClick: () => onPrompt?.(stuckChip.prompt),
597
+ }, stuckChip.label)),
598
+ isExpanded ? h('div', { className: 'pfc_drawer' },
599
+ five(),
600
+ metaNote(),
601
+ lessonList('blocked', '止损换窗'),
602
+ h('div', { className: 'pfc_drawer_foot' },
603
+ h('div', { className: 'pfc_drawer_right' },
604
+ typeof onSettings === 'function' ? h('button', { type: 'button', className: 'pfc_ghost', onClick: onSettings }, '管理经验库') : null,
605
+ typeof onClose === 'function' ? h('button', { type: 'button', className: 'pfc_ghost', title: '在所有创造会话中同时关闭向导浮条与后台省 Token 经验', disabled: busy !== '', onClick: onClose }, '全局关闭') : null))) : null,
606
+ noticeEl);
229
607
  }
230
608
 
231
- const current = stages.find(stage => stage.state === 'current') ?? stages[Math.min(Math.max(reached, 0), (stages.length || 1) - 1)];
232
- return h('div', { className: 'pfc_dock', role: 'region', 'aria-label': '发现好插件 · 创造进度' },
233
- h('div', { className: 'pfc_hd' }, brick(),
234
- h('b', null, `做到第 ${Math.min(Math.max(reached, 1), stages.length || 5)} 步${current ? `:${current.plain ?? current.label}` : ''}`),
235
- links(true)),
236
- h('p', null, last?.summary ? last.summary : '每一步都先问你,你说了才往下走。'),
609
+ const stepNum = Math.min(Math.max(reached, 1), stages.length || 5);
610
+ const chips = STAGE_CHIPS[currentId] ?? STAGE_CHIPS.search;
611
+ const shortTitle = STAGE_SHORT[currentId] ?? current?.label ?? '进行中';
612
+ const hintText = running ? '正在按你的要求更新,完成后再核对效果' : (STAGE_HINTS[currentId] ?? '');
613
+ const badgeText = running ? `第 ${stepNum}/5 步 · 正在改动…` : `第 ${stepNum}/5 步 · ${shortTitle}`;
614
+
615
+ return h('div', {
616
+ className: 'pfc_dock',
617
+ 'data-mode': 'run',
618
+ 'data-compact': isExpanded ? 'false' : 'true',
619
+ 'data-stage': currentId,
620
+ 'data-running': running ? 'true' : 'false',
621
+ role: 'region',
622
+ 'aria-label': '发现好插件 · 创造向导',
623
+ },
624
+ h('div', { className: 'pfc_bar' },
625
+ h('button', {
626
+ type: 'button',
627
+ className: 'pfc_bar_toggle',
628
+ 'aria-expanded': isExpanded,
629
+ onClick: onToggleExpand,
630
+ title: isExpanded ? '收起向导详情' : '点击查看 5 步轨迹与验收锦囊(来自「发现好插件」,后台省 Token 引导生效中)',
631
+ },
632
+ h('span', { className: 'pfc_mini_steps', 'aria-hidden': 'true' }, ...stages.map((stage, index) => h('i', {
633
+ key: stage.id,
634
+ title: stageTip(stage, index, running),
635
+ className: stage.state === 'done'
636
+ ? 'is_done'
637
+ : stage.state === 'skipped'
638
+ ? 'is_skipped'
639
+ : stage.state === 'current'
640
+ ? (running ? 'is_current is_running' : 'is_current')
641
+ : '',
642
+ }))),
643
+ h('span', { className: 'pfc_badge' }, badgeText),
644
+ h('span', { className: 'pfc_hint' }, hintText)),
645
+ h('div', { className: 'pfc_bar_actions' },
646
+ !running && chips.primary ? h('button', {
647
+ type: 'button',
648
+ className: 'pfc_chip',
649
+ title: chips.primary.prompt,
650
+ onClick: () => onPrompt?.(chips.primary.prompt),
651
+ }, chips.primary.label) : null,
652
+ h('button', {
653
+ type: 'button',
654
+ className: 'pfc_icon_btn',
655
+ 'aria-expanded': isExpanded,
656
+ 'aria-label': isExpanded ? '收起向导详情' : '展开向导详情',
657
+ title: isExpanded ? '收起向导详情' : '展开阶段与锦囊',
658
+ onClick: onToggleExpand,
659
+ }, chevronIcon(isExpanded)),
660
+ typeof onDismiss === 'function' ? h('button', {
661
+ type: 'button',
662
+ className: 'pfc_icon_btn',
663
+ 'aria-label': '本会话收起向导',
664
+ title: '本次对话先收起浮条(后台省 Token 引导继续生效)',
665
+ onClick: onDismiss,
666
+ }, closeIcon()) : null)),
667
+ isExpanded ? h('div', { className: 'pfc_drawer' },
237
668
  five(),
238
- lessonList(current?.id || 'search', current?.label || ''),
239
- notice ? h('span', { className: 'pfc_notice', role: 'status' }, notice) : null);
669
+ metaNote(),
670
+ last?.summary ? h('p', { className: 'pfc_summary' }, `最近记录:${last.summary}`) : null,
671
+ lessonList(currentId, shortTitle),
672
+ h('div', { className: 'pfc_drawer_foot' },
673
+ h('div', { className: 'pfc_drawer_left' },
674
+ chips.secondary ? h('button', {
675
+ type: 'button',
676
+ className: 'pfc_chip',
677
+ title: chips.secondary.prompt,
678
+ onClick: () => onPrompt?.(chips.secondary.prompt),
679
+ }, chips.secondary.label) : null,
680
+ typeof onOpenNext === 'function' ? h('button', {
681
+ type: 'button',
682
+ className: 'pfc_chip',
683
+ disabled: busy !== '',
684
+ onClick: onOpenNext,
685
+ }, '带进展换新窗口') : null),
686
+ h('div', { className: 'pfc_drawer_right' },
687
+ typeof onShowSteps === 'function' ? h('button', { type: 'button', className: 'pfc_ghost', onClick: onShowSteps }, '查看起步模板') : null,
688
+ typeof onSettings === 'function' ? h('button', { type: 'button', className: 'pfc_ghost', onClick: onSettings }, '管理经验库') : null,
689
+ typeof onClose === 'function' ? h('button', { type: 'button', className: 'pfc_ghost', title: '在所有创造会话中同时关闭向导浮条与后台省 Token 经验', disabled: busy !== '', onClick: onClose }, '全局关闭') : null))) : null,
690
+ noticeEl);
240
691
  };
241
692
  }
242
693
 
@@ -280,10 +731,12 @@ export function createCreatorStrip(React, { ctx, request, openSettings }) {
280
731
  const [busy, setBusy] = React.useState('');
281
732
  const [notice, setNotice] = React.useState('');
282
733
  const [closedHere, setClosedHere] = React.useState(false);
283
- // 「先不用」只关这一个入口,不动全局的创造经验开关。
284
- const [dismissed, setDismissed] = React.useState(false);
285
- // The five stages mean nothing without a first explanation, so it is shown
286
- // once per session and can be reopened with the 「这几步是什么」 link.
734
+ const [expanded, setExpanded] = React.useState(false);
735
+ const [running, setRunning] = React.useState(false);
736
+ const [turnEnds, setTurnEnds] = React.useState(0);
737
+ // 记录关闭时的步数;只有之后新产生卡点步骤时才自动重新冒头打扰。
738
+ const [dismissedAt, setDismissedAt] = React.useState(-1);
739
+ const [manualIntro, setManualIntro] = React.useState(false);
287
740
  const [introOpen, setIntroOpen] = React.useState(() => {
288
741
  try {
289
742
  const store = globalThis.localStorage;
@@ -291,15 +744,34 @@ export function createCreatorStrip(React, { ctx, request, openSettings }) {
291
744
  && store?.getItem(`finder.creator.skip.${text(props?.sessionId)}`) !== '1';
292
745
  } catch { return true; }
293
746
  });
747
+ const noticeTimerRef = React.useRef(null);
748
+ const showNotice = React.useCallback(message => {
749
+ if (noticeTimerRef.current) clearTimeout(noticeTimerRef.current);
750
+ setNotice(message);
751
+ if (message) noticeTimerRef.current = setTimeout(() => { noticeTimerRef.current = null; setNotice(''); }, 2400);
752
+ }, []);
753
+ React.useEffect(() => () => { if (noticeTimerRef.current) clearTimeout(noticeTimerRef.current); }, []);
754
+
294
755
  const dismissIntro = hideForever => {
295
756
  try {
296
757
  globalThis.localStorage?.setItem(hideForever ? `finder.creator.skip.${sessionId}` : `finder.creator.intro.${sessionId}`, '1');
297
758
  } catch { /* 无痕模式就只在本次渲染生效 */ }
298
759
  setIntroOpen(false);
760
+ setManualIntro(false);
299
761
  };
300
762
 
301
763
  React.useEffect(() => {
302
764
  setPreset(presetOf(ctx, sessionId));
765
+ setExpanded(false);
766
+ setDismissedAt(-1);
767
+ setManualIntro(false);
768
+ setRunning(false);
769
+ setTurnEnds(0);
770
+ setNotice('');
771
+ try {
772
+ const store = globalThis.localStorage;
773
+ setIntroOpen(store?.getItem(`finder.creator.intro.${sessionId}`) !== '1' && store?.getItem(`finder.creator.skip.${sessionId}`) !== '1');
774
+ } catch { setIntroOpen(true); }
303
775
  const face = (() => { try { return ctx.sessions?.binding?.(sessionId)?.session?.projections?.faceOf?.('agentPreset'); } catch { return null; } })();
304
776
  const stop = typeof face?.subscribe === 'function' ? face.subscribe(() => setPreset(presetOf(ctx, sessionId))) : null;
305
777
  return () => { if (typeof stop === 'function') stop(); };
@@ -309,20 +781,42 @@ export function createCreatorStrip(React, { ctx, request, openSettings }) {
309
781
  React.useEffect(() => {
310
782
  if (!creator || !sessionId) return undefined;
311
783
  let live = true, timer = null, seen = -1;
312
- const load = () => { void request('creator-session', { sessionId }).then(value => { if (live) setData(value); }).catch(() => { if (live) setData(current => current ?? { enabled: true, steps: [] }); }); };
784
+ const load = () => {
785
+ void request('creator-session', { sessionId })
786
+ .then(value => { if (live) setData(value); })
787
+ .catch(() => { if (live) setData(current => current ?? { enabled: true, steps: [] }); });
788
+ };
313
789
  load();
314
790
  const source = (() => { try { return ctx.sessions?.binding?.(sessionId)?.eventSource; } catch { return null; } })();
315
- const count = () => {
791
+ const scan = () => {
316
792
  const entries = source?.getSnapshot?.()?.entries;
317
- if (!Array.isArray(entries)) return 0;
318
- let total = 0;
793
+ if (!Array.isArray(entries)) return { signalCount: 0, endedCount: 0, isRunning: false };
794
+ let signalCount = 0;
795
+ let endedCount = 0;
796
+ let lastTurnType = '';
319
797
  for (const entry of entries) {
320
798
  const event = entry?.event;
321
- if (entry?.type === 'event' && (event?.type === 'turn/end' || event?.type === 'tool/call' && event.data?.name === 'finder_creator_step')) total += 1;
799
+ if (entry?.type !== 'event') continue;
800
+ if (event?.type === 'turn/start') { lastTurnType = 'turn/start'; continue; }
801
+ if (event?.type === 'turn/end') {
802
+ lastTurnType = 'turn/end';
803
+ endedCount += 1;
804
+ signalCount += 1;
805
+ continue;
806
+ }
807
+ if (event?.type === 'tool/call' && event.data?.name === 'finder_creator_step') signalCount += 1;
322
808
  }
323
- return total;
809
+ return { signalCount, endedCount, isRunning: lastTurnType === 'turn/start' };
810
+ };
811
+ const check = () => {
812
+ const next = scan();
813
+ setRunning(next.isRunning);
814
+ setTurnEnds(next.endedCount);
815
+ if (next.signalCount === seen) return;
816
+ seen = next.signalCount;
817
+ if (timer) clearTimeout(timer);
818
+ timer = setTimeout(() => { timer = null; load(); }, 900);
324
819
  };
325
- const check = () => { const now = count(); if (now === seen) return; seen = now; if (timer) clearTimeout(timer); timer = setTimeout(() => { timer = null; load(); }, 900); };
326
820
  const stop = typeof source?.subscribe === 'function' ? source.subscribe(check) : null;
327
821
  check();
328
822
  return () => { live = false; if (timer) clearTimeout(timer); if (typeof stop === 'function') stop(); };
@@ -331,35 +825,59 @@ export function createCreatorStrip(React, { ctx, request, openSettings }) {
331
825
  if (!creator || !data) return null;
332
826
  const enable = () => {
333
827
  setBusy('enable');
334
- void request('creator-configure', { enabled: true }).then(() => { setClosedHere(false); setData(current => ({ ...(current ?? {}), enabled: true })); }).catch(() => setNotice('没有重新开启,请稍后再试。')).finally(() => setBusy(''));
828
+ void request('creator-configure', { enabled: true })
829
+ .then(() => { setClosedHere(false); setData(current => ({ ...(current ?? {}), enabled: true })); })
830
+ .catch(() => showNotice('没有重新开启,请稍后再试。'))
831
+ .finally(() => setBusy(''));
335
832
  };
336
833
  if (closedHere) return h(Dock, { mode: 'closed', busy, notice, onEnable: enable });
337
834
  if (data.enabled === false) return null;
835
+
338
836
  const progress = creatorProgress(data.steps);
339
837
  const openNext = () => {
340
- setBusy('next'); setNotice('');
838
+ setBusy('next'); showNotice('');
341
839
  void openCreatorContinuation(ctx, sessionId, creatorHandoffPrompt(data.steps))
342
- .then(result => { if (result.draft !== 'applied') setNotice('新窗口已打开,交接内容没能放进输入框,可以手动说明进展。'); })
343
- .catch(error => setNotice(error?.safeForUser ? error.message : '没能开新窗口,请从左侧新建创造模式会话。'))
840
+ .then(result => { if (result.draft !== 'applied') showNotice('新窗口已打开,交接内容没能放进输入框,可以手动说明进展。'); })
841
+ .catch(error => showNotice(error?.safeForUser ? error.message : '没能开新窗口,请从左侧新建创造模式会话。'))
344
842
  .finally(() => setBusy(''));
345
843
  };
346
844
  const close = () => {
347
- setBusy('close'); setNotice('');
348
- void request('creator-configure', { enabled: false }).then(() => setClosedHere(true)).catch(() => setNotice('没有关闭成功,请稍后再试。')).finally(() => setBusy(''));
845
+ setBusy('close'); showNotice('');
846
+ void request('creator-configure', { enabled: false })
847
+ .then(() => setClosedHere(true))
848
+ .catch(() => showNotice('没有关闭成功,请稍后再试。'))
849
+ .finally(() => setBusy(''));
850
+ };
851
+ const handlePrompt = (prompt, opts = {}) => {
852
+ void applyCreatorPrompt({ ctx, sessionId, inputActions: props?.inputActions }, prompt).then(status => {
853
+ if (opts.fromIntro) dismissIntro(false);
854
+ if (status === 'copied') showNotice('已复制引导话术,可直接粘贴到输入框');
855
+ else if (status === 'unavailable') showNotice('暂时写入不到输入框,请先点一下输入框再试');
856
+ else if (status === 'inserted' && !opts.fromIntro) showNotice('已填入输入框,补充细节即可发送');
857
+ });
349
858
  };
350
- // 没有记录、也关掉了第一次的说明:不打扰。
351
- if (!progress.count && !introOpen) return null;
352
- // 这一条只关当前入口;下一次有问题时再出现。
353
- if (dismissed) return null;
354
- const mode = progress.blocked ? 'stuck' : progress.count ? 'run' : 'intro';
859
+
860
+ // 普通闲聊首轮结束后(还没记过创造步骤),自动退场不打扰;手动点「查看起步模板」时重新展开。
861
+ if (!progress.count && !manualIntro && (!introOpen || turnEnds > 0)) return null;
862
+ const isDismissed = dismissedAt >= 0 && !(progress.blocked && progress.count > dismissedAt);
863
+ if (isDismissed && !manualIntro) return null;
864
+
865
+ const mode = manualIntro ? 'intro' : progress.blocked ? 'stuck' : progress.count ? 'run' : 'intro';
355
866
  return h(Dock, {
356
- mode, progress, busy, notice,
867
+ mode,
868
+ progress,
869
+ expanded,
870
+ running,
871
+ busy,
872
+ notice,
357
873
  onKnow: () => dismissIntro(false),
358
874
  onSkip: () => dismissIntro(true),
359
- onShowSteps: () => setIntroOpen(true),
875
+ onToggleExpand: () => setExpanded(v => !v),
876
+ onPrompt: handlePrompt,
877
+ onShowSteps: () => { setExpanded(false); setManualIntro(true); setIntroOpen(true); },
360
878
  onOpenNext: openNext,
361
879
  onClose: close,
362
- onDismiss: () => setDismissed(true),
880
+ onDismiss: () => { setExpanded(false); setManualIntro(false); setDismissedAt(progress.count); },
363
881
  onSettings: typeof openSettings === 'function' ? openSettings : null,
364
882
  onEnable: enable,
365
883
  });