dsh-git-push 2.20.11 → 2.20.17

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.
Files changed (58) hide show
  1. package/README.md +10 -6
  2. package/cli-audit.mjs +141 -0
  3. package/cli-tool.mjs +86 -0
  4. package/cli.mjs +114 -335
  5. package/lib/app/command-registry.js +3 -2
  6. package/lib/app/constants.js +9 -0
  7. package/lib/app/handlers/clone.js +12 -3
  8. package/lib/app/handlers/http-constants.js +11 -2
  9. package/lib/app/handlers/npm.js +4 -2
  10. package/lib/app/handlers/repos.js +10 -1
  11. package/lib/app/handlers/settings.js +9 -1
  12. package/lib/app/http-handlers.js +24 -3
  13. package/lib/app/schema-audit.js +42 -0
  14. package/lib/app/schema.js +19 -19
  15. package/lib/app/settings-bridge.js +51 -0
  16. package/lib/app/tool-call.js +7 -5
  17. package/lib/audit-rules/audit-rules-paths.yml +7 -1
  18. package/lib/audit-ui-sdk/contract.js +117 -0
  19. package/lib/audit-ui-sdk/index.js +17 -0
  20. package/lib/checks/regex.js +6 -1
  21. package/lib/cli/commands-audit.mjs +12 -17
  22. package/lib/cli/commands-tool.mjs +93 -0
  23. package/lib/cli/commands-vcs.mjs +2 -1
  24. package/lib/cli/shared.mjs +448 -0
  25. package/lib/client-parts/{account.js → git/account.js} +1 -1
  26. package/lib/client-parts/{actions.js → git/actions.js} +26 -11
  27. package/lib/client-parts/{apply.js → git/apply.js} +1 -1
  28. package/lib/client-parts/{browser.js → git/browser.js} +1 -1
  29. package/lib/client-parts/{const.js → git/const.js} +6 -1
  30. package/lib/client-parts/{controller.js → git/controller.js} +23 -11
  31. package/lib/client-parts/{icons.js → git/icons.js} +1 -1
  32. package/lib/client-parts/{loader.js → git/loader.js} +1 -1
  33. package/lib/client-parts/{npm.js → git/npm.js} +1 -1
  34. package/lib/client-parts/{page.js → git/page.js} +11 -21
  35. package/lib/client-parts/{repo.js → git/repo.js} +1 -1
  36. package/lib/client-parts/{settings.js → git/settings.js} +1 -1
  37. package/lib/client-parts/{utils.js → git/utils.js} +1 -1
  38. package/lib/client.js +75 -354
  39. package/lib/commit-push/pre-commit-engine.js +388 -0
  40. package/lib/commit-push.js +42 -20
  41. package/lib/git/transport.js +31 -10
  42. package/lib/http/index.js +82 -10
  43. package/lib/npm/npmrc.js +22 -5
  44. package/lib/self/index.js +1 -1
  45. package/package.json +6 -2
  46. package/scripts/audit-gate.mjs +235 -0
  47. package/scripts/build-client.mjs +15 -8
  48. package/scripts/check.mjs +12 -3
  49. package/scripts/scan-file-io.mjs +5 -1
  50. package/scripts/scan-version.mjs +10 -7
  51. package/skills/dev/dsh-git-push.md +62 -0
  52. package/skills/guide/guide-audit.md +11 -11
  53. package/skills/guide/guide-cli-scripts.md +3 -3
  54. package/skills/guide/guide-commit-push.md +2 -2
  55. package/skills/guide/guide-inject-ui.md +0 -16
  56. package/assets/start.sh +0 -396
  57. package/scripts/scan-hardcoded-paths.mjs +0 -125
  58. /package/lib/client-parts/{audit.js → audit/audit.js} +0 -0
package/lib/client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * dsh-git-push v2 设置侧边栏(settings.section 独立页)
3
- * 分片顺序锚点:第 1/14 片(顺序唯一权威 = scripts/build-client.mjs 的 PART_ORDER)
3
+ * 分片顺序锚点:第 1/13 片(顺序唯一权威 = scripts/build-client.mjs 的 PART_ORDER)
4
4
  * ============================================================================
5
5
  * 重写(三选项卡版):
6
6
  * - 纯中文:删 zh/en 键值对字典,用户可见文案直接硬编码中文(产品设计)。
