dsh-devdock-review 0.0.0-stage → 3.0.0

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/client.js ADDED
@@ -0,0 +1,1657 @@
1
+ /**
2
+ * DevDock · 发布前审查 · 浏览器半边。
3
+ *
4
+ * 三种审查对象各一个对话框:
5
+ *
6
+ * - `ReviewDialog` 推送前审查 git 改动(GitHub 面板用)
7
+ * - `NpmReviewDialog` 发布前审查 npm 包内容(npm 面板用)
8
+ * - `ProjectReviewDialog` 一次覆盖 git + npm 的整个项目
9
+ *
10
+ * 它们都通过内核的 API 层请求本包的 Host 半边(`/api/push/review/*`)。
11
+ *
12
+ * ## 与 GitHub / npm 插件的关系
13
+ *
14
+ * 这两个插件**不 import 本包**,而是通过内核的**能力注册表**探测:
15
+ *
16
+ * ```js
17
+ * const review = core.useCapability('review'); // 没有就是 null
18
+ * if (review) h(review.Dialog, { ... });
19
+ * else h(core.FeatureMissing, { label: '审查', packageName: 'dsh-devdock-review' });
20
+ * ```
21
+ *
22
+ * 所以只装 npm 时不会有任何报错,只是那个入口变成灰色并提示去装审查插件。
23
+ * 本包的 `apply` 负责把 `Dialog` 登记进去。
24
+ */
25
+ window.__ModuleLoader__.load({
26
+ // Must equal package.json `name`: the loader keys client modules by package
27
+ // name, so a mismatch registers the module under an id nobody resolves and
28
+ // every surface vanishes while the Host half still reports active.
29
+ id: 'dsh-devdock-review',
30
+ factory: (require) => {
31
+ 'use strict';
32
+ const module = { exports: {} };
33
+ const exports = module.exports;
34
+
35
+ const core = require('dsh-devdock-core/client');
36
+ const {
37
+ h, Icon, Btn, Modal, Switch, api, t, copyText,
38
+ SEVERITY_TONE, SEVERITY_LABEL,
39
+ } = core;
40
+ const { useState, useEffect, useRef, useCallback } = core.React;
41
+
42
+ /** 本平台的路由前缀:内核前缀 + 平台 id。 */
43
+ const API = core.API + '/review';
44
+
45
+ /* ────────────────────────────── 文案 ────────────────────────────────── */
46
+
47
+ /**
48
+ * 审查的全部措辞(71 条)。由脚本从元包抽取后固化——逐条重写是
49
+ * 纯粹的浪费,而且键名已被 verify-review-* 系列测试覆盖。
50
+ */
51
+ const ZH = {
52
+ rvAgentAsked: "Agent 请求",
53
+ rvAgentAskedHint: "这次审查由智能体发起,需要你确认审查项后才会执行",
54
+ npmReviewTitle: "发布前审查",
55
+ npmReviewHint: "先检查即将发布的包内容,再决定是否发布。规则扫描(敏感信息)始终执行,模型审查可选。",
56
+ npmReviewOpen: "发布前审查",
57
+ npmReviewFindings: "问题",
58
+ npmReviewBlockerCount: "阻断项",
59
+ npmReviewBlocker: "存在阻断级问题。仍可发布,但请确认这些内容确实要公开。",
60
+ npmReviewHintShort: "发布前先检查包内容",
61
+ npmReviewSummary: "{n} 个问题({b} 个阻断)",
62
+ npmReviewResultTitle: "审查结果",
63
+ npmReviewNeedDir: "请先在上方选择一个目录,审查需要读取包内容。",
64
+ npmReviewRunningTitle: "正在审查",
65
+ npmReviewStep1: "已读取 npm 将要打包的文件",
66
+ npmReviewStep2: "规则扫描:敏感信息、空包、README、体积",
67
+ npmReviewStep3Rules: "正在整理结果",
68
+ npmReviewStep3Model: "正在调用模型审查({model})",
69
+ npmReviewElapsed: "已用时 {s} 秒",
70
+ npmReviewWaitHint: "可以直接关掉这个窗口,结果不会丢失。",
71
+ npmReviewSlowHint: "模型审查通常需要 10–60 秒,取决于包的大小和模型速度。",
72
+ rvRunningFooter: "审查进行中,请稍候…",
73
+ rvTitle: "推送前审查",
74
+ rvClose: "关闭",
75
+ rvSettings: "设置",
76
+ rvModel: "模型配置",
77
+ rvNoModels: "宿主未提供模型配置",
78
+ rvEffort: "思考强度",
79
+ rvEffortDefault: "默认",
80
+ rvPresets: "审查项",
81
+ rvCustom: "自定义",
82
+ rvCustomPrompt: "自定义提示词",
83
+ rvCustomPlaceholder: "补充你想让审查额外注意的内容…",
84
+ rvSavePreset: "存档为预设",
85
+ rvSavePresetTitle: "给这条提示词起个名字",
86
+ rvSave: "保存",
87
+ rvClear: "清空",
88
+ rvCancel: "取消",
89
+ rvNext: "下一步",
90
+ rvSelected: "已选 {n} 项审查",
91
+ rvSelectionEmpty: "尚未选择审查项",
92
+ rvConfirmTitle: "确认审查",
93
+ rvConfirmModel: "模型",
94
+ rvConfirmEffort: "思考强度",
95
+ rvConfirmFiles: "本次审查涉及 {n} 个文件",
96
+ rvConfirmFilesHint: "点击展开",
97
+ rvConfirmFeatures: "将使用的审查项",
98
+ rvConfirmCustomChip: "自定义提示词",
99
+ rvBack: "返回配置",
100
+ rvStart: "开始审查",
101
+ rvRunning: "审查中…",
102
+ rvRunningWith: "正在使用 {model} 审查",
103
+ rvResult: "审查结果",
104
+ rvRerun: "重新审查",
105
+ rvDone: "关闭",
106
+ rvNoFindings: "未发现问题",
107
+ rvDegraded: "本次只执行了规则检查,未调用模型。",
108
+ rvTruncated: "改动较多,超出部分未送审。",
109
+ rvStagedOnly: "只审查已暂存内容",
110
+ rvMaxFiles: "最大文件数",
111
+ rvIncludeUntracked: "包含未跟踪文件",
112
+ rvApproxFiles: "约 {n} 个文件",
113
+ rvAgentReview: "Agent 审查",
114
+ rvBlockedBadge: "审查发现阻断级问题",
115
+ rvFileSkipped: "未送审",
116
+ rvSeverityBlocker: "阻断",
117
+ rvSeverityHigh: "高",
118
+ rvSeverityMedium: "中",
119
+ rvSeverityLow: "低",
120
+ rvSeverityInfo: "提示",
121
+ rvPresetSaved: "已存档",
122
+ rvDeletePreset: "删除这条预设",
123
+ };
124
+
125
+ const EN = {
126
+ rvAgentAsked: "Agent request",
127
+ rvAgentAskedHint: "The agent asked for this review; nothing runs until you confirm the items",
128
+ npmReviewTitle: "Pre-publish review",
129
+ npmReviewHint: "Review what will be published before it goes out. Secret scanning always runs; model review is optional.",
130
+ npmReviewOpen: "Pre-publish review",
131
+ npmReviewFindings: "Findings",
132
+ npmReviewBlockerCount: "Blockers",
133
+ npmReviewBlocker: "Blocking issues found. You can still publish, but make sure this content is meant to be public.",
134
+ npmReviewHintShort: "Check the package before publishing",
135
+ npmReviewSummary: "{n} findings ({b} blockers)",
136
+ npmReviewResultTitle: "Review results",
137
+ npmReviewNeedDir: "Choose a folder above first — the review reads the package contents.",
138
+ npmReviewRunningTitle: "Reviewing",
139
+ npmReviewStep1: "Read the files npm will pack",
140
+ npmReviewStep2: "Rule scan: secrets, empty package, README, size",
141
+ npmReviewStep3Rules: "Collecting results",
142
+ npmReviewStep3Model: "Asking the model ({model})",
143
+ npmReviewElapsed: "{s}s elapsed",
144
+ npmReviewWaitHint: "You can close this dialog — the result is kept.",
145
+ npmReviewSlowHint: "Model review usually takes 10–60 seconds depending on package size and model speed.",
146
+ rvRunningFooter: "Review in progress…",
147
+ rvTitle: "Pre-push review",
148
+ rvClose: "Close",
149
+ rvSettings: "Settings",
150
+ rvModel: "Model",
151
+ rvNoModels: "The host provides no model configuration",
152
+ rvEffort: "Reasoning effort",
153
+ rvEffortDefault: "Default",
154
+ rvPresets: "Review checks",
155
+ rvCustom: "Custom",
156
+ rvCustomPrompt: "Custom prompt",
157
+ rvCustomPlaceholder: "Anything else the review should watch for…",
158
+ rvSavePreset: "Save as preset",
159
+ rvSavePresetTitle: "Name this prompt",
160
+ rvSave: "Save",
161
+ rvClear: "Clear",
162
+ rvCancel: "Cancel",
163
+ rvNext: "Next",
164
+ rvSelected: "{n} checks selected",
165
+ rvSelectionEmpty: "No checks selected",
166
+ rvConfirmTitle: "Confirm review",
167
+ rvConfirmModel: "Model",
168
+ rvConfirmEffort: "Reasoning effort",
169
+ rvConfirmFiles: "Reviewing {n} files",
170
+ rvConfirmFilesHint: "Click to expand",
171
+ rvConfirmFeatures: "Checks that will run",
172
+ rvConfirmCustomChip: "Custom prompt",
173
+ rvBack: "Back",
174
+ rvStart: "Start review",
175
+ rvRunning: "Reviewing…",
176
+ rvRunningWith: "Reviewing with {model}",
177
+ rvResult: "Review result",
178
+ rvRerun: "Review again",
179
+ rvDone: "Close",
180
+ rvNoFindings: "No problems found",
181
+ rvDegraded: "Only the rule-based pass ran; no model was called.",
182
+ rvTruncated: "The diff was large; the remainder was not reviewed.",
183
+ rvStagedOnly: "Only staged changes",
184
+ rvMaxFiles: "Max files",
185
+ rvIncludeUntracked: "Include untracked files",
186
+ rvApproxFiles: "about {n} files",
187
+ rvAgentReview: "Agent review",
188
+ rvBlockedBadge: "The review found blocking issues",
189
+ rvFileSkipped: "skipped",
190
+ rvSeverityBlocker: "Blocker",
191
+ rvSeverityHigh: "High",
192
+ rvSeverityMedium: "Medium",
193
+ rvSeverityLow: "Low",
194
+ rvSeverityInfo: "Info",
195
+ rvPresetSaved: "Saved",
196
+ rvDeletePreset: "Delete this preset",
197
+ };
198
+
199
+ /* ─────────────────────────── 共用小组件 ─────────────────────────────── */
200
+
201
+ function ReviewField(props) {
202
+ return h('div', { className: 'dsh-push-rv-field' },
203
+ h('span', { className: 'dsh-push-rv-field-label' }, props.label),
204
+ h('div', { className: 'dsh-push-rv-field-body' }, props.children));
205
+ }
206
+
207
+ function ModelPicker(props) {
208
+ const models = props.models || { providers: [], default: null };
209
+ const value = props.value || {};
210
+ const providers = models.providers || [];
211
+
212
+ const currentProvider = providers.find((p) => p.id === value.provider);
213
+ const currentModel = currentProvider
214
+ ? (currentProvider.models || []).find((m) => m.id === value.model)
215
+ : null;
216
+ const efforts = (currentModel && currentModel.efforts) || [];
217
+ const showEffort = efforts.length > 0;
218
+
219
+ if (providers.length === 0) {
220
+ return h('span', { className: 'dsh-push-rv-muted' }, t('rvNoModels'));
221
+ }
222
+
223
+ return h('div', { className: 'dsh-push-rv-model' },
224
+ h('select', {
225
+ className: 'dsh-push-select dsh-push-rv-select',
226
+ value: providerAndModel(value),
227
+ onChange: (event) => {
228
+ const parts = String(event.target.value).split('\u0000');
229
+ const provider = providers.find((p) => p.id === parts[0]);
230
+ const model = provider && (provider.models || []).find((m) => m.id === parts[1]);
231
+ props.onChange({
232
+ provider: parts[0],
233
+ model: parts[1],
234
+ reasoningEffort: (model && model.defaultEffort) || '',
235
+ });
236
+ },
237
+ }, providers.flatMap((provider) => (provider.models || []).map((model) => h('option', {
238
+ key: provider.id + '\u0000' + model.id,
239
+ value: provider.id + '\u0000' + model.id,
240
+ }, (provider.name || provider.id) + ' / ' + (model.name || model.id))))),
241
+ showEffort
242
+ ? (efforts.length >= 3
243
+ // A slider reads better than a short ordered list of efforts, which is
244
+ // exactly what a reasoning scale is.
245
+ ? h('div', { className: 'dsh-push-rv-effort' },
246
+ h('input', {
247
+ className: 'dsh-push-rv-slider',
248
+ type: 'range',
249
+ min: 0,
250
+ max: efforts.length - 1,
251
+ step: 1,
252
+ value: String(effortIndex(efforts, value.reasoningEffort, currentModel)),
253
+ onChange: (event) => {
254
+ const effort = efforts[Number(event.target.value)];
255
+ if (effort) props.onChange({ ...value, reasoningEffort: effort.id });
256
+ },
257
+ }),
258
+ h('span', { className: 'dsh-push-rv-effort-label' },
259
+ effortName(efforts, value.reasoningEffort, currentModel)))
260
+ : h('select', {
261
+ className: 'dsh-push-select dsh-push-rv-select',
262
+ value: value.reasoningEffort || '',
263
+ onChange: (event) => props.onChange({ ...value, reasoningEffort: event.target.value }),
264
+ }, efforts.map((effort) => h('option', {
265
+ key: effort.id,
266
+ value: effort.id,
267
+ }, effort.name || effort.id))))
268
+ : null);
269
+ }
270
+
271
+ /* ─────────────────── 模型与思考强度的换算(审查界面用) ──────────────── */
272
+
273
+ /** 把 provider + model 折成 select 的复合值。 */
274
+
275
+ function providerAndModel(value) {
276
+ if (!value || !value.provider || !value.model) return '';
277
+ return value.provider + '\u0000' + value.model;
278
+ }
279
+
280
+ function effortIndex(efforts, current, model) {
281
+ const wanted = current || (model && model.defaultEffort);
282
+ const found = efforts.findIndex((effort) => effort.id === wanted);
283
+ return found >= 0 ? found : 0;
284
+ }
285
+
286
+ function effortName(efforts, current, model) {
287
+ const index = effortIndex(efforts, current, model);
288
+ const effort = efforts[index];
289
+ return effort ? (effort.name || effort.id) : '';
290
+ }
291
+
292
+ function effortLabelFor(models, value) {
293
+ const providers = (models && models.providers) || [];
294
+ const provider = providers.find((p) => p.id === value.provider);
295
+ const model = provider && (provider.models || []).find((m) => m.id === value.model);
296
+ const efforts = (model && model.efforts) || [];
297
+ if (efforts.length === 0) return '';
298
+ return effortName(efforts, value.reasoningEffort, model);
299
+ }
300
+
301
+ /* ─────────────────── 推送前审查(git 改动,GitHub 用) ─────────────────── */
302
+
303
+ function ReviewDialog(props) {
304
+ const ctx = props.ctx;
305
+ const [step, setStep] = useState('configure');
306
+ const [presets, setPresets] = useState({ builtin: [], custom: [], categories: [] });
307
+ const [models, setModels] = useState({ providers: [], default: null });
308
+ const [picked, setPicked] = useState({});
309
+ const [customPrompt, setCustomPrompt] = useState('');
310
+ const [modelValue, setModelValue] = useState({ provider: '', model: '', reasoningEffort: '' });
311
+ const [settingsOpen, setSettingsOpen] = useState(false);
312
+ const [stagedOnly, setStagedOnly] = useState(false);
313
+ const [maxFiles, setMaxFiles] = useState(60);
314
+ const [saveOpen, setSaveOpen] = useState(false);
315
+ const [saveTitle, setSaveTitle] = useState('');
316
+ const [result, setResult] = useState(null);
317
+ const [running, setRunning] = useState(false);
318
+ const [error, setError] = useState('');
319
+ const [notice, setNotice] = useState('');
320
+ const [filesOpen, setFilesOpen] = useState(false);
321
+ const aliveRef = useRef(true);
322
+
323
+ useEffect(() => {
324
+ aliveRef.current = true;
325
+ return () => { aliveRef.current = false; };
326
+ }, []);
327
+
328
+ // Load the catalog once per open. A failure here is not fatal: the custom
329
+ // prompt alone is still a valid review.
330
+ useEffect(() => {
331
+ if (!props.open) return undefined;
332
+ let cancelled = false;
333
+ (async () => {
334
+ try {
335
+ const data = await api(ctx, API + '/presets');
336
+ if (cancelled || !aliveRef.current) return;
337
+ setPresets({
338
+ builtin: (data && data.builtin) || [],
339
+ custom: (data && data.custom) || [],
340
+ categories: (data && data.categories) || [],
341
+ });
342
+ } catch (err) {
343
+ if (!cancelled && aliveRef.current) setError(err.message);
344
+ }
345
+ try {
346
+ const data = await api(ctx, API + '/models');
347
+ if (cancelled || !aliveRef.current) return;
348
+ const list = data || { providers: [], default: null };
349
+ setModels(list);
350
+ const def = list.default;
351
+ const provider = def ? def.provider : '';
352
+ const model = def ? def.model : '';
353
+ let effort = '';
354
+ const group = (list.providers || []).find((p) => p.id === provider);
355
+ const entry = group && (group.models || []).find((m) => m.id === model);
356
+ if (entry && entry.defaultEffort) effort = entry.defaultEffort;
357
+ setModelValue({ provider, model, reasoningEffort: effort });
358
+ } catch {
359
+ // The picker renders its own "no model" state.
360
+ }
361
+ })();
362
+ return () => { cancelled = true; };
363
+ }, [props.open, ctx]);
364
+
365
+ // An agent-initiated request arrives with a path and proposed items; seed
366
+ // the form from it so confirming is a single click. Declared BEFORE the
367
+ // catalog load so `picked` is ready by the time the cards render.
368
+ useEffect(() => {
369
+ if (!props.open) return;
370
+ const pending = props.pending;
371
+ if (!pending) return;
372
+ const next = {};
373
+ for (const id of (pending.presetIds || [])) next[id] = true;
374
+ setPicked(next);
375
+ if (typeof pending.customPrompt === 'string') setCustomPrompt(pending.customPrompt);
376
+ // A request always starts at the configuration step: the user must see
377
+ // and confirm the choices.
378
+ setStep('configure');
379
+ setResult(null);
380
+ }, [props.open, props.pending]);
381
+
382
+ useEffect(() => {
383
+ if (!notice) return undefined;
384
+ const id = setTimeout(() => { if (aliveRef.current) setNotice(''); }, 3000);
385
+ return () => clearTimeout(id);
386
+ }, [notice]);
387
+
388
+ const allPresets = [...presets.builtin, ...presets.custom];
389
+ const selectedIds = allPresets.filter((preset) => picked[preset.id]).map((preset) => preset.id);
390
+ const hasSelection = selectedIds.length > 0 || customPrompt.trim() !== '';
391
+
392
+ const togglePreset = (id) => {
393
+ setPicked((previous) => ({ ...previous, [id]: !previous[id] }));
394
+ };
395
+
396
+ const savePreset = async () => {
397
+ const title = saveTitle.trim();
398
+ const prompt = customPrompt.trim();
399
+ if (title === '' || prompt === '') return;
400
+ try {
401
+ const data = await api(ctx, API + '/presets', {
402
+ method: 'POST',
403
+ body: { title, prompt, category: 'custom' },
404
+ });
405
+ if (!aliveRef.current) return;
406
+ setSaveOpen(false);
407
+ setSaveTitle('');
408
+ setNotice(t('rvPresetSaved'));
409
+ const preset = data && data.preset;
410
+ if (preset) {
411
+ setPresets((previous) => ({ ...previous, custom: [...previous.custom, preset] }));
412
+ setPicked((previous) => ({ ...previous, [preset.id]: true }));
413
+ }
414
+ } catch (err) {
415
+ if (aliveRef.current) setError(err.message);
416
+ }
417
+ };
418
+
419
+ const deletePreset = async (id) => {
420
+ try {
421
+ await api(ctx, API + '/presets/delete', { method: 'POST', body: { id } });
422
+ if (!aliveRef.current) return;
423
+ setPresets((previous) => ({
424
+ ...previous,
425
+ custom: previous.custom.filter((preset) => preset.id !== id),
426
+ }));
427
+ } catch (err) {
428
+ if (aliveRef.current) setError(err.message);
429
+ }
430
+ };
431
+
432
+ const run = async () => {
433
+ setRunning(true);
434
+ setError('');
435
+ setResult(null);
436
+ setStep('running');
437
+ try {
438
+ /* 与 npm 的发布前审查共用同一套后端:/review/project 一次覆盖
439
+ * git 改动与包内容,避免两份审查逻辑各自演化。GitHub 面板只要
440
+ * git 那部分,所以关掉 includePack。 */
441
+ const data = await api(ctx, API + '/project', {
442
+ method: 'POST',
443
+ body: {
444
+ path: props.path,
445
+ presetIds: selectedIds,
446
+ customPrompt: customPrompt.trim(),
447
+ provider: modelValue.provider,
448
+ model: modelValue.model,
449
+ reasoningEffort: modelValue.reasoningEffort || undefined,
450
+ includeGit: true,
451
+ // GitHub 面板只关心即将提交的改动,不重复审 npm 包内容。
452
+ includePack: false,
453
+ maxFiles,
454
+ },
455
+ });
456
+ if (!aliveRef.current) return;
457
+ setResult(data);
458
+ setStep('result');
459
+ if (props.onReviewed) props.onReviewed(data);
460
+ } catch (err) {
461
+ if (!aliveRef.current) return;
462
+ setError(err.message);
463
+ setStep('confirm');
464
+ } finally {
465
+ if (aliveRef.current) setRunning(false);
466
+ }
467
+ };
468
+
469
+ /**
470
+ * The files the confirmation screen advertises.
471
+ *
472
+ * The authoritative list only exists after the Host collects the diff, so
473
+ * this is the caller's best estimate from the status it already has; the
474
+ * wording says so for exactly that reason.
475
+ */
476
+ const estimatedFiles = (props.status && Array.isArray(props.status.files)
477
+ ? props.status.files.filter((file) => (stagedOnly ? file.staged : true))
478
+ : []);
479
+
480
+ /* ---------------- screen 1: configure ---------------- */
481
+ const configureBody = [
482
+ h('div', { className: 'dsh-push-rv-head', key: 'head' },
483
+ h('span', { className: 'dsh-push-rv-title' }, t('rvTitle')),
484
+ // A dialog that opened by itself must say why. Computed inline on
485
+ // purpose: a component-local flag was once declared in ANOTHER
486
+ // component by mistake, and the resulting ReferenceError stopped the
487
+ // whole sidebar from opening.
488
+ (props.pending && props.pending.source === 'agent')
489
+ ? h('span', { className: 'dsh-push-rv-agenttag', title: t('rvAgentAskedHint') },
490
+ t('rvAgentAsked'))
491
+ : null,
492
+ h('span', { className: 'dsh-push-rv-spacer' }),
493
+ h('button', {
494
+ type: 'button',
495
+ className: 'dsh-push-iconbtn' + (settingsOpen ? ' is-on' : ''),
496
+ title: t('rvSettings'),
497
+ 'aria-label': t('rvSettings'),
498
+ onClick: () => setSettingsOpen((v) => !v),
499
+ }, h(Icon, { name: 'gear', size: 14 })),
500
+ h('button', {
501
+ type: 'button',
502
+ className: 'dsh-push-iconbtn',
503
+ title: t('rvClose'),
504
+ 'aria-label': t('rvClose'),
505
+ onClick: props.onClose,
506
+ }, h(Icon, { name: 'close', size: 13 }))),
507
+
508
+ h('div', { className: 'dsh-push-rv-sub', key: 'model' },
509
+ h('span', { className: 'dsh-push-rv-sub-label' }, t('rvModel')),
510
+ h(ModelPicker, { models, value: modelValue, onChange: setModelValue })),
511
+
512
+ settingsOpen
513
+ ? h('div', { className: 'dsh-push-rv-settings', key: 'settings' },
514
+ h(ReviewField, { label: t('rvStagedOnly') },
515
+ h(Switch, { checked: stagedOnly, label: t('rvStagedOnly'), onChange: setStagedOnly })),
516
+ h(ReviewField, { label: t('rvMaxFiles') },
517
+ h('input', {
518
+ className: 'dsh-push-input dsh-push-rv-number',
519
+ type: 'number',
520
+ min: 1,
521
+ max: 500,
522
+ value: String(maxFiles),
523
+ onChange: (event) => {
524
+ const next = Number(event.target.value);
525
+ setMaxFiles(Number.isFinite(next) && next > 0 ? Math.trunc(next) : 60);
526
+ },
527
+ })))
528
+ : null,
529
+
530
+ h('div', { className: 'dsh-push-rv-divider', key: 'd1' }),
531
+
532
+ // The ONLY scrolling region: presets can be numerous, so everything else
533
+ // stays put and the footer is always reachable.
534
+ h('div', { className: 'dsh-push-rv-scroll', key: 'presets' },
535
+ presets.categories.map((category) => {
536
+ const inCategory = allPresets.filter((preset) => preset.category === category.id);
537
+ if (inCategory.length === 0) return null;
538
+ return h('div', { className: 'dsh-push-rv-group', key: category.id },
539
+ h('div', { className: 'dsh-push-rv-group-head' }, category.label),
540
+ h('div', { className: 'dsh-push-rv-cards' }, inCategory.map((preset) => {
541
+ const on = Boolean(picked[preset.id]);
542
+ return h('button', {
543
+ key: preset.id,
544
+ type: 'button',
545
+ className: 'dsh-push-rv-card' + (on ? ' is-on' : ''),
546
+ 'aria-pressed': on ? 'true' : 'false',
547
+ onClick: () => togglePreset(preset.id),
548
+ },
549
+ h('span', { className: 'dsh-push-rv-card-check' },
550
+ on ? h(Icon, { name: 'check', size: 11 }) : null),
551
+ h('span', { className: 'dsh-push-rv-card-main' },
552
+ h('span', { className: 'dsh-push-rv-card-title' }, preset.title),
553
+ h('span', { className: 'dsh-push-rv-card-desc' }, preset.description)),
554
+ preset.builtin
555
+ ? null
556
+ : h('span', {
557
+ className: 'dsh-push-rv-card-del',
558
+ role: 'button',
559
+ tabIndex: 0,
560
+ title: t('rvDeletePreset'),
561
+ onClick: (event) => {
562
+ event.stopPropagation();
563
+ deletePreset(preset.id);
564
+ },
565
+ }, h(Icon, { name: 'close', size: 10 })));
566
+ })));
567
+ })),
568
+
569
+ h('div', { className: 'dsh-push-rv-divider', key: 'd2' }),
570
+
571
+ h('div', { className: 'dsh-push-rv-custom', key: 'custom' },
572
+ h('div', { className: 'dsh-push-rv-custom-head' },
573
+ h('span', null, t('rvCustomPrompt')),
574
+ saveOpen
575
+ ? h('div', { className: 'dsh-push-rv-inline' },
576
+ h('input', {
577
+ className: 'dsh-push-input dsh-push-rv-number',
578
+ type: 'text',
579
+ placeholder: t('rvSavePresetTitle'),
580
+ value: saveTitle,
581
+ onChange: (event) => setSaveTitle(event.target.value),
582
+ onKeyDown: (event) => { if (event.key === 'Enter') savePreset(); },
583
+ }),
584
+ h(Btn, { kind: 'primary', mini: true, onClick: savePreset }, t('rvSave')),
585
+ h(Btn, { mini: true, onClick: () => setSaveOpen(false) }, t('rvCancel')))
586
+ : h(Btn, {
587
+ mini: true,
588
+ disabled: customPrompt.trim() === '',
589
+ onClick: () => setSaveOpen(true),
590
+ }, t('rvSavePreset'))),
591
+ h('textarea', {
592
+ className: 'dsh-push-rv-textarea',
593
+ placeholder: t('rvCustomPlaceholder'),
594
+ value: customPrompt,
595
+ onChange: (event) => setCustomPrompt(event.target.value),
596
+ })),
597
+
598
+ error ? h('div', { className: 'dsh-push-error dsh-push-rv-error', key: 'err' }, error) : null,
599
+ notice ? h('div', { className: 'dsh-push-ok dsh-push-rv-error', key: 'notice' }, notice) : null,
600
+ ];
601
+
602
+ const configureFooter = [
603
+ h('span', { className: 'dsh-push-rv-muted', key: 'count' },
604
+ selectedIds.length > 0
605
+ ? t('rvSelected', { n: selectedIds.length })
606
+ : t('rvSelectionEmpty')),
607
+ h('span', { className: 'dsh-push-rv-spacer', key: 'spacer' }),
608
+ h(Btn, { key: 'cancel', onClick: props.onClose }, t('rvCancel')),
609
+ h(Btn, {
610
+ key: 'next',
611
+ kind: 'primary',
612
+ disabled: !hasSelection,
613
+ onClick: () => { setStep('confirm'); setResult(null); },
614
+ }, t('rvNext')),
615
+ ];
616
+
617
+ /* ---------------- screen 2: confirm ---------------- */
618
+ const confirmBody = [
619
+ h('div', { className: 'dsh-push-rv-head', key: 'head' },
620
+ h('span', { className: 'dsh-push-rv-title' }, t('rvConfirmTitle')),
621
+ h('span', { className: 'dsh-push-rv-spacer' }),
622
+ h('button', {
623
+ type: 'button',
624
+ className: 'dsh-push-iconbtn',
625
+ title: t('rvClose'),
626
+ 'aria-label': t('rvClose'),
627
+ onClick: props.onClose,
628
+ }, h(Icon, { name: 'close', size: 13 }))),
629
+
630
+ h('div', { className: 'dsh-push-rv-confirm', key: 'body' },
631
+ h(ReviewField, { label: t('rvConfirmModel') },
632
+ h(ModelPicker, { models, value: modelValue, onChange: setModelValue })),
633
+
634
+ h(ReviewField, { label: t('rvConfirmEffort') },
635
+ h('span', { className: 'dsh-push-rv-muted' },
636
+ effortLabelFor(models, modelValue) || t('rvEffortDefault'))),
637
+
638
+ h('div', { className: 'dsh-push-rv-files' },
639
+ h('button', {
640
+ type: 'button',
641
+ className: 'dsh-push-rv-files-head',
642
+ onClick: () => setFilesOpen((v) => !v),
643
+ },
644
+ h(Icon, { name: 'chevron', size: 11 }),
645
+ h('span', null, t('rvConfirmFiles', { n: estimatedFiles.length })),
646
+ h('span', { className: 'dsh-push-rv-muted' }, ' (' + t('rvConfirmFilesHint') + ')')),
647
+ filesOpen
648
+ ? h('div', { className: 'dsh-push-rv-filelist' },
649
+ estimatedFiles.length === 0
650
+ ? h('div', { className: 'dsh-push-rv-muted' }, t('rvNoFindings'))
651
+ : estimatedFiles.map((file) => h('div', {
652
+ key: file.path,
653
+ className: 'dsh-push-rv-filerow',
654
+ },
655
+ h('span', { className: 'dsh-push-rv-filename' }, file.path),
656
+ h('span', { className: 'dsh-push-rv-muted' },
657
+ ' +' + (file.additions || 0) + ' -' + (file.deletions || 0)))))
658
+ : null),
659
+
660
+ h(ReviewField, { label: t('rvConfirmFeatures') },
661
+ h('div', { className: 'dsh-push-rv-chips' },
662
+ selectedIds.length === 0 && customPrompt.trim() === ''
663
+ ? h('span', { className: 'dsh-push-rv-muted' }, t('rvSelectionEmpty'))
664
+ : [
665
+ ...allPresets
666
+ .filter((preset) => picked[preset.id])
667
+ .map((preset) => h('span', {
668
+ key: preset.id,
669
+ className: 'dsh-push-pill',
670
+ }, preset.title)),
671
+ customPrompt.trim() === ''
672
+ ? null
673
+ : h('span', { key: 'custom', className: 'dsh-push-pill dsh-push-pill--active' },
674
+ t('rvConfirmCustomChip')),
675
+ ]))),
676
+
677
+ error ? h('div', { className: 'dsh-push-error dsh-push-rv-error', key: 'err' }, error) : null,
678
+ ];
679
+
680
+ const confirmFooter = [
681
+ h(Btn, { key: 'back', onClick: () => setStep('configure') }, t('rvBack')),
682
+ h('span', { className: 'dsh-push-rv-spacer', key: 'spacer' }),
683
+ running
684
+ ? h('span', { className: 'dsh-push-rv-muted', key: 'running' },
685
+ t('rvRunningWith', { model: modelValue.model || t('rvNoModels') }))
686
+ : h(Btn, { key: 'start', kind: 'primary', onClick: run }, t('rvStart')),
687
+ ];
688
+
689
+ /* ---------------- screen 3: result ---------------- */
690
+ const findings = (result && result.findings) || [];
691
+ const resultBody = [
692
+ h('div', { className: 'dsh-push-rv-head', key: 'head' },
693
+ h('span', { className: 'dsh-push-rv-title' }, t('rvResult')),
694
+ h('span', { className: 'dsh-push-rv-spacer' }),
695
+ h('button', {
696
+ type: 'button',
697
+ className: 'dsh-push-iconbtn',
698
+ title: t('rvClose'),
699
+ 'aria-label': t('rvClose'),
700
+ onClick: props.onClose,
701
+ }, h(Icon, { name: 'close', size: 13 }))),
702
+
703
+ h('div', { className: 'dsh-push-rv-result', key: 'body' },
704
+ h('p', { className: 'dsh-push-rv-summary' }, (result && result.summary) || ''),
705
+ result && result.degraded
706
+ ? h('div', { className: 'dsh-push-rv-muted' }, t('rvDegraded'))
707
+ : null,
708
+ result && result.truncated
709
+ ? h('div', { className: 'dsh-push-rv-muted' }, t('rvTruncated'))
710
+ : null,
711
+ findings.length === 0
712
+ ? h('div', { className: 'dsh-push-rv-empty' }, t('rvNoFindings'))
713
+ : h('div', { className: 'dsh-push-rv-findings' }, findings.map((finding, index) => h('div', {
714
+ key: index,
715
+ className: 'dsh-push-rv-finding ' + (SEVERITY_TONE[finding.severity] || ''),
716
+ },
717
+ h('div', { className: 'dsh-push-rv-finding-head' },
718
+ h('span', { className: 'dsh-push-rv-sev' },
719
+ t(SEVERITY_LABEL[finding.severity] || 'rvSeverityInfo')),
720
+ h('span', { className: 'dsh-push-rv-finding-title' }, finding.title),
721
+ finding.file
722
+ ? h('span', { className: 'dsh-push-rv-muted dsh-push-rv-loc' },
723
+ finding.file + (finding.line ? ':' + finding.line : ''))
724
+ : null),
725
+ finding.detail ? h('div', { className: 'dsh-push-rv-finding-detail' }, finding.detail) : null,
726
+ finding.suggestion
727
+ ? h('div', { className: 'dsh-push-rv-finding-sug' }, finding.suggestion)
728
+ : null)))),
729
+ ];
730
+
731
+ return h(Modal, {
732
+ open: props.open,
733
+ onClose: props.onClose,
734
+ // The dialogs render their own header (title + gear + close), so the shell's
735
+ // title bar is suppressed.
736
+ bare: true,
737
+ wide: true,
738
+ footer: step === 'configure'
739
+ ? configureFooter
740
+ : step === 'result'
741
+ ? [
742
+ h(Btn, { key: 'again', onClick: () => { setStep('confirm'); setResult(null); } }, t('rvRerun')),
743
+ h('span', { className: 'dsh-push-rv-spacer', key: 'spacer' }),
744
+ h(Btn, { key: 'done', kind: 'primary', onClick: props.onClose }, t('rvDone')),
745
+ ]
746
+ : confirmFooter,
747
+ }, step === 'configure' ? configureBody : (step === 'result' ? resultBody : confirmBody));
748
+ }
749
+
750
+ /* ───────────────────── 发布前审查(npm 包内容,npm 用) ────────────────── */
751
+
752
+ function NpmReviewDialog(props) {
753
+ const ctx = props.ctx;
754
+ const [step, setStep] = useState('configure');
755
+ const [presets, setPresets] = useState({ builtin: [], custom: [], categories: [] });
756
+ const [models, setModels] = useState({ providers: [], default: null });
757
+ const [picked, setPicked] = useState({});
758
+ const [customPrompt, setCustomPrompt] = useState('');
759
+ const [modelValue, setModelValue] = useState({ provider: '', model: '', reasoningEffort: '' });
760
+ const [result, setResult] = useState(null);
761
+ const [running, setRunning] = useState(false);
762
+ // 已用时间:让「还在跑」和「卡死了」可以区分。
763
+ const [elapsedMs, setElapsedMs] = useState(0);
764
+ /* 运行期间每秒刷新已用时间。清理函数确保关闭后不再计时。
765
+ * 这个计时器是「让人理解在等什么」的关键:
766
+ * 没有它,界面停在同一个画面,用户无法区分「还在跑」与「卡死了」。 */
767
+ useEffect(() => {
768
+ if (!running) return undefined;
769
+ const startedAt = Date.now();
770
+ setElapsedMs(0);
771
+ const timer = setInterval(() => {
772
+ if (aliveRef.current) setElapsedMs(Date.now() - startedAt);
773
+ }, 1000);
774
+ return () => clearInterval(timer);
775
+ }, [running]);
776
+ const [error, setError] = useState('');
777
+ const aliveRef = useRef(true);
778
+
779
+ useEffect(() => {
780
+ aliveRef.current = true;
781
+ return () => { aliveRef.current = false; };
782
+ }, []);
783
+
784
+ /* 每次打开都重新拉目录:设置里刚改的预设应当立即可见。 */
785
+ useEffect(() => {
786
+ if (!props.open) return undefined;
787
+ let cancelled = false;
788
+ (async () => {
789
+ try {
790
+ const data = await api(ctx, API + '/presets');
791
+ if (cancelled || !aliveRef.current) return;
792
+ setPresets({
793
+ builtin: (data && data.builtin) || [],
794
+ custom: (data && data.custom) || [],
795
+ categories: (data && data.categories) || [],
796
+ });
797
+ } catch (err) {
798
+ if (!cancelled && aliveRef.current) setError(err.message);
799
+ }
800
+ try {
801
+ const data = await api(ctx, API + '/models');
802
+ if (cancelled || !aliveRef.current) return;
803
+ setModels({
804
+ providers: (data && data.providers) || [],
805
+ default: (data && data.default) || null,
806
+ });
807
+ if (data && data.default) {
808
+ setModelValue({
809
+ provider: data.default.provider || '',
810
+ model: data.default.model || '',
811
+ reasoningEffort: data.default.reasoningEffort || '',
812
+ });
813
+ }
814
+ } catch { /* 没有模型也能只跑规则扫描 */ }
815
+ })();
816
+ return () => { cancelled = true; };
817
+ }, [ctx, props.open]);
818
+
819
+ const reset = () => {
820
+ setStep('configure');
821
+ setResult(null);
822
+ setError('');
823
+ setRunning(false);
824
+ };
825
+
826
+ const togglePreset = (id) => setPicked((prev) => ({ ...prev, [id]: !prev[id] }));
827
+
828
+ const allPresets = [...presets.builtin, ...presets.custom];
829
+ const selectedIds = Object.keys(picked).filter((id) => picked[id]);
830
+
831
+ const run = async () => {
832
+ setRunning(true);
833
+ setError('');
834
+ setResult(null);
835
+ setStep('running');
836
+ try {
837
+ const data = await api(ctx, API + '/package', {
838
+ method: 'POST',
839
+ body: {
840
+ path: props.cwd,
841
+ presetIds: selectedIds,
842
+ customPrompt: customPrompt.trim(),
843
+ provider: modelValue.provider,
844
+ model: modelValue.model,
845
+ reasoningEffort: modelValue.reasoningEffort || undefined,
846
+ },
847
+ });
848
+ if (!aliveRef.current) return;
849
+ setResult(data);
850
+ setStep('result');
851
+ if (typeof props.onReviewed === 'function') props.onReviewed(data);
852
+ } catch (err) {
853
+ if (!aliveRef.current) return;
854
+ setError(err.message);
855
+ setStep('configure');
856
+ } finally {
857
+ if (aliveRef.current) setRunning(false);
858
+ }
859
+ };
860
+
861
+ if (!props.open) return null;
862
+
863
+ const providerList = models.providers || [];
864
+ const activeProvider = providerList.find((row) => row.id === modelValue.provider);
865
+ const modelList = (activeProvider && activeProvider.models) || [];
866
+
867
+ /* ---- 配置页:结构与 GitHub 的 ReviewDialog 一致 ---- */
868
+ const configureBody = [
869
+ h('div', { className: 'dsh-push-rv-head', key: 'head' },
870
+ h('span', { className: 'dsh-push-rv-title' }, t('npmReviewTitle')),
871
+ h('span', { className: 'dsh-push-rv-spacer' }),
872
+ h('button', {
873
+ type: 'button',
874
+ className: 'dsh-push-iconbtn',
875
+ title: t('rvClose'),
876
+ 'aria-label': t('rvClose'),
877
+ onClick: props.onClose,
878
+ }, h(Icon, { name: 'close', size: 13 }))),
879
+
880
+ h('div', { className: 'dsh-push-rv-sub', key: 'model' },
881
+ h('span', { className: 'dsh-push-rv-sub-label' }, t('rvModel')),
882
+ h('select', {
883
+ className: 'dsh-push-select',
884
+ value: modelValue.provider,
885
+ onChange: (e) => setModelValue({ provider: e.target.value, model: '', reasoningEffort: '' }),
886
+ },
887
+ h('option', { value: '' }, t('rvNoModel')),
888
+ providerList.map((row) => h('option', { key: row.id, value: row.id }, row.name || row.id))),
889
+ h('select', {
890
+ className: 'dsh-push-select',
891
+ value: modelValue.model,
892
+ disabled: modelList.length === 0,
893
+ onChange: (e) => setModelValue(Object.assign({}, modelValue, { model: e.target.value, reasoningEffort: '' })),
894
+ },
895
+ h('option', { value: '' }, '—'),
896
+ modelList.map((row) => h('option', { key: row.id, value: row.id }, row.name || row.id)))),
897
+
898
+ h('div', { className: 'dsh-push-rv-divider', key: 'd1' }),
899
+
900
+ /* 唯一可滚动的区域:预设可能很多,其余部分保持不动、页脚始终可达。 */
901
+ h('div', { className: 'dsh-push-rv-scroll', key: 'presets' },
902
+ presets.categories.map((category) => {
903
+ const inCategory = allPresets.filter((preset) => preset.category === category.id);
904
+ if (inCategory.length === 0) return null;
905
+ return h('div', { className: 'dsh-push-rv-group', key: category.id },
906
+ h('div', { className: 'dsh-push-rv-group-head' }, category.label || category.title),
907
+ h('div', { className: 'dsh-push-rv-cards' }, inCategory.map((preset) => {
908
+ const on = Boolean(picked[preset.id]);
909
+ return h('button', {
910
+ key: preset.id,
911
+ type: 'button',
912
+ className: 'dsh-push-rv-card' + (on ? ' is-on' : ''),
913
+ 'aria-pressed': on ? 'true' : 'false',
914
+ onClick: () => togglePreset(preset.id),
915
+ },
916
+ h('span', { className: 'dsh-push-rv-card-check' },
917
+ on ? h(Icon, { name: 'check', size: 11 }) : null),
918
+ h('span', { className: 'dsh-push-rv-card-main' },
919
+ h('span', { className: 'dsh-push-rv-card-title' }, preset.title),
920
+ h('span', { className: 'dsh-push-rv-card-desc' }, preset.description || '')));
921
+ })));
922
+ })),
923
+
924
+ h('div', { className: 'dsh-push-rv-divider', key: 'd2' }),
925
+
926
+ h('div', { className: 'dsh-push-rv-custom', key: 'custom' },
927
+ h('div', { className: 'dsh-push-rv-custom-head' },
928
+ h('span', null, t('rvCustomPrompt'))),
929
+ h('textarea', {
930
+ className: 'dsh-push-rv-textarea',
931
+ placeholder: t('rvCustomPlaceholder'),
932
+ value: customPrompt,
933
+ onChange: (e) => setCustomPrompt(e.target.value),
934
+ })),
935
+
936
+ props.cwd === ''
937
+ ? h('div', { className: 'dsh-push-error dsh-push-rv-error', key: 'nodir' }, t('npmReviewNeedDir'))
938
+ : null,
939
+ error ? h('div', { className: 'dsh-push-error dsh-push-rv-error', key: 'err' }, error) : null,
940
+ ];
941
+
942
+ const configureFooter = [
943
+ h('span', { className: 'dsh-push-rv-muted', key: 'count' },
944
+ selectedIds.length > 0
945
+ ? t('rvSelected', { n: selectedIds.length })
946
+ : t('rvSelectionEmpty')),
947
+ h('span', { className: 'dsh-push-rv-spacer', key: 'spacer' }),
948
+ h('span', { className: 'dsh-push-rv-muted', key: 'busyhint' },
949
+ running ? t('rvRunningFooter') : ''),
950
+ h(Btn, { key: 'cancel', onClick: props.onClose }, t('rvCancel')),
951
+ h(Btn, {
952
+ key: 'run',
953
+ kind: 'primary',
954
+ disabled: running || props.cwd === '',
955
+ onClick: run,
956
+ }, running ? t('rvRunning') : t('rvRun')),
957
+ ];
958
+
959
+ /* ---- 结果页 ---- */
960
+ const findings = (result && result.findings) || [];
961
+ const blockers = findings.filter((row) => row.severity === 'blocker').length;
962
+
963
+ const resultBody = [
964
+ h('div', { className: 'dsh-push-rv-head', key: 'head' },
965
+ h('span', { className: 'dsh-push-rv-title' }, t('npmReviewResultTitle')),
966
+ h('span', { className: 'dsh-push-rv-spacer' }),
967
+ h('button', {
968
+ type: 'button',
969
+ className: 'dsh-push-iconbtn',
970
+ title: t('rvClose'),
971
+ 'aria-label': t('rvClose'),
972
+ onClick: props.onClose,
973
+ }, h(Icon, { name: 'close', size: 13 }))),
974
+
975
+ h('div', { className: 'dsh-push-rv-summary', key: 'summary' },
976
+ (result && result.summary) || ''),
977
+
978
+ result && result.degraded
979
+ ? h('div', { className: 'dsh-push-rv-muted', key: 'degraded' }, t('rvDegraded'))
980
+ : null,
981
+ props.cwd === ''
982
+ ? null
983
+ : null,
984
+
985
+ h('div', { className: 'dsh-push-rv-scroll', key: 'findings' },
986
+ findings.length === 0
987
+ ? h('div', { className: 'dsh-push-ok' }, t('rvNoFindings'))
988
+ : h('div', { className: 'dsh-push-rv-findings' }, findings.map((finding, index) => h('div', {
989
+ key: (finding.id || finding.file || 'f') + ':' + index,
990
+ className: 'dsh-push-rv-finding ' + (SEVERITY_TONE[finding.severity] || ''),
991
+ },
992
+ h('div', { className: 'dsh-push-rv-finding-head' },
993
+ h('span', { className: 'dsh-push-rv-sev' },
994
+ h('span', { className: 'dsh-push-rv-dot' }),
995
+ t(SEVERITY_LABEL[finding.severity] || 'rvSeverityInfo')),
996
+ h('span', { className: 'dsh-push-rv-finding-title' }, finding.title)),
997
+ finding.detail
998
+ ? h('div', { className: 'dsh-push-rv-finding-detail' }, finding.detail)
999
+ : null,
1000
+ finding.file
1001
+ ? h('div', { className: 'dsh-push-rv-finding-file' }, finding.file)
1002
+ : null)))),
1003
+
1004
+ blockers > 0
1005
+ ? h('div', { className: 'dsh-push-error dsh-push-rv-error', key: 'blocked' }, t('npmReviewBlocker'))
1006
+ : null,
1007
+ ];
1008
+
1009
+ const resultFooter = [
1010
+ h('span', { className: 'dsh-push-rv-spacer', key: 'spacer' }),
1011
+ h(Btn, { key: 'again', onClick: reset }, t('rvRunAgain')),
1012
+ h(Btn, { key: 'done', kind: 'primary', onClick: () => { reset(); props.onClose(); } }, t('rvDone')),
1013
+ ];
1014
+
1015
+ /* ---- 运行中:说明正在做什么,并显示已用时间 ---- */
1016
+ const runningBody = [
1017
+ h('div', { className: 'dsh-push-rv-head', key: 'head' },
1018
+ h('span', { className: 'dsh-push-rv-title' }, t('npmReviewRunningTitle')),
1019
+ h('span', { className: 'dsh-push-rv-spacer' }),
1020
+ h('button', {
1021
+ type: 'button',
1022
+ className: 'dsh-push-iconbtn',
1023
+ title: t('rvClose'),
1024
+ 'aria-label': t('rvClose'),
1025
+ onClick: props.onClose,
1026
+ }, h(Icon, { name: 'close', size: 13 }))),
1027
+
1028
+ h('div', { className: 'dsh-push-rv-scroll', key: 'body' },
1029
+ h('div', { className: 'dsh-push-npm-reviewrunning' },
1030
+ /* 三步说明:用户能对上「现在到哪一步了」。 */
1031
+ h('div', { className: 'dsh-push-npm-step' },
1032
+ h('span', { className: 'dsh-push-npm-step-dot is-done' }),
1033
+ h('span', null, t('npmReviewStep1'))),
1034
+ h('div', { className: 'dsh-push-npm-step' },
1035
+ h('span', { className: 'dsh-push-npm-step-dot is-done' }),
1036
+ h('span', null, t('npmReviewStep2'))),
1037
+ h('div', { className: 'dsh-push-npm-step' },
1038
+ h('span', { className: 'dsh-push-npm-step-dot is-active' }),
1039
+ h('span', null,
1040
+ modelValue.model
1041
+ ? t('npmReviewStep3Model', { model: modelValue.model })
1042
+ : t('npmReviewStep3Rules'))),
1043
+
1044
+ h('div', { className: 'dsh-push-npm-elapsed' },
1045
+ t('npmReviewElapsed', { s: Math.floor(elapsedMs / 1000) })),
1046
+
1047
+ h('div', { className: 'dsh-push-hint' }, t('npmReviewWaitHint')),
1048
+
1049
+ /* 没有模型时会很快,有模型则可能需要几十秒。 */
1050
+ modelValue.model
1051
+ ? h('div', { className: 'dsh-push-row-hint' }, t('npmReviewSlowHint'))
1052
+ : null)),
1053
+ ];
1054
+
1055
+ return h(Modal, {
1056
+ open: props.open,
1057
+ // bare:对话框自己渲染头部(标题 + 关闭),避免出现两条标题栏。
1058
+ bare: true,
1059
+ wide: true,
1060
+ onClose: () => { reset(); props.onClose(); },
1061
+ footer: step === 'result' ? resultFooter : configureFooter,
1062
+ }, step === 'running' ? runningBody
1063
+ : (step === 'result' ? resultBody : configureBody));
1064
+ }
1065
+
1066
+ /* ─────────────── 统一项目审查(一次覆盖 git + npm) ─────────────── */
1067
+
1068
+ function buildFixPrompt(findings, cwd) {
1069
+ const lines = [
1070
+ '请修复以下审查发现的问题。',
1071
+ '',
1072
+ '项目目录:' + (cwd || '(未指定)'),
1073
+ '需要修复 ' + findings.length + ' 处:',
1074
+ '',
1075
+ ];
1076
+ for (const [index, finding] of findings.entries()) {
1077
+ lines.push((index + 1) + '. [' + finding.severity + '] ' + finding.title);
1078
+ if (finding.file) lines.push(' 文件:' + finding.file);
1079
+ if (finding.line) lines.push(' 行号:' + finding.line);
1080
+ if (finding.detail) lines.push(' 说明:' + finding.detail);
1081
+ lines.push('');
1082
+ }
1083
+ lines.push('要求:只修改上述问题涉及的地方,不要顺带重构无关代码。');
1084
+ lines.push('修改完成后列出每个文件改了什么。');
1085
+ return lines.join('\n');
1086
+ }
1087
+
1088
+ function ProjectReviewDialog(props) {
1089
+ const ctx = props.ctx;
1090
+ const [step, setStep] = useState('configure');
1091
+ const [presets, setPresets] = useState({ builtin: [], custom: [], categories: [] });
1092
+ const [models, setModels] = useState({ providers: [], default: null });
1093
+ const [picked, setPicked] = useState({});
1094
+ const [customPrompt, setCustomPrompt] = useState('');
1095
+ const [modelValue, setModelValue] = useState({ provider: '', model: '', reasoningEffort: '' });
1096
+ const [includeGit, setIncludeGit] = useState(true);
1097
+ const [includePack, setIncludePack] = useState(true);
1098
+ const [result, setResult] = useState(props.initialResult || null);
1099
+ const [running, setRunning] = useState(false);
1100
+ const [error, setError] = useState('');
1101
+ const [elapsedMs, setElapsedMs] = useState(0);
1102
+ /* 结果页里被勾选的问题(用于一键复制修复提示词)。 */
1103
+ const [chosenFindings, setChosenFindings] = useState({});
1104
+ const [copied, setCopied] = useState(false);
1105
+ const aliveRef = useRef(true);
1106
+
1107
+ useEffect(() => {
1108
+ aliveRef.current = true;
1109
+ return () => { aliveRef.current = false; };
1110
+ }, []);
1111
+
1112
+ /* 打开时若已带结果(用户点了摘要卡片),直接进结果页。 */
1113
+ useEffect(() => {
1114
+ if (!props.open) return;
1115
+ if (props.initialResult) {
1116
+ setResult(props.initialResult);
1117
+ setStep('result');
1118
+ } else if (!result) {
1119
+ setStep(props.initialStep || 'configure');
1120
+ }
1121
+ }, [props.open, props.initialResult, props.initialStep, result]);
1122
+
1123
+ useEffect(() => {
1124
+ if (!props.open) return undefined;
1125
+ let cancelled = false;
1126
+ (async () => {
1127
+ try {
1128
+ const data = await api(ctx, API + '/presets');
1129
+ if (cancelled || !aliveRef.current) return;
1130
+ setPresets({
1131
+ builtin: (data && data.builtin) || [],
1132
+ custom: (data && data.custom) || [],
1133
+ categories: (data && data.categories) || [],
1134
+ });
1135
+ } catch (err) {
1136
+ if (!cancelled && aliveRef.current) setError(err.message);
1137
+ }
1138
+ try {
1139
+ const data = await api(ctx, API + '/models');
1140
+ if (cancelled || !aliveRef.current) return;
1141
+ setModels({ providers: (data && data.providers) || [], default: (data && data.default) || null });
1142
+ if (data && data.default) {
1143
+ setModelValue({
1144
+ provider: data.default.provider || '',
1145
+ model: data.default.model || '',
1146
+ reasoningEffort: data.default.reasoningEffort || '',
1147
+ });
1148
+ }
1149
+ } catch { /* 没有模型也能只跑规则扫描 */ }
1150
+ })();
1151
+ return () => { cancelled = true; };
1152
+ }, [ctx, props.open]);
1153
+
1154
+ useEffect(() => {
1155
+ if (!running) return undefined;
1156
+ const startedAt = Date.now();
1157
+ setElapsedMs(0);
1158
+ const timer = setInterval(() => {
1159
+ if (aliveRef.current) setElapsedMs(Date.now() - startedAt);
1160
+ }, 1000);
1161
+ return () => clearInterval(timer);
1162
+ }, [running]);
1163
+
1164
+ const togglePreset = (id) => setPicked((prev) => ({ ...prev, [id]: !prev[id] }));
1165
+ const allPresets = [...presets.builtin, ...presets.custom];
1166
+ const selectedIds = Object.keys(picked).filter((id) => picked[id]);
1167
+ const providerList = models.providers || [];
1168
+ const activeProvider = providerList.find((row) => row.id === modelValue.provider);
1169
+ const modelList = (activeProvider && activeProvider.models) || [];
1170
+
1171
+ const run = async () => {
1172
+ setRunning(true);
1173
+ setError('');
1174
+ setResult(null);
1175
+ setChosenFindings({});
1176
+ setStep('running');
1177
+ try {
1178
+ const data = await api(ctx, API + '/project', {
1179
+ method: 'POST',
1180
+ body: {
1181
+ path: props.cwd,
1182
+ presetIds: selectedIds,
1183
+ customPrompt: customPrompt.trim(),
1184
+ provider: modelValue.provider,
1185
+ model: modelValue.model,
1186
+ reasoningEffort: modelValue.reasoningEffort || undefined,
1187
+ includeGit,
1188
+ includePack,
1189
+ },
1190
+ });
1191
+ if (!aliveRef.current) return;
1192
+ setResult(data);
1193
+ setStep('result');
1194
+ if (typeof props.onReviewed === 'function') props.onReviewed(data);
1195
+ } catch (err) {
1196
+ if (!aliveRef.current) return;
1197
+ setError(err.message);
1198
+ setStep('configure');
1199
+ } finally {
1200
+ if (aliveRef.current) setRunning(false);
1201
+ }
1202
+ };
1203
+
1204
+ const close = () => {
1205
+ setRunning(false);
1206
+ setError('');
1207
+ props.onClose();
1208
+ };
1209
+
1210
+ if (!props.open) return null;
1211
+
1212
+ /* ---- 配置页 ---- */
1213
+ const configureBody = [
1214
+ h('div', { className: 'dsh-push-rv-head', key: 'head' },
1215
+ h('span', { className: 'dsh-push-rv-title' }, t('pjReviewTitle')),
1216
+ h('span', { className: 'dsh-push-rv-spacer' }),
1217
+ h('button', {
1218
+ type: 'button', className: 'dsh-push-iconbtn',
1219
+ title: t('rvClose'), 'aria-label': t('rvClose'), onClick: close,
1220
+ }, h(Icon, { name: 'close', size: 13 }))),
1221
+
1222
+ h('div', { className: 'dsh-push-rv-sub', key: 'model' },
1223
+ h('span', { className: 'dsh-push-rv-sub-label' }, t('rvModel')),
1224
+ h('select', {
1225
+ className: 'dsh-push-select',
1226
+ value: modelValue.provider,
1227
+ onChange: (e) => setModelValue({ provider: e.target.value, model: '', reasoningEffort: '' }),
1228
+ },
1229
+ h('option', { value: '' }, t('rvNoModel')),
1230
+ providerList.map((row) => h('option', { key: row.id, value: row.id }, row.name || row.id))),
1231
+ h('select', {
1232
+ className: 'dsh-push-select',
1233
+ value: modelValue.model,
1234
+ disabled: modelList.length === 0,
1235
+ onChange: (e) => setModelValue(Object.assign({}, modelValue, { model: e.target.value, reasoningEffort: '' })),
1236
+ },
1237
+ h('option', { value: '' }, '—'),
1238
+ modelList.map((row) => h('option', { key: row.id, value: row.id }, row.name || row.id)))),
1239
+
1240
+ /* 审查范围:这是「统一入口」的核心,一个开关决定覆盖哪些内容。 */
1241
+ h('div', { className: 'dsh-push-rv-sub', key: 'scope' },
1242
+ h('span', { className: 'dsh-push-rv-sub-label' }, t('pjScope')),
1243
+ h('label', { className: 'dsh-push-inline' },
1244
+ h('input', {
1245
+ type: 'checkbox', checked: includeGit,
1246
+ onChange: (e) => setIncludeGit(e.target.checked),
1247
+ }),
1248
+ h('span', { className: 'dsh-push-row-hint' }, t('pjScopeGit'))),
1249
+ h('label', { className: 'dsh-push-inline' },
1250
+ h('input', {
1251
+ type: 'checkbox', checked: includePack,
1252
+ onChange: (e) => setIncludePack(e.target.checked),
1253
+ }),
1254
+ h('span', { className: 'dsh-push-row-hint' }, t('pjScopeNpm')))),
1255
+
1256
+ h('div', { className: 'dsh-push-rv-divider', key: 'd1' }),
1257
+
1258
+ h('div', { className: 'dsh-push-rv-scroll', key: 'presets' },
1259
+ presets.categories.map((category) => {
1260
+ const inCategory = allPresets.filter((preset) => preset.category === category.id);
1261
+ if (inCategory.length === 0) return null;
1262
+ return h('div', { className: 'dsh-push-rv-group', key: category.id },
1263
+ h('div', { className: 'dsh-push-rv-group-head' }, category.label || category.title),
1264
+ h('div', { className: 'dsh-push-rv-cards' }, inCategory.map((preset) => {
1265
+ const on = Boolean(picked[preset.id]);
1266
+ return h('button', {
1267
+ key: preset.id, type: 'button',
1268
+ className: 'dsh-push-rv-card' + (on ? ' is-on' : ''),
1269
+ 'aria-pressed': on ? 'true' : 'false',
1270
+ onClick: () => togglePreset(preset.id),
1271
+ },
1272
+ h('span', { className: 'dsh-push-rv-card-check' },
1273
+ on ? h(Icon, { name: 'check', size: 11 }) : null),
1274
+ h('span', { className: 'dsh-push-rv-card-main' },
1275
+ h('span', { className: 'dsh-push-rv-card-title' }, preset.title),
1276
+ h('span', { className: 'dsh-push-rv-card-desc' }, preset.description || '')));
1277
+ })));
1278
+ })),
1279
+
1280
+ h('div', { className: 'dsh-push-rv-divider', key: 'd2' }),
1281
+
1282
+ h('div', { className: 'dsh-push-rv-custom', key: 'custom' },
1283
+ h('div', { className: 'dsh-push-rv-custom-head' }, h('span', null, t('rvCustomPrompt'))),
1284
+ h('textarea', {
1285
+ className: 'dsh-push-rv-textarea',
1286
+ placeholder: t('rvCustomPlaceholder'),
1287
+ value: customPrompt,
1288
+ onChange: (e) => setCustomPrompt(e.target.value),
1289
+ })),
1290
+
1291
+ props.cwd === ''
1292
+ ? h('div', { className: 'dsh-push-error dsh-push-rv-error', key: 'nodir' }, t('pjNeedDir'))
1293
+ : null,
1294
+ error ? h('div', { className: 'dsh-push-error dsh-push-rv-error', key: 'err' }, error) : null,
1295
+ ];
1296
+
1297
+ /* ---- 运行中 ---- */
1298
+ const runningBody = [
1299
+ h('div', { className: 'dsh-push-rv-head', key: 'head' },
1300
+ h('span', { className: 'dsh-push-rv-title' }, t('pjReviewRunning')),
1301
+ h('span', { className: 'dsh-push-rv-spacer' }),
1302
+ h('button', {
1303
+ type: 'button', className: 'dsh-push-iconbtn',
1304
+ title: t('rvClose'), 'aria-label': t('rvClose'), onClick: close,
1305
+ }, h(Icon, { name: 'close', size: 13 }))),
1306
+ h('div', { className: 'dsh-push-rv-scroll', key: 'body' },
1307
+ h('div', { className: 'dsh-push-npm-reviewrunning' },
1308
+ h('div', { className: 'dsh-push-npm-step' },
1309
+ h('span', { className: 'dsh-push-npm-step-dot' + (includeGit ? ' is-done' : '') }),
1310
+ h('span', null, t('pjStepGit'))),
1311
+ h('div', { className: 'dsh-push-npm-step' },
1312
+ h('span', { className: 'dsh-push-npm-step-dot' + (includePack ? ' is-done' : '') }),
1313
+ h('span', null, t('pjStepNpm'))),
1314
+ h('div', { className: 'dsh-push-npm-step' },
1315
+ h('span', { className: 'dsh-push-npm-step-dot is-active' }),
1316
+ h('span', null, modelValue.model
1317
+ ? t('pjStepModel', { model: modelValue.model })
1318
+ : t('pjStepRules'))),
1319
+ h('div', { className: 'dsh-push-npm-elapsed' },
1320
+ t('npmReviewElapsed', { s: Math.floor(elapsedMs / 1000) })),
1321
+ h('div', { className: 'dsh-push-hint' }, t('pjWaitHint')))),
1322
+ ];
1323
+
1324
+ /* ---- 结果页:可多选 + 一键复制修复提示词 ---- */
1325
+ const findings = (result && result.findings) || [];
1326
+ const chosenList = findings.filter((row, index) => chosenFindings[index]);
1327
+ const toggleFinding = (index) => setChosenFindings((prev) => ({ ...prev, [index]: !prev[index] }));
1328
+ const allChosen = findings.length > 0 && chosenList.length === findings.length;
1329
+
1330
+ const copyFix = async () => {
1331
+ const target = chosenList.length > 0 ? chosenList : findings;
1332
+ const ok = await copyText(buildFixPrompt(target, props.cwd));
1333
+ if (aliveRef.current) {
1334
+ setCopied(ok);
1335
+ setTimeout(() => { if (aliveRef.current) setCopied(false); }, 2000);
1336
+ }
1337
+ };
1338
+
1339
+ const findingCard = (finding, index) => h('label', {
1340
+ key: index,
1341
+ className: 'dsh-push-rv-finding ' + (SEVERITY_TONE[finding.severity] || '')
1342
+ + (chosenFindings[index] ? ' is-picked' : ''),
1343
+ },
1344
+ h('input', {
1345
+ type: 'checkbox',
1346
+ className: 'dsh-push-rv-finding-pick',
1347
+ checked: Boolean(chosenFindings[index]),
1348
+ onChange: () => toggleFinding(index),
1349
+ }),
1350
+ h('span', { className: 'dsh-push-rv-finding-body' },
1351
+ h('span', { className: 'dsh-push-rv-finding-head' },
1352
+ h('span', { className: 'dsh-push-rv-sev' },
1353
+ h('span', { className: 'dsh-push-rv-dot' }),
1354
+ t(SEVERITY_LABEL[finding.severity] || 'rvSeverityInfo')),
1355
+ finding.scope
1356
+ ? h('span', { className: 'dsh-push-pill dsh-push-pill--idle' }, finding.scope)
1357
+ : null,
1358
+ h('span', { className: 'dsh-push-rv-finding-title' }, finding.title)),
1359
+ finding.detail ? h('span', { className: 'dsh-push-rv-finding-detail' }, finding.detail) : null,
1360
+ finding.file ? h('span', { className: 'dsh-push-rv-finding-file' }, finding.file) : null));
1361
+
1362
+ const resultBody = [
1363
+ h('div', { className: 'dsh-push-rv-head', key: 'head' },
1364
+ h('span', { className: 'dsh-push-rv-title' }, t('pjReviewResult')),
1365
+ h('span', { className: 'dsh-push-rv-spacer' }),
1366
+ h('button', {
1367
+ type: 'button', className: 'dsh-push-iconbtn',
1368
+ title: t('rvClose'), 'aria-label': t('rvClose'), onClick: close,
1369
+ }, h(Icon, { name: 'close', size: 13 }))),
1370
+
1371
+ h('div', { className: 'dsh-push-rv-summary', key: 'summary' }, (result && result.summary) || ''),
1372
+
1373
+ result && result.degraded
1374
+ ? h('div', { className: 'dsh-push-rv-muted', key: 'degraded' }, t('rvDegraded'))
1375
+ : null,
1376
+
1377
+ result && (result.skipped || []).length > 0
1378
+ ? h('div', { className: 'dsh-push-rv-muted', key: 'skipped' },
1379
+ t('pjSkipped') + ' ' + result.skipped.map((row) => row.scope + ':' + row.reason).join(';'))
1380
+ : null,
1381
+
1382
+ h('div', { className: 'dsh-push-rv-scroll', key: 'findings' },
1383
+ findings.length === 0
1384
+ ? h('div', { className: 'dsh-push-ok' }, t('rvNoFindings'))
1385
+ : h('div', { className: 'dsh-push-rv-findings' }, findings.map(findingCard))),
1386
+ ];
1387
+
1388
+ /* ---- footer ---- */
1389
+ const configureFooter = [
1390
+ h('span', { className: 'dsh-push-rv-muted', key: 'count' },
1391
+ selectedIds.length > 0 ? t('rvSelected', { n: selectedIds.length }) : t('rvSelectionEmpty')),
1392
+ h('span', { className: 'dsh-push-rv-spacer', key: 'spacer' }),
1393
+ h(Btn, { key: 'cancel', onClick: close }, t('rvCancel')),
1394
+ h(Btn, {
1395
+ key: 'run', kind: 'primary',
1396
+ disabled: running || props.cwd === '',
1397
+ onClick: run,
1398
+ }, t('pjRun')),
1399
+ ];
1400
+
1401
+ const runningFooter = [
1402
+ h('span', { className: 'dsh-push-rv-muted', key: 'busy' }, t('rvRunningFooter')),
1403
+ h('span', { className: 'dsh-push-rv-spacer', key: 'spacer' }),
1404
+ h(Btn, { key: 'cancel', onClick: close }, t('rvCancel')),
1405
+ ];
1406
+
1407
+ const resultFooter = [
1408
+ h('span', { className: 'dsh-push-rv-muted', key: 'count' },
1409
+ chosenList.length > 0
1410
+ ? t('pjChosen', { n: chosenList.length })
1411
+ : t('pjChooseHint')),
1412
+ /* 全选/取消全选:问题多时不用一个个点。 */
1413
+ findings.length > 1
1414
+ ? h(Btn, {
1415
+ key: 'all',
1416
+ mini: true,
1417
+ onClick: () => {
1418
+ const next = {};
1419
+ if (!allChosen) findings.forEach((row, index) => { next[index] = true; });
1420
+ setChosenFindings(next);
1421
+ },
1422
+ }, allChosen ? t('pjChooseNone') : t('pjChooseAll'))
1423
+ : null,
1424
+ h(Btn, {
1425
+ key: 'copy',
1426
+ mini: true,
1427
+ disabled: findings.length === 0,
1428
+ onClick: copyFix,
1429
+ }, copied ? t('pjCopied') : t('pjCopyPrompt')),
1430
+ h('span', { className: 'dsh-push-rv-spacer', key: 'spacer' }),
1431
+ h(Btn, { key: 'again', onClick: () => { setResult(null); setStep('configure'); } }, t('rvRunAgain')),
1432
+ h(Btn, { key: 'done', kind: 'primary', onClick: close }, t('rvDone')),
1433
+ ];
1434
+
1435
+ return h(Modal, {
1436
+ open: props.open,
1437
+ bare: true,
1438
+ wide: true,
1439
+ onClose: close,
1440
+ footer: step === 'result' ? resultFooter : (step === 'running' ? runningFooter : configureFooter),
1441
+ }, step === 'running' ? runningBody : (step === 'result' ? resultBody : configureBody));
1442
+ }
1443
+
1444
+ /* ─────────────────────── 平台面板(三段界面) ───────────────────────── */
1445
+
1446
+ /**
1447
+ * 设置页那一块:审查项管理与默认模型。
1448
+ *
1449
+ * 这里只读不审——真正的审查发生在工作区标签页里,因为审查需要一个具体
1450
+ * 目录。设置页放一个「点一下不知道审哪里」的按钮只会让人困惑。
1451
+ */
1452
+ function ReviewSettingsPanel(props) {
1453
+ const { ctx } = props;
1454
+ const [presets, setPresets] = useState({ builtin: [], custom: [], categories: [] });
1455
+ const [models, setModels] = useState({ providers: [], default: null });
1456
+ const [error, setError] = useState('');
1457
+ const aliveRef = useRef(true);
1458
+
1459
+ useEffect(() => {
1460
+ aliveRef.current = true;
1461
+ return () => { aliveRef.current = false; };
1462
+ }, []);
1463
+
1464
+ useEffect(() => {
1465
+ (async () => {
1466
+ try {
1467
+ const [p, m] = await Promise.all([
1468
+ api(ctx, API + '/presets'),
1469
+ api(ctx, API + '/models'),
1470
+ ]);
1471
+ if (!aliveRef.current) return;
1472
+ if (p) setPresets(p);
1473
+ if (m) setModels(m);
1474
+ } catch (err) {
1475
+ if (aliveRef.current) setError(err.message);
1476
+ }
1477
+ })();
1478
+ }, [ctx]);
1479
+
1480
+ const builtin = presets.builtin || [];
1481
+ const custom = presets.custom || [];
1482
+ const providers = models.providers || [];
1483
+
1484
+ return h('div', { className: 'dsh-push-root dsh-push-settings' },
1485
+ h('div', { className: 'dsh-push-group' },
1486
+ h('div', { className: 'dsh-push-group-head' },
1487
+ h(Icon, { name: 'gear', size: 13 }),
1488
+ h('span', null, '审查')),
1489
+ h('div', { className: 'dsh-push-row-hint' },
1490
+ '规则扫描(敏感信息)始终执行,不花 token;模型审查可选,未配置模型时自动降级。'),
1491
+ error ? h('div', { className: 'dsh-push-error' }, error) : null),
1492
+
1493
+ h('div', { className: 'dsh-push-group' },
1494
+ h('div', { className: 'dsh-push-group-head' }, '内置审查项(' + builtin.length + ')'),
1495
+ h('div', { className: 'dsh-push-rows' },
1496
+ builtin.map((preset) => h('div', { key: preset.id, className: 'dsh-push-row' },
1497
+ h('div', { className: 'dsh-push-row-main' },
1498
+ h('div', { className: 'dsh-push-row-title' }, preset.title),
1499
+ h('div', { className: 'dsh-push-row-hint' }, preset.description || '')))))),
1500
+
1501
+ h('div', { className: 'dsh-push-group' },
1502
+ h('div', { className: 'dsh-push-group-head' }, '自定义审查项(' + custom.length + ')'),
1503
+ custom.length === 0
1504
+ ? h('div', { className: 'dsh-push-row-hint' }, '还没有保存的自定义审查项。审查时可以把提示词存成一项。')
1505
+ : h('div', { className: 'dsh-push-rows' },
1506
+ custom.map((preset) => h('div', { key: preset.id, className: 'dsh-push-row' },
1507
+ h('div', { className: 'dsh-push-row-main' },
1508
+ h('div', { className: 'dsh-push-row-title' }, preset.title),
1509
+ h('div', { className: 'dsh-push-row-hint' }, preset.description || '')))))),
1510
+
1511
+ h('div', { className: 'dsh-push-group' },
1512
+ h('div', { className: 'dsh-push-group-head' }, '可用模型(' + providers.length + ' 个 provider)'),
1513
+ providers.length === 0
1514
+ ? h('div', { className: 'dsh-push-row-hint' }, '宿主未提供模型配置,审查只会执行规则扫描。')
1515
+ : h('div', { className: 'dsh-push-rows' },
1516
+ providers.map((provider) => h('div', { key: provider.id, className: 'dsh-push-row' },
1517
+ h('div', { className: 'dsh-push-row-main' },
1518
+ h('div', { className: 'dsh-push-row-title' }, provider.name || provider.id),
1519
+ h('div', { className: 'dsh-push-row-hint' },
1520
+ ((provider.models || []).map((m) => m.name || m.id).join('、')) || '(无模型)')))))));
1521
+ }
1522
+
1523
+ /** 左侧栏:同样只做只读概览——审查需要具体目录,侧栏拿不到。 */
1524
+ function ReviewSidebarPanel(props) {
1525
+ return h('div', { className: 'dsh-push-root dsh-push-tab' },
1526
+ h('div', { className: 'dsh-push-pickguide' },
1527
+ h('div', { className: 'dsh-push-pickguide-title' }, '审查'),
1528
+ h('div', { className: 'dsh-push-pickguide-text' },
1529
+ '审查在工作区标签页里进行,因为它需要一个具体目录。'),
1530
+ h('div', { className: 'dsh-push-hint' },
1531
+ 'GitHub 与 npm 插件的审查入口也会直接打开这里的对话框。')));
1532
+ }
1533
+
1534
+ /**
1535
+ * 工作区标签页:在一次会话里选择审查对象。
1536
+ *
1537
+ * 三个按钮对应三种对象,选中后打开对应对话框。默认选「整个项目」——
1538
+ * 它一次覆盖 git 与 npm,是大多数人真正想做的事。
1539
+ */
1540
+ function ReviewWorkspacePanel(props) {
1541
+ const { ctx, scope } = props;
1542
+ const [open, setOpen] = useState('');
1543
+ const cwd = (scope && scope.cwd) || '';
1544
+
1545
+ const head = h('div', { className: 'dsh-push-group-head' },
1546
+ h(Icon, { name: 'gear', size: 13 }),
1547
+ h('span', null, '审查'));
1548
+
1549
+ if (!cwd) {
1550
+ return h('div', { className: 'dsh-push-root dsh-push-tab' },
1551
+ h('div', { className: 'dsh-push-pickguide' },
1552
+ h('div', { className: 'dsh-push-pickguide-title' }, '先选一个目录'),
1553
+ h('div', { className: 'dsh-push-pickguide-text' },
1554
+ '审查要读具体文件,所以需要一个工作目录。')));
1555
+ }
1556
+
1557
+ const card = (id, title, hint) => h('button', {
1558
+ key: id,
1559
+ type: 'button',
1560
+ className: 'dsh-push-acc-card' + (open === id ? ' is-on' : ''),
1561
+ onClick: () => setOpen(id),
1562
+ },
1563
+ h('div', { className: 'dsh-push-acc-card-main' },
1564
+ h('div', { className: 'dsh-push-acc-card-name' }, title),
1565
+ h('div', { className: 'dsh-push-acc-card-hint' }, hint)));
1566
+
1567
+ return h('div', { className: 'dsh-push-root dsh-push-tab' },
1568
+ h('div', { className: 'dsh-push-group' },
1569
+ head,
1570
+ h('div', { className: 'dsh-push-row-hint' }, cwd),
1571
+ h('div', { className: 'dsh-push-acc-cards' },
1572
+ card('project', '整个项目', 'git 改动 + npm 包内容,一次审完'),
1573
+ card('git', '待推送改动', '只看即将推送的提交'),
1574
+ card('package', '发布包内容', '只看 npm pack 会打进去的文件'))),
1575
+
1576
+ open === 'project'
1577
+ ? h(ProjectReviewDialog, { ctx, cwd, open: true, initialResult: null, onClose: () => setOpen('') })
1578
+ : null,
1579
+ open === 'git'
1580
+ ? h(ReviewDialog, { ctx, path: cwd, open: true, onClose: () => setOpen('') })
1581
+ : null,
1582
+ open === 'package'
1583
+ ? h(NpmReviewDialog, { ctx, cwd, open: true, onClose: () => setOpen('') })
1584
+ : null);
1585
+ }
1586
+
1587
+ /* ─────────────────────────── 插件装配 ───────────────────────────────── */
1588
+
1589
+ /**
1590
+ * 登记三样东西:
1591
+ * 1. 本平台自己的三段面板(设置 / 左栏 / 工作区);
1592
+ * 2. **能力** `review`——GitHub 与 npm 插件靠它判断审查功能在不在;
1593
+ * 3. 文案。
1594
+ *
1595
+ * 能力与面板都在同一个 `ctx.effect` 上,所以卸载插件时两样一起消失:
1596
+ * npm 的审查入口会自动退回灰色状态,而不是留下一个点了报错的按钮。
1597
+ */
1598
+ function apply(ctx) {
1599
+ core.attachHostLocale(ctx);
1600
+ core.registerMessages('zh', ZH);
1601
+ core.registerMessages('en', EN);
1602
+
1603
+ ctx.effect(() => {
1604
+ const offPanel = core.registerPanel({
1605
+ id: 'review',
1606
+ label: '审查',
1607
+ order: 40,
1608
+ mark: ReviewMark,
1609
+ settings: ReviewSettingsPanel,
1610
+ sidebar: ReviewSidebarPanel,
1611
+ workspace: ReviewWorkspacePanel,
1612
+ });
1613
+ return offPanel;
1614
+ }, 'review: panel');
1615
+
1616
+ /* 能力表:这是 GitHub / npm 插件探测「审查装没装」的唯一入口。
1617
+ * 三个对话框都给出去,让调用方按自己的场景挑。 */
1618
+ ctx.effect(() => core.registerCapability('review', {
1619
+ Dialog: ReviewDialog,
1620
+ NpmDialog: NpmReviewDialog,
1621
+ ProjectDialog: ProjectReviewDialog,
1622
+ // 路由前缀也一起给:调用方不必自己拼 /api/push/review。
1623
+ api: API,
1624
+ }), 'review: capability');
1625
+ }
1626
+
1627
+ /** 审查标记:放大镜 + 对勾。与 icon.svg 同一形状,缩到 16px 仍可辨。 */
1628
+ function ReviewMark(props) {
1629
+ const size = (props && props.size) || 16;
1630
+ return h('svg', {
1631
+ width: size,
1632
+ height: size,
1633
+ viewBox: '0 0 24 24',
1634
+ 'aria-hidden': 'true',
1635
+ style: { display: 'block', flex: 'none' },
1636
+ },
1637
+ h('circle', {
1638
+ cx: 10.5, cy: 10, r: 6.2, fill: 'none',
1639
+ stroke: 'currentColor', 'stroke-width': 2.2,
1640
+ }),
1641
+ h('line', {
1642
+ x1: 15, y1: 14.5, x2: 20, y2: 19.5,
1643
+ stroke: 'currentColor', 'stroke-width': 2.2, 'stroke-linecap': 'round',
1644
+ }),
1645
+ h('path', {
1646
+ d: 'M7.6 10 L9.8 12.2 L13.6 8.4',
1647
+ fill: 'none', stroke: '#2F7BF6', 'stroke-width': 1.9,
1648
+ 'stroke-linecap': 'round', 'stroke-linejoin': 'round',
1649
+ }));
1650
+ }
1651
+
1652
+ exports.apply = apply;
1653
+ exports.inject = ['slots'];
1654
+
1655
+ return module.exports;
1656
+ },
1657
+ });