@@ -32,7 +32,7 @@ window.__ModuleLoader__.load({
32
32
  const NS = 'git-push';
33
33
  const SETTINGS_NS = 'git-push';
34
34
 
35
- /* ─── 第 2/14 片 · 常量区(NS/维度表/样式串) ─────────────────── */
35
+ /* ─── 第 2/13 片 · 常量区(NS/维度表/样式串) ─────────────────── */
36
36
  // 面板「忙碌中」状态键的前缀(clone / vis / push 三类操作共用**同一出处**)。
37
37
  // 此前这三个字面量散落在组件与类方法里各写一遍,改一处不会同步另一处;
38
38
  // 命名带 dshgp_ 前缀,符合本文件的形态铁律(防 combo 拼接撞名)。
@@ -60,6 +60,11 @@ window.__ModuleLoader__.load({
60
60
  // 现在 repo-clone 提交即返回 202、下载在服务端后台跑,提交本身是快操作,
61
61
  // 故该长超时常量已删除——提交用下面的短超时,进度与终态由轮询接管。
62
62
  const dshgp_SCAN_WAIT_MAX_ROUNDS = 600; // 后台扫描等待循环上限(每次挂起等新进度)
63
+ // 扫描长轮询的**单个请求**超时:必须**大于**服务端单次挂起上限(SCAN_WAIT_TIMEOUT_MS=20s,
64
+ // 服务端到点返回 {timeout:true} 而非失败),又**不超过**默认 fetch 超时(30s)。
65
+ // 三层关系(服务端挂起 < 本值 ≤ 默认超时)由 test/test-repos-live-budget.mjs 断言守着:
66
+ // 任一层漂移都会让长轮询变成「客户端先 abort」的假失败(实测就是这么踩到的)。
67
+ const dshgp_SCAN_WAIT_FETCH_MS = 25_000;
63
68
  const dshgp_SAVED_MSG_MS = 4000; // 「已保存」提示显示时长
64
69
  const dshgp_LOG_TRUNCATE = 40; // 调试日志 value 截断长度
65
70
 
@@ -245,7 +250,7 @@ window.__ModuleLoader__.load({
245
250
  '.dshgp_browsefoot{display:flex;justify-content:flex-end}',
246
251
  ].join('');
247
252
 
248
- /* ─── 第 3/14 片 · 工具区(ensureCss/getJson/postJson/tokenConfigured/copyText) ─────────────────── */
253
+ /* ─── 第 3/13 片 · 工具区(ensureCss/getJson/postJson/tokenConfigured/copyText) ─────────────────── */
249
254
  function dshgp_ensureCss() {
250
255
  if (typeof document === 'undefined') return;
251
256
  if (document.querySelector('style[data-plugin-css="dsh-git-push"]')) return;
@@ -307,7 +312,7 @@ window.__ModuleLoader__.load({
307
312
  return Promise.resolve();
308
313
  }
309
314
 
310
- /* ─── 第 4/14 片 · 图标区(ghIcon/refreshIcon) ─────────────────── */
315
+ /* ─── 第 4/13 片 · 图标区(ghIcon/refreshIcon) ─────────────────── */
311
316
  /* ═══════════════════ 选项卡一:账号信息(美化版:渐变卡片 + GitHub 图标 + 状态徽标) ═══════════════════ */
312
317
  const dshgp_ghIcon = jsx.jsx('svg', {
313
318
  width: '22', height: '22', viewBox: '0 0 24 24', fill: 'none',
@@ -319,7 +324,7 @@ window.__ModuleLoader__.load({
319
324
  stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'round',
320
325
  children: jsx.jsx('path', { d: 'M21 12a9 9 0 1 1-2.64-6.36M21 3v6h-6' }),
321
326
  });
322
- /* ─── 第 5/14 片 · 账号信息 Tab(AcctHead/AccountCard/AccountTab) ─────────────────── */
327
+ /* ─── 第 5/13 片 · 账号信息 Tab(AcctHead/AccountCard/AccountTab) ─────────────────── */
323
328
  /** 账号卡片头部:GitHub 图标 + 标题 + 状态徽标。 */
324
329
  function dshgp_AcctHead(props) {
325
330
  return jsx.jsxs('div', {
@@ -402,7 +407,7 @@ window.__ModuleLoader__.load({
402
407
  });
403
408
  }
404
409
 
405
- /* ─── 第 6/14 片 · 目录选择器(browseEnsureDom/browseLoad/browseOpen/browseClose/browseAttach) ─────────────────── */
410
+ /* ─── 第 6/13 片 · 目录选择器(browseEnsureDom/browseLoad/browseOpen/browseClose/browseAttach) ─────────────────── */
406
411
  let dshgp_browseTarget = null; // 当前打开的输入框(null = 走 onPick 回调)
407
412
  // 移植 gamebanana-mods-downloader 的 path-picker 小模块:一行接入 📂 按钮 // 当前打开的输入框(null = 走 onPick 回调)
408
413
  let dshgp_browseOpt = null; // { onPick } 确认回调(clone 场景)
@@ -508,7 +513,7 @@ window.__ModuleLoader__.load({
508
513
  }
509
514
 
510
515
  /* ═══════════════════ 账号卡片:本地/云端 仓库管理 ═══════════════════ */
511
- /* ─── 第 7/14 片 · 仓库管理卡(RepoManagerCard/RepoLocalPane/RepoCloudPane) ─────────────────── */
516
+ /* ─── 第 7/13 片 · 仓库管理卡(RepoManagerCard/RepoLocalPane/RepoCloudPane) ─────────────────── */
512
517
  function dshgp_RepoManagerCard(props) {
513
518
  const s = props.state;
514
519
  const [view, setView] = react.useState('local');
@@ -883,7 +888,7 @@ window.__ModuleLoader__.load({
883
888
  }
884
889
 
885
890
  // dsh-skip-func-length: NPM 子页为自包含组件(自有 useState/useEffect,不依赖 controller),拆分会改动 hook 顺序与状态归属,风险高于收益
886
- /* ─── 第 8/14 片 · NPM 面板(账号卡 + 装包表单 + 已装列表 + npm 凭据字段) ───────────────────
891
+ /* ─── 第 8/13 片 · NPM 面板(账号卡 + 装包表单 + 已装列表 + npm 凭据字段) ───────────────────
887
892
  * 设计取舍:完全自包含(自己 useState/useEffect + 直接走 HTTP),不碰 40-controller(884 行)与 41-actions,
888
893
  * 把 Step 4 的改动面压到最小;数据源:/npm-account、/npm-packages、/npm-install、/settings-set、/status。
889
894
  * 安全默认与后端一致:`ignore-scripts` 默认勾选(不执行 postinstall)、默认非全局、**安装需二次确认**。
@@ -1266,308 +1271,7 @@ window.__ModuleLoader__.load({
1266
1271
  });
1267
1272
  }
1268
1273
 
1269
- /* ─── 第 9/14 片 · 审计 Tab(WeightRows/RuleRow/AuditSwitchBlock/InjectPromptSwitchBlock/CommentWordingBlock/AuditAdvancedBlock/RuleListBlock/AuditTab) ─────────────────── */
1270
- /** 10 维度权重行(值来自 state.weightValues,改即写回 weightOverrides JSON)。 */
1271
- function dshgp_WeightRows(props) {
1272
- const s = props.state;
1273
- const rows = dshgp_DIMENSIONS.map((d) => jsx.jsxs('div', {
1274
- key: d.key,
1275
- className: 'dshgp_weightrow',
1276
- children: [
1277
- jsx.jsx('span', { className: 'dshgp_weightkey', children: d.key }),
1278
- jsx.jsx('input', {
1279
- type: 'number', min: 0, max: 100,
1280
- className: 'dshgp_weightinput',
1281
- value: s.weightValues[d.key] != null ? s.weightValues[d.key] : d.def,
1282
- onChange: (ev) => props.editWeight(d.key, Number(ev.target.value) || 0),
1283
- }),
1284
- jsx.jsx('span', { className: 'dshgp_rulemeta', children: '默认 ' + d.def }),
1285
- ],
1286
- }));
1287
- const total = dshgp_DIMENSIONS.reduce((a, d) => a + (s.weightValues[d.key] != null ? s.weightValues[d.key] : d.def), 0);
1288
- return jsx.jsxs('div', {
1289
- children: [
1290
- rows,
1291
- jsx.jsx('p', { className: 'dshgp_weighttotal', children: '合计 ' + total + '(建议 100;保存后下次审计生效)' }),
1292
- ],
1293
- });
1294
- }
1295
-
1296
- /**
1297
- * 规则包行(交互改版):
1298
- * ① 详细信息改为**悬停浮层**(.dshgp_hovercard,悬停行内信息区显示描述/作者/统计口径),
1299
- * 常显只留「名称 + 拦截/警告/通过」——不再占用行高、不推挤列表。
1300
- * ② 启用/禁用**只由行尾的启停按钮**触发(.dshgp_powerBtn);整行不再可点击切换,
1301
- * 避免想拖选/看详情时误触状态。
1302
- * ③ 状态底色:启用 = 绿底 + 绿左条,禁用 = 红底 + 红左条(见 CSS .dshgp_rowOn/.dshgp_rowOff)。
1303
- * 其余:↑↓ 调次序;nodejs/private 为安全红线锁定不可禁用。
1304
- */
1305
- function dshgp_RuleRow(props, slot, idx, len) {
1306
- const s = props.state;
1307
- const meta = (s.slotMeta && s.slotMeta[slot]) || {};
1308
- const name = meta.name || slot;
1309
- const author = meta.author || '';
1310
- const stats = (meta && meta.stats) || { blocker: 0, warning: 0, pass: 0, total: 0, source: 'rules' };
1311
- // 口径统一为 yml 规则条数:三个数字是「该规则包里各严重级的规则条数」,
1312
- // 不是审计命中数。此前后端在跑过审计时改显命中数,而命中数按**次数**累加、规则数是**条数**,
1313
- // 同排对比会出现「245 警告 / 37 总规则」这类越界假数据;现固定为条数口径,不再分支。
1314
- const countTitle = (kind) => {
1315
- const n = kind === '拦截' ? stats.blocker : (kind === '警告' ? stats.warning : stats.pass);
1316
- return `${name}:${kind}级规则 ${n} 条(共 ${stats.total} 条规则)`;
1317
- };
1318
- // 禁用态 = yml 顶层 disabled(后端 listRuleSlots 解析);点击即时反馈靠 toggleDisabled
1319
- // 本地翻转 slotMeta,loadSlots 对账 yml 真实状态。
1320
- const disabled = !!meta.disabled;
1321
- const locked = slot === 'nodejs' || slot === 'private';
1322
- const move = (dir) => props.moveSlot(slot, dir);
1323
- // 悬停浮层内容:描述/作者/统计口径说明(原常显 meta 行移到这里)
1324
- const hoverCard = jsx.jsxs('div', {
1325
- className: 'dshgp_hovercard',
1326
- children: [
1327
- jsx.jsx('div', { className: 'dshgp_hoverTitle', children: name }),
1328
- author ? jsx.jsx('div', { className: 'dshgp_hoverRow', children: '作者: ' + author }) : null,
1329
- meta.description ? jsx.jsx('div', { className: 'dshgp_hoverRow', children: meta.description }) : null,
1330
- jsx.jsx('div', {
1331
- className: 'dshgp_hoverRow',
1332
- children: `规则条数:拦截级 ${stats.blocker} 条 · 警告级 ${stats.warning} 条 · 提示级 ${stats.pass} 条(共 ${stats.total} 条规则)`,
1333
- }),
1334
- jsx.jsx('div', { className: 'dshgp_hoverRow', children: locked ? '安全红线:nodejs/private 不可禁用' : (disabled ? '当前禁用——点右侧按钮启用' : '当前启用——点右侧按钮禁用') }),
1335
- ],
1336
- });
1337
- // 启停按钮:行内唯一可切换状态的位置(整行 onClick 已移除)
1338
- const powerBtn = jsx.jsx('button', {
1339
- type: 'button',
1340
- className: 'dshgp_powerBtn ' + (disabled ? 'dshgp_powerOff' : 'dshgp_powerOn'),
1341
- disabled: locked,
1342
- onClick: (ev) => { ev.stopPropagation(); props.toggleDisabled(slot); },
1343
- title: locked ? 'nodejs/private 安全红线,不可禁用' : (disabled ? '点击启用该规则包' : '点击禁用该规则包'),
1344
- 'aria-label': (disabled ? '启用规则包 ' : '禁用规则包 ') + name,
1345
- 'aria-pressed': !disabled,
1346
- children: disabled ? '禁用' : '启用',
1347
- });
1348
- return jsx.jsxs('li', {
1349
- key: slot,
1350
- className: 'dshgp_rulerow ' + (disabled ? 'dshgp_rowOff' : 'dshgp_rowOn'),
1351
- children: [
1352
- jsx.jsx('button', { type: 'button', className: 'dshgp_mini', disabled: idx === 0, onClick: (ev) => { ev.stopPropagation(); move(-1); }, 'aria-label': name + ' 上移', children: '↑' }),
1353
- jsx.jsx('button', { type: 'button', className: 'dshgp_mini', disabled: idx === len - 1, onClick: (ev) => { ev.stopPropagation(); move(1); }, 'aria-label': name + ' 下移', children: '↓' }),
1354
- jsx.jsxs('div', {
1355
- className: 'dshgp_ruleinfo',
1356
- children: [
1357
- jsx.jsx('span', { className: 'dshgp_rulename', children: name }),
1358
- hoverCard,
1359
- ],
1360
- }),
1361
- jsx.jsx('span', { className: 'dshgp_rulecountRed', title: countTitle('拦截'), children: String(stats.blocker) }),
1362
- jsx.jsx('span', { className: 'dshgp_rulecountYellow', title: countTitle('警告'), children: String(stats.warning) }),
1363
- jsx.jsx('span', { className: 'dshgp_rulecountGreen', title: countTitle('通过'), children: String(stats.pass) }),
1364
- jsx.jsx('span', { className: 'dshgp_rulebadge', children: powerBtn }),
1365
- ],
1366
- });
1367
- }
1368
-
1369
- /** 审计开关块:提交前自动审计 + 注入开发者要求清单子开关。 */
1370
- function dshgp_AuditSwitchBlock(props) {
1371
- const s = props.state;
1372
- return jsx.jsxs('div', {
1373
- className: 'dshgp_block',
1374
- children: [
1375
- jsx.jsxs('div', {
1376
- className: 'dshgp_switchrow',
1377
- children: [
1378
- jsx.jsx('span', { className: 'dshgp_switchlabel', children: '提交前自动审计' }),
1379
- jsx.jsx('input', { type: 'checkbox', checked: !!s.auditEnabled, onChange: (ev) => props.toggleAudit(ev.target.checked), 'aria-label': '提交前自动审计' }),
1380
- ],
1381
- }),
1382
- jsx.jsx('p', { className: 'dshgp_hint', children: '开启后 git_commit_push 提交前自动跑 L0 静态检查 + 10 维度质量评分;有 blocker 拦截提交。' }),
1383
- /* 审计扫描范围单按钮:**一个按钮单击切换** diff/full,状态体现在
1384
- 按钮标题 + 颜色(diff=绿色「部分」,full=黄色「全量」)。父开关关闭时置灰
1385
- (不生效但保留选择)。持久化走 host HTTP(persistence=memory 陷阱绕开方案)。 */
1386
- jsx.jsxs('div', {
1387
- className: 'dshgp_scanrow' + (s.auditEnabled ? '' : ' dshgp_subswitchOff'),
1388
- children: [
1389
- jsx.jsx('span', { className: 'dshgp_switchlabel', children: '审计扫描范围' }),
1390
- jsx.jsx('button', {
1391
- type: 'button',
1392
- className: 'dshgp_scanbtn '
1393
- + (s.auditScanScope === 'full' ? 'dshgp_scanbtnFull' : 'dshgp_scanbtnDiff')
1394
- + (s.auditEnabled ? '' : ' dshgp_scanbtnOff'),
1395
- onClick: () => props.toggleAuditScanScope(s.auditScanScope === 'full' ? 'diff' : 'full'),
1396
- children: s.auditScanScope === 'full' ? '🔴 全量(auditFull)' : '🟢 部分(本次变动)',
1397
- 'aria-label': '审计扫描范围:' + (s.auditScanScope === 'full' ? '全量' : '仅本次变动') + '(单击切换)',
1398
- title: s.auditScanScope === 'full'
1399
- ? '当前:全量扫描(auditFull)——单击切回「部分」(仅本次变动,快)'
1400
- : '当前:仅本次变动(auditChanged,diff)——单击切换「全量」(慢但彻底)',
1401
- disabled: !s.auditEnabled,
1402
- }),
1403
- ],
1404
- }),
1405
- jsx.jsx('p', { className: 'dshgp_hint', children: s.auditScanScope === 'full'
1406
- ? '全量扫描(auditFull):涵括历史遗留文件与全仓 js-yaml 引用证据;大仓库耗时明显。'
1407
- : '部分扫描(auditChanged,diff):只审提交相关的文件,最快(默认)。' }),
1408
- /* 子开关:注入开发者要求清单。
1409
- 2026-09-13 交互修正:原来父开关关闭时 `disabled` + toggle 直接 return,等于
1410
- 「点不动、点了也没反应」,必须先点一次父开关再点它(两遍)。现改为:
1411
- **一遍即可勾选并保留**(勾选是偏好,与父开关无关),父开关关闭时只把整行置灰
1412
- (dshgp_subswitchOff)表示「暂不生效」,host 侧注入本身由
1413
- `cfg.auditEnabled && cfg.injectRequirements` 门控,不会真的注入。 */
1414
- jsx.jsxs('div', {
1415
- className: 'dshgp_switchrow dshgp_subswitch' + (s.auditEnabled ? '' : ' dshgp_subswitchOff'),
1416
- children: [
1417
- jsx.jsx('span', { className: 'dshgp_switchlabel', children: '↳ 注入开发者要求清单到系统提示词' }),
1418
- jsx.jsx('input', {
1419
- type: 'checkbox',
1420
- checked: !!s.injectRequirements,
1421
- onChange: (ev) => props.toggleInjectRequirements(ev.target.checked),
1422
- 'aria-label': '注入开发者要求清单到系统提示词',
1423
- title: s.auditEnabled ? '' : '已勾选但暂不生效:需开启上方「提交前自动审计」',
1424
- }),
1425
- ],
1426
- }),
1427
- jsx.jsx('p', { className: 'dshgp_hint', children: s.auditEnabled
1428
- ? '开启后把「开发者特殊要求」清单注入系统提示词,AI 常驻可见、不必等提交被拦截才去读清单(省一次失败的工具往返)。'
1429
- : (s.injectRequirements
1430
- ? '已勾选,但上方「提交前自动审计」未开启 → 暂不注入(勾选已保留,开启父开关即生效)。'
1431
- : '可直接勾选;「提交前自动审计」未开启时置灰、暂不注入。') }),
1432
- ],
1433
- });
1434
- }
1435
-
1436
- /** 注入总开关块(新增, 语义扩展):控制 systemPrompt 段 + 上下文注入启停。 */
1437
- function dshgp_InjectPromptSwitchBlock(props) {
1438
- const s = props.state;
1439
- return jsx.jsxs('div', {
1440
- className: 'dshgp_block',
1441
- children: [
1442
- jsx.jsxs('div', {
1443
- className: 'dshgp_switchrow',
1444
- children: [
1445
- jsx.jsx('span', { className: 'dshgp_switchlabel', children: '注入系统提示词/上下文' }),
1446
- jsx.jsx('input', {
1447
- type: 'checkbox',
1448
- checked: s.injectSystemPrompt !== false,
1449
- onChange: (ev) => props.toggleInjectSystemPrompt(ev.target.checked),
1450
- 'aria-label': '注入系统提示词/上下文',
1451
- }),
1452
- ],
1453
- }),
1454
- jsx.jsx('p', { className: 'dshgp_hint', children: s.injectSystemPrompt !== false
1455
- ? '系统提示词:①插件功能用法(每个工具怎么用 + 凭据由插件托管,避免 AI 绕开插件到处找 token)③提交前 README 核对提醒 + 要求清单。上下文:②环境(工作区目录映射 + 工具安装路径 + skill 总入口一行,每个 agent 首次 step 注入一次;工具按 lib/tool-probes.json 模板探测,路径生成到运行目录 tools.json)。只注入目录/路径级信息,不注入 skill 正文。'
1456
- : '已关闭:不注入任何系统提示词段落与上下文环境信息(AI 仍可调用插件工具,但看不到功能用法与环境目录)。' }),
1457
- ],
1458
- });
1459
- }
1460
-
1461
- /** 代码禁交流残留词开关块(控制 comment 槽位启停)。 */
1462
- function dshgp_CommentWordingBlock(props) {
1463
- const s = props.state;
1464
- return jsx.jsxs('div', {
1465
- className: 'dshgp_block',
1466
- children: [
1467
- jsx.jsxs('div', {
1468
- className: 'dshgp_switchrow',
1469
- children: [
1470
- jsx.jsx('span', { className: 'dshgp_switchlabel', children: '代码禁交流残留词(命中 Block 提交)' }),
1471
- jsx.jsx('input', { type: 'checkbox', checked: !((s.slotMeta && s.slotMeta['comment']) || {}).disabled, onChange: () => props.toggleDisabled('comment'), 'aria-label': '代码禁交流残留词' }),
1472
- ],
1473
- }),
1474
- jsx.jsx('p', { className: 'dshgp_hint', children: '代码注释/文档出现交流残留措辞(见 comment 规则包黑名单)→ blocker 拦截提交;白名单业务词(用户ID/用户登录等)自动豁免。' }),
1475
- ],
1476
- });
1477
- }
1478
-
1479
- /** 审计进阶设置块(收敛:只剩「全量扫描文件上限」)。 */
1480
- function dshgp_AuditAdvancedBlock(props) {
1481
- const s = props.state;
1482
- // 修复:React 的 jsx(type, props, key) 第三参数是 **key 不是 children**——
1483
- // 此前写成 jsx('select', props, options.map(...)) 导致 children 丢失、下拉框渲染为空
1484
- // (页面只剩一个空 <select>,用户看到「下拉没有那三种」)。children 必须放进 props。
1485
- const sel = (key, values) => jsx.jsx('select', {
1486
- className: 'dshgp_input dshgp_inputInline',
1487
- value: s[key],
1488
- onChange: (ev) => props.setAdvanced(key, ev.target.value),
1489
- children: values.map((v) => jsx.jsx('option', { key: v, value: v, children: v })),
1490
- });
1491
- return jsx.jsxs('div', {
1492
- className: 'dshgp_block',
1493
- children: [
1494
- jsx.jsx('p', { className: 'dshgp_h2', children: '审计进阶设置' }),
1495
- // 本块只保留「全量扫描文件上限」一项。
1496
- // 删除项(均为 AI 擅自添加、非用户可配):审计强度(固定完整流程)、自定规则目录、
1497
- // 硬编码全量扫(该项其实从未接上审计实现,是空开关)。
1498
- // 硬编码扫描范围随审计范围走——审计扫多少,硬编码就扫多少,不再单独控制。
1499
- jsx.jsxs('div', { className: 'dshgp_field', children: [
1500
- jsx.jsx('label', { className: 'dshgp_label', htmlFor: 'dshgp-maxfiles', children: '全量扫描文件上限' }),
1501
- jsx.jsx('input', { id: 'dshgp-maxfiles', type: 'number', min: 0, className: 'dshgp_input', value: s.maxScanFiles, onChange: (ev) => props.setAdvanced('maxScanFiles', ev.target.value) }),
1502
- jsx.jsx('p', { className: 'dshgp_hint', children: '全量审计最多扫多少个文件(0=不限);超限按「变动优先」截断,弱机防卡死。硬编码检查随此范围一并进行。' }),
1503
- ] }),
1504
- ],
1505
- });
1506
- }
1507
-
1508
- /** 规则包列表块:列表容器 + 榜单表头 + 逐行渲染(dshgp_RuleRow)。 */
1509
- function dshgp_RuleListBlock(props) {
1510
- const s = props.state;
1511
- const order = Array.isArray(s.ruleOrder) ? s.ruleOrder : [];
1512
- return jsx.jsxs('div', {
1513
- className: 'dshgp_block',
1514
- children: [
1515
- jsx.jsx('p', { className: 'dshgp_h2', children: '规则包列表(↑↓ 调整次序,单击切换启用/禁用)' }),
1516
- s.statusMsg ? jsx.jsx('p', { className: 'dshgp_saved', children: s.statusMsg }) : null,
1517
- order.length === 0
1518
- ? jsx.jsx('div', { className: 'dshgp_loading', children: s.slotLoading ? '加载中…' : '(无规则包)' })
1519
- : jsx.jsxs('ul', {
1520
- className: 'dshgp_rulenext',
1521
- children: [
1522
- /* 榜单表头(模仿 skill 记分榜) */
1523
- jsx.jsxs('li', {
1524
- className: 'dshgp_ruleheadrow',
1525
- children: [
1526
- jsx.jsx('span', { className: 'dshgp_ruleheadrowinfo', children: '规则包' }),
1527
- jsx.jsx('span', { className: 'dshgp_rulecountRed', title: '该规则包内拦截级(blocker/error)的规则条数', children: '拦截级' }),
1528
- jsx.jsx('span', { className: 'dshgp_rulecountYellow', title: '该规则包内警告级(warning)的规则条数', children: '警告级' }),
1529
- jsx.jsx('span', { className: 'dshgp_rulecountGreen', title: '该规则包内提示级(info/notice 等其余严重级)的规则条数', children: '提示级' }),
1530
- jsx.jsx('span', { className: 'dshgp_rulebadge', children: '状态' }),
1531
- ],
1532
- }),
1533
- order.map((slot, idx) => dshgp_RuleRow(props, slot, idx, order.length)),
1534
- ],
1535
- }),
1536
- jsx.jsx('p', { className: 'dshgp_hint', children: '数字含义:三个数字是该规则包内各严重级的**规则条数**(拦截级 + 警告级 + 提示级 = 规则总数),取自 yml 规则文件,与是否跑过审计无关。想知道实际命中情况请看审计报告。' }),
1537
- s.slotError ? jsx.jsx('p', { className: 'dshgp_error', children: s.slotError }) : null,
1538
- ],
1539
- });
1540
- }
1541
-
1542
- /**
1543
- * 选项卡二:审计(块组合)。
1544
- * 原单函数 122 行(超可读性阈值 max-function-length)拆为四个块组件 + 权重块;
1545
- * **渲染输出零变化**——拆分前后同一预览页审计 tab 的 DOM 逐字节比对为空。
1546
- */
1547
- function dshgp_AuditTab(props) {
1548
- return jsx.jsxs('div', {
1549
- className: 'dshgp_section',
1550
- children: [
1551
- jsx.jsx(dshgp_AuditSwitchBlock, props),
1552
- jsx.jsx(dshgp_InjectPromptSwitchBlock, props),
1553
- jsx.jsx(dshgp_CommentWordingBlock, props),
1554
- /* ② 审计权重(10 维度) */
1555
- jsx.jsxs('div', {
1556
- className: 'dshgp_block',
1557
- children: [
1558
- jsx.jsx('p', { className: 'dshgp_h2', children: '审计权重(10 维度)' }),
1559
- jsx.jsx(dshgp_WeightRows, { state: props.state, editWeight: props.editWeight }),
1560
- ],
1561
- }),
1562
- /* ③ 审计进阶(补齐 UI) */
1563
- jsx.jsx(dshgp_AuditAdvancedBlock, props),
1564
- jsx.jsx(dshgp_RuleListBlock, props),
1565
- ],
1566
- });
1567
- }
1568
-
1569
- /* ═══════════════════ 选项卡三:设置 ═══════════════════ */
1570
- /* ─── 第 10/14 片 · 设置 Tab(SettingsTab) ─────────────────── */
1274
+ /* ─── 第 9/13 片 · 设置 Tab(SettingsTab) ─────────────────── */
1571
1275
  function dshgp_CredentialBlock(props) {
1572
1276
  const s = props.state;
1573
1277
  return jsx.jsxs('div', {
@@ -1713,13 +1417,14 @@ window.__ModuleLoader__.load({
1713
1417
  });
1714
1418
  }
1715
1419
 
1716
- /* ─── 第 11/14 片 · 页面装配(GitPushPage:三选项卡聚合) ─────────────────── */
1420
+ /* ─── 第 10/13 片 · 页面装配(GitPushPage:两选项卡聚合;审计 Tab 已移出构建) ─── */
1717
1421
  function dshgp_GitPushPage(props) {
1718
1422
  dshgp_ensureCss();
1719
1423
  const [tab, setTab] = react.useState('account');
1424
+ // 两选项卡:审计 Tab 随审计侧解耦一起移出构建(分片在 lib/client-parts/audit/,
1425
+ // 不进产物 ⇒ UI 上不出现)。后端审计能力不受影响,提交门禁照常。
1720
1426
  const tabs = [
1721
1427
  { id: 'account', label: '账号信息' },
1722
- { id: 'audit', label: '审计' },
1723
1428
  { id: 'settings', label: '设置' },
1724
1429
  ];
1725
1430
  const tabBar = jsx.jsxs('div', {
@@ -1738,27 +1443,16 @@ window.__ModuleLoader__.load({
1738
1443
  // pushLocalRepo/cloneFlow),只传 state+refreshAccount 会导致卡片按钮 onClick 报
1739
1444
  // 「props.xxx is not a function」——整包传 props(state + 全部注入动作)。
1740
1445
  const panel = tab === 'account' ? jsx.jsx(dshgp_AccountTab, props)
1741
- : tab === 'audit' ? jsx.jsx(dshgp_AuditTab, {
1446
+ : jsx.jsx(dshgp_SettingsTab, {
1742
1447
  state: props.state,
1743
- toggleAudit: props.toggleAudit,
1744
- toggleInjectRequirements: props.toggleInjectRequirements,
1745
- toggleInjectSystemPrompt: props.toggleInjectSystemPrompt,
1746
- toggleAuditScanScope: props.toggleAuditScanScope,
1747
- editWeight: props.editWeight,
1448
+ edit: props.edit,
1449
+ editSsh: props.editSsh,
1450
+ editEmail: props.editEmail,
1451
+ save: props.save,
1452
+ discard: props.discard,
1453
+ genKey: props.genKey,
1748
1454
  setAdvanced: props.setAdvanced,
1749
- moveSlot: props.moveSlot,
1750
- toggleDisabled: props.toggleDisabled,
1751
- })
1752
- : jsx.jsx(dshgp_SettingsTab, {
1753
- state: props.state,
1754
- edit: props.edit,
1755
- editSsh: props.editSsh,
1756
- editEmail: props.editEmail,
1757
- save: props.save,
1758
- discard: props.discard,
1759
- genKey: props.genKey,
1760
- setAdvanced: props.setAdvanced,
1761
- });
1455
+ });
1762
1456
  return jsx.jsxs('div', {
1763
1457
  style: { padding: '0 4px' },
1764
1458
  children: [
@@ -1769,7 +1463,7 @@ window.__ModuleLoader__.load({
1769
1463
  });
1770
1464
  }
1771
1465
 
1772
- /* ─── 第 12/14 片 · Controller(状态机 + 数据加载 + 动作注入) ─────────────────── */
1466
+ /* ─── 第 11/13 片 · Controller(状态机 + 数据加载 + 动作注入) ─────────────────── */
1773
1467
  class dshgp_Controller {
1774
1468
  constructor(scope) {
1775
1469
  this.scope = scope;
@@ -2060,7 +1754,7 @@ window.__ModuleLoader__.load({
2060
1754
  if (this.repoBusy) return; // 已有交互在进行(含本页面自己发起的 clone),不抢
2061
1755
  let st;
2062
1756
  try {
2063
- st = await dshgp_postJson('/api/git-push/clone-progress', {});
1757
+ st = await dshgp_getJson('/api/git-push/clone-progress');
2064
1758
  } catch { return; /* 探测失败静默:下次刷新再试 */ }
2065
1759
  if (!st || st.state !== 'running' || !st.progress) return;
2066
1760
  const p = st.progress;
@@ -2072,14 +1766,14 @@ window.__ModuleLoader__.load({
2072
1766
  if (this._cloneResumeTimer) clearInterval(this._cloneResumeTimer);
2073
1767
  this._cloneResumeTimer = setInterval(async () => {
2074
1768
  try {
2075
- const s2 = await dshgp_postJson('/api/git-push/clone-progress', {});
1769
+ const s2 = await dshgp_getJson('/api/git-push/clone-progress');
2076
1770
  if (s2 && s2.state === 'running' && s2.progress) {
2077
1771
  this.cloneProgress = s2.progress;
2078
1772
  this.publish();
2079
1773
  return;
2080
1774
  }
2081
1775
  if (s2 && s2.state === 'done') {
2082
- const fin = await dshgp_postJson('/api/git-push/clone-progress', { consume: true });
1776
+ const fin = await dshgp_getJson('/api/git-push/clone-progress?consume=1');
2083
1777
  const res = (fin && fin.result) || (s2 && s2.result) || null;
2084
1778
  this.cloudMsg = res && res.ok
2085
1779
  ? '✅ 已克隆 ' + (p.target || '') + ' → ' + (res.dest || p.dest || '')
@@ -2484,15 +2178,18 @@ window.__ModuleLoader__.load({
2484
2178
  this.localMsg = '⏳ 扫描中…(后台独立进程,扫到一个追加一个)';
2485
2179
  this.publish();
2486
2180
  let seen = this.localRepos.length;
2181
+ let scanFinished = false; // 是否**真的收到**结束事件(轮次耗尽不算)
2487
2182
  try {
2488
2183
  const started = await dshgp_postJson('/api/git-push/repos-local-scan', { path: p });
2489
2184
  if (started && started.running && started.ok === false) {
2490
2185
  this.localMsg = '⚠️ ' + (started.error || '扫描进行中,不能重复扫描');
2491
2186
  return;
2492
2187
  }
2493
- // 循环等待新增:每次 wait 挂起直到独立进程写了新进度(非轮询)
2188
+ // 循环等待新增:每次 wait 挂起直到独立进程写了新进度(非轮询)。
2189
+ // 单请求超时显式给 dshgp_SCAN_WAIT_FETCH_MS(> 服务端挂起上限、≤ 默认超时),
2190
+ // 否则服务端还在挂起、前端先 abort,长轮询就成了假失败。
2494
2191
  for (let i = 0; i < dshgp_SCAN_WAIT_MAX_ROUNDS; i += 1) {
2495
- const waitRes = await dshgp_postJson('/api/git-push/repos-local-scan-wait', { from: seen });
2192
+ const waitRes = await dshgp_postJson('/api/git-push/repos-local-scan-wait', { from: seen }, dshgp_SCAN_WAIT_FETCH_MS);
2496
2193
  const newest = (waitRes && waitRes.newest) || [];
2497
2194
  if (newest.length) {
2498
2195
  // 只追加新增:从索引取这几条详情(不全量重读列表)
@@ -2501,16 +2198,25 @@ window.__ModuleLoader__.load({
2501
2198
  this.localMsg = '⏳ 扫描中… 已发现 ' + seen + ' 个仓库';
2502
2199
  this.publish();
2503
2200
  }
2504
- if (waitRes && waitRes.done) break;
2505
- if (!waitRes || waitRes.running === false) break;
2201
+ // 推进只由「结束」这件事驱动:done 事件,或独立进程已退出(running=false)
2202
+ if (waitRes && waitRes.done) { scanFinished = true; break; }
2203
+ if (!waitRes || waitRes.running === false) { scanFinished = true; break; }
2204
+ // waitRes.timeout && running → 服务端到点返回,属于正常「还没结束」,继续下一轮
2506
2205
  }
2507
2206
  } catch (e) {
2508
2207
  this.localMsg = '❌ 扫描失败: ' + (e && e.message || e);
2208
+ this.localScanning = false;
2209
+ this.publish();
2210
+ return;
2509
2211
  }
2510
2212
  this.localScanning = false;
2511
2213
  // 收尾:按索引读一次对齐(保证领先/落后等字段完整)
2512
2214
  await this.scanLocalRepos(p, false);
2513
- this.localMsg = '✅ 扫描完成,读取到 ' + this.localRepos.length + ' 个仓库';
2215
+ // **轮次耗尽 != 扫描完成**:只等到循环上限却没收到 done/退出事件,必须如实报「未结束」
2216
+ // 而不是报「✅ 完成」(那是把超时当成功,等于把「事件永远不来」这个 bug 藏起来)。
2217
+ this.localMsg = scanFinished
2218
+ ? '✅ 扫描完成,读取到 ' + this.localRepos.length + ' 个仓库'
2219
+ : '⚠️ 扫描未收到结束事件(已等 ' + dshgp_SCAN_WAIT_MAX_ROUNDS + ' 轮),进度见 scan-live.json;可稍后刷新查看';
2514
2220
  this.publish();
2515
2221
  }
2516
2222
 
@@ -2777,13 +2483,13 @@ window.__ModuleLoader__.load({
2777
2483
  // consume=true 让后端取走终态,避免下次打开面板读到上次结果。
2778
2484
  const poll = async () => {
2779
2485
  try {
2780
- const st = await dshgp_postJson('/api/git-push/clone-progress', {});
2486
+ const st = await dshgp_getJson('/api/git-push/clone-progress');
2781
2487
  if (st && st.state === 'running' && st.progress) {
2782
2488
  this.cloneProgress = st.progress;
2783
2489
  this.publish();
2784
2490
  } else if (st && st.state === 'done') {
2785
2491
  // 任务已结束:先取终态再 consume 清掉(顺序反了会读到空)
2786
- const fin = await dshgp_postJson('/api/git-push/clone-progress', { consume: true });
2492
+ const fin = await dshgp_getJson('/api/git-push/clone-progress?consume=1');
2787
2493
  stopPoll();
2788
2494
  renderResult(fin && fin.result ? fin.result : (st.result || null));
2789
2495
  this.cloneProgress = null;
@@ -2861,7 +2567,7 @@ window.__ModuleLoader__.load({
2861
2567
  }
2862
2568
 
2863
2569
  /** 审计 tab 顶部即时反馈(区别于设置 tab 的 flashSaved)。 */
2864
- /* ─── 第 13/14 片 · Controller 动作注入(接 controller.js 的类体,方法声明不可拆出类外) ─────────────────── */
2570
+ /* ─── 第 12/13 片 · Controller 动作注入(接 controller.js 的类体,方法声明不可拆出类外) ─────────────────── */
2865
2571
  setStatus(msg) {
2866
2572
  this.statusMsg = String(msg || '');
2867
2573
  if (this.statusTimer) clearTimeout(this.statusTimer);
@@ -2929,28 +2635,33 @@ window.__ModuleLoader__.load({
2929
2635
  // persistSshPub 另有 isMaskedValue 拦截,这里是 UI 侧提前拦住不发请求)。
2930
2636
  if (key === 'githubToken' || key === 'sshPub') {
2931
2637
  const sv = String(value ?? '').trim();
2932
- if (!sv) return; // 空值:不动该键(留空=保持不变)
2638
+ if (!sv) return Promise.resolve(false); // 空值:不动该键(留空=保持不变)
2933
2639
  if (sv.includes('…') || sv.includes('****') || /^gh[pous]_…/.test(sv)) {
2934
2640
  this.failed = true;
2935
2641
  this.flashSaved('❌ 拒绝写入:这是脱敏显示值,请输入完整凭据');
2936
2642
  this.publish();
2937
- return;
2643
+ return Promise.resolve(false);
2938
2644
  }
2939
2645
  }
2940
2646
  // UI 提交调试日志(浏览器控制台可见;服务端另有 settings-ui.log 持久留痕)
2941
2647
  if (typeof console !== 'undefined' && console.debug) {
2942
2648
  try { console.debug('[dsh-git-push] UI 提交', key, '=', String(value).slice(0, dshgp_LOG_TRUNCATE) + (String(value).length > dshgp_LOG_TRUNCATE ? '…' : '')); } catch { /* 控制台不可用时跳过调试输出 */ }
2943
2649
  }
2944
- void dshgp_postJson('/api/git-push/settings-set', { key, value }).then((data) => {
2650
+ // 返回 promise<boolean>:调用方若需要「先确认成功再提示」就 await 它。
2651
+ // 多数调用方(开关/下拉)不 await —— 它们只关心最终状态,失败时 UI 有 failed 标记;
2652
+ // 凭据保存(save)必须 await,否则会先弹「已保存」再失败,误导用户(外部报告已实测踩到)。
2653
+ return dshgp_postJson('/api/git-push/settings-set', { key, value }).then((data) => {
2945
2654
  if (data && data.ok) {
2946
2655
  if (okMsg) this.flashSaved(okMsg);
2947
- } else {
2948
- this.failed = true;
2949
- this.publish();
2656
+ return true;
2950
2657
  }
2658
+ this.failed = true;
2659
+ this.publish();
2660
+ return false;
2951
2661
  }).catch(() => {
2952
2662
  this.failed = true;
2953
2663
  this.publish();
2664
+ return false;
2954
2665
  });
2955
2666
  }
2956
2667
 
@@ -3041,16 +2752,26 @@ window.__ModuleLoader__.load({
3041
2752
  // 凭据持久化走 persistSetting(纯 HTTP /settings-set → 服务端
3042
2753
  // writeSettingsKey 写 config.json + persistGithubToken/persistSshPub 落插件目录,
3043
2754
  // 不 scope.set——scope.set 会把凭据写进公共 settings.yaml 明文,反代下还不落盘)。
3044
- if (raw) this.persistSetting('githubToken', raw);
3045
- if (pub) this.persistSetting('sshPub', pub);
2755
+ // 先**等**两次写入各自有结果,再决定提示什么。
2756
+ // 旧实现不 await 就 flashSaved('✅ 凭据已保存'):写失败(如桌面端 403)时
2757
+ // 用户先看到成功、随后才看到失败,正是「已保存但没生效」这一误解的来源。
2758
+ const writeResults = [];
2759
+ if (raw) writeResults.push(await this.persistSetting('githubToken', raw));
2760
+ if (pub) writeResults.push(await this.persistSetting('sshPub', pub));
2761
+ const allOk = writeResults.length > 0 && writeResults.every((okFlag) => okFlag === true);
3046
2762
  this.text = '';
3047
2763
  this.sshPub = '';
3048
2764
  this.saving = false;
3049
2765
  // 保存后**刷新凭据与密钥的「已填写」状态**——此前只在写入 token 时本地置位
3050
2766
  // tokenConfigured、sshConfigured 从不置位(保存公钥后徽标仍显示未填写),且本地置位
3051
2767
  // 无法反映服务端规范化/落盘失败。统一走 refresh('account') 从 account-status 真源读回。
3052
- // 顺序:先弹「已保存」提示,再异步读回状态(读回过程不遮挡保存成功的反馈)。
3053
- this.flashSaved('✅ 凭据已保存');
2768
+ // 顺序:先给保存结果提示,再异步读回状态(读回过程不遮挡保存反馈)。
2769
+ if (allOk) {
2770
+ this.flashSaved('✅ 凭据已保存');
2771
+ } else {
2772
+ this.failed = true;
2773
+ this.flashSaved('❌ 保存失败:请求未写入(详情见 http-rejects.log / settings-ui.log)');
2774
+ }
3054
2775
  await this.refresh('account');
3055
2776
  } catch (_e) {
3056
2777
  this.saving = false;
@@ -3141,7 +2862,7 @@ window.__ModuleLoader__.load({
3141
2862
 
3142
2863
  const inject = ['slots'];
3143
2864
 
3144
- /* ─── 第 14/14 片 · 收尾:注册 settings.section + factory 返回(必须末片) ─────────────────── */
2865
+ /* ─── 第 13/13 片 · 收尾:注册 settings.section + factory 返回(必须末片) ─────────────────── */
3145
2866
  function apply(ctx) {
3146
2867
  // 【常驻诊断 · 前端接线失败可见化】apply 整体包一层 try/catch,把真实异常打到控制台。
3147
2868
  // 背景:cordis 只把失败的 client entry 标成 failed(页面仅显示