dsh-git-push 0.0.0-stage → 2.8.6
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/.auditignore +30 -0
- package/.gitignore +39 -0
- package/LICENSE +21 -0
- package/README.md +1486 -2
- package/cli.mjs +360 -0
- package/cordis.patch.yml +14 -0
- package/lib/ARCHITECTURE.md +34 -0
- package/lib/BUGFIX-NOTES-2026-09-14.md +278 -0
- package/lib/app/apply.js +275 -0
- package/lib/app/audit-api.js +158 -0
- package/lib/app/command-registry.js +266 -0
- package/lib/app/constants.js +16 -0
- package/lib/app/handlers/account.js +166 -0
- package/lib/app/handlers/clone.js +168 -0
- package/lib/app/handlers/http-constants.js +9 -0
- package/lib/app/handlers/identity-rewrite.js +94 -0
- package/lib/app/handlers/meta.js +175 -0
- package/lib/app/handlers/npm.js +169 -0
- package/lib/app/handlers/repo-actions.js +143 -0
- package/lib/app/handlers/repos.js +231 -0
- package/lib/app/handlers/settings.js +62 -0
- package/lib/app/host-doc-checks.js +25 -0
- package/lib/app/http-handlers.js +131 -0
- package/lib/app/index.js +30 -0
- package/lib/app/inject-text.js +192 -0
- package/lib/app/scan-root.js +23 -0
- package/lib/app/schema.js +150 -0
- package/lib/app/settings-bridge.js +167 -0
- package/lib/app/slash-commands.js +395 -0
- package/lib/app/slot-stats.js +35 -0
- package/lib/app/tool-call.js +672 -0
- package/lib/app/tools.js +34 -0
- package/lib/ast/brace.js +105 -0
- package/lib/ast/callgraph.js +135 -0
- package/lib/ast/code-lines.js +114 -0
- package/lib/ast/consts.js +12 -0
- package/lib/ast/control-flow.js +461 -0
- package/lib/ast/credential.js +199 -0
- package/lib/ast/dataflow.js +274 -0
- package/lib/ast/dup-code.js +165 -0
- package/lib/ast/index.js +36 -0
- package/lib/ast/io-risk-const.js +95 -0
- package/lib/ast/io-risk-fn.js +208 -0
- package/lib/ast/io-risk-loop.js +308 -0
- package/lib/ast/io-risk.js +314 -0
- package/lib/ast/lang.js +156 -0
- package/lib/ast/line-count.js +52 -0
- package/lib/ast/magic-number.js +272 -0
- package/lib/ast/naming.js +284 -0
- package/lib/ast/perf.js +472 -0
- package/lib/ast/scope.js +241 -0
- package/lib/ast/shell.js +131 -0
- package/lib/ast/size.js +378 -0
- package/lib/ast/symbol-index.js +399 -0
- package/lib/ast/tokenizer.js +341 -0
- package/lib/audit/analysis-coverage.js +98 -0
- package/lib/audit/audit-file.js +182 -0
- package/lib/audit/checks.js +17 -0
- package/lib/audit/client-entry.js +93 -0
- package/lib/audit/collector.js +477 -0
- package/lib/audit/ext-runner.js +80 -0
- package/lib/audit/file-context.js +138 -0
- package/lib/audit/finding.js +50 -0
- package/lib/audit/gitignore-match.js +113 -0
- package/lib/audit/glob.js +63 -0
- package/lib/audit/history-report.js +100 -0
- package/lib/audit/history.js +126 -0
- package/lib/audit/ignore-blind.js +101 -0
- package/lib/audit/index.js +33 -0
- package/lib/audit/orchestrate.js +476 -0
- package/lib/audit/public.js +24 -0
- package/lib/audit/repo-level.js +30 -0
- package/lib/audit/report-yaml.js +86 -0
- package/lib/audit/slot.js +65 -0
- package/lib/audit-defaults.js +18 -0
- package/lib/audit-rules/audit-rules-comment.yml +247 -0
- package/lib/audit-rules/audit-rules-cpp.yml +22 -0
- package/lib/audit-rules/audit-rules-docs.yml +32 -0
- package/lib/audit-rules/audit-rules-dsh.yml +162 -0
- package/lib/audit-rules/audit-rules-filehealth.yml +42 -0
- package/lib/audit-rules/audit-rules-folder.yml +99 -0
- package/lib/audit-rules/audit-rules-frontend.yml +335 -0
- package/lib/audit-rules/audit-rules-go.yml +22 -0
- package/lib/audit-rules/audit-rules-i18n.yml +45 -0
- package/lib/audit-rules/audit-rules-java.yml +105 -0
- package/lib/audit-rules/audit-rules-nodejs.yml +647 -0
- package/lib/audit-rules/audit-rules-npm.yml +187 -0
- package/lib/audit-rules/audit-rules-paths.yml +92 -0
- package/lib/audit-rules/audit-rules-performance.yml +215 -0
- package/lib/audit-rules/audit-rules-php.yml +22 -0
- package/lib/audit-rules/audit-rules-private.yml +24 -0
- package/lib/audit-rules/audit-rules-python.yml +106 -0
- package/lib/audit-rules/audit-rules-robustness.yml +27 -0
- package/lib/audit-rules/audit-rules-rust.yml +22 -0
- package/lib/audit-rules/audit-rules-structure.yml +159 -0
- package/lib/audit-rules/audit-rules-swift.yml +22 -0
- package/lib/audit-rules/audit-rules-template.yml +108 -0
- package/lib/checks/button-bind.js +276 -0
- package/lib/checks/common.js +170 -0
- package/lib/checks/credential-file.js +43 -0
- package/lib/checks/dataflow.js +40 -0
- package/lib/checks/dispatch.js +112 -0
- package/lib/checks/dup-code.js +69 -0
- package/lib/checks/dup-const.js +232 -0
- package/lib/checks/file-health.js +150 -0
- package/lib/checks/filter.js +137 -0
- package/lib/checks/folder.js +173 -0
- package/lib/checks/hardcoded-path.js +98 -0
- package/lib/checks/index.js +46 -0
- package/lib/checks/io.js +66 -0
- package/lib/checks/magic-number.js +42 -0
- package/lib/checks/npm-json.js +273 -0
- package/lib/checks/private.js +63 -0
- package/lib/checks/regex.js +256 -0
- package/lib/checks/semantic.js +134 -0
- package/lib/checks/structural.js +274 -0
- package/lib/cli/commands-account.mjs +107 -0
- package/lib/cli/commands-audit.mjs +144 -0
- package/lib/cli/commands-doc.mjs +127 -0
- package/lib/cli/commands-vcs.mjs +175 -0
- package/lib/client/index.js +162 -0
- package/lib/client-parts/00-loader.js +33 -0
- package/lib/client-parts/01-const.js +207 -0
- package/lib/client-parts/02-utils.js +62 -0
- package/lib/client-parts/03-icons.js +12 -0
- package/lib/client-parts/10-account.js +83 -0
- package/lib/client-parts/11-browser.js +95 -0
- package/lib/client-parts/20-repo.js +374 -0
- package/lib/client-parts/21-audit.js +301 -0
- package/lib/client-parts/22-settings.js +146 -0
- package/lib/client-parts/23-npm.js +383 -0
- package/lib/client-parts/30-page.js +56 -0
- package/lib/client-parts/40-controller.js +1092 -0
- package/lib/client-parts/41-actions.js +279 -0
- package/lib/client-parts/99-apply.js +72 -0
- package/lib/client.js +3195 -0
- package/lib/commit-push.js +148 -0
- package/lib/context/index.js +363 -0
- package/lib/core/atomic-json.js +98 -0
- package/lib/core/config.js +40 -0
- package/lib/core/credentials.js +274 -0
- package/lib/core/endpoints.js +109 -0
- package/lib/core/exec.js +162 -0
- package/lib/exempt/index.js +292 -0
- package/lib/fs/edit-after-read.js +103 -0
- package/lib/fsx.js +87 -0
- package/lib/git/account-status.js +140 -0
- package/lib/git/account.js +233 -0
- package/lib/git/api.js +136 -0
- package/lib/git/atomic-json.js +6 -0
- package/lib/git/browse.js +38 -0
- package/lib/git/clone-download.js +397 -0
- package/lib/git/clone-history-mode.js +143 -0
- package/lib/git/clone-history.js +175 -0
- package/lib/git/clone-jobs.js +250 -0
- package/lib/git/clone-replay-io.js +172 -0
- package/lib/git/clone-replay.js +275 -0
- package/lib/git/clone.js +445 -0
- package/lib/git/cloud.js +46 -0
- package/lib/git/commit-message.js +141 -0
- package/lib/git/config.js +6 -0
- package/lib/git/cred-env.js +88 -0
- package/lib/git/credentials.js +6 -0
- package/lib/git/endpoints.js +6 -0
- package/lib/git/exec.js +6 -0
- package/lib/git/identity-rewrite.js +297 -0
- package/lib/git/identity.js +150 -0
- package/lib/git/ignore.js +69 -0
- package/lib/git/index.js +41 -0
- package/lib/git/module-splitter.js +47 -0
- package/lib/git/post-push.js +101 -0
- package/lib/git/push-diagnose.js +142 -0
- package/lib/git/push.js +476 -0
- package/lib/git/remote-resolve.js +146 -0
- package/lib/git/remote.js +128 -0
- package/lib/git/repo-index.js +512 -0
- package/lib/git/repos.js +235 -0
- package/lib/git/scan-runner.js +159 -0
- package/lib/git/sensitive.js +134 -0
- package/lib/git/transport.js +430 -0
- package/lib/git/visibility.js +35 -0
- package/lib/git/wrapped-git.js +68 -0
- package/lib/http/index.js +170 -0
- package/lib/index.js +24 -0
- package/lib/link-check/index.js +187 -0
- package/lib/npm/account.js +64 -0
- package/lib/npm/install.js +211 -0
- package/lib/npm/npmrc.js +56 -0
- package/lib/npm/publish.js +171 -0
- package/lib/npm/registry.js +168 -0
- package/lib/plugin/auto-detect.js +92 -0
- package/lib/plugin/auto-push.js +154 -0
- package/lib/plugin/index.js +250 -0
- package/lib/readme-templates/readme.yml +38 -0
- package/lib/rule/compilers/credential.js +62 -0
- package/lib/rule/compilers/dataflow.js +38 -0
- package/lib/rule/compilers/file-health.js +75 -0
- package/lib/rule/compilers/frontend.js +86 -0
- package/lib/rule/compilers/func.js +35 -0
- package/lib/rule/compilers/helpers.js +71 -0
- package/lib/rule/compilers/index.js +29 -0
- package/lib/rule/compilers/link-semantic.js +45 -0
- package/lib/rule/compilers/list-kinds.js +12 -0
- package/lib/rule/compilers/numeric-kinds.js +66 -0
- package/lib/rule/compilers/regex.js +78 -0
- package/lib/rule/compilers/structure.js +80 -0
- package/lib/rule/compilers.js +17 -0
- package/lib/rule/homoglyph.js +45 -0
- package/lib/rule/loader.js +270 -0
- package/lib/rule/registry.js +115 -0
- package/lib/rule/scope.js +67 -0
- package/lib/score/docs-score.js +166 -0
- package/lib/score/index.js +140 -0
- package/lib/self/index.js +196 -0
- package/lib/skip-dirs.js +64 -0
- package/lib/tool-probes.json +50 -0
- package/lib/user-requirements.json +14 -0
- package/lib/vendor/js-yaml/LICENSE +21 -0
- package/lib/vendor/js-yaml/js-yaml.mjs +3073 -0
- package/package.json +95 -4
- package/scripts/__pycache__/module-splitter.cpython-38.pyc +0 -0
- package/scripts/audit-ext/_example-readme-present.mjs +34 -0
- package/scripts/audit-ext/variable-min-length.mjs +102 -0
- package/scripts/audit-runner.mjs +35 -0
- package/scripts/audit-runtime-check.mjs +129 -0
- package/scripts/browser-page-probe.mjs +271 -0
- package/scripts/build-client.mjs +119 -0
- package/scripts/check.mjs +88 -0
- package/scripts/clean-date-comments.py +102 -0
- package/scripts/cpu-sample.mjs +188 -0
- package/scripts/doc-drift.mjs +200 -0
- package/scripts/doc-func.mjs +212 -0
- package/scripts/doc-tree.mjs +456 -0
- package/scripts/doc-version.mjs +220 -0
- package/scripts/frontend-preview-check.mjs +124 -0
- package/scripts/hot-path-probe-cjs.cjs +71 -0
- package/scripts/hot-path-probe-fs-shim.mjs +28 -0
- package/scripts/hot-path-probe-fsp-shim.mjs +31 -0
- package/scripts/hot-path-probe.mjs +153 -0
- package/scripts/module-splitter.py +800 -0
- package/scripts/platform-scan.mjs +168 -0
- package/scripts/preview-gen.mjs +489 -0
- package/scripts/preview-local-runner.mjs +55 -0
- package/scripts/preview-server-direct.mjs +116 -0
- package/scripts/preview-server.mjs +305 -0
- package/scripts/preview-slot-data.mjs +123 -0
- package/scripts/probe-recheck.mjs +47 -0
- package/scripts/readme-gen.mjs +268 -0
- package/scripts/rename-locator.mjs +97 -0
- package/scripts/rule-switch.mjs +97 -0
- package/scripts/rules-solo-audit.mjs +173 -0
- package/scripts/scan-file-io.mjs +713 -0
- package/scripts/scan-hardcoded-paths.mjs +125 -0
- package/scripts/scan-repos.mjs +167 -0
- package/scripts/scan-version.mjs +122 -0
- package/scripts/scrub-user-wording.mjs +420 -0
- package/scripts/symbol-index.mjs +85 -0
- package/scripts/sync-plugin-install.mjs +223 -0
- package/scripts/sync-plugin.mjs +279 -0
- package/scripts/verify-prestep.mjs +100 -0
- package/skills/dev/audit-rule-authoring.md +58 -0
- package/skills/dev/dsh-git-push.md +323 -0
- package/skills/dev/git-push-live-fix.md +45 -0
- package/skills/dsh-repo-index.md +35 -0
- package/skills/guide/guide-audit.md +167 -0
- package/skills/guide/guide-cli-scripts.md +104 -0
- package/skills/guide/guide-clone-repos.md +173 -0
- package/skills/guide/guide-commit-push.md +156 -0
- package/skills/guide/guide-inject-ui.md +166 -0
- package/skills/guide/guide-slash-completion.md +118 -0
- package/skills/workflow/README.md +21 -0
- package/skills/workflow/git-commit-discipline.md +68 -0
- package/skills/workflow/git-project-startup.md +85 -0
- package/skills/workflow/git-rebuild-process.md +57 -0
- package/skills/workflow/github-operations.md +91 -0
- package/skills/workflow/readme-sync-git-md.md +28 -0
- package/skills/workflow/task-completion-report.md +73 -0
- package/skills/workflow/tool-json-add-ask.md +35 -0
- package/skills/workflow/versioning-rule.md +211 -0
package/lib/client.js
ADDED
|
@@ -0,0 +1,3195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-git-push v2 设置侧边栏(settings.section 独立页)
|
|
3
|
+
* ============================================================================
|
|
4
|
+
* 重写(三选项卡版):
|
|
5
|
+
* - 纯中文:删 zh/en 键值对字典,用户可见文案直接硬编码中文(产品设计)。
|
|
6
|
+
* - 三选项卡(对齐插件市场 .tabs/.tab/.on 样式,参考 skill 记分板):
|
|
7
|
+
* ① 账号信息(纯展示):token/SSH 公钥检测 → GitHub 登录态/用户名/套餐
|
|
8
|
+
* ② 审计:审计开关 + 10 维度权重 + 规则包列表(上下调次序、下覆盖上、
|
|
9
|
+
* 动态加载全部 yml(模板不显示)、规则名后直接显示 描述/作者/拦截/警告/通过 数量、
|
|
10
|
+
* 单击整行切换禁用/启用(auditDisabledSlots,nodejs/private 安全红线不可禁用))
|
|
11
|
+
* ③ 设置:token / sshkey / 邮箱 + 一键生成(保存按钮在标题右侧、放弃已删)
|
|
12
|
+
* - 只保留 settings.section 注册;settings.plugin.item(插件配置卡)已删除。
|
|
13
|
+
*
|
|
14
|
+
* ⛔ 形态铁律(client-modules 聚合 bundle 兼容):
|
|
15
|
+
* 1. window.__ModuleLoader__.load 必须在文件第 1 行。
|
|
16
|
+
* 2. 全部代码在 factory 函数体内,文件顶层【零声明】(防 combo 拼接撞名)。
|
|
17
|
+
* 3. 内部命名专属前缀 dshgp_(防与其他插件同名声明撞名)。
|
|
18
|
+
* 4. 手写 jsx-runtime(jsx/jsxs),禁止 JSX 构建步骤;零外部资源。
|
|
19
|
+
* ============================================================================
|
|
20
|
+
*/
|
|
21
|
+
window.__ModuleLoader__.load({
|
|
22
|
+
id: 'dsh-git-push',
|
|
23
|
+
factory: (require) => {
|
|
24
|
+
var module = { exports: {} };
|
|
25
|
+
var exports = module.exports;
|
|
26
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
27
|
+
const jsx = require('react/jsx-runtime');
|
|
28
|
+
const react = require('react');
|
|
29
|
+
const store = require('@deepseek-ai/dsh-client-store');
|
|
30
|
+
|
|
31
|
+
const NS = 'git-push';
|
|
32
|
+
const SETTINGS_NS = 'git-push';
|
|
33
|
+
|
|
34
|
+
/* ─────────────────── [1] 常量区(NS/维度表/样式串) ─────────────────── */
|
|
35
|
+
// 面板「忙碌中」状态键的前缀(clone / vis / push 三类操作共用**同一出处**)。
|
|
36
|
+
// 此前这三个字面量散落在组件与类方法里各写一遍,改一处不会同步另一处;
|
|
37
|
+
// 命名带 dshgp_ 前缀,符合本文件的形态铁律(防 combo 拼接撞名)。
|
|
38
|
+
const dshgp_BUSY_CLONE = 'clone:';
|
|
39
|
+
const dshgp_BUSY_VIS = 'vis:';
|
|
40
|
+
const dshgp_BUSY_PUSH = 'push:';
|
|
41
|
+
/** 10 维度质量评分权重(合计 100;与 lib/score/index.js DEFAULT_WEIGHTS 一致)。 */
|
|
42
|
+
const dshgp_DIMENSIONS = [
|
|
43
|
+
{ key: '可读性', def: 15 },
|
|
44
|
+
{ key: '可维护性', def: 15 },
|
|
45
|
+
{ key: '健壮性', def: 15 },
|
|
46
|
+
{ key: '安全性', def: 18 },
|
|
47
|
+
{ key: '性能', def: 10 },
|
|
48
|
+
{ key: '测试覆盖', def: 10 },
|
|
49
|
+
{ key: '可观测性', def: 5 },
|
|
50
|
+
{ key: '可部署性', def: 5 },
|
|
51
|
+
{ key: '文档', def: 4 },
|
|
52
|
+
{ key: '开发者体验', def: 3 },
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
// 逻辑类常量(fetch 超时 / 扫描循环上限 / 提示时长 / 日志截断长度)
|
|
56
|
+
const dshgp_FETCH_TIMEOUT_MS = 30_000; // fetch 超时(same-origin)
|
|
57
|
+
// 克隆后台化:原先 clone 用 30 分钟长超时(请求一直阻塞到克隆结束,
|
|
58
|
+
// 而带 tools/ffmpeg-lib 的仓库可达 154MB,默认 30s 必然超时)。
|
|
59
|
+
// 现在 repo-clone 提交即返回 202、下载在服务端后台跑,提交本身是快操作,
|
|
60
|
+
// 故该长超时常量已删除——提交用下面的短超时,进度与终态由轮询接管。
|
|
61
|
+
const dshgp_SCAN_WAIT_MAX_ROUNDS = 600; // 后台扫描等待循环上限(每次挂起等新进度)
|
|
62
|
+
const dshgp_SAVED_MSG_MS = 4000; // 「已保存」提示显示时长
|
|
63
|
+
const dshgp_LOG_TRUNCATE = 40; // 调试日志 value 截断长度
|
|
64
|
+
|
|
65
|
+
const dshgp_css = [
|
|
66
|
+
// 选项卡条(对齐插件市场)
|
|
67
|
+
'.dshgp_tabs{display:flex;align-items:flex-end;gap:2px;border-bottom:1px solid var(--dsw-alias-border-l2);margin:0 0 12px}',
|
|
68
|
+
'.dshgp_tab{font:inherit;color:var(--dsw-alias-label-secondary);cursor:pointer;white-space:nowrap;background:0 0;border:none;border-bottom:2px solid transparent;padding:7px 12px;font-size:13px}',
|
|
69
|
+
'.dshgp_tab:hover{color:var(--dsw-alias-label-primary)}',
|
|
70
|
+
'.dshgp_tabOn{color:var(--dsw-alias-brand-primary);border-bottom-color:var(--dsw-alias-brand-primary);font-weight:600}',
|
|
71
|
+
// 区块
|
|
72
|
+
'.dshgp_section{display:flex;flex-direction:column;gap:10px}',
|
|
73
|
+
'.dshgp_block{border:.5px solid var(--dsw-alias-border-l4);border-radius:16px;background:var(--dsw-alias-bg-layer-3);padding:12px 14px}',
|
|
74
|
+
'.dshgp_h2{margin:0 0 8px;font-size:13px;font-weight:600;color:var(--dsw-alias-label-primary)}',
|
|
75
|
+
'.dshgp_desc{margin:0;font-size:12px;color:var(--dsw-alias-label-tertiary);line-height:1.6;white-space:pre-wrap}',
|
|
76
|
+
'.dshgp_ok{color:var(--dsw-alias-label-primary)}',
|
|
77
|
+
'.dshgp_err{color:var(--dsw-alias-label-error)}',
|
|
78
|
+
// v1 账号块(完全移植 v1 GitPushAccountTop 显示)
|
|
79
|
+
'.dshgp_top{display:flex;flex-direction:column;gap:6px}',
|
|
80
|
+
'.dshgp_toplabel{margin:0;font-size:11px;color:var(--dsw-alias-label-tertiary)}',
|
|
81
|
+
'.dshgp_acctblock{white-space:pre-wrap;margin:0;font-size:12px;line-height:1.6;padding:8px 10px;border-radius:8px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary)}',
|
|
82
|
+
'.dshgp_keybtn{padding:3px 10px;font-size:12px;border:.5px solid var(--dsw-alias-border-l4);border-radius:8px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);cursor:pointer;white-space:nowrap}',
|
|
83
|
+
'.dshgp_keybtn:disabled{opacity:.5;cursor:not-allowed}',
|
|
84
|
+
// 滑动切换视图(顶部账号区 GitHub↔NPM、子标签 本地/GitHub/NPM 共用):靠 key 变化重挂载触发一次入场动画
|
|
85
|
+
'.dshgp_supview{animation:dshgp_slidein .18s ease-out}',
|
|
86
|
+
'@keyframes dshgp_slidein{from{opacity:0;transform:translateX(12px)}to{opacity:1;transform:translateX(0)}}',
|
|
87
|
+
// 账号信息美化面板(设计稿落地:渐变卡片 + GitHub 图标 + 状态徽标 + 凭据状态标签)
|
|
88
|
+
'.dshgp_acctpanel{position:relative;overflow:hidden;border:.5px solid var(--dsw-alias-border-l4);border-radius:16px;background:linear-gradient(160deg,var(--dsw-alias-bg-layer-3),var(--dsw-alias-bg-layer-2));padding:14px 14px 12px}',
|
|
89
|
+
'.dshgp_acctpanel::before{content:"";position:absolute;inset:0;background:radial-gradient(420px 140px at 15% -20%,color-mix(in srgb,var(--dsw-alias-brand-primary) 14%,transparent),transparent 70%),radial-gradient(300px 120px at 95% 115%,color-mix(in srgb,var(--dsw-alias-label-success) 10%,transparent),transparent 70%);pointer-events:none}',
|
|
90
|
+
'.dshgp_accthead{position:relative;display:flex;align-items:center;gap:10px}',
|
|
91
|
+
'.dshgp_acctic{width:38px;height:38px;border-radius:11px;display:flex;align-items:center;justify-content:center;flex-shrink:0;background:linear-gradient(135deg,color-mix(in srgb,var(--dsw-alias-brand-primary) 22%,transparent),color-mix(in srgb,var(--dsw-alias-brand-primary) 8%,transparent));border:.5px solid color-mix(in srgb,var(--dsw-alias-brand-primary) 25%,transparent);color:var(--dsw-alias-brand-primary)}',
|
|
92
|
+
'.dshgp_accttitle{margin:0;font-size:13px;font-weight:600;color:var(--dsw-alias-label-primary)}',
|
|
93
|
+
'.dshgp_acctsub{margin:2px 0 0;font-size:11px;color:var(--dsw-alias-label-tertiary)}',
|
|
94
|
+
'.dshgp_acctstat{margin-left:auto;display:inline-flex;align-items:center;gap:5px;font-size:10px;font-weight:600;padding:3px 10px;border-radius:999px;white-space:nowrap}',
|
|
95
|
+
'.dshgp_acctstat_ok{background:color-mix(in srgb,var(--dsw-alias-label-success) 14%,transparent);color:var(--dsw-alias-label-success)}',
|
|
96
|
+
'.dshgp_acctstat_warn{background:color-mix(in srgb,var(--dsw-alias-label-warning) 14%,transparent);color:var(--dsw-alias-label-warning)}',
|
|
97
|
+
'.dshgp_acctstat_err{background:color-mix(in srgb,var(--dsw-alias-label-error) 14%,transparent);color:var(--dsw-alias-label-error)}',
|
|
98
|
+
'.dshgp_acctdot{width:6px;height:6px;border-radius:50%;background:currentColor}',
|
|
99
|
+
'.dshgp_acctblock2{position:relative;margin:12px 0 0;padding:11px 13px;border-radius:12px;font-size:12px;line-height:1.7;white-space:pre-wrap;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;border:.5px solid var(--dsw-alias-border-l2);background:color-mix(in srgb,var(--dsw-alias-bg-base) 55%,transparent);color:var(--dsw-alias-label-primary)}',
|
|
100
|
+
'.dshgp_acctblock2_ok{border-color:color-mix(in srgb,var(--dsw-alias-label-success) 30%,transparent)}',
|
|
101
|
+
'.dshgp_acctblock2_err{border-color:color-mix(in srgb,var(--dsw-alias-label-error) 30%,transparent);color:var(--dsw-alias-label-error)}',
|
|
102
|
+
'.dshgp_acctblock2_loading{color:var(--dsw-alias-label-secondary)}',
|
|
103
|
+
'.dshgp_pill{display:inline-flex;align-items:center;gap:4px;font-size:10px;font-weight:600;padding:2px 8px;border-radius:999px}',
|
|
104
|
+
'.dshgp_pill_on{background:color-mix(in srgb,var(--dsw-alias-label-success) 14%,transparent);color:var(--dsw-alias-label-success)}',
|
|
105
|
+
'.dshgp_pill_off{background:color-mix(in srgb,var(--dsw-alias-label-tertiary) 14%,transparent);color:var(--dsw-alias-label-secondary)}',
|
|
106
|
+
// 凭据行「徽标 + 各自有效时间」的容器与时间小字;两用户提示行
|
|
107
|
+
'.dshgp_credwrap{display:inline-flex;align-items:center;gap:6px;flex-wrap:wrap}',
|
|
108
|
+
'.dshgp_credtime{font-size:10px;color:var(--dsw-alias-label-tertiary)}',
|
|
109
|
+
'.dshgp_acctnote{margin-top:6px;font-size:10px;line-height:1.5;color:var(--dsw-alias-label-secondary)}',
|
|
110
|
+
'.dshgp_acctfoot{position:relative;display:flex;align-items:center;justify-content:space-between;margin-top:10px}',
|
|
111
|
+
'.dshgp_accthint{font-size:10px;color:var(--dsw-alias-label-tertiary)}',
|
|
112
|
+
// 已填写徽标(token/SSH 配置后提示,不显示内容)
|
|
113
|
+
'.dshgp_configured{margin-left:6px;border-radius:999px;padding:1px 8px;font-size:10px;background:color-mix(in srgb,var(--dsw-alias-label-success) 14%,transparent);color:var(--dsw-alias-label-success);white-space:nowrap}',
|
|
114
|
+
// 开关行
|
|
115
|
+
'.dshgp_switchrow{display:flex;align-items:center;justify-content:space-between;gap:10px}',
|
|
116
|
+
'.dshgp_switchlabel{font-size:13px;color:var(--dsw-alias-label-primary)}',
|
|
117
|
+
/* 子开关:缩进显示从属关系;父开关关闭时整体置灰且不可点 */
|
|
118
|
+
'.dshgp_subswitch{padding-left:18px;margin-top:2px}',
|
|
119
|
+
'.dshgp_subswitchOff{opacity:.45}',
|
|
120
|
+
'.dshgp_subswitchOff .dshgp_switchlabel{cursor:not-allowed}',
|
|
121
|
+
'.dshgp_subswitchOff input{cursor:not-allowed}',
|
|
122
|
+
// 克隆预览框新增的两处元素(此前用浏览器默认样式,能显示但与面板风格不一致):
|
|
123
|
+
// · 勾选项行:复选框与说明文字横向对齐、字号与小字提示一致;
|
|
124
|
+
// · 不完整克隆提示:独立一行、留出行距便于阅读。
|
|
125
|
+
'.dshgp_previewopt{display:flex;align-items:center;gap:6px;margin:6px 0 2px;font-size:12px;opacity:.9}',
|
|
126
|
+
'.dshgp_previewopt input{margin:0;cursor:pointer}',
|
|
127
|
+
'.dshgp_previewpartial{margin:4px 0 2px;font-size:12px;opacity:.85;line-height:1.5}',
|
|
128
|
+
// 输入
|
|
129
|
+
'.dshgp_input{border:.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-layer-3);height:32px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 10px;font-size:13px;width:100%;box-sizing:border-box}',
|
|
130
|
+
'.dshgp_textarea{border:.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-layer-3);font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:8px 10px;font-size:12px;width:100%;box-sizing:border-box;resize:vertical;min-height:56px}',
|
|
131
|
+
'.dshgp_field{margin:0 0 8px}',
|
|
132
|
+
'.dshgp_label{font-size:12px;font-weight:500;color:var(--dsw-alias-label-primary);display:block;margin-bottom:4px}',
|
|
133
|
+
'.dshgp_hint{margin:2px 0 0;font-size:11px;color:var(--dsw-alias-label-tertiary)}',
|
|
134
|
+
// 按钮
|
|
135
|
+
'.dshgp_btn{font:inherit;font-size:12px;border-radius:8px;padding:5px 10px;cursor:pointer;border:.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary)}',
|
|
136
|
+
'.dshgp_btn:disabled{opacity:.45;cursor:default}',
|
|
137
|
+
// 可见性切换独立确认弹窗(1.5.4 改版):mask/dialog 复用 browse modal 样式,
|
|
138
|
+
// 按钮行 + 风险提示
|
|
139
|
+
'.dshgp_previewbtns{display:flex;gap:8px;justify-content:flex-end;margin-top:4px}',
|
|
140
|
+
'.dshgp_viswarn{font-size:12px;line-height:1.6;padding:7px 9px;border-radius:8px;background:color-mix(in srgb,var(--dsw-alias-label-warning) 11%,transparent);border:.5px solid color-mix(in srgb,var(--dsw-alias-label-warning) 30%,transparent);color:var(--dsw-alias-label-warning)}',
|
|
141
|
+
'.dshgp_btnPrimary{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary)}',
|
|
142
|
+
// 审计扫描范围单按钮:一个按钮单击切换 diff/full,状态体现在标题 + 颜色
|
|
143
|
+
'.dshgp_scanbtn{font:inherit;font-size:12px;border-radius:8px;padding:5px 12px;cursor:pointer;border:.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);display:inline-flex;align-items:center;gap:6px;transition:border-color .15s,color .15s,background-color .15s}',
|
|
144
|
+
'.dshgp_scanbtn:hover{border-color:var(--dsw-alias-brand-primary)}',
|
|
145
|
+
'.dshgp_scanbtnDiff{color:var(--dsw-alias-label-success);border-color:color-mix(in srgb,var(--dsw-alias-label-success) 55%,transparent)}',
|
|
146
|
+
'.dshgp_scanbtnFull{border-color:color-mix(in srgb,var(--dsw-alias-label-warning) 55%,transparent);color:var(--dsw-alias-label-warning);background:color-mix(in srgb,var(--dsw-alias-label-warning) 8%,transparent)}',
|
|
147
|
+
'.dshgp_scanbtnOff{opacity:.45;cursor:not-allowed}',
|
|
148
|
+
'.dshgp_foot{display:flex;gap:8px;flex-wrap:wrap;margin-top:4px}',
|
|
149
|
+
// 权重
|
|
150
|
+
'.dshgp_weightrow{display:flex;align-items:center;gap:8px;margin:3px 0}',
|
|
151
|
+
'.dshgp_weightkey{flex:1;font-size:12px;color:var(--dsw-alias-label-primary)}',
|
|
152
|
+
'.dshgp_weightinput{width:64px;border:.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-layer-3);height:26px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:6px;padding:0 6px;font-size:12px;text-align:right}',
|
|
153
|
+
'.dshgp_weighttotal{margin:6px 0 0;font-size:11px;color:var(--dsw-alias-label-tertiary)}',
|
|
154
|
+
// 规则包列表
|
|
155
|
+
// 规则包列表(榜单样式:模仿 skill 记分榜 表头行 + 定宽右对齐列 + hover)
|
|
156
|
+
'.dshgp_rulenext{list-style:none;margin:0;padding:0;border:.5px solid var(--dsw-alias-border-l4);border-radius:12px;background:var(--dsw-alias-bg-layer-3);overflow:hidden}',
|
|
157
|
+
'.dshgp_ruleheadrow{display:flex;align-items:center;gap:8px;padding:8px 12px;font-size:11px;text-transform:uppercase;letter-spacing:.06em;color:var(--dsw-alias-label-tertiary);border-bottom:.5px solid var(--dsw-alias-border-l2)}',
|
|
158
|
+
'.dshgp_rulerow{display:flex;align-items:center;gap:8px;padding:8px 12px;font-size:13px;border-bottom:.5px solid var(--dsw-alias-border-l1)}',
|
|
159
|
+
'.dshgp_rulerow:last-child{border-bottom:0}',
|
|
160
|
+
'.dshgp_rulerow:hover{background:var(--dsw-alias-bg-layer-2)}',
|
|
161
|
+
'.dshgp_mini{font:inherit;font-size:12px;border:0;background:0 0;color:var(--dsw-alias-label-secondary);cursor:pointer;padding:1px 5px;border-radius:4px}',
|
|
162
|
+
'.dshgp_mini:hover{background:var(--dsw-alias-bg-layer-2)}',
|
|
163
|
+
'.dshgp_mini:disabled{opacity:.3;cursor:default}',
|
|
164
|
+
'.dshgp_ruleinfo{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}',
|
|
165
|
+
'.dshgp_ruleheadrowinfo{flex:1;min-width:0}',
|
|
166
|
+
'.dshgp_rulename{font-size:13px;font-weight:500;color:var(--dsw-alias-label-primary);font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}',
|
|
167
|
+
'.dshgp_rulemeta{font-size:11px;color:var(--dsw-alias-label-tertiary)}',
|
|
168
|
+
'.dshgp_rulecount{flex-shrink:0;width:56px;text-align:right;font-size:12px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-primary)}',
|
|
169
|
+
'.dshgp_rulecountRed{flex-shrink:0;width:56px;text-align:right;font-size:12px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-error)}',
|
|
170
|
+
'.dshgp_rulecountYellow{flex-shrink:0;width:56px;text-align:right;font-size:12px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-warning)}',
|
|
171
|
+
'.dshgp_rulecountGreen{flex-shrink:0;width:56px;text-align:right;font-size:12px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-success)}',
|
|
172
|
+
'.dshgp_rulebadge{flex-shrink:0;width:48px;text-align:right}',
|
|
173
|
+
'.dshgp_badge{border-radius:999px;padding:1px 8px;font-size:10px;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);white-space:nowrap}',
|
|
174
|
+
'.dshgp_badgeRed{background:color-mix(in srgb,var(--dsw-alias-label-error) 14%,transparent);color:var(--dsw-alias-label-error)}',
|
|
175
|
+
'.dshgp_badgeYellow{background:color-mix(in srgb,var(--dsw-alias-label-warning) 14%,transparent);color:var(--dsw-alias-label-warning)}',
|
|
176
|
+
'.dshgp_badgeGreen{background:color-mix(in srgb,var(--dsw-alias-label-success) 14%,transparent);color:var(--dsw-alias-label-success)}',
|
|
177
|
+
// 规则明细表格(对齐记分榜表格)
|
|
178
|
+
'.dshgp_table{width:100%;border-collapse:collapse;font-size:12px;margin-top:4px}',
|
|
179
|
+
'.dshgp_table th{text-align:left;font-weight:600;color:var(--dsw-alias-label-secondary);padding:4px 8px;border-bottom:.5px solid var(--dsw-alias-border-l2);font-size:11px}',
|
|
180
|
+
'.dshgp_table td{padding:5px 8px;border-bottom:.5px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-primary);vertical-align:top}',
|
|
181
|
+
'.dshgp_table tr:last-child td{border-bottom:none}',
|
|
182
|
+
'.dshgp_tdname{font-weight:500}',
|
|
183
|
+
'.dshgp_tddesc{color:var(--dsw-alias-label-secondary)}',
|
|
184
|
+
'.dshgp_tdsev{white-space:nowrap}',
|
|
185
|
+
// 统计条
|
|
186
|
+
'.dshgp_stats{display:flex;gap:8px;flex-wrap:wrap;margin:8px 0 4px}',
|
|
187
|
+
'.dshgp_loading{padding:12px;text-align:center;font-size:12px;color:var(--dsw-alias-label-tertiary)}',
|
|
188
|
+
// 启用/禁用底色加强 + 左侧色条,状态一眼可辨。
|
|
189
|
+
// 启用 = 绿底 + 绿左条;禁用 = 红底 + 红左条(禁用行不再整体降透明度,保持可读)。
|
|
190
|
+
'.dshgp_rowOn{background:color-mix(in srgb,var(--dsw-alias-label-success) 13%,transparent);border-left:3px solid var(--dsw-alias-label-success)}',
|
|
191
|
+
'.dshgp_rowOff{background:color-mix(in srgb,var(--dsw-alias-label-error) 15%,transparent);border-left:3px solid var(--dsw-alias-label-error)}',
|
|
192
|
+
// 行内浮层 tooltip(悬停显示详细信息:描述/作者/统计口径)——不占布局、不推挤下方行。
|
|
193
|
+
'.dshgp_ruleinfo{position:relative}',
|
|
194
|
+
'.dshgp_hovercard{display:none;position:absolute;left:0;top:100%;z-index:40;min-width:260px;max-width:420px;margin-top:6px;padding:8px 10px;border:.5px solid var(--dsw-alias-border-l4);border-radius:8px;background:var(--dsw-alias-bg-layer-3);box-shadow:0 6px 20px rgba(0,0,0,.18);font-size:11px;line-height:1.5;color:var(--dsw-alias-label-secondary);white-space:normal}',
|
|
195
|
+
'.dshgp_ruleinfo:hover .dshgp_hovercard{display:block}',
|
|
196
|
+
'.dshgp_hoverTitle{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary);margin-bottom:2px}',
|
|
197
|
+
'.dshgp_hoverRow{margin-top:2px}',
|
|
198
|
+
// 启停按钮(行内唯一可点击切换状态的位置)——绿/红实色胶囊,一眼看出点它会切到哪一侧
|
|
199
|
+
'.dshgp_powerBtn{flex-shrink:0;font:inherit;font-size:11px;border:.5px solid transparent;border-radius:999px;padding:2px 10px;cursor:pointer;white-space:nowrap}',
|
|
200
|
+
'.dshgp_powerOn{background:var(--dsw-alias-label-success);color:#fff}',
|
|
201
|
+
'.dshgp_powerOff{background:var(--dsw-alias-label-error);color:#fff}',
|
|
202
|
+
'.dshgp_powerBtn:disabled{opacity:.45;cursor:default}',
|
|
203
|
+
'.dshgp_powerBtn:hover:not(:disabled){filter:brightness(1.08)}',
|
|
204
|
+
'.dshgp_error{margin:8px 0 0;font-size:12px;color:var(--dsw-alias-label-error)}',
|
|
205
|
+
'.dshgp_saved{margin:6px 0 0;font-size:12px;color:var(--dsw-alias-label-success)}',
|
|
206
|
+
// 账号卡片:本地/云端(仓库管理)
|
|
207
|
+
'.dshgp_repocard{position:relative;border:.5px solid var(--dsw-alias-border-l4);border-radius:16px;background:var(--dsw-alias-bg-layer-3);padding:10px 12px 12px}',
|
|
208
|
+
'.dshgp_suptabs{display:flex;gap:2px;border-bottom:.5px solid var(--dsw-alias-border-l2);margin:0 0 10px}',
|
|
209
|
+
'.dshgp_suptab{font:inherit;font-size:12px;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;border-bottom:2px solid transparent;padding:5px 14px}',
|
|
210
|
+
'.dshgp_suptabOn{color:var(--dsw-alias-brand-primary);border-bottom-color:var(--dsw-alias-brand-primary);font-weight:600}',
|
|
211
|
+
'.dshgp_repanepane{display:flex;flex-direction:column;gap:8px}',
|
|
212
|
+
'.dshgp_repobar{display:flex;align-items:center;gap:8px}',
|
|
213
|
+
'.dshgp_pickinput{flex:1;min-width:0;font:inherit;font-size:12px;padding:5px 9px;border:.5px solid var(--dsw-alias-border-l4);border-radius:8px;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary)}',
|
|
214
|
+
'.dshgp_repohint{font-size:12px;color:var(--dsw-alias-label-tertiary)}',
|
|
215
|
+
'.dshgp_repomsg{margin:0;font-size:11px;color:var(--dsw-alias-label-tertiary);line-height:1.5}',
|
|
216
|
+
'.dshgp_pushcol{display:flex;flex-direction:column;align-items:flex-end;gap:3px;max-width:46%;min-width:100px}',
|
|
217
|
+
'.dshgp_fb{font-size:11px;line-height:1.35;word-break:break-all;text-align:right}',
|
|
218
|
+
'.dshgp_fbok{color:#2fa84f}',
|
|
219
|
+
'.dshgp_fbfail{color:#d64545}',
|
|
220
|
+
'.dshgp_replist{display:flex;flex-direction:column;gap:6px;max-height:320px;overflow-y:auto}',
|
|
221
|
+
'.dshgp_reprow{display:flex;align-items:center;gap:8px;padding:7px 10px;border:.5px solid var(--dsw-alias-border-l2);border-radius:10px;background:color-mix(in srgb,var(--dsw-alias-bg-base) 55%,transparent)}',
|
|
222
|
+
'.dshgp_reprowinfo{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}',
|
|
223
|
+
'.dshgp_reprowpath{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%}',
|
|
224
|
+
'.dshgp_reprowmeta{font-size:11px;color:var(--dsw-alias-label-tertiary);word-break:break-all}',
|
|
225
|
+
'.dshgp_browsebtn{flex-shrink:0;font-size:12px;padding:4px 8px;border:.5px solid var(--dsw-alias-border-l4);border-radius:8px;background:var(--dsw-alias-bg-layer-2);cursor:pointer}',
|
|
226
|
+
// 目录选择弹窗(移植 gbmd path-picker:一行接入 📂 按钮)
|
|
227
|
+
'.dshgp_browsemask{position:fixed;inset:0;z-index:9999;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.4)}',
|
|
228
|
+
'.dshgp_browsedialog{width:min(480px,88vw);max-height:70vh;display:flex;flex-direction:column;gap:8px;padding:14px;border:.5px solid var(--dsw-alias-border-l4);border-radius:14px;background:var(--dsw-alias-bg-layer-3);box-shadow:0 12px 40px rgba(0,0,0,.35)}',
|
|
229
|
+
'.dshgp_browsehead{display:flex;align-items:center;justify-content:space-between}',
|
|
230
|
+
'.dshgp_browsetitle{font-size:13px;font-weight:600;color:var(--dsw-alias-label-primary)}',
|
|
231
|
+
'.dshgp_browseclose{font:inherit;font-size:13px;color:var(--dsw-alias-label-tertiary);cursor:pointer;background:0 0;border:none;padding:2px 6px}',
|
|
232
|
+
'.dshgp_browsepath{font-size:11px;color:var(--dsw-alias-label-secondary);word-break:break-all;padding:6px 8px;border:.5px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-base)}',
|
|
233
|
+
'.dshgp_browseup{font-size:12px;color:var(--dsw-alias-brand-primary);cursor:pointer;padding:3px 2px}',
|
|
234
|
+
'.dshgp_browselist{flex:1;min-height:120px;max-height:38vh;overflow-y:auto;display:flex;flex-direction:column;gap:2px}',
|
|
235
|
+
'.dshgp_browsedir{font-size:12px;color:var(--dsw-alias-label-primary);cursor:pointer;padding:5px 8px;border-radius:6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}',
|
|
236
|
+
'.dshgp_browsedir:hover{background:color-mix(in srgb,var(--dsw-alias-brand-primary) 12%,transparent)}',
|
|
237
|
+
'.dshgp_browsehint{font-size:12px;color:var(--dsw-alias-label-tertiary);padding:8px}',
|
|
238
|
+
'.dshgp_browsefoot{display:flex;justify-content:flex-end}',
|
|
239
|
+
].join('');
|
|
240
|
+
|
|
241
|
+
/* ─────────────────── [2] 工具区(ensureCss/getJson/postJson/tokenConfigured/copyText) ─────────────────── */
|
|
242
|
+
function dshgp_ensureCss() {
|
|
243
|
+
if (typeof document === 'undefined') return;
|
|
244
|
+
if (document.querySelector('style[data-plugin-css="dsh-git-push"]')) return;
|
|
245
|
+
const tag = document.createElement('style');
|
|
246
|
+
tag.dataset.plugin = 'dsh-git-push';
|
|
247
|
+
tag.dataset.pluginCss = 'dsh-git-push';
|
|
248
|
+
tag.textContent = dshgp_css;
|
|
249
|
+
document.head.appendChild(tag);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** fetch 封装:GET JSON(same-origin)。 */
|
|
253
|
+
async function dshgp_getJson(url) {
|
|
254
|
+
const resp = await fetch(url, { credentials: 'same-origin', signal: AbortSignal.timeout(dshgp_FETCH_TIMEOUT_MS) });
|
|
255
|
+
return resp.json();
|
|
256
|
+
}
|
|
257
|
+
/** fetch 封装:POST JSON(same-origin)。 */
|
|
258
|
+
async function dshgp_postJson(url, payload, timeoutMs) {
|
|
259
|
+
const resp = await fetch(url, {
|
|
260
|
+
method: 'POST',
|
|
261
|
+
headers: { 'Content-Type': 'application/json' },
|
|
262
|
+
body: JSON.stringify(payload || {}),
|
|
263
|
+
credentials: 'same-origin',
|
|
264
|
+
signal: AbortSignal.timeout((timeoutMs || dshgp_FETCH_TIMEOUT_MS)),
|
|
265
|
+
});
|
|
266
|
+
return resp.json();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* token 是否已配置:优先用 host 派生的布尔位。
|
|
271
|
+
* githubToken 标了 role('secret'),远端读不下发明文 → 设置快照里该字段为空,
|
|
272
|
+
* 旧写法(看 githubToken 真值)会永远判成「未配置」。故改为优先读 status 给的
|
|
273
|
+
* tokenConfigured,明文仍在时(旧 host / 未脱敏环境)沿用旧判断兜底。
|
|
274
|
+
*/
|
|
275
|
+
function dshgp_tokenConfigured(value) {
|
|
276
|
+
var v = value || {};
|
|
277
|
+
if (v.tokenConfigured === true) return true;
|
|
278
|
+
return !!(v.githubToken && String(v.githubToken).trim());
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* 安全 localStorage 读(sandbox iframe 缺 allow-same-origin 时访问即抛 SecurityError,
|
|
283
|
+
* `window.localStorage` 存在性判断拦不住 getItem 抛错——必须 try/catch 兜底)。
|
|
284
|
+
* @returns {string} 值或 ''(不可用/抛错时静默返回空)
|
|
285
|
+
*/
|
|
286
|
+
function dshgp_localGet(key) {
|
|
287
|
+
try { return window.localStorage.getItem(key); } catch { return ''; }
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** 安全 localStorage 写(同上,不可用/抛错静默忽略)。 */
|
|
291
|
+
function dshgp_localSet(key, value) {
|
|
292
|
+
try { if (value) window.localStorage.setItem(key, value); } catch { /* localStorage 不可用 */ }
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** 复制文本到剪贴板(优先 Clipboard API,兜底 execCommand)。 */
|
|
296
|
+
function dshgp_copyText(text) {
|
|
297
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard && navigator.clipboard.writeText) {
|
|
298
|
+
return navigator.clipboard.writeText(String(text || ''));
|
|
299
|
+
}
|
|
300
|
+
return Promise.resolve();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/* ─────────────────── [3] 图标区(ghIcon/refreshIcon) ─────────────────── */
|
|
304
|
+
/* ═══════════════════ 选项卡一:账号信息(美化版:渐变卡片 + GitHub 图标 + 状态徽标) ═══════════════════ */
|
|
305
|
+
const dshgp_ghIcon = jsx.jsx('svg', {
|
|
306
|
+
width: '22', height: '22', viewBox: '0 0 24 24', fill: 'none',
|
|
307
|
+
stroke: 'currentColor', strokeWidth: '1.8', strokeLinecap: 'round', strokeLinejoin: 'round',
|
|
308
|
+
children: jsx.jsx('path', { d: 'M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22' }),
|
|
309
|
+
});
|
|
310
|
+
const dshgp_refreshIcon = jsx.jsx('svg', {
|
|
311
|
+
width: '13', height: '13', viewBox: '0 0 24 24', fill: 'none',
|
|
312
|
+
stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'round',
|
|
313
|
+
children: jsx.jsx('path', { d: 'M21 12a9 9 0 1 1-2.64-6.36M21 3v6h-6' }),
|
|
314
|
+
});
|
|
315
|
+
/* ─────────────────── [4] 账号信息 Tab(AcctHead/AccountCard/AccountTab) ─────────────────── */
|
|
316
|
+
/** 账号卡片头部:GitHub 图标 + 标题 + 状态徽标。 */
|
|
317
|
+
function dshgp_AcctHead(props) {
|
|
318
|
+
return jsx.jsxs('div', {
|
|
319
|
+
className: 'dshgp_accthead',
|
|
320
|
+
children: [
|
|
321
|
+
jsx.jsx('div', { className: 'dshgp_acctic', children: dshgp_ghIcon }),
|
|
322
|
+
jsx.jsxs('div', {
|
|
323
|
+
children: [
|
|
324
|
+
jsx.jsx('p', { className: 'dshgp_accttitle', children: 'GitHub 账号' }),
|
|
325
|
+
jsx.jsx('p', { className: 'dshgp_acctsub', children: 'Token / SSH 公钥检测结果 · 进入设置自动检测' }),
|
|
326
|
+
],
|
|
327
|
+
}),
|
|
328
|
+
jsx.jsxs('span', { className: 'dshgp_acctstat ' + props.statCls, children: [jsx.jsx('span', { className: 'dshgp_acctdot' }), props.statTxt] }),
|
|
329
|
+
],
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** 账号卡片(渐变面板)渲染:头部 + 状态块 + 凭据标签 + 刷新按钮。 */
|
|
334
|
+
function dshgp_AccountCard(props) {
|
|
335
|
+
const s = props.state;
|
|
336
|
+
const loggedIn = !!s.accountLoggedIn;
|
|
337
|
+
const loading = !!s.accountLoading;
|
|
338
|
+
const statCls = loggedIn ? 'dshgp_acctstat_ok' : (loading ? 'dshgp_acctstat_warn' : 'dshgp_acctstat_err');
|
|
339
|
+
const statTxt = loggedIn ? '已连接' : (loading ? '检测中' : '未连接');
|
|
340
|
+
const blockCls = loggedIn ? 'dshgp_acctblock2_ok' : (loading ? 'dshgp_acctblock2_loading' : 'dshgp_acctblock2_err');
|
|
341
|
+
const blockBody = s.accountBlock
|
|
342
|
+
? s.accountBlock
|
|
343
|
+
: (loading ? '正在检测 Token / SSH 公钥…' : '未配置 Token / SSH 公钥——请到「设置」选项卡填写凭据');
|
|
344
|
+
// 两条凭据各自独立——Token 与 SSH 可以是**不同 GitHub 用户**;明细(用户名/校验时间/
|
|
345
|
+
// 配额)统一由凭据块(block,后端生成)逐行给出,页面不再另列重复的分项行。
|
|
346
|
+
// 两凭据属不同用户时如实提示:推送实际走 SSH 通道
|
|
347
|
+
const twoUsers = !!(s.tokenStatus && s.tokenStatus.login && s.sshStatus && s.sshStatus.login
|
|
348
|
+
&& s.tokenStatus.login !== s.sshStatus.login);
|
|
349
|
+
return jsx.jsxs('div', {
|
|
350
|
+
className: 'dshgp_acctpanel',
|
|
351
|
+
children: [
|
|
352
|
+
jsx.jsx(dshgp_AcctHead, { statCls, statTxt }),
|
|
353
|
+
jsx.jsx('pre', { className: 'dshgp_acctblock2 ' + blockCls, children: blockBody }),
|
|
354
|
+
// Token / SSH 公钥的登录名与校验时间已在**凭据块内**逐行给出(Token 那行还带 API 配额后缀),
|
|
355
|
+
// 此处不再另列一遍分项行——同一份登录信息展示两遍正是之前的重复问题。
|
|
356
|
+
// 两条凭据可属不同 GitHub 用户(都有效),这条提示不在块内,单独保留。
|
|
357
|
+
twoUsers
|
|
358
|
+
? jsx.jsx('div', {
|
|
359
|
+
className: 'dshgp_acctnote',
|
|
360
|
+
children: `Token 属 ${s.tokenStatus.login},SSH 属 ${s.sshStatus.login}——推送走 SSH 通道(${s.sshStatus.login})`,
|
|
361
|
+
})
|
|
362
|
+
: null,
|
|
363
|
+
jsx.jsxs('div', {
|
|
364
|
+
className: 'dshgp_acctfoot',
|
|
365
|
+
children: [
|
|
366
|
+
jsx.jsx('button', {
|
|
367
|
+
type: 'button',
|
|
368
|
+
className: 'dshgp_keybtn',
|
|
369
|
+
disabled: loading,
|
|
370
|
+
onClick: props.recheckAccount,
|
|
371
|
+
children: [dshgp_refreshIcon, loading ? '检测中…' : '重新检测'],
|
|
372
|
+
}),
|
|
373
|
+
jsx.jsx('span', { className: 'dshgp_accthint', children: loggedIn ? '登录态有效,凭据已生效' : '凭据状态来自保存的 Token / SSH 公钥' }),
|
|
374
|
+
],
|
|
375
|
+
}),
|
|
376
|
+
],
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** 选项卡一:账号信息(拆卡片:渐变面板 AccountCard + 本地/云端 RepoManagerCard)。 */
|
|
381
|
+
function dshgp_AccountTab(props) {
|
|
382
|
+
// 账号信息/本地仓库列表的读取时机已收敛到三种(不再每次切 tab 重读):
|
|
383
|
+
// ①插件启动时(apply 里一次性读:refreshAccount + scanLocalRepos)
|
|
384
|
+
// ②云端 push 完成时(pushLocalRepo 成功后顺延重读)
|
|
385
|
+
// ③本地仓库手动「扫描」完成索引重建后(扫描按钮 rebuild=true 自带重读)
|
|
386
|
+
// 因此这里**不再**挂载时刷新——条件渲染(tab==='account')每次切回都重挂载,
|
|
387
|
+
// 若在此触发会「一直刷新」;读取全部改由 Controller 层显式调用。
|
|
388
|
+
return jsx.jsxs('div', {
|
|
389
|
+
className: 'dshgp_section',
|
|
390
|
+
children: [
|
|
391
|
+
jsx.jsx(dshgp_AccountSwitcher, props),
|
|
392
|
+
// 账号卡片:本地/云端 仓库管理(本地扫描可手动指定路径 / 云端列表可 clone)
|
|
393
|
+
jsx.jsx(dshgp_RepoManagerCard, props),
|
|
394
|
+
],
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/* ─────────────────── [5] 目录选择器(browseEnsureDom/browseLoad/browseOpen/browseClose/browseAttach) ─────────────────── */
|
|
399
|
+
let dshgp_browseTarget = null; // 当前打开的输入框(null = 走 onPick 回调)
|
|
400
|
+
// 移植 gamebanana-mods-downloader 的 path-picker 小模块:一行接入 📂 按钮 // 当前打开的输入框(null = 走 onPick 回调)
|
|
401
|
+
let dshgp_browseOpt = null; // { onPick } 确认回调(clone 场景)
|
|
402
|
+
let dshgp_browsePath = ''; // 弹窗当前所在目录
|
|
403
|
+
function dshgp_browseEnsureDom() {
|
|
404
|
+
if (typeof document === 'undefined' || document.getElementById('dshgp-browse-mask')) return;
|
|
405
|
+
const mask = document.createElement('div');
|
|
406
|
+
mask.id = 'dshgp-browse-mask';
|
|
407
|
+
mask.className = 'dshgp_browsemask';
|
|
408
|
+
mask.style.display = 'none';
|
|
409
|
+
mask.innerHTML = ''
|
|
410
|
+
+ '<div class="dshgp_browsedialog">'
|
|
411
|
+
+ '<div class="dshgp_browsehead"><span class="dshgp_browsetitle">选择目录</span><button type="button" class="dshgp_browseclose" id="dshgp-browse-close">✕</button></div>'
|
|
412
|
+
+ '<div class="dshgp_browsepath" id="dshgp-browse-crumb"></div>'
|
|
413
|
+
+ '<div class="dshgp_browseup" id="dshgp-browse-up">⬆ 上级目录</div>'
|
|
414
|
+
+ '<div class="dshgp_browselist" id="dshgp-browse-list"></div>'
|
|
415
|
+
+ '<div class="dshgp_browsefoot"><button type="button" class="dshgp_keybtn" id="dshgp-browse-ok">选择当前目录</button></div>'
|
|
416
|
+
+ '</div>';
|
|
417
|
+
document.body.appendChild(mask);
|
|
418
|
+
mask.addEventListener('click', (e) => { if (e.target === mask) dshgp_browseClose(); });
|
|
419
|
+
document.getElementById('dshgp-browse-close').addEventListener('click', dshgp_browseClose);
|
|
420
|
+
document.getElementById('dshgp-browse-up').addEventListener('click', () => {
|
|
421
|
+
const up = document.getElementById('dshgp-browse-up');
|
|
422
|
+
if (up && up.dataset.path) dshgp_browseLoad(up.dataset.path);
|
|
423
|
+
});
|
|
424
|
+
document.getElementById('dshgp-browse-ok').addEventListener('click', () => {
|
|
425
|
+
const onPick = dshgp_browseOpt;
|
|
426
|
+
const target = dshgp_browseTarget;
|
|
427
|
+
dshgp_browseClose();
|
|
428
|
+
if (onPick) onPick(dshgp_browsePath);
|
|
429
|
+
else if (target) target.value = dshgp_browsePath;
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
function dshgp_browseGuess() {
|
|
433
|
+
return dshgp_localGet('dshgp-browse-path');
|
|
434
|
+
}
|
|
435
|
+
function dshgp_browseRemember(p) {
|
|
436
|
+
dshgp_localSet('dshgp-browse-path', p);
|
|
437
|
+
}
|
|
438
|
+
async function dshgp_browseLoad(p) {
|
|
439
|
+
const list = document.getElementById('dshgp-browse-list');
|
|
440
|
+
const crumb = document.getElementById('dshgp-browse-crumb');
|
|
441
|
+
const up = document.getElementById('dshgp-browse-up');
|
|
442
|
+
if (!list || !crumb) return;
|
|
443
|
+
crumb.textContent = '读取中…';
|
|
444
|
+
let browseRes;
|
|
445
|
+
try { browseRes = await dshgp_getJson('/api/git-push/browse?path=' + encodeURIComponent(String(p || ''))); }
|
|
446
|
+
catch (e) { crumb.textContent = '读取失败: ' + (e && e.message || e); return; }
|
|
447
|
+
if (!browseRes || !browseRes.ok) { crumb.textContent = (browseRes && browseRes.error) || '读取失败'; return; }
|
|
448
|
+
dshgp_browsePath = browseRes.path;
|
|
449
|
+
dshgp_browseRemember(browseRes.path);
|
|
450
|
+
crumb.textContent = browseRes.path;
|
|
451
|
+
up.style.display = browseRes.parent ? 'block' : 'none';
|
|
452
|
+
up.dataset.path = browseRes.parent || '';
|
|
453
|
+
let html = '';
|
|
454
|
+
if (!browseRes.dirs.length) html += '<div class="dshgp_browsehint">(无子目录)</div>';
|
|
455
|
+
(browseRes.dirs || []).forEach((dirName) => {
|
|
456
|
+
const full = browseRes.path === '/' ? '/' + dirName : browseRes.path + '/' + dirName;
|
|
457
|
+
html += '<div class="dshgp_browsedir" data-path="' + String(full).replace(/"/g, '"') + '">📁 ' + String(dirName).replace(/</g, '<') + '</div>';
|
|
458
|
+
});
|
|
459
|
+
list.innerHTML = html;
|
|
460
|
+
list.querySelectorAll('.dshgp_browsedir').forEach((el) => {
|
|
461
|
+
el.addEventListener('click', () => dshgp_browseLoad(el.dataset.path));
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
function dshgp_browseOpen(input, onPick) {
|
|
465
|
+
if (typeof document === 'undefined') return;
|
|
466
|
+
dshgp_browseTarget = input || null;
|
|
467
|
+
dshgp_browseOpt = onPick || null;
|
|
468
|
+
dshgp_browseEnsureDom();
|
|
469
|
+
const mask = document.getElementById('dshgp-browse-mask');
|
|
470
|
+
mask.style.display = 'flex';
|
|
471
|
+
void dshgp_browseLoad(dshgp_browseGuess());
|
|
472
|
+
}
|
|
473
|
+
function dshgp_browseClose() {
|
|
474
|
+
if (typeof document === 'undefined') return;
|
|
475
|
+
const mask = document.getElementById('dshgp-browse-mask');
|
|
476
|
+
if (mask) mask.style.display = 'none';
|
|
477
|
+
dshgp_browseTarget = null;
|
|
478
|
+
dshgp_browseOpt = null;
|
|
479
|
+
}
|
|
480
|
+
function dshgp_browseAttach(inputEl) {
|
|
481
|
+
if (!inputEl || inputEl.dataset.dshgpBrowse) return; // 幂等
|
|
482
|
+
inputEl.dataset.dshgpBrowse = '1';
|
|
483
|
+
const btn = document.createElement('button');
|
|
484
|
+
btn.type = 'button';
|
|
485
|
+
btn.className = 'dshgp_browsebtn';
|
|
486
|
+
btn.textContent = '📂';
|
|
487
|
+
btn.title = '选择目录';
|
|
488
|
+
btn.addEventListener('click', () => dshgp_browseOpen(inputEl, null));
|
|
489
|
+
inputEl.insertAdjacentElement('afterend', btn);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/* ═══════════════════ 账号卡片:本地/云端 仓库管理 ═══════════════════ */
|
|
493
|
+
/* ─────────────────── [6] 仓库管理卡(RepoManagerCard/RepoLocalPane/RepoCloudPane) ─────────────────── */
|
|
494
|
+
function dshgp_RepoManagerCard(props) {
|
|
495
|
+
const s = props.state;
|
|
496
|
+
const [view, setView] = react.useState('local');
|
|
497
|
+
// 每次渲染后为路径输入框挂 📂 按钮(attach 幂等)
|
|
498
|
+
react.useEffect(() => {
|
|
499
|
+
const el = document.getElementById('dshgp-local-path');
|
|
500
|
+
if (el) dshgp_browseAttach(el);
|
|
501
|
+
});
|
|
502
|
+
const subTabs = [
|
|
503
|
+
{ id: 'local', label: '本地' },
|
|
504
|
+
{ id: 'cloud', label: 'GitHub' },
|
|
505
|
+
{ id: 'npm', label: 'NPM' },
|
|
506
|
+
];
|
|
507
|
+
return jsx.jsxs('div', {
|
|
508
|
+
className: 'dshgp_repocard',
|
|
509
|
+
children: [
|
|
510
|
+
jsx.jsxs('div', {
|
|
511
|
+
className: 'dshgp_suptabs',
|
|
512
|
+
children: subTabs.map((t) => jsx.jsxs('button', {
|
|
513
|
+
key: t.id,
|
|
514
|
+
type: 'button',
|
|
515
|
+
className: view === t.id ? 'dshgp_suptab dshgp_suptabOn' : 'dshgp_suptab',
|
|
516
|
+
onClick: () => setView(t.id),
|
|
517
|
+
children: [t.label],
|
|
518
|
+
})),
|
|
519
|
+
}),
|
|
520
|
+
view === 'local'
|
|
521
|
+
? jsx.jsx('div', { className: 'dshgp_supview', key: 'local', children: jsx.jsx(dshgp_RepoLocalPane, props) })
|
|
522
|
+
: (view === 'cloud'
|
|
523
|
+
? jsx.jsx('div', { className: 'dshgp_supview', key: 'cloud', children: jsx.jsx(dshgp_RepoCloudPane, props) })
|
|
524
|
+
: jsx.jsx('div', { className: 'dshgp_supview', key: 'npm', children: jsx.jsx(dshgp_NpmPanel, props) })),
|
|
525
|
+
],
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** 本地面板单行:路径 + 分支/领先状态 + push 按钮(领先远端可点;工作树未提交改动无影响)。 */
|
|
530
|
+
function dshgp_RepoLocalRow(props) {
|
|
531
|
+
const r = props.repo;
|
|
532
|
+
const s = props.state;
|
|
533
|
+
// 忙标记前缀与后端约定一致(`<kind>:<repoPath>`):提取为命名常量,避免同一裸字面量重复。
|
|
534
|
+
const BUSY_PUSH = dshgp_BUSY_PUSH; // 兼容旧引用;新代码请直接用 dshgp_BUSY_PUSH(单一出处)
|
|
535
|
+
const busy = s.repoBusy === BUSY_PUSH + r.path;
|
|
536
|
+
// 修正「推送判定写反」:可推 = 有远端 + 有未推送提交。
|
|
537
|
+
// ahead>0 → 本地有领先提交,按钮亮;ahead=null → 状态未知(未 fetch/首次推送),
|
|
538
|
+
// 交给后端 ls-remote 精确判定,允许点;ahead=0 → 已同步、没有可推的新提交,灰。
|
|
539
|
+
// 原实现用 `changed === 0`(工作树干净)当可推条件,方向反了:
|
|
540
|
+
// github push 推的是已提交内容,工作树脏不脏无影响——把「有领先提交但工作树脏」的
|
|
541
|
+
// 仓库拦死(能推的不让推),又把「已同步无新提交」的仓库点亮(不能推的按钮才能点)。
|
|
542
|
+
const canPush = !!r.hasRemote && (r.ahead === null || r.ahead > 0);
|
|
543
|
+
// 语义纠正:stat 只体现「远端有无」与领先关系。
|
|
544
|
+
// 修复「文案写死」:ahead===null 此前一律显示「远端状态未知」,
|
|
545
|
+
// 但后端 null 有**两种完全不同的成因**,必须分开措辞(否则远端明明探到了还说未知):
|
|
546
|
+
// ① liveSkipped=true —— 真的没探测(超预算/SSH 熔断/远端不可达),此时才叫未知;
|
|
547
|
+
// ② liveSkipped 非真 —— 已探到远端(remoteHead 有值),只是本地缺该提交对象
|
|
548
|
+
// 算不出领先/落后(缓存过期/未 fetch),此时应说「已连通,待 fetch 后比较」。
|
|
549
|
+
const remoteKnown = !!r.remoteHead; // 远端 HEAD 已真实取到
|
|
550
|
+
const skipped = r.liveSkipped === true; // 本轮未探测
|
|
551
|
+
let stat;
|
|
552
|
+
if (!r.hasRemote) stat = '无远端';
|
|
553
|
+
else if (r.ahead === null) {
|
|
554
|
+
stat = skipped
|
|
555
|
+
? '未探测远端' // 真未知:可点「补查」或 push 时核对
|
|
556
|
+
: (remoteKnown ? '远端 ' + r.remoteHead + ' · 待 fetch 比较' : '远端已连通 · 待比较');
|
|
557
|
+
} else if (r.ahead > 0) stat = '领先 ' + r.ahead;
|
|
558
|
+
else if (r.behind > 0) stat = '落后 ' + r.behind;
|
|
559
|
+
else stat = '同步';
|
|
560
|
+
// 联动仓库索引:本地无 remote/上游时也能显示它的 GitHub 归属
|
|
561
|
+
const idx = r.indexed;
|
|
562
|
+
const idxTag = idx ? ' · 🔗 索引 ' + (idx.owner ? idx.owner + '/' + idx.repo : idx.repo) + '(' + idx.visibility + ')' : '';
|
|
563
|
+
// 云端扫描写索引后透传的云端状态(默认分支 / 云端最后推送时间 / 纯云端标记)
|
|
564
|
+
const cloudAt = r.cloudPushedAt ? ' · 云端更新 ' + String(r.cloudPushedAt).slice(0, 10) : '';
|
|
565
|
+
const cloudTag = (r.defaultBranch ? ' · 默认分支 ' + r.defaultBranch : '') + cloudAt + (r.cloudOnly ? ' · 仅云端' : '');
|
|
566
|
+
// 本地/云端 HEAD 与提交时间并排(后端 liveRemoteHead 真源补 remoteHead/remoteHeadAt)
|
|
567
|
+
const localTime = r.localHeadAt ? new Date(r.localHeadAt).toLocaleString('zh-CN', { hour12: false }) : '';
|
|
568
|
+
const remoteTime = r.remoteHeadAt ? new Date(r.remoteHeadAt).toLocaleString('zh-CN', { hour12: false }) : '';
|
|
569
|
+
const headsStr = (r.localHead ? '本地 ' + r.localHead + (localTime ? ' ' + localTime : '') : '')
|
|
570
|
+
+ (r.remoteHead ? ' · 云端 ' + r.remoteHead + (remoteTime ? ' ' + remoteTime : '') : '');
|
|
571
|
+
return jsx.jsxs('div', {
|
|
572
|
+
className: 'dshgp_reprow',
|
|
573
|
+
children: [
|
|
574
|
+
jsx.jsxs('div', {
|
|
575
|
+
className: 'dshgp_reprowinfo',
|
|
576
|
+
children: [
|
|
577
|
+
jsx.jsx('span', { className: 'dshgp_reprowpath', title: r.path, children: String(r.path).split('/').pop() || r.path }),
|
|
578
|
+
jsx.jsx('span', { className: 'dshgp_reprowmeta', children: ['分支 ' + r.branch + ' · ' + stat + idxTag + cloudTag + (r.changed > 0 ? ' · 未提交 ' + r.changed : '')] }),
|
|
579
|
+
jsx.jsx('span', { className: 'dshgp_reprowmeta' + (r.synced ? ' dshgp_synced' : ''), children: headsStr || (r.lastCommit ? r.lastCommit : '') }),
|
|
580
|
+
],
|
|
581
|
+
}),
|
|
582
|
+
jsx.jsxs('div', {
|
|
583
|
+
className: 'dshgp_pushcol',
|
|
584
|
+
children: [
|
|
585
|
+
// commit 按钮与 push 并排——本地提交(复用提交推送的本地提交审计,
|
|
586
|
+
// 精简报拦截/警告);有未提交改动才可点;push 保持只负责推送。
|
|
587
|
+
jsx.jsx('button', {
|
|
588
|
+
type: 'button',
|
|
589
|
+
className: 'dshgp_keybtn',
|
|
590
|
+
disabled: busy || !(r.changed > 0),
|
|
591
|
+
onClick: () => props.onCommit(r.path),
|
|
592
|
+
children: busy === 'commit:' + r.path ? '提交中…' : 'commit',
|
|
593
|
+
}),
|
|
594
|
+
jsx.jsx('button', {
|
|
595
|
+
type: 'button',
|
|
596
|
+
className: 'dshgp_keybtn',
|
|
597
|
+
disabled: !canPush || busy,
|
|
598
|
+
onClick: () => props.onPush(r.path),
|
|
599
|
+
children: busy === dshgp_BUSY_PUSH + r.path ? '推送中…' : 'push',
|
|
600
|
+
}),
|
|
601
|
+
(s.repoFeedback && s.repoFeedback[r.path])
|
|
602
|
+
? jsx.jsx('span', { className: s.repoFeedback[r.path].ok ? 'dshgp_fb dshgp_fbok' : 'dshgp_fb dshgp_fbfail', children: s.repoFeedback[r.path].msg })
|
|
603
|
+
: null,
|
|
604
|
+
],
|
|
605
|
+
}),
|
|
606
|
+
],
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/** 本地面板:默认扫描工作区目录,可手动指定路径(📂 选择器);仓库领先 + 无未提交改动可手动 push。 */
|
|
611
|
+
function dshgp_RepoLocalPane(props) {
|
|
612
|
+
const s = props.state;
|
|
613
|
+
// key 用 path,空 path 时回退 name(索引里云端-only 条目 path 为空,纯 path 作 key 会
|
|
614
|
+
// 多条撞同一空 key → React「two children with the same key」警告)
|
|
615
|
+
const rows = (s.localRepos || []).map((r) => jsx.jsx(dshgp_RepoLocalRow, { key: r.path || `name:${r.name}`, repo: r, state: s, onPush: props.pushLocalRepo, onCommit: props.commitLocalRepo }));
|
|
616
|
+
return jsx.jsxs('div', {
|
|
617
|
+
className: 'dshgp_repanepane',
|
|
618
|
+
children: [
|
|
619
|
+
jsx.jsxs('div', {
|
|
620
|
+
className: 'dshgp_repobar',
|
|
621
|
+
children: [
|
|
622
|
+
jsx.jsx('input', {
|
|
623
|
+
id: 'dshgp-local-path',
|
|
624
|
+
type: 'text',
|
|
625
|
+
className: 'dshgp_pickinput',
|
|
626
|
+
placeholder: '扫描路径(默认 DSH 家根)',
|
|
627
|
+
defaultValue: dshgp_localGet('dshgp-scan-path'),
|
|
628
|
+
}),
|
|
629
|
+
jsx.jsx('button', {
|
|
630
|
+
type: 'button',
|
|
631
|
+
className: 'dshgp_keybtn',
|
|
632
|
+
// 扫描中禁用,不可重复点击(后台独立进程扫描链路)
|
|
633
|
+
disabled: s.localLoading || s.localScanning,
|
|
634
|
+
onClick: () => {
|
|
635
|
+
const el = document.getElementById('dshgp-local-path');
|
|
636
|
+
// 手动「扫描」= **独立进程后台离线重建 + 逐条追加**:
|
|
637
|
+
// 扫描进程每登记一个仓库就写进度文件 → 前端只追加新增(不全量重读)。
|
|
638
|
+
props.startScan(el ? el.value : '');
|
|
639
|
+
},
|
|
640
|
+
children: (s.localLoading || s.localScanning) ? '扫描中…' : '扫描',
|
|
641
|
+
}),
|
|
642
|
+
],
|
|
643
|
+
}),
|
|
644
|
+
jsx.jsx('p', { className: 'dshgp_repomsg', children: s.localMsg || '扫描目录下的 git 仓库;仓库「领先远端(有未推送提交)」时可手动 push(工作树未提交改动不影响 push,推的是已提交内容)' }),
|
|
645
|
+
rows.length ? jsx.jsxs('div', { className: 'dshgp_replist', children: rows }) : null,
|
|
646
|
+
],
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/** 云端面板单行:仓库名 + 私有/公开/分支/更新时间 + clone 按钮 + 可见性切换(1.5.4,独立弹窗二次确认)。 */
|
|
651
|
+
function dshgp_RepoCloudRow(props) {
|
|
652
|
+
const r = props.repo;
|
|
653
|
+
const s = props.state;
|
|
654
|
+
// 忙标记前缀与后端约定一致(`<kind>:<repoPath>`):提取为命名常量,避免同一裸字面量重复。
|
|
655
|
+
const BUSY_CLONE = dshgp_BUSY_CLONE; // 同上:指向单一出处
|
|
656
|
+
const BUSY_VIS = dshgp_BUSY_VIS;
|
|
657
|
+
const busy = s.repoBusy === BUSY_CLONE + r.fullName;
|
|
658
|
+
const visBusy = s.repoBusy === BUSY_VIS + r.fullName;
|
|
659
|
+
const target = r.private ? 'public' : 'private';
|
|
660
|
+
// 云端仓库标记本地是否已有(后端 repos-cloud 附 localExists/localPath)
|
|
661
|
+
const localTag = r.localExists
|
|
662
|
+
? jsx.jsx('span', { className: 'dshgp_pill dshgp_pill_on', children: '本地已有' })
|
|
663
|
+
: null;
|
|
664
|
+
return jsx.jsxs('div', {
|
|
665
|
+
className: 'dshgp_reprow',
|
|
666
|
+
children: [
|
|
667
|
+
jsx.jsxs('div', {
|
|
668
|
+
className: 'dshgp_reprowinfo',
|
|
669
|
+
children: [
|
|
670
|
+
jsx.jsx('span', { className: 'dshgp_reprowpath', children: r.fullName }),
|
|
671
|
+
jsx.jsx('span', { className: 'dshgp_reprowmeta', children: [(r.private ? '🔒 私有' : '🌐 公开') + ' · ' + (r.defaultBranch || '') + (r.pushedAt ? ' · 更新 ' + r.pushedAt.slice(0, 10) : '')] }),
|
|
672
|
+
localTag,
|
|
673
|
+
],
|
|
674
|
+
}),
|
|
675
|
+
jsx.jsxs('div', {
|
|
676
|
+
className: 'dshgp_pushcol',
|
|
677
|
+
children: [
|
|
678
|
+
jsx.jsx('button', {
|
|
679
|
+
type: 'button',
|
|
680
|
+
className: 'dshgp_keybtn',
|
|
681
|
+
disabled: busy,
|
|
682
|
+
onClick: () => props.onClone(r.fullName),
|
|
683
|
+
children: busy ? '克隆中…' : 'clone',
|
|
684
|
+
}),
|
|
685
|
+
jsx.jsx('button', {
|
|
686
|
+
type: 'button',
|
|
687
|
+
className: 'dshgp_keybtn',
|
|
688
|
+
disabled: visBusy,
|
|
689
|
+
// 二次确认改为**独立弹窗**(Controller.visConfirm + 全局确认面板),
|
|
690
|
+
// 不再行内展开确认条——点击只弹窗,确认动作全在弹窗里完成。
|
|
691
|
+
onClick: () => props.requestVisSwitch(r.fullName, target),
|
|
692
|
+
children: visBusy ? '切换中…' : (r.private ? '切公开' : '切私有'),
|
|
693
|
+
}),
|
|
694
|
+
],
|
|
695
|
+
}),
|
|
696
|
+
],
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* 可见性切换独立确认弹窗(1.5.4 改版:行内确认条 → 独立面板弹出)。
|
|
702
|
+
* 复用 browse modal 的 fixed mask/dialog 风格;确认才调后端,取消/点遮罩关闭。
|
|
703
|
+
*/
|
|
704
|
+
function dshgp_VisConfirmDialog(props) {
|
|
705
|
+
const p = props.p || {};
|
|
706
|
+
const fullName = p.fullName || '';
|
|
707
|
+
const target = p.target === 'public' ? '公开' : (p.target === 'private' ? '私有' : '');
|
|
708
|
+
const cur = p.cur === 'public' ? '公开' : (p.cur === 'private' ? '私有' : '');
|
|
709
|
+
const busy = props.busy === true;
|
|
710
|
+
return jsx.jsxs('div', {
|
|
711
|
+
className: 'dshgp_browsemask',
|
|
712
|
+
children: [
|
|
713
|
+
jsx.jsxs('div', {
|
|
714
|
+
className: 'dshgp_browsedialog',
|
|
715
|
+
children: [
|
|
716
|
+
jsx.jsxs('div', { className: 'dshgp_browsehead', children: [
|
|
717
|
+
jsx.jsx('span', { className: 'dshgp_browsetitle', children: '切换仓库可见性' }),
|
|
718
|
+
jsx.jsx('button', { type: 'button', className: 'dshgp_browseclose', disabled: busy, onClick: props.onCancel, children: '✕' }),
|
|
719
|
+
] }),
|
|
720
|
+
jsx.jsx('p', { className: 'dshgp_previewtitle', children: '确认将 ' + fullName + ' 从「' + cur + '」改为「' + target + '」?' }),
|
|
721
|
+
p.target === 'public'
|
|
722
|
+
? jsx.jsx('p', { className: 'dshgp_viswarn', children: '⚠ 公开后仓库对全网可见,若含 token/密钥/隐私将直接暴露——先确认无敏感信息。' })
|
|
723
|
+
: jsx.jsx('p', { className: 'dshgp_repohint', children: '改为私有后,仅你(及已授予的协作者)可访问。' }),
|
|
724
|
+
jsx.jsxs('div', { className: 'dshgp_previewbtns', children: [
|
|
725
|
+
jsx.jsx('button', { className: 'dshgp_btn', disabled: busy, onClick: props.onConfirm, children: busy ? '切换中…' : '确认切换' }),
|
|
726
|
+
jsx.jsx('button', { className: 'dshgp_btn dshgp_btnghost', disabled: busy, onClick: props.onCancel, children: '取消' }),
|
|
727
|
+
] }),
|
|
728
|
+
],
|
|
729
|
+
}),
|
|
730
|
+
],
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/** 云端面板:账号名下所有 GitHub 仓库(token 拉取),clone 时弹目录选择器选目标目录。 */
|
|
735
|
+
function dshgp_RepoCloudPane(props) {
|
|
736
|
+
const s = props.state;
|
|
737
|
+
const rows = (s.cloudRepos || []).map((r) => jsx.jsx(dshgp_RepoCloudRow, { key: r.fullName, repo: r, state: s, onClone: props.cloneFlow, requestVisSwitch: props.requestVisSwitch })); // bugfix:传参名写错(visSwitch→requestVisSwitch),父 props 无 visSwitch,按钮点击 = undefined() 没反应
|
|
738
|
+
return jsx.jsxs('div', {
|
|
739
|
+
className: 'dshgp_repanepane',
|
|
740
|
+
children: [
|
|
741
|
+
jsx.jsxs('div', {
|
|
742
|
+
className: 'dshgp_repobar',
|
|
743
|
+
children: [
|
|
744
|
+
jsx.jsx('span', { className: 'dshgp_repohint', children: '账号名下仓库(按最近更新)' }),
|
|
745
|
+
jsx.jsx('button', {
|
|
746
|
+
type: 'button',
|
|
747
|
+
className: 'dshgp_keybtn',
|
|
748
|
+
disabled: s.cloudLoading,
|
|
749
|
+
onClick: () => props.loadCloudRepos(),
|
|
750
|
+
children: s.cloudLoading ? '加载中…' : '加载仓库列表',
|
|
751
|
+
}),
|
|
752
|
+
],
|
|
753
|
+
}),
|
|
754
|
+
jsx.jsx('p', { className: 'dshgp_repomsg', children: s.cloudMsg || '点仓库行的 clone,弹出目录选择器选定目标目录后克隆' }),
|
|
755
|
+
// clone 相关设置:跟随 clone 入口(属账号/云端职责)。不放进「审计」选项卡——
|
|
756
|
+
// 那里只保留 maxScanFiles 一项可配(该不变量由 test-sidebar-state 守住)。
|
|
757
|
+
jsx.jsxs('div', { className: 'dshgp_clonecfg', children: [
|
|
758
|
+
jsx.jsxs('label', { className: 'dshgp_label', htmlFor: 'dshgp-maxclone', children: [
|
|
759
|
+
'单文件上限(MB)',
|
|
760
|
+
jsx.jsx('input', { id: 'dshgp-maxclone', type: 'number', min: 0, className: 'dshgp_input dshgp_inputsm', value: s.maxCloneFileMB, onChange: (ev) => props.setAdvanced('maxCloneFileMB', ev.target.value) }),
|
|
761
|
+
] }),
|
|
762
|
+
jsx.jsxs('label', { className: 'dshgp_label', htmlFor: 'dshgp-cloneconc', children: [
|
|
763
|
+
'并发数',
|
|
764
|
+
jsx.jsx('input', { id: 'dshgp-cloneconc', type: 'number', min: 1, max: 16, className: 'dshgp_input dshgp_inputsm', value: s.cloneConcurrency, onChange: (ev) => props.setAdvanced('cloneConcurrency', ev.target.value) }),
|
|
765
|
+
] }),
|
|
766
|
+
] }),
|
|
767
|
+
// clone 进度条:上百 MB 的仓库下载要几分钟,没有进度会被当成卡死。
|
|
768
|
+
// 百分比按字节算(大文件占绝对多数耗时),并显示停滞时长。
|
|
769
|
+
s.cloneProgress ? dshgp_CloneProgress({ p: s.cloneProgress }) : null,
|
|
770
|
+
// clone 预览:先告知「会下载什么、会跳过什么」,确认再开始
|
|
771
|
+
// 修:原先这里用 this.cloneConfirmed / this.publish,但本组件是普通函数
|
|
772
|
+
// `dshgp_RepoCloudPane(props)`,函数体内**没有 this**(全文件仅本行误用),
|
|
773
|
+
// ESM 严格模式下 this 为 undefined → 点击直接抛 TypeError → 按钮「点了没反应」。
|
|
774
|
+
// 动作一律走 props(与同文件其余按钮一致)。
|
|
775
|
+
s.clonePreview ? dshgp_ClonePreview({ p: s.clonePreview, history: s.cloneHistory, onHistoryToggle: (v) => { props.setCloneHistory(v); }, onRestart: () => { void props.cloneConfirmed(true); }, onConfirm: () => { void props.cloneConfirmed(); }, onCancel: () => { props.cancelPreview(); } }) : null,
|
|
776
|
+
// 1.5.4 可见性切换独立确认面板(fixed mask + dialog):确认才调后端
|
|
777
|
+
s.visConfirm ? dshgp_VisConfirmDialog({
|
|
778
|
+
p: s.visConfirm,
|
|
779
|
+
busy: s.repoBusy === dshgp_BUSY_VIS + s.visConfirm.fullName,
|
|
780
|
+
onConfirm: () => { void props.confirmVisSwitch(); },
|
|
781
|
+
onCancel: () => { props.cancelVisSwitch(); },
|
|
782
|
+
}) : null,
|
|
783
|
+
rows.length ? jsx.jsxs('div', { className: 'dshgp_replist', children: rows }) : null,
|
|
784
|
+
],
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/* ─────────────── clone 进度条 / 预览确认(大仓库人机交互) ─────────────── */
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* clone 进度条。
|
|
792
|
+
*
|
|
793
|
+
* 上百 MB 的仓库要下几分钟,而前端 fetch 曾固定 30s 超时(用户实测 signal timed out)。
|
|
794
|
+
* 现在由后端记录进度、前端轮询显示;**判失败不靠绝对超时,而看进度是否停滞**——
|
|
795
|
+
* 单个 30MB 文件传得慢但进度在涨,不该被判死。
|
|
796
|
+
*/
|
|
797
|
+
function dshgp_CloneProgress(props) {
|
|
798
|
+
const p = props.p || {};
|
|
799
|
+
const mb = (n) => (n / 1024 / 1024).toFixed(1);
|
|
800
|
+
// 停滞超过 45s 才提示「可能卡住」;只提示,不自动中断(交给用户决定)
|
|
801
|
+
const stalled = (p.stalledMs || 0) > 45_000;
|
|
802
|
+
const phaseText = p.phase === 'done' ? '收尾中' : '下载中';
|
|
803
|
+
return jsx.jsxs('div', { className: 'dshgp_cloneprog', children: [
|
|
804
|
+
jsx.jsxs('div', { className: 'dshgp_cloneproghead', children: [
|
|
805
|
+
jsx.jsx('span', { children: phaseText + ' ' + (p.done || 0) + '/' + (p.totalFiles || 0) + ' 个文件' }),
|
|
806
|
+
jsx.jsx('span', { children: mb(p.transferred || 0) + ' / ' + mb(p.totalBytes || 0) + ' MB(' + (p.percent || 0) + '%)' }),
|
|
807
|
+
] }),
|
|
808
|
+
jsx.jsx('div', { className: 'dshgp_progbar', children:
|
|
809
|
+
jsx.jsx('div', { className: 'dshgp_progfill', style: { width: (p.percent || 0) + '%' } }),
|
|
810
|
+
}),
|
|
811
|
+
stalled ? jsx.jsx('p', { className: 'dshgp_cloneprogwarn', children: '⚠ 已 ' + Math.round((p.stalledMs || 0) / 1000) + ' 秒无新数据,可能网络受限(可继续等待,或取消后重试)' }) : null,
|
|
812
|
+
(p.failed || 0) > 0 ? jsx.jsx('p', { className: 'dshgp_cloneprogwarn', children: '⚠ 已有 ' + p.failed + ' 个文件下载失败' }) : null,
|
|
813
|
+
] });
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* clone 预览确认框:列出将下载 / 将跳过的文件,点「开始克隆」后才真正下载。
|
|
818
|
+
*
|
|
819
|
+
* 为什么必须先预览:体积守卫会**主动跳过**超大文件,若不提前告知,用户会以为
|
|
820
|
+
* 克隆完整,直到使用时才发现缺文件("悄悄少东西"最难排查)。
|
|
821
|
+
*/
|
|
822
|
+
function dshgp_ClonePreview(props) {
|
|
823
|
+
const p = props.p || {};
|
|
824
|
+
const mb = (n) => (n / 1024 / 1024).toFixed(1);
|
|
825
|
+
const skipped = p.skipped || [];
|
|
826
|
+
return jsx.jsxs('div', { className: 'dshgp_clonepreview', children: [
|
|
827
|
+
jsx.jsx('p', { className: 'dshgp_previewtitle', children: '将克隆 ' + p.repo + '(分支 ' + p.branch + ')' }),
|
|
828
|
+
jsx.jsxs('ul', { className: 'dshgp_previewlist', children: [
|
|
829
|
+
jsx.jsx('li', { children: '下载 ' + p.downloadCount + ' 个文件,约 ' + mb(p.downloadBytes) + ' MB' }),
|
|
830
|
+
p.skippedCount > 0
|
|
831
|
+
? jsx.jsx('li', { className: 'dshgp_previewskip', children: '跳过 ' + p.skippedCount + ' 个文件(单个超过 ' + p.maxFileMB + ' MB),约 ' + mb(p.skippedBytes) + ' MB' })
|
|
832
|
+
: null,
|
|
833
|
+
] }),
|
|
834
|
+
// 跳过清单如实列出:让用户自行判断这些文件是否真的不需要
|
|
835
|
+
skipped.length ? jsx.jsxs('div', { className: 'dshgp_previewskipbox', children: [
|
|
836
|
+
jsx.jsx('p', { children: '以下文件不会下载(可在设置里调大「单文件上限」):' }),
|
|
837
|
+
jsx.jsx('ul', { children: skipped.slice(0, 8).map((x) => jsx.jsx('li', { children: x.path + '(' + mb(x.size) + ' MB)' }, x.path)) }),
|
|
838
|
+
skipped.length > 8 ? jsx.jsx('p', { children: '…等共 ' + skipped.length + ' 个' }) : null,
|
|
839
|
+
] }) : null,
|
|
840
|
+
// 全被跳过时强提示:否则用户会得到一个空目录
|
|
841
|
+
p.empty ? jsx.jsx('p', { className: 'dshgp_cloneprogwarn', children: '⚠ 所有文件都超过上限,将得到一个空仓库。请先调大「单文件上限」或设为 0 关闭限制' }) : null,
|
|
842
|
+
// 真实历史模式(可选,默认不勾):勾选后由后端用 git fetch 取回**原始对象**,
|
|
843
|
+
// 克隆结果与远端 HEAD 逐字节一致(可推回远端、可 git log 读演进);
|
|
844
|
+
// 不勾则走整树快照(与远端无祖先、不能推回)。两种模式的差别对用户是可见后果,故明写在选项上。
|
|
845
|
+
// 回调做存在性保护:父组件尚未接线时勾选不会抛错(避免半接线状态炸掉整个预览框)。
|
|
846
|
+
jsx.jsxs('label', { className: 'dshgp_previewopt', children: [
|
|
847
|
+
jsx.jsx('input', {
|
|
848
|
+
type: 'checkbox',
|
|
849
|
+
// 与后端默认保持一致:**不勾也带历史**(后端默认开)。显式取消勾选才会退回整树快照。
|
|
850
|
+
// 这样即使父组件尚未接线,界面语义也与真实行为一致(不会出现「看着没勾、其实带历史」)。
|
|
851
|
+
checked: props.history !== false,
|
|
852
|
+
onChange: (e) => { if (typeof props.onHistoryToggle === 'function') props.onHistoryToggle(!!e.target.checked); },
|
|
853
|
+
}),
|
|
854
|
+
jsx.jsx('span', { children: '带真实历史(可推回远端;文件按提交逐个下载,较慢)' }),
|
|
855
|
+
] }),
|
|
856
|
+
// 目标目录已存在且不完整时,明确告知「默认续传」并给出「重来」
|
|
857
|
+
// (重来 = 只清 .dsh-parts 分片、不动已下文件与用户内容;后端 restart 语义已验证)
|
|
858
|
+
p.partial ? jsx.jsx('p', { className: 'dshgp_previewpartial', children: '检测到上次未完成的克隆(已下载的文件保留)——默认可直接续传;若要丢弃断点重下,点「重来」。' }) : null,
|
|
859
|
+
jsx.jsxs('div', { className: 'dshgp_previewbtns', children: [
|
|
860
|
+
jsx.jsx('button', { className: 'dshgp_btn', onClick: props.onConfirm, children: '开始克隆' }),
|
|
861
|
+
p.partial ? jsx.jsx('button', { className: 'dshgp_btn dshgp_btnghost', onClick: () => { if (typeof props.onRestart === 'function') props.onRestart(); }, children: '重来' }) : null,
|
|
862
|
+
jsx.jsx('button', { className: 'dshgp_btn dshgp_btnghost', onClick: props.onCancel, children: '取消' }),
|
|
863
|
+
] }),
|
|
864
|
+
] });
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/* ─────────────────── [6续] NPM 面板(账号卡 + 装包表单 + 已装列表 + npm 凭据字段) ───────────────────
|
|
868
|
+
* 设计取舍:完全自包含(自己 useState/useEffect + 直接走 HTTP),不碰 40-controller(884 行)与 41-actions,
|
|
869
|
+
* 把 Step 4 的改动面压到最小;数据源:/npm-account、/npm-packages、/npm-install、/settings-set、/status。
|
|
870
|
+
* 安全默认与后端一致:`ignore-scripts` 默认勾选(不执行 postinstall)、默认非全局、**安装需二次确认**。
|
|
871
|
+
* 复用既有 CSS 类(dshgp_block/field/label/input/hint/btn/suptab),不新增样式。
|
|
872
|
+
*/
|
|
873
|
+
|
|
874
|
+
/** npm 账号卡(与 GitHub 账号卡**同款**:渐变面板 + 图标块 + 状态徽标 + 勾选明细块 + 底部操作)。 */
|
|
875
|
+
function dshgp_NpmAccountCard(props) {
|
|
876
|
+
const a = props.acct || {};
|
|
877
|
+
const busy = !!props.busy;
|
|
878
|
+
const okState = !!(a.configured && a.loggedIn);
|
|
879
|
+
// 三态与 GitHub 卡同规格:已连接(ok)/ 读取中或凭据未过校验(warn)/ 未配置(err)
|
|
880
|
+
const statCls = okState ? 'dshgp_acctstat_ok' : (busy || a.configured ? 'dshgp_acctstat_warn' : 'dshgp_acctstat_err');
|
|
881
|
+
const statTxt = okState ? '已连接' : (busy ? '读取中' : (a.configured ? '校验未过' : '未配置'));
|
|
882
|
+
const blockCls = okState ? 'dshgp_acctblock2_ok' : (busy ? 'dshgp_acctblock2_loading' : 'dshgp_acctblock2_err');
|
|
883
|
+
// 明细逐行给出(成功 ✅ / 缺配置或失败 ⚠️),与 GitHub 卡那几行 ✅ 同一形态
|
|
884
|
+
const blockBody = busy
|
|
885
|
+
? '正在读取 npm 登录态…'
|
|
886
|
+
: (okState
|
|
887
|
+
? `✅ 凭据可用\n✅ npm token:${a.user}|registry ${a.registry || ''}\n✅ 登录态:npm whoami 通过${a.maskedToken ? `(${a.maskedToken})` : ''}`
|
|
888
|
+
: (a.configured
|
|
889
|
+
? `⚠️ npm token 已配置但校验未通过\n⚠️ registry:${a.registry || ''}\n⚠️ 原因:${a.error || '未知'}`
|
|
890
|
+
: `⚠️ 未配置 npm token\n⚠️ registry:${a.registry || ''}\n⚠️ 到「设置 → 凭据与密钥」填写 npm token 后可显示登录态`));
|
|
891
|
+
return jsx.jsxs('div', {
|
|
892
|
+
className: 'dshgp_acctpanel',
|
|
893
|
+
children: [
|
|
894
|
+
jsx.jsxs('div', {
|
|
895
|
+
className: 'dshgp_accthead',
|
|
896
|
+
children: [
|
|
897
|
+
// 图标块复用同一套 .dshgp_acctic(npm 官方 logo 就是 npm 字样,故用文字形式落进图标块)
|
|
898
|
+
jsx.jsx('div', {
|
|
899
|
+
className: 'dshgp_acctic',
|
|
900
|
+
children: jsx.jsx('span', { style: { fontSize: '13px', fontWeight: 700, letterSpacing: '-.5px' }, children: 'npm' }),
|
|
901
|
+
}),
|
|
902
|
+
jsx.jsxs('div', {
|
|
903
|
+
children: [
|
|
904
|
+
jsx.jsx('p', { className: 'dshgp_accttitle', children: 'NPM 账号' }),
|
|
905
|
+
jsx.jsx('p', { className: 'dshgp_acctsub', children: 'Token / registry 检测结果 · 保存后点刷新' }),
|
|
906
|
+
],
|
|
907
|
+
}),
|
|
908
|
+
jsx.jsxs('span', { className: 'dshgp_acctstat ' + statCls, children: [jsx.jsx('span', { className: 'dshgp_acctdot' }), statTxt] }),
|
|
909
|
+
],
|
|
910
|
+
}),
|
|
911
|
+
jsx.jsx('pre', { className: 'dshgp_acctblock2 ' + blockCls, children: blockBody }),
|
|
912
|
+
jsx.jsxs('div', {
|
|
913
|
+
className: 'dshgp_acctfoot',
|
|
914
|
+
children: [
|
|
915
|
+
jsx.jsx('button', {
|
|
916
|
+
type: 'button', className: 'dshgp_keybtn', disabled: busy,
|
|
917
|
+
onClick: props.onRefresh, children: [dshgp_refreshIcon, busy ? '读取中…' : '刷新'],
|
|
918
|
+
}),
|
|
919
|
+
jsx.jsx('span', { className: 'dshgp_accthint', children: okState ? '凭据有效,可用于安装与发布' : '凭据只存本机配置目录(0600),不回传明文' }),
|
|
920
|
+
],
|
|
921
|
+
}),
|
|
922
|
+
],
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/** 装包表单:包名 + 目标目录 + 全局/脚本开关 + 二次确认 + 回执。 */
|
|
927
|
+
function dshgp_NpmInstallForm(props) {
|
|
928
|
+
const st = props.st;
|
|
929
|
+
return jsx.jsxs('div', {
|
|
930
|
+
className: 'dshgp_block',
|
|
931
|
+
children: [
|
|
932
|
+
jsx.jsx('p', { className: 'dshgp_h2', style: { margin: 0 }, children: '安装包' }),
|
|
933
|
+
jsx.jsx('div', {
|
|
934
|
+
className: 'dshgp_field',
|
|
935
|
+
children: [
|
|
936
|
+
jsx.jsx('label', { className: 'dshgp_label', htmlFor: 'dshgp-npm-names', children: '包名(多个用空格或逗号分隔;支持 @scope/name@版本)' }),
|
|
937
|
+
jsx.jsx('input', {
|
|
938
|
+
id: 'dshgp-npm-names', type: 'text', autoComplete: 'off', spellCheck: false, className: 'dshgp_input',
|
|
939
|
+
placeholder: '如 left-pad 或 @scope/pkg@1.2.3', value: st.names, disabled: st.busy,
|
|
940
|
+
onChange: (ev) => st.setNames(ev.target.value),
|
|
941
|
+
}),
|
|
942
|
+
],
|
|
943
|
+
}),
|
|
944
|
+
jsx.jsx('div', {
|
|
945
|
+
className: 'dshgp_field',
|
|
946
|
+
children: [
|
|
947
|
+
jsx.jsx('label', { className: 'dshgp_label', htmlFor: 'dshgp-npm-dir', children: '安装到目录(全局安装时忽略)' }),
|
|
948
|
+
jsx.jsx('input', {
|
|
949
|
+
id: 'dshgp-npm-dir', type: 'text', autoComplete: 'off', spellCheck: false, className: 'dshgp_input',
|
|
950
|
+
placeholder: '默认:当前工作区', value: st.dir, disabled: st.busy,
|
|
951
|
+
onChange: (ev) => st.setDir(ev.target.value),
|
|
952
|
+
}),
|
|
953
|
+
],
|
|
954
|
+
}),
|
|
955
|
+
jsx.jsxs('div', {
|
|
956
|
+
className: 'dshgp_field',
|
|
957
|
+
style: { display: 'flex', gap: '16px', alignItems: 'center', flexWrap: 'wrap' },
|
|
958
|
+
children: [
|
|
959
|
+
jsx.jsxs('label', { className: 'dshgp_label', style: { display: 'flex', gap: '6px', alignItems: 'center' }, children: [
|
|
960
|
+
jsx.jsx('input', { type: 'checkbox', checked: st.global, disabled: st.busy, onChange: (ev) => st.setGlobal(ev.target.checked) }),
|
|
961
|
+
jsx.jsx('span', { children: '全局安装(-g,会影响宿主 node 环境)' }),
|
|
962
|
+
] }),
|
|
963
|
+
jsx.jsxs('label', { className: 'dshgp_label', style: { display: 'flex', gap: '6px', alignItems: 'center' }, children: [
|
|
964
|
+
jsx.jsx('input', { type: 'checkbox', checked: st.ignoreScripts, disabled: st.busy, onChange: (ev) => st.setIgnoreScripts(ev.target.checked) }),
|
|
965
|
+
jsx.jsx('span', { children: '不执行安装脚本(--ignore-scripts,推荐)' }),
|
|
966
|
+
] }),
|
|
967
|
+
],
|
|
968
|
+
}),
|
|
969
|
+
jsx.jsxs('div', { style: { display: 'flex', gap: '8px', alignItems: 'center', marginTop: '6px' }, children: [
|
|
970
|
+
jsx.jsx('button', {
|
|
971
|
+
type: 'button', className: 'dshgp_btn', disabled: st.busy || !st.names.trim(),
|
|
972
|
+
onClick: () => st.setConfirming(true), children: st.busy ? '安装中…' : '安装',
|
|
973
|
+
}),
|
|
974
|
+
st.confirming ? jsx.jsx('button', {
|
|
975
|
+
type: 'button', className: 'dshgp_btn', disabled: st.busy, onClick: st.doInstall, children: '确认安装(二次确认)',
|
|
976
|
+
}) : null,
|
|
977
|
+
st.confirming ? jsx.jsx('button', { type: 'button', className: 'dshgp_btn', disabled: st.busy, onClick: () => st.setConfirming(false), children: '取消' }) : null,
|
|
978
|
+
] }),
|
|
979
|
+
st.confirming ? jsx.jsx('p', { className: 'dshgp_hint', children: '即将执行 npm install' + (st.global ? '(全局)' : '') + ';装包会写入目标目录并在默认关闭脚本的前提下不执行 postinstall。确认后不可撤销。' }) : null,
|
|
980
|
+
st.result ? jsx.jsxs('div', {
|
|
981
|
+
className: 'dshgp_field',
|
|
982
|
+
children: [
|
|
983
|
+
jsx.jsx('label', { className: 'dshgp_label', children: st.result.ok ? '安装成功' : '安装失败' }),
|
|
984
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: (st.result.ok ? '' : (st.result.error || '') + ' ') + (st.result.logPath ? '日志:' + st.result.logPath : '') }),
|
|
985
|
+
st.result.stdout ? jsx.jsx('pre', { className: 'dshgp_hint', style: { whiteSpace: 'pre-wrap', maxHeight: '160px', overflow: 'auto' }, children: st.result.stdout }) : null,
|
|
986
|
+
],
|
|
987
|
+
}) : null,
|
|
988
|
+
],
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
/** NPM 子页:登录账号名下的包列表(与 GitHub 云端仓库列表**同款行**)+ 手动安装框。 */
|
|
993
|
+
function dshgp_NpmPanel(props) {
|
|
994
|
+
const s = (props && props.state) || {};
|
|
995
|
+
const [acct, setAcct] = react.useState(null);
|
|
996
|
+
const [pkgs, setPkgs] = react.useState(null);
|
|
997
|
+
const [dir, setDir] = react.useState('');
|
|
998
|
+
const [names, setNames] = react.useState('');
|
|
999
|
+
const [global, setGlobal] = react.useState(false);
|
|
1000
|
+
const [ignoreScripts, setIgnoreScripts] = react.useState(true);
|
|
1001
|
+
const [confirming, setConfirming] = react.useState(false);
|
|
1002
|
+
const [busy, setBusy] = react.useState(false);
|
|
1003
|
+
const [result, setResult] = react.useState(null);
|
|
1004
|
+
const [err, setErr] = react.useState('');
|
|
1005
|
+
|
|
1006
|
+
/** 读账号态 + 已装依赖;d 为空时沿用当前目录(服务端默认工作区)。 */
|
|
1007
|
+
const load = react.useCallback(async (d) => {
|
|
1008
|
+
setBusy(true);
|
|
1009
|
+
try {
|
|
1010
|
+
const a = await dshgp_getJson('/api/git-push/npm-account');
|
|
1011
|
+
const p = await dshgp_getJson('/api/git-push/npm-packages' + (d ? '?dir=' + encodeURIComponent(d) : ''));
|
|
1012
|
+
setAcct(a || null);
|
|
1013
|
+
setPkgs(p || null);
|
|
1014
|
+
if (p && p.dir) setDir(p.dir);
|
|
1015
|
+
setErr('');
|
|
1016
|
+
} catch (e) {
|
|
1017
|
+
setErr(String((e && e.message) || e));
|
|
1018
|
+
} finally {
|
|
1019
|
+
setBusy(false);
|
|
1020
|
+
}
|
|
1021
|
+
}, []);
|
|
1022
|
+
// 只在挂载时读一次(与既有 tab 的读取时机约定一致:不在每次切 tab 时重复触发)
|
|
1023
|
+
react.useEffect(() => { load(''); }, [load]);
|
|
1024
|
+
|
|
1025
|
+
const doInstall = async () => {
|
|
1026
|
+
setBusy(true);
|
|
1027
|
+
setResult(null);
|
|
1028
|
+
try {
|
|
1029
|
+
const body = { names: names.split(/[\s,]+/).filter(Boolean), confirm: true, global, ignoreScripts };
|
|
1030
|
+
if (!global && dir.trim()) body.dest = dir.trim();
|
|
1031
|
+
// 超时给 320s(服务端安装默认 300s),避免前端先断
|
|
1032
|
+
const r = await dshgp_postJson('/api/git-push/npm-install', body, 320000);
|
|
1033
|
+
setResult(r || null);
|
|
1034
|
+
setConfirming(false);
|
|
1035
|
+
await load(dir.trim());
|
|
1036
|
+
} catch (e) {
|
|
1037
|
+
setResult({ ok: false, error: String((e && e.message) || e) });
|
|
1038
|
+
} finally {
|
|
1039
|
+
setBusy(false);
|
|
1040
|
+
}
|
|
1041
|
+
};
|
|
1042
|
+
|
|
1043
|
+
const st = {
|
|
1044
|
+
names, setNames, dir, setDir, global, setGlobal, ignoreScripts, setIgnoreScripts,
|
|
1045
|
+
confirming, setConfirming, busy, result, doInstall,
|
|
1046
|
+
};
|
|
1047
|
+
const deps = (pkgs && Array.isArray(pkgs.dependencies)) ? pkgs.dependencies : [];
|
|
1048
|
+
return jsx.jsxs('div', {
|
|
1049
|
+
className: 'dshgp_section',
|
|
1050
|
+
children: [
|
|
1051
|
+
// 账号卡已上移到顶部账号区(与 GitHub 卡**同位置、滑动切换**)⇒ 这里不再重复渲染
|
|
1052
|
+
// 说明:原先自创的「安装包」表单(包名输入 + 目录输入 + 两个复选框)已按用户要求**停用**——
|
|
1053
|
+
// 改为照 GitHub 的四段交互:行内「安装」→ 选择目录 / 全局安装 → 进度轮询 → 回执。
|
|
1054
|
+
// 组件 dshgp_NpmInstallForm 的源码暂留备查,不再渲染(comment-not-delete:只停用不删代码)。
|
|
1055
|
+
jsx.jsxs('div', {
|
|
1056
|
+
className: 'dshgp_block',
|
|
1057
|
+
children: [
|
|
1058
|
+
jsx.jsx('p', { className: 'dshgp_h2', style: { margin: 0 }, children: '已装依赖(' + (pkgs && pkgs.name ? pkgs.name : '当前目录') + ')' }),
|
|
1059
|
+
pkgs && pkgs.hasPackageJson === false
|
|
1060
|
+
? jsx.jsx('p', { className: 'dshgp_hint', children: '该目录没有 package.json —— 安装会在目录下新建依赖树(建议先初始化)。' })
|
|
1061
|
+
: null,
|
|
1062
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: 'node_modules:' + (pkgs && pkgs.nodeModules ? '已存在' : '不存在') + ' · 依赖 ' + deps.length + ' 个' }),
|
|
1063
|
+
deps.length
|
|
1064
|
+
? jsx.jsx('div', { className: 'dshgp_field', children: deps.map((d) => jsx.jsx('div', { key: d.name, className: 'dshgp_hint', children: d.name + ' ' + d.range })) })
|
|
1065
|
+
: jsx.jsx('p', { className: 'dshgp_hint', children: '(无已装依赖)' }),
|
|
1066
|
+
],
|
|
1067
|
+
}),
|
|
1068
|
+
jsx.jsxs('div', {
|
|
1069
|
+
className: 'dshgp_block',
|
|
1070
|
+
children: [
|
|
1071
|
+
jsx.jsxs('div', {
|
|
1072
|
+
style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px', marginBottom: '8px' },
|
|
1073
|
+
children: [
|
|
1074
|
+
jsx.jsx('p', { className: 'dshgp_h2', style: { margin: 0 }, children: '我的包(' + (s.npmAccountUser || '未登录') + ')' }),
|
|
1075
|
+
jsx.jsx('button', { type: 'button', className: 'dshgp_keybtn', disabled: !!s.npmOwnedLoading, onClick: () => props.refreshNpmOwned(), children: s.npmOwnedLoading ? '读取中…' : '刷新列表' }),
|
|
1076
|
+
],
|
|
1077
|
+
}),
|
|
1078
|
+
(Array.isArray(s.npmOwned) && s.npmOwned.length)
|
|
1079
|
+
? jsx.jsx('div', {
|
|
1080
|
+
children: s.npmOwned.map((p) => jsx.jsxs('div', {
|
|
1081
|
+
className: 'dshgp_reprow',
|
|
1082
|
+
children: [
|
|
1083
|
+
jsx.jsxs('div', {
|
|
1084
|
+
className: 'dshgp_reprowinfo',
|
|
1085
|
+
children: [
|
|
1086
|
+
jsx.jsx('span', { className: 'dshgp_reprowpath', children: p.name }),
|
|
1087
|
+
jsx.jsx('span', { className: 'dshgp_reprowmeta', children: 'v' + (p.version || '?') + (p.date ? ' · ' + String(p.date).slice(0, 10) : '') }),
|
|
1088
|
+
],
|
|
1089
|
+
}),
|
|
1090
|
+
jsx.jsxs('div', {
|
|
1091
|
+
className: 'dshgp_pushcol',
|
|
1092
|
+
children: [
|
|
1093
|
+
jsx.jsx('button', {
|
|
1094
|
+
type: 'button', className: 'dshgp_keybtn',
|
|
1095
|
+
disabled: !!s.npmInstallBusy,
|
|
1096
|
+
onClick: () => props.openInstallFlow(p.name),
|
|
1097
|
+
children: s.npmInstallBusy === p.name ? '安装中…' : '安装',
|
|
1098
|
+
}),
|
|
1099
|
+
],
|
|
1100
|
+
}),
|
|
1101
|
+
],
|
|
1102
|
+
})),
|
|
1103
|
+
})
|
|
1104
|
+
: jsx.jsx('p', { className: 'dshgp_hint', children: s.npmOwnedError || '(没有取到包:先在上方账号卡点「刷新」完成登录校验)' }),
|
|
1105
|
+
],
|
|
1106
|
+
}),
|
|
1107
|
+
// 选择段(照抄 GitHub 可见性切换的遮罩对话框):选择目录 / 全局安装 / 取消
|
|
1108
|
+
s.npmInstallDialog ? jsx.jsx('div', {
|
|
1109
|
+
className: 'dshgp_browsemask',
|
|
1110
|
+
children: [jsx.jsxs('div', {
|
|
1111
|
+
className: 'dshgp_browsedialog',
|
|
1112
|
+
children: [
|
|
1113
|
+
jsx.jsx('div', { className: 'dshgp_browsehead', children: jsx.jsx('span', { className: 'dshgp_browsetitle', children: '安装 ' + (s.npmInstallDialog.name || '') }) }),
|
|
1114
|
+
jsx.jsxs('div', {
|
|
1115
|
+
className: 'dshgp_field',
|
|
1116
|
+
children: [
|
|
1117
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: '选择安装位置:装到某个目录(弹目录选择器),或全局安装(-g,会影响宿主 node 环境)。默认不执行安装脚本(--ignore-scripts)。' }),
|
|
1118
|
+
jsx.jsxs('div', {
|
|
1119
|
+
style: { display: 'flex', gap: '8px', flexWrap: 'wrap', marginTop: '6px' },
|
|
1120
|
+
children: [
|
|
1121
|
+
jsx.jsx('button', { type: 'button', className: 'dshgp_keybtn', onClick: () => props.chooseInstallDir(), children: '选择目录…' }),
|
|
1122
|
+
jsx.jsx('button', { type: 'button', className: 'dshgp_keybtn', onClick: () => props.confirmInstallGlobal(), children: '全局安装' }),
|
|
1123
|
+
jsx.jsx('button', { type: 'button', className: 'dshgp_keybtn', onClick: () => props.cancelInstallDialog(), children: '取消' }),
|
|
1124
|
+
],
|
|
1125
|
+
}),
|
|
1126
|
+
],
|
|
1127
|
+
}),
|
|
1128
|
+
],
|
|
1129
|
+
})],
|
|
1130
|
+
}) : null,
|
|
1131
|
+
// 进度段(照抄 clone 进度框样式):运行中实时显示 npm 输出尾部
|
|
1132
|
+
(s.npmInstallProgress && s.npmInstallProgress.state) ? jsx.jsxs('div', {
|
|
1133
|
+
className: 'dshgp_cloneprog',
|
|
1134
|
+
children: [
|
|
1135
|
+
jsx.jsxs('div', {
|
|
1136
|
+
className: 'dshgp_cloneproghead',
|
|
1137
|
+
children: [
|
|
1138
|
+
jsx.jsx('span', { children: '安装 ' + (s.npmInstallProgress.name || '') + ' · ' + s.npmInstallProgress.state }),
|
|
1139
|
+
jsx.jsx('span', { children: Math.round((s.npmInstallProgress.elapsedMs || 0) / 1000) + 's' }),
|
|
1140
|
+
],
|
|
1141
|
+
}),
|
|
1142
|
+
jsx.jsx('pre', {
|
|
1143
|
+
className: 'dshgp_hint',
|
|
1144
|
+
style: { whiteSpace: 'pre-wrap', maxHeight: '160px', overflow: 'auto' },
|
|
1145
|
+
children: (s.npmInstallProgress.lines || []).slice(-12).join('\n') || '(等待 npm 输出…)',
|
|
1146
|
+
}),
|
|
1147
|
+
],
|
|
1148
|
+
}) : null,
|
|
1149
|
+
err ? jsx.jsx('p', { className: 'dshgp_hint', children: '读取失败:' + err }) : null,
|
|
1150
|
+
],
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
/**
|
|
1155
|
+
* 顶部账号区:**GitHub 账号 ↔ NPM 账号 滑动切换**(同位置、同款卡片、同一套「离线读 + 在线校验」语义)。
|
|
1156
|
+
* 两个卡片都不感知数据来源:GitHub 卡读 props.state.account*,NPM 卡读 props.state.npmAccount*(映射后传入)。
|
|
1157
|
+
*/
|
|
1158
|
+
function dshgp_AccountSwitcher(props) {
|
|
1159
|
+
const s = props.state || {};
|
|
1160
|
+
const [which, setWhich] = react.useState('github');
|
|
1161
|
+
const seg = [{ id: 'github', label: 'GitHub' }, { id: 'npm', label: 'NPM' }];
|
|
1162
|
+
const block = String(s.npmAccountBlock || '');
|
|
1163
|
+
const npmAcct = {
|
|
1164
|
+
// 直接采用后端返回的 configured 布尔(**不再从块文案反推**:旧后端不返回 block 时会误判「未配置」)
|
|
1165
|
+
configured: !!s.npmConfigured,
|
|
1166
|
+
loggedIn: !!s.npmAccountLoggedIn,
|
|
1167
|
+
user: s.npmAccountUser || '',
|
|
1168
|
+
registry: '',
|
|
1169
|
+
maskedToken: '',
|
|
1170
|
+
block,
|
|
1171
|
+
error: '',
|
|
1172
|
+
};
|
|
1173
|
+
return jsx.jsxs('div', {
|
|
1174
|
+
children: [
|
|
1175
|
+
jsx.jsx('div', {
|
|
1176
|
+
className: 'dshgp_suptabs',
|
|
1177
|
+
children: seg.map((t) => jsx.jsxs('button', {
|
|
1178
|
+
key: t.id,
|
|
1179
|
+
type: 'button',
|
|
1180
|
+
className: which === t.id ? 'dshgp_suptab dshgp_suptabOn' : 'dshgp_suptab',
|
|
1181
|
+
onClick: () => setWhich(t.id),
|
|
1182
|
+
children: [t.label],
|
|
1183
|
+
})),
|
|
1184
|
+
}),
|
|
1185
|
+
jsx.jsx('div', {
|
|
1186
|
+
className: 'dshgp_supview',
|
|
1187
|
+
key: which,
|
|
1188
|
+
children: [
|
|
1189
|
+
which === 'github'
|
|
1190
|
+
? jsx.jsx(dshgp_AccountCard, props)
|
|
1191
|
+
: jsx.jsx(dshgp_NpmAccountCard, { acct: npmAcct, busy: !!s.npmAccountLoading, onRefresh: props.recheckNpmAccount }),
|
|
1192
|
+
],
|
|
1193
|
+
}),
|
|
1194
|
+
],
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
/** 设置页「npm token / registry」字段(自包含:直接 POST /settings-set,不依赖设置快照)。 */
|
|
1199
|
+
function dshgp_NpmCredFields() {
|
|
1200
|
+
const [token, setToken] = react.useState('');
|
|
1201
|
+
const [registry, setRegistry] = react.useState('');
|
|
1202
|
+
const [msg, setMsg] = react.useState('');
|
|
1203
|
+
const [saving, setSaving] = react.useState(false);
|
|
1204
|
+
react.useEffect(() => {
|
|
1205
|
+
dshgp_getJson('/api/git-push/status').then((s) => {
|
|
1206
|
+
const c = (s && s.config) || {};
|
|
1207
|
+
setRegistry(c.npmRegistry || '');
|
|
1208
|
+
setMsg(c.npmConfigured ? '已配置(明文不回传,可覆盖填写)' : '');
|
|
1209
|
+
}).catch(() => { /* status 读失败不阻塞设置页 */ });
|
|
1210
|
+
}, []);
|
|
1211
|
+
const save = async () => {
|
|
1212
|
+
setSaving(true);
|
|
1213
|
+
try {
|
|
1214
|
+
if (registry.trim()) await dshgp_postJson('/api/git-push/settings-set', { key: 'npmRegistry', value: registry.trim() });
|
|
1215
|
+
if (!token.trim()) {
|
|
1216
|
+
setMsg(registry.trim() ? 'registry 已保存' : '没有要保存的内容');
|
|
1217
|
+
} else {
|
|
1218
|
+
const r = await dshgp_postJson('/api/git-push/settings-set', { key: 'npmToken', value: token.trim() });
|
|
1219
|
+
if (r && r.ok === false) setMsg('保存失败:' + (r.error || '未知错误'));
|
|
1220
|
+
else { setToken(''); setMsg('npm token 已保存(明文不回传)'); }
|
|
1221
|
+
}
|
|
1222
|
+
} catch (e) {
|
|
1223
|
+
setMsg('保存失败:' + String((e && e.message) || e));
|
|
1224
|
+
} finally {
|
|
1225
|
+
setSaving(false);
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
return jsx.jsxs('div', {
|
|
1229
|
+
className: 'dshgp_field',
|
|
1230
|
+
children: [
|
|
1231
|
+
jsx.jsx('label', { className: 'dshgp_label', htmlFor: 'dshgp-npm-token', children: ['npm token', msg ? jsx.jsx('span', { className: 'dshgp_configured', children: msg }) : null] }),
|
|
1232
|
+
jsx.jsx('input', {
|
|
1233
|
+
id: 'dshgp-npm-token', type: 'text', autoComplete: 'off', spellCheck: false, className: 'dshgp_input',
|
|
1234
|
+
placeholder: 'npm_… (自建 registry 的 token 亦可)', value: token, disabled: saving,
|
|
1235
|
+
onChange: (ev) => setToken(ev.target.value),
|
|
1236
|
+
}),
|
|
1237
|
+
jsx.jsx('input', {
|
|
1238
|
+
id: 'dshgp-npm-registry', type: 'text', autoComplete: 'off', spellCheck: false, className: 'dshgp_input',
|
|
1239
|
+
placeholder: 'registry(默认 https://registry.npmjs.org/)', value: registry, disabled: saving,
|
|
1240
|
+
onChange: (ev) => setRegistry(ev.target.value),
|
|
1241
|
+
}),
|
|
1242
|
+
jsx.jsxs('div', { style: { display: 'flex', gap: '8px', alignItems: 'center', marginTop: '4px' }, children: [
|
|
1243
|
+
jsx.jsx('button', { type: 'button', className: 'dshgp_btn', disabled: saving, onClick: save, children: saving ? '保存中…' : '保存 npm 凭据' }),
|
|
1244
|
+
] }),
|
|
1245
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: 'token 与 GitHub token 存同一份 config.json(0600,原子写入互不覆盖),接口不回传明文;调用 npm 时才物化成独立 npmrc。' }),
|
|
1246
|
+
],
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
/* ─────────────────── [7] 审计 Tab(WeightRows/RuleRow/AuditSwitchBlock/InjectPromptSwitchBlock/CommentWordingBlock/AuditAdvancedBlock/RuleListBlock/AuditTab) ─────────────────── */
|
|
1251
|
+
/** 10 维度权重行(值来自 state.weightValues,改即写回 weightOverrides JSON)。 */
|
|
1252
|
+
function dshgp_WeightRows(props) {
|
|
1253
|
+
const s = props.state;
|
|
1254
|
+
const rows = dshgp_DIMENSIONS.map((d) => jsx.jsxs('div', {
|
|
1255
|
+
key: d.key,
|
|
1256
|
+
className: 'dshgp_weightrow',
|
|
1257
|
+
children: [
|
|
1258
|
+
jsx.jsx('span', { className: 'dshgp_weightkey', children: d.key }),
|
|
1259
|
+
jsx.jsx('input', {
|
|
1260
|
+
type: 'number', min: 0, max: 100,
|
|
1261
|
+
className: 'dshgp_weightinput',
|
|
1262
|
+
value: s.weightValues[d.key] != null ? s.weightValues[d.key] : d.def,
|
|
1263
|
+
onChange: (ev) => props.editWeight(d.key, Number(ev.target.value) || 0),
|
|
1264
|
+
}),
|
|
1265
|
+
jsx.jsx('span', { className: 'dshgp_rulemeta', children: '默认 ' + d.def }),
|
|
1266
|
+
],
|
|
1267
|
+
}));
|
|
1268
|
+
const total = dshgp_DIMENSIONS.reduce((a, d) => a + (s.weightValues[d.key] != null ? s.weightValues[d.key] : d.def), 0);
|
|
1269
|
+
return jsx.jsxs('div', {
|
|
1270
|
+
children: [
|
|
1271
|
+
rows,
|
|
1272
|
+
jsx.jsx('p', { className: 'dshgp_weighttotal', children: '合计 ' + total + '(建议 100;保存后下次审计生效)' }),
|
|
1273
|
+
],
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
/**
|
|
1278
|
+
* 规则包行(交互改版):
|
|
1279
|
+
* ① 详细信息改为**悬停浮层**(.dshgp_hovercard,悬停行内信息区显示描述/作者/统计口径),
|
|
1280
|
+
* 常显只留「名称 + 拦截/警告/通过」——不再占用行高、不推挤列表。
|
|
1281
|
+
* ② 启用/禁用**只由行尾的启停按钮**触发(.dshgp_powerBtn);整行不再可点击切换,
|
|
1282
|
+
* 避免想拖选/看详情时误触状态。
|
|
1283
|
+
* ③ 状态底色:启用 = 绿底 + 绿左条,禁用 = 红底 + 红左条(见 CSS .dshgp_rowOn/.dshgp_rowOff)。
|
|
1284
|
+
* 其余:↑↓ 调次序;nodejs/private 为安全红线锁定不可禁用。
|
|
1285
|
+
*/
|
|
1286
|
+
function dshgp_RuleRow(props, slot, idx, len) {
|
|
1287
|
+
const s = props.state;
|
|
1288
|
+
const meta = (s.slotMeta && s.slotMeta[slot]) || {};
|
|
1289
|
+
const name = meta.name || slot;
|
|
1290
|
+
const author = meta.author || '';
|
|
1291
|
+
const stats = (meta && meta.stats) || { blocker: 0, warning: 0, pass: 0, total: 0, source: 'rules' };
|
|
1292
|
+
// 口径统一为 yml 规则条数:三个数字是「该规则包里各严重级的规则条数」,
|
|
1293
|
+
// 不是审计命中数。此前后端在跑过审计时改显命中数,而命中数按**次数**累加、规则数是**条数**,
|
|
1294
|
+
// 同排对比会出现「245 警告 / 37 总规则」这类越界假数据;现固定为条数口径,不再分支。
|
|
1295
|
+
const countTitle = (kind) => {
|
|
1296
|
+
const n = kind === '拦截' ? stats.blocker : (kind === '警告' ? stats.warning : stats.pass);
|
|
1297
|
+
return `${name}:${kind}级规则 ${n} 条(共 ${stats.total} 条规则)`;
|
|
1298
|
+
};
|
|
1299
|
+
// 禁用态 = yml 顶层 disabled(后端 listRuleSlots 解析);点击即时反馈靠 toggleDisabled
|
|
1300
|
+
// 本地翻转 slotMeta,loadSlots 对账 yml 真实状态。
|
|
1301
|
+
const disabled = !!meta.disabled;
|
|
1302
|
+
const locked = slot === 'nodejs' || slot === 'private';
|
|
1303
|
+
const move = (dir) => props.moveSlot(slot, dir);
|
|
1304
|
+
// 悬停浮层内容:描述/作者/统计口径说明(原常显 meta 行移到这里)
|
|
1305
|
+
const hoverCard = jsx.jsxs('div', {
|
|
1306
|
+
className: 'dshgp_hovercard',
|
|
1307
|
+
children: [
|
|
1308
|
+
jsx.jsx('div', { className: 'dshgp_hoverTitle', children: name }),
|
|
1309
|
+
author ? jsx.jsx('div', { className: 'dshgp_hoverRow', children: '作者: ' + author }) : null,
|
|
1310
|
+
meta.description ? jsx.jsx('div', { className: 'dshgp_hoverRow', children: meta.description }) : null,
|
|
1311
|
+
jsx.jsx('div', {
|
|
1312
|
+
className: 'dshgp_hoverRow',
|
|
1313
|
+
children: `规则条数:拦截级 ${stats.blocker} 条 · 警告级 ${stats.warning} 条 · 提示级 ${stats.pass} 条(共 ${stats.total} 条规则)`,
|
|
1314
|
+
}),
|
|
1315
|
+
jsx.jsx('div', { className: 'dshgp_hoverRow', children: locked ? '安全红线:nodejs/private 不可禁用' : (disabled ? '当前禁用——点右侧按钮启用' : '当前启用——点右侧按钮禁用') }),
|
|
1316
|
+
],
|
|
1317
|
+
});
|
|
1318
|
+
// 启停按钮:行内唯一可切换状态的位置(整行 onClick 已移除)
|
|
1319
|
+
const powerBtn = jsx.jsx('button', {
|
|
1320
|
+
type: 'button',
|
|
1321
|
+
className: 'dshgp_powerBtn ' + (disabled ? 'dshgp_powerOff' : 'dshgp_powerOn'),
|
|
1322
|
+
disabled: locked,
|
|
1323
|
+
onClick: (ev) => { ev.stopPropagation(); props.toggleDisabled(slot); },
|
|
1324
|
+
title: locked ? 'nodejs/private 安全红线,不可禁用' : (disabled ? '点击启用该规则包' : '点击禁用该规则包'),
|
|
1325
|
+
'aria-label': (disabled ? '启用规则包 ' : '禁用规则包 ') + name,
|
|
1326
|
+
'aria-pressed': !disabled,
|
|
1327
|
+
children: disabled ? '禁用' : '启用',
|
|
1328
|
+
});
|
|
1329
|
+
return jsx.jsxs('li', {
|
|
1330
|
+
key: slot,
|
|
1331
|
+
className: 'dshgp_rulerow ' + (disabled ? 'dshgp_rowOff' : 'dshgp_rowOn'),
|
|
1332
|
+
children: [
|
|
1333
|
+
jsx.jsx('button', { type: 'button', className: 'dshgp_mini', disabled: idx === 0, onClick: (ev) => { ev.stopPropagation(); move(-1); }, 'aria-label': name + ' 上移', children: '↑' }),
|
|
1334
|
+
jsx.jsx('button', { type: 'button', className: 'dshgp_mini', disabled: idx === len - 1, onClick: (ev) => { ev.stopPropagation(); move(1); }, 'aria-label': name + ' 下移', children: '↓' }),
|
|
1335
|
+
jsx.jsxs('div', {
|
|
1336
|
+
className: 'dshgp_ruleinfo',
|
|
1337
|
+
children: [
|
|
1338
|
+
jsx.jsx('span', { className: 'dshgp_rulename', children: name }),
|
|
1339
|
+
hoverCard,
|
|
1340
|
+
],
|
|
1341
|
+
}),
|
|
1342
|
+
jsx.jsx('span', { className: 'dshgp_rulecountRed', title: countTitle('拦截'), children: String(stats.blocker) }),
|
|
1343
|
+
jsx.jsx('span', { className: 'dshgp_rulecountYellow', title: countTitle('警告'), children: String(stats.warning) }),
|
|
1344
|
+
jsx.jsx('span', { className: 'dshgp_rulecountGreen', title: countTitle('通过'), children: String(stats.pass) }),
|
|
1345
|
+
jsx.jsx('span', { className: 'dshgp_rulebadge', children: powerBtn }),
|
|
1346
|
+
],
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
/** 审计开关块:提交前自动审计 + 注入开发者要求清单子开关。 */
|
|
1351
|
+
function dshgp_AuditSwitchBlock(props) {
|
|
1352
|
+
const s = props.state;
|
|
1353
|
+
return jsx.jsxs('div', {
|
|
1354
|
+
className: 'dshgp_block',
|
|
1355
|
+
children: [
|
|
1356
|
+
jsx.jsxs('div', {
|
|
1357
|
+
className: 'dshgp_switchrow',
|
|
1358
|
+
children: [
|
|
1359
|
+
jsx.jsx('span', { className: 'dshgp_switchlabel', children: '提交前自动审计' }),
|
|
1360
|
+
jsx.jsx('input', { type: 'checkbox', checked: !!s.auditEnabled, onChange: (ev) => props.toggleAudit(ev.target.checked), 'aria-label': '提交前自动审计' }),
|
|
1361
|
+
],
|
|
1362
|
+
}),
|
|
1363
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: '开启后 git_commit_push 提交前自动跑 L0 静态检查 + 10 维度质量评分;有 blocker 拦截提交。' }),
|
|
1364
|
+
/* 审计扫描范围单按钮:**一个按钮单击切换** diff/full,状态体现在
|
|
1365
|
+
按钮标题 + 颜色(diff=绿色「部分」,full=黄色「全量」)。父开关关闭时置灰
|
|
1366
|
+
(不生效但保留选择)。持久化走 host HTTP(persistence=memory 陷阱绕开方案)。 */
|
|
1367
|
+
jsx.jsxs('div', {
|
|
1368
|
+
className: 'dshgp_scanrow' + (s.auditEnabled ? '' : ' dshgp_subswitchOff'),
|
|
1369
|
+
children: [
|
|
1370
|
+
jsx.jsx('span', { className: 'dshgp_switchlabel', children: '审计扫描范围' }),
|
|
1371
|
+
jsx.jsx('button', {
|
|
1372
|
+
type: 'button',
|
|
1373
|
+
className: 'dshgp_scanbtn '
|
|
1374
|
+
+ (s.auditScanScope === 'full' ? 'dshgp_scanbtnFull' : 'dshgp_scanbtnDiff')
|
|
1375
|
+
+ (s.auditEnabled ? '' : ' dshgp_scanbtnOff'),
|
|
1376
|
+
onClick: () => props.toggleAuditScanScope(s.auditScanScope === 'full' ? 'diff' : 'full'),
|
|
1377
|
+
children: s.auditScanScope === 'full' ? '🔴 全量(auditFull)' : '🟢 部分(本次变动)',
|
|
1378
|
+
'aria-label': '审计扫描范围:' + (s.auditScanScope === 'full' ? '全量' : '仅本次变动') + '(单击切换)',
|
|
1379
|
+
title: s.auditScanScope === 'full'
|
|
1380
|
+
? '当前:全量扫描(auditFull)——单击切回「部分」(仅本次变动,快)'
|
|
1381
|
+
: '当前:仅本次变动(auditChanged,diff)——单击切换「全量」(慢但彻底)',
|
|
1382
|
+
disabled: !s.auditEnabled,
|
|
1383
|
+
}),
|
|
1384
|
+
],
|
|
1385
|
+
}),
|
|
1386
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: s.auditScanScope === 'full'
|
|
1387
|
+
? '全量扫描(auditFull):涵括历史遗留文件与全仓 js-yaml 引用证据;大仓库耗时明显。'
|
|
1388
|
+
: '部分扫描(auditChanged,diff):只审提交相关的文件,最快(默认)。' }),
|
|
1389
|
+
/* 子开关:注入开发者要求清单。
|
|
1390
|
+
2026-09-13 交互修正:原来父开关关闭时 `disabled` + toggle 直接 return,等于
|
|
1391
|
+
「点不动、点了也没反应」,必须先点一次父开关再点它(两遍)。现改为:
|
|
1392
|
+
**一遍即可勾选并保留**(勾选是偏好,与父开关无关),父开关关闭时只把整行置灰
|
|
1393
|
+
(dshgp_subswitchOff)表示「暂不生效」,host 侧注入本身由
|
|
1394
|
+
`cfg.auditEnabled && cfg.injectRequirements` 门控,不会真的注入。 */
|
|
1395
|
+
jsx.jsxs('div', {
|
|
1396
|
+
className: 'dshgp_switchrow dshgp_subswitch' + (s.auditEnabled ? '' : ' dshgp_subswitchOff'),
|
|
1397
|
+
children: [
|
|
1398
|
+
jsx.jsx('span', { className: 'dshgp_switchlabel', children: '↳ 注入开发者要求清单到系统提示词' }),
|
|
1399
|
+
jsx.jsx('input', {
|
|
1400
|
+
type: 'checkbox',
|
|
1401
|
+
checked: !!s.injectRequirements,
|
|
1402
|
+
onChange: (ev) => props.toggleInjectRequirements(ev.target.checked),
|
|
1403
|
+
'aria-label': '注入开发者要求清单到系统提示词',
|
|
1404
|
+
title: s.auditEnabled ? '' : '已勾选但暂不生效:需开启上方「提交前自动审计」',
|
|
1405
|
+
}),
|
|
1406
|
+
],
|
|
1407
|
+
}),
|
|
1408
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: s.auditEnabled
|
|
1409
|
+
? '开启后把「开发者特殊要求」清单注入系统提示词,AI 常驻可见、不必等提交被拦截才去读清单(省一次失败的工具往返)。'
|
|
1410
|
+
: (s.injectRequirements
|
|
1411
|
+
? '已勾选,但上方「提交前自动审计」未开启 → 暂不注入(勾选已保留,开启父开关即生效)。'
|
|
1412
|
+
: '可直接勾选;「提交前自动审计」未开启时置灰、暂不注入。') }),
|
|
1413
|
+
],
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
/** 注入总开关块(新增, 语义扩展):控制 systemPrompt 段 + 上下文注入启停。 */
|
|
1418
|
+
function dshgp_InjectPromptSwitchBlock(props) {
|
|
1419
|
+
const s = props.state;
|
|
1420
|
+
return jsx.jsxs('div', {
|
|
1421
|
+
className: 'dshgp_block',
|
|
1422
|
+
children: [
|
|
1423
|
+
jsx.jsxs('div', {
|
|
1424
|
+
className: 'dshgp_switchrow',
|
|
1425
|
+
children: [
|
|
1426
|
+
jsx.jsx('span', { className: 'dshgp_switchlabel', children: '注入系统提示词/上下文' }),
|
|
1427
|
+
jsx.jsx('input', {
|
|
1428
|
+
type: 'checkbox',
|
|
1429
|
+
checked: s.injectSystemPrompt !== false,
|
|
1430
|
+
onChange: (ev) => props.toggleInjectSystemPrompt(ev.target.checked),
|
|
1431
|
+
'aria-label': '注入系统提示词/上下文',
|
|
1432
|
+
}),
|
|
1433
|
+
],
|
|
1434
|
+
}),
|
|
1435
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: s.injectSystemPrompt !== false
|
|
1436
|
+
? '系统提示词:①插件功能用法(每个工具怎么用 + 凭据由插件托管,避免 AI 绕开插件到处找 token)③提交前 README 核对提醒 + 要求清单。上下文:②环境(工作区目录映射 + 工具安装路径 + skill 总入口一行,每个 agent 首次 step 注入一次;工具按 lib/tool-probes.json 模板探测,路径生成到运行目录 tools.json)。只注入目录/路径级信息,不注入 skill 正文。'
|
|
1437
|
+
: '已关闭:不注入任何系统提示词段落与上下文环境信息(AI 仍可调用插件工具,但看不到功能用法与环境目录)。' }),
|
|
1438
|
+
],
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
/** 代码禁用户沟通词开关块(控制 comment 槽位启停)。 */
|
|
1443
|
+
function dshgp_CommentWordingBlock(props) {
|
|
1444
|
+
const s = props.state;
|
|
1445
|
+
return jsx.jsxs('div', {
|
|
1446
|
+
className: 'dshgp_block',
|
|
1447
|
+
children: [
|
|
1448
|
+
jsx.jsxs('div', {
|
|
1449
|
+
className: 'dshgp_switchrow',
|
|
1450
|
+
children: [
|
|
1451
|
+
jsx.jsx('span', { className: 'dshgp_switchlabel', children: '代码禁用户沟通词(命中 Block 提交)' }),
|
|
1452
|
+
jsx.jsx('input', { type: 'checkbox', checked: !((s.slotMeta && s.slotMeta['comment']) || {}).disabled, onChange: () => props.toggleDisabled('comment'), 'aria-label': '代码禁用户沟通词' }),
|
|
1453
|
+
],
|
|
1454
|
+
}),
|
|
1455
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: '代码注释/文档出现沟通残留措辞(见 comment 规则包黑名单)→ blocker 拦截提交;白名单业务词(用户ID/用户登录等)自动豁免。' }),
|
|
1456
|
+
],
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
/** 审计进阶设置块(收敛:只剩「全量扫描文件上限」)。 */
|
|
1461
|
+
function dshgp_AuditAdvancedBlock(props) {
|
|
1462
|
+
const s = props.state;
|
|
1463
|
+
// 修复:React 的 jsx(type, props, key) 第三参数是 **key 不是 children**——
|
|
1464
|
+
// 此前写成 jsx('select', props, options.map(...)) 导致 children 丢失、下拉框渲染为空
|
|
1465
|
+
// (页面只剩一个空 <select>,用户看到「下拉没有那三种」)。children 必须放进 props。
|
|
1466
|
+
const sel = (key, values) => jsx.jsx('select', {
|
|
1467
|
+
className: 'dshgp_input dshgp_inputInline',
|
|
1468
|
+
value: s[key],
|
|
1469
|
+
onChange: (ev) => props.setAdvanced(key, ev.target.value),
|
|
1470
|
+
children: values.map((v) => jsx.jsx('option', { key: v, value: v, children: v })),
|
|
1471
|
+
});
|
|
1472
|
+
return jsx.jsxs('div', {
|
|
1473
|
+
className: 'dshgp_block',
|
|
1474
|
+
children: [
|
|
1475
|
+
jsx.jsx('p', { className: 'dshgp_h2', children: '审计进阶设置' }),
|
|
1476
|
+
// 本块只保留「全量扫描文件上限」一项。
|
|
1477
|
+
// 删除项(均为 AI 擅自添加、非用户可配):审计强度(固定完整流程)、自定规则目录、
|
|
1478
|
+
// 硬编码全量扫(该项其实从未接上审计实现,是空开关)。
|
|
1479
|
+
// 硬编码扫描范围随审计范围走——审计扫多少,硬编码就扫多少,不再单独控制。
|
|
1480
|
+
jsx.jsxs('div', { className: 'dshgp_field', children: [
|
|
1481
|
+
jsx.jsx('label', { className: 'dshgp_label', htmlFor: 'dshgp-maxfiles', children: '全量扫描文件上限' }),
|
|
1482
|
+
jsx.jsx('input', { id: 'dshgp-maxfiles', type: 'number', min: 0, className: 'dshgp_input', value: s.maxScanFiles, onChange: (ev) => props.setAdvanced('maxScanFiles', ev.target.value) }),
|
|
1483
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: '全量审计最多扫多少个文件(0=不限);超限按「变动优先」截断,弱机防卡死。硬编码检查随此范围一并进行。' }),
|
|
1484
|
+
] }),
|
|
1485
|
+
],
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
/** 规则包列表块:列表容器 + 榜单表头 + 逐行渲染(dshgp_RuleRow)。 */
|
|
1490
|
+
function dshgp_RuleListBlock(props) {
|
|
1491
|
+
const s = props.state;
|
|
1492
|
+
const order = Array.isArray(s.ruleOrder) ? s.ruleOrder : [];
|
|
1493
|
+
return jsx.jsxs('div', {
|
|
1494
|
+
className: 'dshgp_block',
|
|
1495
|
+
children: [
|
|
1496
|
+
jsx.jsx('p', { className: 'dshgp_h2', children: '规则包列表(↑↓ 调整次序,单击切换启用/禁用)' }),
|
|
1497
|
+
s.statusMsg ? jsx.jsx('p', { className: 'dshgp_saved', children: s.statusMsg }) : null,
|
|
1498
|
+
order.length === 0
|
|
1499
|
+
? jsx.jsx('div', { className: 'dshgp_loading', children: s.slotLoading ? '加载中…' : '(无规则包)' })
|
|
1500
|
+
: jsx.jsxs('ul', {
|
|
1501
|
+
className: 'dshgp_rulenext',
|
|
1502
|
+
children: [
|
|
1503
|
+
/* 榜单表头(模仿 skill 记分榜) */
|
|
1504
|
+
jsx.jsxs('li', {
|
|
1505
|
+
className: 'dshgp_ruleheadrow',
|
|
1506
|
+
children: [
|
|
1507
|
+
jsx.jsx('span', { className: 'dshgp_ruleheadrowinfo', children: '规则包' }),
|
|
1508
|
+
jsx.jsx('span', { className: 'dshgp_rulecountRed', title: '该规则包内拦截级(blocker/error)的规则条数', children: '拦截级' }),
|
|
1509
|
+
jsx.jsx('span', { className: 'dshgp_rulecountYellow', title: '该规则包内警告级(warning)的规则条数', children: '警告级' }),
|
|
1510
|
+
jsx.jsx('span', { className: 'dshgp_rulecountGreen', title: '该规则包内提示级(info/notice 等其余严重级)的规则条数', children: '提示级' }),
|
|
1511
|
+
jsx.jsx('span', { className: 'dshgp_rulebadge', children: '状态' }),
|
|
1512
|
+
],
|
|
1513
|
+
}),
|
|
1514
|
+
order.map((slot, idx) => dshgp_RuleRow(props, slot, idx, order.length)),
|
|
1515
|
+
],
|
|
1516
|
+
}),
|
|
1517
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: '数字含义:三个数字是该规则包内各严重级的**规则条数**(拦截级 + 警告级 + 提示级 = 规则总数),取自 yml 规则文件,与是否跑过审计无关。想知道实际命中情况请看审计报告。' }),
|
|
1518
|
+
s.slotError ? jsx.jsx('p', { className: 'dshgp_error', children: s.slotError }) : null,
|
|
1519
|
+
],
|
|
1520
|
+
});
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
/**
|
|
1524
|
+
* 选项卡二:审计(块组合)。
|
|
1525
|
+
* 原单函数 122 行(超可读性阈值 max-function-length)拆为四个块组件 + 权重块;
|
|
1526
|
+
* **渲染输出零变化**——拆分前后同一预览页审计 tab 的 DOM 逐字节比对为空。
|
|
1527
|
+
*/
|
|
1528
|
+
function dshgp_AuditTab(props) {
|
|
1529
|
+
return jsx.jsxs('div', {
|
|
1530
|
+
className: 'dshgp_section',
|
|
1531
|
+
children: [
|
|
1532
|
+
jsx.jsx(dshgp_AuditSwitchBlock, props),
|
|
1533
|
+
jsx.jsx(dshgp_InjectPromptSwitchBlock, props),
|
|
1534
|
+
jsx.jsx(dshgp_CommentWordingBlock, props),
|
|
1535
|
+
/* ② 审计权重(10 维度) */
|
|
1536
|
+
jsx.jsxs('div', {
|
|
1537
|
+
className: 'dshgp_block',
|
|
1538
|
+
children: [
|
|
1539
|
+
jsx.jsx('p', { className: 'dshgp_h2', children: '审计权重(10 维度)' }),
|
|
1540
|
+
jsx.jsx(dshgp_WeightRows, { state: props.state, editWeight: props.editWeight }),
|
|
1541
|
+
],
|
|
1542
|
+
}),
|
|
1543
|
+
/* ③ 审计进阶(补齐 UI) */
|
|
1544
|
+
jsx.jsx(dshgp_AuditAdvancedBlock, props),
|
|
1545
|
+
jsx.jsx(dshgp_RuleListBlock, props),
|
|
1546
|
+
],
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
/* ═══════════════════ 选项卡三:设置 ═══════════════════ */
|
|
1551
|
+
/* ─────────────────── [8] 设置 Tab(SettingsTab) ─────────────────── */
|
|
1552
|
+
function dshgp_CredentialBlock(props) {
|
|
1553
|
+
const s = props.state;
|
|
1554
|
+
return jsx.jsxs('div', {
|
|
1555
|
+
className: 'dshgp_block',
|
|
1556
|
+
children: [
|
|
1557
|
+
// 保存按钮放「凭据与密钥」标题后面(右侧);放弃按钮已删
|
|
1558
|
+
jsx.jsxs('div', {
|
|
1559
|
+
style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px', marginBottom: '8px' },
|
|
1560
|
+
children: [
|
|
1561
|
+
jsx.jsx('p', { className: 'dshgp_h2', style: { margin: 0 }, children: '凭据与密钥' }),
|
|
1562
|
+
jsx.jsx('button', { type: 'button', className: 'dshgp_btn', disabled: !s.dirty || s.saving, onClick: props.save, children: s.saving ? '保存中…' : '保存' }),
|
|
1563
|
+
],
|
|
1564
|
+
}),
|
|
1565
|
+
jsx.jsx('div', {
|
|
1566
|
+
className: 'dshgp_field',
|
|
1567
|
+
children: [
|
|
1568
|
+
jsx.jsxs('label', { className: 'dshgp_label', htmlFor: 'dshgp-token', children: ['GitHub token', s.tokenConfigured ? jsx.jsx('span', { className: 'dshgp_configured', children: '已填写' }) : null] }),
|
|
1569
|
+
jsx.jsx('input', {
|
|
1570
|
+
// token 编辑框改为**普通编辑框**(原 type=password 掩码显示,
|
|
1571
|
+
// 粘贴长 token 时无法核对是否粘全/粘对;改为可见后可直接比对)。
|
|
1572
|
+
// 明文仍只在输入态存在:保存后落 config.json(0600),接口不回传明文。
|
|
1573
|
+
id: 'dshgp-token', type: 'text', autoComplete: 'off', className: 'dshgp_input',
|
|
1574
|
+
placeholder: 'ghp_… 或 github_pat_…', spellCheck: false,
|
|
1575
|
+
value: s.text, disabled: !s.writable || s.saving,
|
|
1576
|
+
onChange: (ev) => props.edit(ev.target.value),
|
|
1577
|
+
}),
|
|
1578
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: 'ghp_ / github_pat_ 开头。保存后写入插件配置目录的 config.json(0600),不回传明文、不在设置页留存。' }),
|
|
1579
|
+
],
|
|
1580
|
+
}),
|
|
1581
|
+
jsx.jsx('div', {
|
|
1582
|
+
className: 'dshgp_field',
|
|
1583
|
+
children: [
|
|
1584
|
+
jsx.jsxs('label', { className: 'dshgp_label', htmlFor: 'dshgp-ssh', children: ['SSH 公钥', s.sshConfigured ? jsx.jsx('span', { className: 'dshgp_configured', children: '已填写' }) : null] }),
|
|
1585
|
+
jsx.jsx('textarea', {
|
|
1586
|
+
id: 'dshgp-ssh', className: 'dshgp_textarea', rows: 3,
|
|
1587
|
+
value: s.sshPub, disabled: !s.writable || s.saving,
|
|
1588
|
+
onChange: (ev) => props.editSsh(ev.target.value),
|
|
1589
|
+
}),
|
|
1590
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: 'ssh-ed25519 / ssh-rsa 整行。保存后写入 config.json(与 token 同份配置,互不覆盖),不回传明文。' }),
|
|
1591
|
+
],
|
|
1592
|
+
}),
|
|
1593
|
+
// npm 凭据(token / registry):自包含字段,直接 POST /settings-set,不依赖设置快照
|
|
1594
|
+
jsx.jsx(dshgp_NpmCredFields, {}),
|
|
1595
|
+
// 邮箱 + 一键生成同一行(编辑框宽度减少,按钮放编辑框后面)
|
|
1596
|
+
jsx.jsxs('div', {
|
|
1597
|
+
className: 'dshgp_field',
|
|
1598
|
+
children: [
|
|
1599
|
+
jsx.jsx('label', { className: 'dshgp_label', htmlFor: 'dshgp-email', children: 'SSH 邮箱(一键生成用)' }),
|
|
1600
|
+
jsx.jsxs('div', {
|
|
1601
|
+
style: { display: 'flex', alignItems: 'center', gap: '8px' },
|
|
1602
|
+
children: [
|
|
1603
|
+
jsx.jsx('input', {
|
|
1604
|
+
id: 'dshgp-email', type: 'text', autoComplete: 'off', className: 'dshgp_input',
|
|
1605
|
+
style: { flex: '1 1 40%', maxWidth: '200px', minWidth: '120px' },
|
|
1606
|
+
value: s.sshEmail, disabled: s.genKeying,
|
|
1607
|
+
onChange: (ev) => props.editEmail(ev.target.value),
|
|
1608
|
+
}),
|
|
1609
|
+
jsx.jsx('button', { type: 'button', className: 'dshgp_btn dshgp_btnPrimary', disabled: s.genKeying || !s.sshEmail.trim(), onClick: props.genKey, children: s.genKeying ? '生成中…' : '一键生成并复制' }),
|
|
1610
|
+
],
|
|
1611
|
+
}),
|
|
1612
|
+
],
|
|
1613
|
+
}),
|
|
1614
|
+
s.failed ? jsx.jsx('p', { className: 'dshgp_error', children: '保存失败:请检查格式后重试。' }) : null,
|
|
1615
|
+
s.savedMsg ? jsx.jsx('p', { className: 'dshgp_saved', children: s.savedMsg }) : null,
|
|
1616
|
+
s.genKeyError ? jsx.jsx('p', { className: 'dshgp_error', children: s.genKeyError }) : null,
|
|
1617
|
+
],
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
/** 推送与默认值区块(收敛:只保留推送通道;默认扫描路径复用本地仓库列表选择路径)。 */
|
|
1622
|
+
function dshgp_PushDefaultsBlock(props) {
|
|
1623
|
+
const s = props.state;
|
|
1624
|
+
return jsx.jsxs('div', {
|
|
1625
|
+
className: 'dshgp_block',
|
|
1626
|
+
children: [
|
|
1627
|
+
jsx.jsx('p', { className: 'dshgp_h2', children: '推送与默认值' }),
|
|
1628
|
+
jsx.jsxs('div', { className: 'dshgp_field', children: [
|
|
1629
|
+
jsx.jsx('label', { className: 'dshgp_label', htmlFor: 'dshgp-pushmethod', children: '推送通道' }),
|
|
1630
|
+
// 下拉标签带括号注释(选项 value 仍是 ssh/api/auto,不改值——
|
|
1631
|
+
// 兼容 config.json 已保存的 pushMethod;对外显示用「token」称 api 通道)。
|
|
1632
|
+
jsx.jsx('select', {
|
|
1633
|
+
id: 'dshgp-pushmethod', className: 'dshgp_input dshgp_inputInline',
|
|
1634
|
+
value: s.pushMethod, onChange: (ev) => props.setAdvanced('pushMethod', ev.target.value),
|
|
1635
|
+
children: [
|
|
1636
|
+
{ value: 'ssh', label: 'ssh(默认)' },
|
|
1637
|
+
{ value: 'api', label: 'token' },
|
|
1638
|
+
{ value: 'auto', label: 'auto(先 ssh 再 token)' },
|
|
1639
|
+
].map((o) => jsx.jsx('option', { key: o.value, value: o.value, children: o.label })),
|
|
1640
|
+
}),
|
|
1641
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: 'ssh = 只走 SSH 私钥(默认);token = 先走 Git Data API(用 token 推),失败回落 SSH;auto = 先 ssh、失败再回落 token。远端分叉时不静默回落,如实报错。' }),
|
|
1642
|
+
] }),
|
|
1643
|
+
// 推送门禁(类似会话指挥家写操作拦截)——开启后 AI 推送必须
|
|
1644
|
+
// 先取得显式放行(带 pushConfirmed:true 重推),否则推送步骤被拦截。
|
|
1645
|
+
jsx.jsxs('div', { className: 'dshgp_field', children: [
|
|
1646
|
+
jsx.jsx('label', { className: 'dshgp_label', htmlFor: 'dshgp-pushgate', children: '推送门禁' }),
|
|
1647
|
+
jsx.jsx('input', {
|
|
1648
|
+
id: 'dshgp-pushgate', type: 'checkbox', className: 'dshgp_check',
|
|
1649
|
+
checked: !!s.pushGate, onChange: (ev) => props.setAdvanced('pushGate', ev.target.checked),
|
|
1650
|
+
}),
|
|
1651
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: '开启后:commit 可正常提交,但 push 前必须显式传 pushConfirmed:true 放行——未放行的推送被拦截并提示「推送门禁已开启,需确认后重试」。用于防止未经放行直接推远端。' }),
|
|
1652
|
+
] }),
|
|
1653
|
+
// 任务完成自动推送(内置自 dsh-task-completion):开关 + 自定义触发文本 + 范围。
|
|
1654
|
+
jsx.jsxs('div', { className: 'dshgp_field', children: [
|
|
1655
|
+
jsx.jsx('label', { className: 'dshgp_label', htmlFor: 'dshgp-autopush', children: '自动推送(✅任务完成)' }),
|
|
1656
|
+
jsx.jsx('input', {
|
|
1657
|
+
id: 'dshgp-autopush', type: 'checkbox', className: 'dshgp_check',
|
|
1658
|
+
checked: !!s.autoPushEnabled, onChange: (ev) => props.setAdvanced('autoPushEnabled', ev.target.checked),
|
|
1659
|
+
}),
|
|
1660
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: '开启后:AI 回复含指定完成文案(默认「✅任务完成」,可自定义)自动 commit+push——复用审计门禁(blocker 拦截、requirements 核对、pushGate 放行),不裸提交;默认关。' }),
|
|
1661
|
+
] }),
|
|
1662
|
+
jsx.jsxs('div', { className: 'dshgp_field', children: [
|
|
1663
|
+
jsx.jsx('label', { className: 'dshgp_label', htmlFor: 'dshgp-autopush-trigger', children: '自动推送触发文本' }),
|
|
1664
|
+
jsx.jsx('input', {
|
|
1665
|
+
id: 'dshgp-autopush-trigger', type: 'text', className: 'dshgp_input',
|
|
1666
|
+
value: s.autoPushTriggerText ?? '✅任务完成', onChange: (ev) => props.setAdvanced('autoPushTriggerText', ev.target.value),
|
|
1667
|
+
}),
|
|
1668
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: '检测「任务完成」的文本/正则(默认「✅任务完成」),可写成 ✅(任务完成|已解答) 等' }),
|
|
1669
|
+
] }),
|
|
1670
|
+
jsx.jsxs('div', { className: 'dshgp_field', children: [
|
|
1671
|
+
jsx.jsx('label', { className: 'dshgp_label', htmlFor: 'dshgp-autopush-scope', children: '自动推送范围' }),
|
|
1672
|
+
// 修复:jsx(type, props, key) 第三参数是 key 不是 children——
|
|
1673
|
+
// 此前把 options 数组放第三参数导致 children 丢失、下拉渲染为空(与 2026-09-16 同坑)。
|
|
1674
|
+
// children 必须放进 props,与 pushMethod/审计进阶 sel 的写法对齐。
|
|
1675
|
+
jsx.jsx('select', {
|
|
1676
|
+
id: 'dshgp-autopush-scope', className: 'dshgp_input',
|
|
1677
|
+
value: s.autoPushScope ?? 'session', onChange: (ev) => props.setAdvanced('autoPushScope', ev.target.value),
|
|
1678
|
+
children: ['session', 'all'].map((v) => jsx.jsx('option', { key: v, value: v, children: String(v) })),
|
|
1679
|
+
}),
|
|
1680
|
+
jsx.jsx('p', { className: 'dshgp_hint', children: 'session=仅会话 cwd 所在仓库(默认,最安全);all=workspace 全部有变更仓库' }),
|
|
1681
|
+
] }),
|
|
1682
|
+
],
|
|
1683
|
+
});
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
function dshgp_SettingsTab(props) {
|
|
1687
|
+
const s = props.state;
|
|
1688
|
+
return jsx.jsxs('div', {
|
|
1689
|
+
className: 'dshgp_section',
|
|
1690
|
+
children: [
|
|
1691
|
+
jsx.jsx(dshgp_CredentialBlock, Object.assign({}, props)),
|
|
1692
|
+
jsx.jsx(dshgp_PushDefaultsBlock, Object.assign({}, props)),
|
|
1693
|
+
],
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
/* ─────────────────── [9] 页面装配(GitPushPage:三选项卡聚合) ─────────────────── */
|
|
1698
|
+
function dshgp_GitPushPage(props) {
|
|
1699
|
+
dshgp_ensureCss();
|
|
1700
|
+
const [tab, setTab] = react.useState('account');
|
|
1701
|
+
const tabs = [
|
|
1702
|
+
{ id: 'account', label: '账号信息' },
|
|
1703
|
+
{ id: 'audit', label: '审计' },
|
|
1704
|
+
{ id: 'settings', label: '设置' },
|
|
1705
|
+
];
|
|
1706
|
+
const tabBar = jsx.jsxs('div', {
|
|
1707
|
+
className: 'dshgp_tabs',
|
|
1708
|
+
children: tabs.map((t) => jsx.jsxs('button', {
|
|
1709
|
+
key: t.id,
|
|
1710
|
+
type: 'button',
|
|
1711
|
+
role: 'tab',
|
|
1712
|
+
'aria-selected': tab === t.id,
|
|
1713
|
+
className: tab === t.id ? 'dshgp_tab dshgp_tabOn' : 'dshgp_tab',
|
|
1714
|
+
onClick: () => setTab(t.id),
|
|
1715
|
+
children: [t.label],
|
|
1716
|
+
})),
|
|
1717
|
+
});
|
|
1718
|
+
// 账号选项卡下的本地/云端卡片需要全部注入动作(scanLocalRepos/loadCloudRepos/
|
|
1719
|
+
// pushLocalRepo/cloneFlow),只传 state+refreshAccount 会导致卡片按钮 onClick 报
|
|
1720
|
+
// 「props.xxx is not a function」——整包传 props(state + 全部注入动作)。
|
|
1721
|
+
const panel = tab === 'account' ? jsx.jsx(dshgp_AccountTab, props)
|
|
1722
|
+
: tab === 'audit' ? jsx.jsx(dshgp_AuditTab, {
|
|
1723
|
+
state: props.state,
|
|
1724
|
+
toggleAudit: props.toggleAudit,
|
|
1725
|
+
toggleInjectRequirements: props.toggleInjectRequirements,
|
|
1726
|
+
toggleInjectSystemPrompt: props.toggleInjectSystemPrompt,
|
|
1727
|
+
toggleAuditScanScope: props.toggleAuditScanScope,
|
|
1728
|
+
editWeight: props.editWeight,
|
|
1729
|
+
setAdvanced: props.setAdvanced,
|
|
1730
|
+
moveSlot: props.moveSlot,
|
|
1731
|
+
toggleDisabled: props.toggleDisabled,
|
|
1732
|
+
})
|
|
1733
|
+
: jsx.jsx(dshgp_SettingsTab, {
|
|
1734
|
+
state: props.state,
|
|
1735
|
+
edit: props.edit,
|
|
1736
|
+
editSsh: props.editSsh,
|
|
1737
|
+
editEmail: props.editEmail,
|
|
1738
|
+
save: props.save,
|
|
1739
|
+
discard: props.discard,
|
|
1740
|
+
genKey: props.genKey,
|
|
1741
|
+
setAdvanced: props.setAdvanced,
|
|
1742
|
+
});
|
|
1743
|
+
return jsx.jsxs('div', {
|
|
1744
|
+
style: { padding: '0 4px' },
|
|
1745
|
+
children: [
|
|
1746
|
+
jsx.jsxs('h2', { style: { margin: '0 0 10px', fontSize: '14px' }, children: ['Git 提交推送'] }),
|
|
1747
|
+
tabBar,
|
|
1748
|
+
panel,
|
|
1749
|
+
],
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
/* ─────────────────── [10] Controller(状态机 + 数据加载 + 动作注入) ─────────────────── */
|
|
1754
|
+
class dshgp_Controller {
|
|
1755
|
+
constructor(scope) {
|
|
1756
|
+
this.scope = scope;
|
|
1757
|
+
this.text = '';
|
|
1758
|
+
this.sshPub = '';
|
|
1759
|
+
this.sshEmail = '';
|
|
1760
|
+
this.saving = false;
|
|
1761
|
+
this.failed = false;
|
|
1762
|
+
this.savedMsg = '';
|
|
1763
|
+
this.savedTimer = null;
|
|
1764
|
+
this.auditEnabled = false;
|
|
1765
|
+
this.injectRequirements = false;
|
|
1766
|
+
// 注入总开关(默认开;新增, 扩展为系统提示词+上下文)
|
|
1767
|
+
this.injectSystemPrompt = true;
|
|
1768
|
+
// 审计扫描范围(diff|full)——设置持久化走 host HTTP,前端本地字段镜像
|
|
1769
|
+
this.auditScanScope = 'diff';
|
|
1770
|
+
this.ruleOrder = [];
|
|
1771
|
+
this.slotMeta = {};
|
|
1772
|
+
this.weightValues = {};
|
|
1773
|
+
// 补齐:以下键此前只有 schema 声明与 HTTP 白名单,前端**没有 UI 控件**
|
|
1774
|
+
// (只能看不能改)→ 设置「基本都没真正保存」的根源。这里补状态镜像 + 提交 + 回读。
|
|
1775
|
+
this.maxScanFiles = 3000; // 全量审计文件数上限(0=不限)
|
|
1776
|
+
this.pushMethod = 'ssh'; // ssh | api | auto
|
|
1777
|
+
this.pushGate = false; // 推送门禁(开启后 push 需显式放行)
|
|
1778
|
+
// defaultScanRoot/commitMessage 设置移除——默认扫描路径复用本地仓库
|
|
1779
|
+
// 列表选择路径(localStorage dshgp-scan-path),提交信息留空由调用方/AI 生成。
|
|
1780
|
+
// 禁用态不再前端变量存储,以 yml 顶层 disabled 为准(listRuleSlots 解析)
|
|
1781
|
+
this.statusMsg = '';
|
|
1782
|
+
this.statusTimer = null;
|
|
1783
|
+
// 账号信息(纯展示)
|
|
1784
|
+
this.tokenConfigured = false;
|
|
1785
|
+
this.sshConfigured = false;
|
|
1786
|
+
// 凭据有效性快照(token/ssh 各自 valid/login/checkedAt)——来自 account-status.json
|
|
1787
|
+
this.tokenStatus = null;
|
|
1788
|
+
this.sshStatus = null;
|
|
1789
|
+
this.accountBlock = '';
|
|
1790
|
+
this.accountLoggedIn = false;
|
|
1791
|
+
this.accountLoading = false;
|
|
1792
|
+
// npm 账号态(与 GitHub 账号态**同构**:离线快照 + 在线校验两段式;包列表同源刷新)
|
|
1793
|
+
this.npmAccountBlock = '';
|
|
1794
|
+
this.npmAccountLoggedIn = false;
|
|
1795
|
+
this.npmAccountLoading = false;
|
|
1796
|
+
this.npmAccountUser = '';
|
|
1797
|
+
this.npmConfigured = false; // 后端返回的「凭据文件里有没有 npm token」(唯一真源,不从块文案反推)
|
|
1798
|
+
this.npmOwned = [];
|
|
1799
|
+
this.npmOwnedLoading = false;
|
|
1800
|
+
this.npmOwnedError = '';
|
|
1801
|
+
this.npmInstallBusy = ''; // 正在安装的包名('' = 空闲)
|
|
1802
|
+
this.npmInstallResult = null; // 最近一次安装回执(含日志路径与输出摘要)
|
|
1803
|
+
// 安装流程(照 GitHub 克隆四段):选择对话框 + 进度轮询
|
|
1804
|
+
this.npmInstallDialog = null; // { name } = 正在选安装位置
|
|
1805
|
+
this.npmInstallProgress = null;// 轮询到的进度(state/lines/tail)
|
|
1806
|
+
this.npmInstallTimer = null; // 轮询定时器(终态后清理)
|
|
1807
|
+
// API 配额(token 的 /rate_limit 快照):quotaLoading 防重复请求;quotaError 记后端
|
|
1808
|
+
// 写快照失败的原因(此前该失败被静默丢弃,UI 看不出「查了但没落盘」)
|
|
1809
|
+
this.apiQuota = null;
|
|
1810
|
+
this.quotaLoading = false;
|
|
1811
|
+
this.quotaError = '';
|
|
1812
|
+
// 账号卡片:本地/云端(本地扫描 / 云端列表)
|
|
1813
|
+
this.localPath = '';
|
|
1814
|
+
this.localRepos = [];
|
|
1815
|
+
this.localLoading = false;
|
|
1816
|
+
this.localScanning = false; // 独立进程扫描进行中(按钮禁用,不可重复扫描)
|
|
1817
|
+
this.localMsg = '';
|
|
1818
|
+
this.cloudRepos = [];
|
|
1819
|
+
this.cloudLoading = false;
|
|
1820
|
+
this.cloudMsg = '';
|
|
1821
|
+
this.repoBusy = '';
|
|
1822
|
+
this.cloneProgress = null; // 进行中的 clone 进度(轮询填充)
|
|
1823
|
+
this._cloneResumeTimer = null; // 后台克隆接续轮询句柄(后台化配套)
|
|
1824
|
+
this.clonePreview = null; // 待确认的 clone 预览
|
|
1825
|
+
this.cloneHistory = null; // 预览框「带真实历史」勾选:null=未表态(跟随后端默认 true)、true/false=用户显式选择
|
|
1826
|
+
this.clonePending = { repo: '', dir: '' }; // 预览后待确认的上下文
|
|
1827
|
+
this.visConfirm = null; // 1.5.4:待确认的可见性切换({fullName, target, cur},命中则弹独立确认面板)
|
|
1828
|
+
this.maxCloneFileMB = 10; // clone 单文件体积上限(MB);0=不限
|
|
1829
|
+
this.cloneConcurrency = 6; // clone 并发下载数
|
|
1830
|
+
this.repoFeedback = {}; // { path: {ok, msg} } push 结果反馈(成功绿/失败红)
|
|
1831
|
+
// 规则包加载
|
|
1832
|
+
this.slotLoading = false;
|
|
1833
|
+
this.slotError = '';
|
|
1834
|
+
// 统一刷新入口 refresh() 的部分级错误记录(单个部分失败不阻断其余部分)
|
|
1835
|
+
this.refreshError = '';
|
|
1836
|
+
this.genKeying = false;
|
|
1837
|
+
this.genKeyError = '';
|
|
1838
|
+
// 本次编辑会话已触达的设置键集合——loadSettingsFromHttp 的异步 GET
|
|
1839
|
+
// 返回旧值时跳过这些键,防止「点开关被初始化响应弹回」(回弹根因:GET 发出后
|
|
1840
|
+
// 点击发生,POST 未落盘前 GET 旧值先把本地覆盖回去)
|
|
1841
|
+
this.editedKeys = new Set();
|
|
1842
|
+
this.store = store.createSnapshotStore(this.project());
|
|
1843
|
+
this.unsubscribe = scope.subscribe(() => {
|
|
1844
|
+
const snap = this.scope.getSnapshot();
|
|
1845
|
+
if (snap && snap.value) {
|
|
1846
|
+
// 重构:设置/凭据状态全链路统一走 HTTP(settings-get + account-check,
|
|
1847
|
+
// 真源 = config.json + 凭据文件),**scope 快照不再参与任何状态判定**——
|
|
1848
|
+
// 公共 settings.yaml 已零写入(scope.set 全移除),snap.value 里这些键恒缺省,
|
|
1849
|
+
// 此前把 sshConfigured 覆盖成 !!snap.value.sshPub(恒 false)导致「配置了却显示
|
|
1850
|
+
// 未配置」,且每次 scope 发布都弹回,与 loadSettingsFromHttp 拉回的真值互相打架。
|
|
1851
|
+
// 修复「规则包统计全是 0」:slotMeta 与 ruleOrder 同理,也不再从 scope 覆盖。
|
|
1852
|
+
// snap.value.ruleSlotMeta 是 schema 里声明为「host 启动填充」的字段,但**宿主从未写入**,
|
|
1853
|
+
// 于是每次 scope 发布都把它(空对象)赋给 slotMeta,刚由 loadSlots() 拉到的真实统计被清空,
|
|
1854
|
+
// 所有规则包行回退到 {blocker:0,warning:0,pass:0,total:0} 兜底值 → 列表里数字全是 0。
|
|
1855
|
+
// 权威来源 = loadSlots() 的后端结果(动态发现全部 yml 并带 stats);启停的即时反馈由
|
|
1856
|
+
// toggleDisabled 自己改 slotMeta、随后 loadSlots 对账。
|
|
1857
|
+
}
|
|
1858
|
+
this.publish();
|
|
1859
|
+
});
|
|
1860
|
+
// 重构:scope 快照只作「无 HTTP 时的初值兜底」(typeof 守卫保证 yaml 零写入
|
|
1861
|
+
// 时 undefined 不会覆盖;仅单测显式传值才生效)。凭据标志 tokenConfigured/sshConfigured
|
|
1862
|
+
// 不再从快照取——公共 yaml 已零写入,snap 里恒缺省只会种出 false,统一由
|
|
1863
|
+
// refreshAccount(/account-check 读凭据文件真源)与 loadSettingsFromHttp 刷新。
|
|
1864
|
+
const snap0 = this.scope.getSnapshot();
|
|
1865
|
+
if (snap0 && snap0.value) {
|
|
1866
|
+
if (typeof snap0.value.auditEnabled === 'boolean') this.auditEnabled = snap0.value.auditEnabled;
|
|
1867
|
+
if (typeof snap0.value.injectRequirements === 'boolean') this.injectRequirements = snap0.value.injectRequirements;
|
|
1868
|
+
if (typeof snap0.value.injectSystemPrompt === 'boolean') this.injectSystemPrompt = snap0.value.injectSystemPrompt;
|
|
1869
|
+
if (typeof snap0.value.auditScanScope === 'string') this.auditScanScope = snap0.value.auditScanScope;
|
|
1870
|
+
const wo0 = String(snap0.value.weightOverrides || '');
|
|
1871
|
+
if (wo0.trim()) { try { this.weightValues = JSON.parse(wo0) || {}; } catch { /* 忽略 */ } }
|
|
1872
|
+
}
|
|
1873
|
+
// 若 loadSlots 尚未返回,先用已发现的槽位做占位显示(不含 private/template)
|
|
1874
|
+
if (!this.ruleOrder.length && Object.keys(this.slotMeta).length) {
|
|
1875
|
+
this.ruleOrder = Object.keys(this.slotMeta).filter((s) => s !== 'private' && s !== 'template');
|
|
1876
|
+
}
|
|
1877
|
+
// 改走统一刷新入口(一次调用刷设置与槽位;账号仍按需在页面 mount 时刷)
|
|
1878
|
+
void this.refresh(['settings', 'slots']);
|
|
1879
|
+
// 账号状态改由「首次打开账号信息页」时(dshgp_AccountTab 的 mount effect)
|
|
1880
|
+
// 触发 refreshAccount,避免构造阶段与页面打开重复拉取;此处不再自动刷新。
|
|
1881
|
+
// 设置持久化走 HTTP 读宿主 scope(绕开 client isLoopback=memory 陷阱——
|
|
1882
|
+
// 反代访问时 scope 快照恒 unavailable,从宿主侧读已落盘设置,重启后开关保持勾选)
|
|
1883
|
+
// 该读取已并入上方 this.refresh(['settings','slots']),此处不再重复请求。
|
|
1884
|
+
}
|
|
1885
|
+
project() {
|
|
1886
|
+
// 恒可用/恒可写:数据与写入全走 HTTP(settings-get/settings-set/account-check/rule-slots),
|
|
1887
|
+
// client scope 快照只作初值兜底(见构造处注释)。宿主按 isLoopback 决定 scope 的
|
|
1888
|
+
// persistence——反代/非 loopback 访问时恒 memory 模式、status 恒 unavailable、
|
|
1889
|
+
// writable 恒 false(isLoopback=memory 陷阱)。若仍以快照判 available,设置侧边栏
|
|
1890
|
+
// 在反代访问下会整页空白(SectionPage return null)且输入框全禁用,故绕开快照判定。
|
|
1891
|
+
return {
|
|
1892
|
+
available: true,
|
|
1893
|
+
writable: true,
|
|
1894
|
+
text: this.text,
|
|
1895
|
+
sshPub: this.sshPub,
|
|
1896
|
+
sshEmail: this.sshEmail,
|
|
1897
|
+
auditEnabled: this.auditEnabled,
|
|
1898
|
+
injectRequirements: this.injectRequirements,
|
|
1899
|
+
injectSystemPrompt: this.injectSystemPrompt,
|
|
1900
|
+
auditScanScope: this.auditScanScope,
|
|
1901
|
+
ruleOrder: this.ruleOrder,
|
|
1902
|
+
slotMeta: this.slotMeta,
|
|
1903
|
+
weightValues: this.weightValues,
|
|
1904
|
+
// 补齐:审计进阶 / 推送默认值状态镜像(供 UI 渲染)
|
|
1905
|
+
maxScanFiles: this.maxScanFiles,
|
|
1906
|
+
pushMethod: this.pushMethod,
|
|
1907
|
+
pushGate: this.pushGate, // 推送门禁(开启后 push 需显式放行)
|
|
1908
|
+
// defaultScanRoot/commitMessage 状态镜像移除(设置已删除)
|
|
1909
|
+
tokenConfigured: this.tokenConfigured,
|
|
1910
|
+
sshConfigured: this.sshConfigured,
|
|
1911
|
+
// 凭据有效性快照(account-check → account-status.json 的 token/ssh 分项),
|
|
1912
|
+
// 供账号卡片渲染各自 ✅有效/❌无效 徽标 + 登录名。
|
|
1913
|
+
tokenStatus: this.tokenStatus,
|
|
1914
|
+
sshStatus: this.sshStatus,
|
|
1915
|
+
accountBlock: this.accountBlock,
|
|
1916
|
+
accountLoggedIn: this.accountLoggedIn,
|
|
1917
|
+
accountLoading: this.accountLoading,
|
|
1918
|
+
npmAccountBlock: this.npmAccountBlock,
|
|
1919
|
+
npmAccountLoggedIn: this.npmAccountLoggedIn,
|
|
1920
|
+
npmAccountLoading: this.npmAccountLoading,
|
|
1921
|
+
npmAccountUser: this.npmAccountUser,
|
|
1922
|
+
npmConfigured: this.npmConfigured,
|
|
1923
|
+
npmOwned: this.npmOwned,
|
|
1924
|
+
npmOwnedLoading: this.npmOwnedLoading,
|
|
1925
|
+
npmOwnedError: this.npmOwnedError,
|
|
1926
|
+
npmInstallBusy: this.npmInstallBusy,
|
|
1927
|
+
npmInstallResult: this.npmInstallResult,
|
|
1928
|
+
npmInstallDialog: this.npmInstallDialog,
|
|
1929
|
+
npmInstallProgress: this.npmInstallProgress,
|
|
1930
|
+
slotLoading: this.slotLoading,
|
|
1931
|
+
slotError: this.slotError,
|
|
1932
|
+
refreshError: this.refreshError, // 统一刷新入口的部分级错误
|
|
1933
|
+
statusMsg: this.statusMsg,
|
|
1934
|
+
genKeying: this.genKeying,
|
|
1935
|
+
genKeyError: this.genKeyError,
|
|
1936
|
+
localPath: this.localPath,
|
|
1937
|
+
localRepos: this.localRepos,
|
|
1938
|
+
localLoading: this.localLoading,
|
|
1939
|
+
localScanning: this.localScanning, // 独立进程扫描中(按钮禁用)
|
|
1940
|
+
localMsg: this.localMsg,
|
|
1941
|
+
cloudRepos: this.cloudRepos,
|
|
1942
|
+
cloudLoading: this.cloudLoading,
|
|
1943
|
+
cloudMsg: this.cloudMsg,
|
|
1944
|
+
repoBusy: this.repoBusy,
|
|
1945
|
+
cloneProgress: this.cloneProgress,
|
|
1946
|
+
clonePreview: this.clonePreview,
|
|
1947
|
+
cloneHistory: this.cloneHistory,
|
|
1948
|
+
visConfirm: this.visConfirm,
|
|
1949
|
+
maxCloneFileMB: this.maxCloneFileMB,
|
|
1950
|
+
cloneConcurrency: this.cloneConcurrency,
|
|
1951
|
+
repoFeedback: this.repoFeedback,
|
|
1952
|
+
dirty: this.text.trim().length > 0 || this.sshPub.trim().length > 0,
|
|
1953
|
+
saving: this.saving,
|
|
1954
|
+
failed: this.failed,
|
|
1955
|
+
savedMsg: this.savedMsg,
|
|
1956
|
+
};
|
|
1957
|
+
}
|
|
1958
|
+
flashSaved(msg) {
|
|
1959
|
+
this.savedMsg = String(msg || '');
|
|
1960
|
+
if (this.savedTimer) clearTimeout(this.savedTimer);
|
|
1961
|
+
this.savedTimer = setTimeout(() => {
|
|
1962
|
+
this.savedMsg = '';
|
|
1963
|
+
this.publish();
|
|
1964
|
+
}, dshgp_SAVED_MSG_MS);
|
|
1965
|
+
this.publish();
|
|
1966
|
+
}
|
|
1967
|
+
publish() { this.store.set(this.project()); }
|
|
1968
|
+
|
|
1969
|
+
/**
|
|
1970
|
+
* 从宿主读已落盘设置(/settings-get,host scope.get 快照)。
|
|
1971
|
+
* 背景:非 loopback 访问(反代)时 client settingsScope 恒 unavailable(memory 模式),
|
|
1972
|
+
* 插件直读 scope 拿不到任何已保存值 → 打开设置页时开关全回默认(现象:重启后勾选丢失,
|
|
1973
|
+
* 需重新打开)。host 侧 scope 才是真源,经 HTTP 读回后覆盖前端字段、保持勾选状态。
|
|
1974
|
+
* 追加:**用户已编辑过的键跳过**(this.editedKeys)——本请求是异步的,
|
|
1975
|
+
* 若用户在响应回来前点了开关,GET 返回的是 host 旧值,直接覆盖会把刚点的勾选弹回。
|
|
1976
|
+
*/
|
|
1977
|
+
/**
|
|
1978
|
+
* 统一刷新入口:**一个函数 + 一个参数**控制刷新设置侧边栏的哪部分,
|
|
1979
|
+
* 取代此前散落在多个 useEffect / 按钮回调里各自 fetch 的写法。
|
|
1980
|
+
*
|
|
1981
|
+
* @param {string|string[]} [parts='all'] 要刷新的部分,可传单个字符串、数组、或 'all':
|
|
1982
|
+
* · 'settings' —— 设置(/settings-get 读宿主 scope 已落盘值,覆盖前端字段)
|
|
1983
|
+
* · 'account' —— 账号信息(/account-status 离线读凭据真源 + 徽标)
|
|
1984
|
+
* · 'repos' —— 本地仓库列表(/repos-local 读 dsh-repo-index.json;可配 path/rebuild)
|
|
1985
|
+
* · 'cloud' —— 云端仓库列表(/repos-cloud 走 token 列账号名下仓库)
|
|
1986
|
+
* · 'slots' —— 规则槽位(/rule-slots 动态发现 yml + 统计)
|
|
1987
|
+
* · 'all' —— 以上全部(默认)
|
|
1988
|
+
* @param {object} [opts]
|
|
1989
|
+
* · path —— 仅 'repos' 用:扫描根路径(空=沿用上次)
|
|
1990
|
+
* · rebuild —— 仅 'repos' 用:true 先离线重建索引再读回
|
|
1991
|
+
* · silent —— true 时不置 loading 态(用于后台静默刷新,避免界面闪烁)
|
|
1992
|
+
* @returns {Promise<void>}
|
|
1993
|
+
*
|
|
1994
|
+
* 用法:
|
|
1995
|
+
* await this.refresh(); // 全部刷新
|
|
1996
|
+
* await this.refresh('account'); // 只刷账号信息
|
|
1997
|
+
* await this.refresh(['settings','slots']); // 只刷设置与槽位
|
|
1998
|
+
* await this.refresh('repos', { rebuild: true }); // 重建索引后刷本地列表
|
|
1999
|
+
*/
|
|
2000
|
+
async refresh(parts = 'all', opts = {}) {
|
|
2001
|
+
const PARTS = ['settings', 'account', 'npm', 'repos', 'cloud', 'slots'];
|
|
2002
|
+
let list;
|
|
2003
|
+
if (parts === 'all' || parts === undefined || parts === null) list = PARTS.slice();
|
|
2004
|
+
else list = (Array.isArray(parts) ? parts : [parts])
|
|
2005
|
+
.map((p) => String(p || '').trim().toLowerCase())
|
|
2006
|
+
.filter((p) => PARTS.includes(p));
|
|
2007
|
+
if (!list.length) return;
|
|
2008
|
+
|
|
2009
|
+
// 顺序执行而非并行:repos 依赖索引、account 影响徽标,串行可保证先后关系稳定,
|
|
2010
|
+
// 也避免多个请求同时 publish 造成界面连续重排。
|
|
2011
|
+
for (const p of list) {
|
|
2012
|
+
try {
|
|
2013
|
+
if (p === 'settings') await this.loadSettingsFromHttp();
|
|
2014
|
+
else if (p === 'account') await this.refreshAccount({ silent: opts.silent });
|
|
2015
|
+
else if (p === 'npm') {
|
|
2016
|
+
// npm 与 GitHub 同构:先读离线账号态,再拉账号名下的包列表(未登录时列表给可读提示)
|
|
2017
|
+
await this.refreshNpmAccount({ silent: opts.silent });
|
|
2018
|
+
await this.loadNpmOwned({ silent: opts.silent });
|
|
2019
|
+
}
|
|
2020
|
+
else if (p === 'repos') await this.scanLocalRepos(opts.path, opts.rebuild, { silent: opts.silent });
|
|
2021
|
+
else if (p === 'cloud') await this.loadCloudRepos({ silent: opts.silent });
|
|
2022
|
+
else if (p === 'slots') await this.loadSlots({ silent: opts.silent });
|
|
2023
|
+
} catch (e) {
|
|
2024
|
+
// 单个部分失败不影响其余部分:记录到统一错误位,继续刷下一个
|
|
2025
|
+
this.refreshError = `${p}: ` + (e && e.message || e);
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
// 克隆改为后台 job 后,任务不再随 HTTP 请求存活——
|
|
2029
|
+
// 刷新/重开页面时后端可能仍在下载。这里主动探一次,把「正在跑的克隆」
|
|
2030
|
+
// 重新接回进度条与轮询,避免用户以为任务没了而重复发起(会被互斥拒绝)。
|
|
2031
|
+
void this.resumeCloneIfRunning();
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
/**
|
|
2035
|
+
* 页面加载/刷新后接续**仍在后台跑的克隆**(克隆后台化配套)。
|
|
2036
|
+
*
|
|
2037
|
+
* 只在 idle/done 之外做动作:running → 恢复进度条并重启轮询;
|
|
2038
|
+
* done → 如实回显终态(说明上次任务已结束);idle → 什么都不做。
|
|
2039
|
+
*/
|
|
2040
|
+
async resumeCloneIfRunning() {
|
|
2041
|
+
if (this.repoBusy) return; // 已有交互在进行(含本页面自己发起的 clone),不抢
|
|
2042
|
+
let st;
|
|
2043
|
+
try {
|
|
2044
|
+
st = await dshgp_postJson('/api/git-push/clone-progress', {});
|
|
2045
|
+
} catch { return; /* 探测失败静默:下次刷新再试 */ }
|
|
2046
|
+
if (!st || st.state !== 'running' || !st.progress) return;
|
|
2047
|
+
const p = st.progress;
|
|
2048
|
+
this.cloneProgress = p;
|
|
2049
|
+
this.repoBusy = dshgp_BUSY_CLONE + (p.target || '');
|
|
2050
|
+
this.cloudMsg = '⏳ 后台克隆进行中:' + (p.target || '') + ' → ' + (p.dest || '');
|
|
2051
|
+
this.publish();
|
|
2052
|
+
// 重启轮询直到终态(与 cloneConfirmed 同一收敛逻辑,故此处只做等待)
|
|
2053
|
+
if (this._cloneResumeTimer) clearInterval(this._cloneResumeTimer);
|
|
2054
|
+
this._cloneResumeTimer = setInterval(async () => {
|
|
2055
|
+
try {
|
|
2056
|
+
const s2 = await dshgp_postJson('/api/git-push/clone-progress', {});
|
|
2057
|
+
if (s2 && s2.state === 'running' && s2.progress) {
|
|
2058
|
+
this.cloneProgress = s2.progress;
|
|
2059
|
+
this.publish();
|
|
2060
|
+
return;
|
|
2061
|
+
}
|
|
2062
|
+
if (s2 && s2.state === 'done') {
|
|
2063
|
+
const fin = await dshgp_postJson('/api/git-push/clone-progress', { consume: true });
|
|
2064
|
+
const res = (fin && fin.result) || (s2 && s2.result) || null;
|
|
2065
|
+
this.cloudMsg = res && res.ok
|
|
2066
|
+
? '✅ 已克隆 ' + (p.target || '') + ' → ' + (res.dest || p.dest || '')
|
|
2067
|
+
: '❌ ' + ((res && res.error) || '克隆失败');
|
|
2068
|
+
} else if (s2 && s2.state === 'idle') {
|
|
2069
|
+
this.cloudMsg = '⚠️ 克隆任务已不存在(可能插件进程重启过),请重新发起';
|
|
2070
|
+
} else {
|
|
2071
|
+
return; // 未知态:继续轮询,不误判
|
|
2072
|
+
}
|
|
2073
|
+
clearInterval(this._cloneResumeTimer);
|
|
2074
|
+
this._cloneResumeTimer = null;
|
|
2075
|
+
this.cloneProgress = null;
|
|
2076
|
+
this.repoBusy = '';
|
|
2077
|
+
this.publish();
|
|
2078
|
+
} catch { /* 轮询失败不中断 */ }
|
|
2079
|
+
}, 1000);
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
async loadSettingsFromHttp() {
|
|
2083
|
+
try {
|
|
2084
|
+
const settingsRes = await dshgp_getJson('/api/git-push/settings-get');
|
|
2085
|
+
if (!settingsRes || !settingsRes.ok || !settingsRes.settings) return;
|
|
2086
|
+
const v = settingsRes.settings;
|
|
2087
|
+
if (typeof v.auditEnabled === 'boolean' && !this.editedKeys.has('auditEnabled')) this.auditEnabled = v.auditEnabled;
|
|
2088
|
+
if (typeof v.injectRequirements === 'boolean' && !this.editedKeys.has('injectRequirements')) this.injectRequirements = v.injectRequirements;
|
|
2089
|
+
if (typeof v.injectSystemPrompt === 'boolean' && !this.editedKeys.has('injectSystemPrompt')) this.injectSystemPrompt = v.injectSystemPrompt;
|
|
2090
|
+
if (typeof v.auditScanScope === 'string' && !this.editedKeys.has('auditScanScope')) this.auditScanScope = v.auditScanScope;
|
|
2091
|
+
// 补齐回读:新增 UI 的 7 键(advanced),重启后从 config.json 恢复勾选/取值
|
|
2092
|
+
if (typeof v.maxScanFiles === 'number' && !this.editedKeys.has('maxScanFiles')) this.maxScanFiles = v.maxScanFiles;
|
|
2093
|
+
if (typeof v.maxCloneFileMB === 'number' && !this.editedKeys.has('maxCloneFileMB')) this.maxCloneFileMB = v.maxCloneFileMB;
|
|
2094
|
+
if (typeof v.cloneConcurrency === 'number' && !this.editedKeys.has('cloneConcurrency')) this.cloneConcurrency = v.cloneConcurrency;
|
|
2095
|
+
if (typeof v.pushMethod === 'string' && !this.editedKeys.has('pushMethod')) this.pushMethod = v.pushMethod;
|
|
2096
|
+
// 补漏:pushGate(推送门禁)此前**不在回读列表**——构造函数默认 false,
|
|
2097
|
+
// 打开/刷新设置页时不被宿主真值覆盖,界面永远显示未勾选(实测:勾了门禁、重开页面又变未勾选)。
|
|
2098
|
+
if (typeof v.pushGate === 'boolean' && !this.editedKeys.has('pushGate')) this.pushGate = v.pushGate;
|
|
2099
|
+
// defaultScanRoot/commitMessage 不再作为设置键回读(已在 UI/白名单移除)
|
|
2100
|
+
if (typeof v.weightOverrides === 'string' && v.weightOverrides.trim() && !this.editedKeys.has('weightOverrides')) {
|
|
2101
|
+
try { this.weightValues = JSON.parse(v.weightOverrides) || {}; } catch { /* 忽略 */ }
|
|
2102
|
+
}
|
|
2103
|
+
// 凭据布尔位不受编辑守卫影响:只读派生标记,无回弹风险
|
|
2104
|
+
if (typeof v.tokenConfigured === 'boolean') this.tokenConfigured = v.tokenConfigured;
|
|
2105
|
+
if (typeof v.sshConfigured === 'boolean') this.sshConfigured = v.sshConfigured;
|
|
2106
|
+
this.publish();
|
|
2107
|
+
} catch (_e) { /* 端点不可用/未注册时沿用 scope 兜底 */ }
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
/** 加载规则包清单(/rule-slots,动态发现 yml)。 */
|
|
2111
|
+
// 重构:原 loadCredentialFlags(/status 只刷 tokenConfigured)删除——
|
|
2112
|
+
// 凭据标志统一由 refreshAccount(/account-check,读凭据文件真源)刷新,避免第三条链路打架。
|
|
2113
|
+
async loadSlots({ silent = false } = {}) {
|
|
2114
|
+
if (!silent) { this.slotLoading = true; }
|
|
2115
|
+
this.slotError = '';
|
|
2116
|
+
this.publish();
|
|
2117
|
+
try {
|
|
2118
|
+
const slotsRes = await dshgp_getJson('/api/git-push/rule-slots');
|
|
2119
|
+
if (slotsRes && slotsRes.ok && slotsRes.slots) {
|
|
2120
|
+
const meta = slotsRes.slots.meta || {};
|
|
2121
|
+
// 用后端返回的生效顺序;private 恒末尾
|
|
2122
|
+
const list = Array.isArray(slotsRes.slots.order) ? slotsRes.slots.order : [];
|
|
2123
|
+
const order = list.filter((s) => s !== 'template');
|
|
2124
|
+
const forced = Array.isArray(slotsRes.slots.forced) ? slotsRes.slots.forced : [];
|
|
2125
|
+
this.slotMeta = meta;
|
|
2126
|
+
this.ruleOrder = order;
|
|
2127
|
+
if (forced.includes('private') && !this.ruleOrder.includes('private')) this.ruleOrder.push('private');
|
|
2128
|
+
} else {
|
|
2129
|
+
this.slotError = (slotsRes && slotsRes.message) || '规则包加载失败';
|
|
2130
|
+
}
|
|
2131
|
+
} catch (e) {
|
|
2132
|
+
this.slotError = '规则包加载失败: ' + (e && e.message || e);
|
|
2133
|
+
}
|
|
2134
|
+
this.slotLoading = false;
|
|
2135
|
+
this.publish();
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
/** 离线读 npm 账号态(/npm-account,秒级不联网);与 refreshAccount 完全同构。 */
|
|
2139
|
+
async refreshNpmAccount({ silent = false } = {}) {
|
|
2140
|
+
if (!silent) { this.npmAccountLoading = true; }
|
|
2141
|
+
this.publish();
|
|
2142
|
+
try {
|
|
2143
|
+
const res = await dshgp_getJson('/api/git-push/npm-account');
|
|
2144
|
+
this.npmAccountBlock = (res && res.block) || '(无 npm 账号记录,点「刷新」在线校验)';
|
|
2145
|
+
this.npmAccountLoggedIn = !!(res && res.loggedIn);
|
|
2146
|
+
this.npmAccountUser = (res && res.user) || '';
|
|
2147
|
+
this.npmConfigured = !!(res && res.configured);
|
|
2148
|
+
} catch (e) {
|
|
2149
|
+
this.npmAccountBlock = '读取失败: ' + ((e && e.message) || e);
|
|
2150
|
+
this.npmAccountLoggedIn = false;
|
|
2151
|
+
this.npmAccountUser = '';
|
|
2152
|
+
}
|
|
2153
|
+
this.npmAccountLoading = false;
|
|
2154
|
+
this.publish();
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
/** 在线校验 npm 登录态并写快照(/npm-check);与 recheckAccount 完全同构。 */
|
|
2158
|
+
async recheckNpmAccount() {
|
|
2159
|
+
if (this.npmAccountLoading) return;
|
|
2160
|
+
this.npmAccountLoading = true;
|
|
2161
|
+
this.publish();
|
|
2162
|
+
try {
|
|
2163
|
+
const res = await dshgp_postJson('/api/git-push/npm-check', {});
|
|
2164
|
+
if (res && res.block) this.npmAccountBlock = res.block;
|
|
2165
|
+
this.npmAccountLoggedIn = !!(res && res.loggedIn);
|
|
2166
|
+
this.npmAccountUser = (res && res.user) || '';
|
|
2167
|
+
this.npmConfigured = !!(res && res.configured);
|
|
2168
|
+
} catch (e) {
|
|
2169
|
+
this.npmAccountBlock = '⏳ 在线校验失败(网络超时或未配置),可稍后重试:' + ((e && e.message) || e);
|
|
2170
|
+
this.npmAccountLoggedIn = false;
|
|
2171
|
+
}
|
|
2172
|
+
this.npmAccountLoading = false;
|
|
2173
|
+
this.publish();
|
|
2174
|
+
// 校验成功后顺带刷新「账号名下的包」列表(与 GitHub push 后重读云端列表同一节奏)
|
|
2175
|
+
if (this.npmAccountLoggedIn) await this.loadNpmOwned({ silent: true });
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
/** 安装流程第一段(入口):点列表行「安装」⇒ 弹选择(目录 / 全局),与 GitHub 克隆同款入口。 */
|
|
2179
|
+
openInstallFlow(pkg) {
|
|
2180
|
+
const name = String(pkg || '').trim();
|
|
2181
|
+
if (!name) return;
|
|
2182
|
+
this.npmInstallDialog = { name };
|
|
2183
|
+
this.npmInstallResult = null;
|
|
2184
|
+
this.publish();
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
/** 取消选择对话框。 */
|
|
2188
|
+
cancelInstallDialog() {
|
|
2189
|
+
this.npmInstallDialog = null;
|
|
2190
|
+
this.publish();
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
/** 选择段①:打开目录选择器(与 clone 同款 dshgp_browseOpen(input, onPick)),选完即开始安装。 */
|
|
2194
|
+
chooseInstallDir() {
|
|
2195
|
+
const name = (this.npmInstallDialog && this.npmInstallDialog.name) || '';
|
|
2196
|
+
if (!name) return;
|
|
2197
|
+
if (typeof dshgp_browseOpen !== 'function') {
|
|
2198
|
+
this.npmInstallResult = { ok: false, error: '目录选择器不可用' };
|
|
2199
|
+
this.npmInstallDialog = null;
|
|
2200
|
+
this.publish();
|
|
2201
|
+
return;
|
|
2202
|
+
}
|
|
2203
|
+
dshgp_browseOpen(null, (picked) => { void this.startInstallTo({ name, dir: String(picked || '') }); });
|
|
2204
|
+
}
|
|
2205
|
+
|
|
2206
|
+
/** 选择段②:确认全局安装(-g,会影响宿主 node 环境)。 */
|
|
2207
|
+
confirmInstallGlobal() {
|
|
2208
|
+
const name = (this.npmInstallDialog && this.npmInstallDialog.name) || '';
|
|
2209
|
+
if (!name) return;
|
|
2210
|
+
void this.startInstallTo({ name, global: true });
|
|
2211
|
+
}
|
|
2212
|
+
|
|
2213
|
+
/** 起安装(异步)+ 开始轮询进度;启动失败直接落回执。 */
|
|
2214
|
+
async startInstallTo({ name = '', dir = '', global = false } = {}) {
|
|
2215
|
+
const pkg = String(name || '').trim();
|
|
2216
|
+
if (!pkg) return;
|
|
2217
|
+
this.npmInstallDialog = null;
|
|
2218
|
+
this.npmInstallBusy = pkg;
|
|
2219
|
+
this.npmInstallProgress = { state: 'running', name: pkg, lines: [], startedAt: Date.now() };
|
|
2220
|
+
this.publish();
|
|
2221
|
+
try {
|
|
2222
|
+
const res = await dshgp_postJson('/api/git-push/npm-install', {
|
|
2223
|
+
names: [pkg], dest: global ? '' : dir, global, ignoreScripts: true, confirm: true, async: true,
|
|
2224
|
+
});
|
|
2225
|
+
if (!res || res.ok === false || res.started !== true) {
|
|
2226
|
+
this.npmInstallResult = res || { ok: false, error: '启动安装失败' };
|
|
2227
|
+
this.npmInstallBusy = '';
|
|
2228
|
+
this.npmInstallProgress = null;
|
|
2229
|
+
this.publish();
|
|
2230
|
+
return;
|
|
2231
|
+
}
|
|
2232
|
+
this.pollInstallProgress();
|
|
2233
|
+
} catch (e) {
|
|
2234
|
+
this.npmInstallResult = { ok: false, error: String((e && e.message) || e) };
|
|
2235
|
+
this.npmInstallBusy = '';
|
|
2236
|
+
this.npmInstallProgress = null;
|
|
2237
|
+
}
|
|
2238
|
+
this.publish();
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
/** 进度段:轮询 /npm-install-progress(对应 clone 的轮询),终态取回执并清表。 */
|
|
2242
|
+
pollInstallProgress() {
|
|
2243
|
+
if (this.npmInstallTimer) return;
|
|
2244
|
+
const tick = async () => {
|
|
2245
|
+
try {
|
|
2246
|
+
const st = await dshgp_postJson('/api/git-push/npm-install-progress', {});
|
|
2247
|
+
const p = st && st.progress;
|
|
2248
|
+
if (!p) return;
|
|
2249
|
+
this.npmInstallProgress = p;
|
|
2250
|
+
if (p.state !== 'running') {
|
|
2251
|
+
this.clearInstallTimer();
|
|
2252
|
+
this.npmInstallBusy = '';
|
|
2253
|
+
this.npmInstallResult = {
|
|
2254
|
+
ok: p.state === 'done', state: p.state, tail: p.tail || '',
|
|
2255
|
+
lines: p.lines || [], logPath: p.logPath || '', error: p.error || '',
|
|
2256
|
+
};
|
|
2257
|
+
await this.loadNpmOwned({ silent: true }); // 安装后同源刷新(与 clone 完成后重读同一节奏)
|
|
2258
|
+
await this.refresh('repos');
|
|
2259
|
+
}
|
|
2260
|
+
this.publish();
|
|
2261
|
+
} catch { /* 单次轮询失败不致命,下一拍重试 */ }
|
|
2262
|
+
};
|
|
2263
|
+
this.npmInstallTimer = setInterval(() => { void tick(); }, 1200);
|
|
2264
|
+
void tick();
|
|
2265
|
+
}
|
|
2266
|
+
|
|
2267
|
+
/** 清理进度轮询定时器(终态必须调,防定时器泄漏)。 */
|
|
2268
|
+
clearInstallTimer() {
|
|
2269
|
+
if (this.npmInstallTimer) {
|
|
2270
|
+
clearInterval(this.npmInstallTimer);
|
|
2271
|
+
this.npmInstallTimer = null;
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
|
|
2275
|
+
/**
|
|
2276
|
+
* 安装一个包(/npm-install)。二次确认由 UI 负责;此处固定安全默认:
|
|
2277
|
+
* 默认不执行安装脚本(ignoreScripts)、默认非全局(除非 UI 显式传 global:true)。
|
|
2278
|
+
* 失败不抛错,回执写进 npmInstallResult 供 UI 展示(含日志路径)。
|
|
2279
|
+
*/
|
|
2280
|
+
async installNpmPackage({ name = '', dest = '', global = false, ignoreScripts = true } = {}) {
|
|
2281
|
+
const pkg = String(name || '').trim();
|
|
2282
|
+
if (!pkg || this.npmInstallBusy) return;
|
|
2283
|
+
this.npmInstallBusy = pkg;
|
|
2284
|
+
this.publish();
|
|
2285
|
+
try {
|
|
2286
|
+
const res = await dshgp_postJson('/api/git-push/npm-install', {
|
|
2287
|
+
names: [pkg], dest: String(dest || ''), global: !!global, ignoreScripts: !!ignoreScripts, confirm: true,
|
|
2288
|
+
}, 320000);
|
|
2289
|
+
this.npmInstallResult = res || null;
|
|
2290
|
+
// 包安装到工作区依赖后,本地面板同源重读(与 GitHub push 后重读云端列表同一节奏)
|
|
2291
|
+
if (res && res.ok) await this.refresh('repos');
|
|
2292
|
+
} catch (e) {
|
|
2293
|
+
this.npmInstallResult = { ok: false, error: String((e && e.message) || e) };
|
|
2294
|
+
}
|
|
2295
|
+
this.npmInstallBusy = '';
|
|
2296
|
+
this.publish();
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2299
|
+
/** 拉取登录账号名下的包(/npm-owned);未登录或失败 ⇒ 空列表 + 可读提示(不抛错)。 */
|
|
2300
|
+
async loadNpmOwned({ silent = false } = {}) {
|
|
2301
|
+
if (!silent) { this.npmOwnedLoading = true; this.publish(); }
|
|
2302
|
+
try {
|
|
2303
|
+
const res = await dshgp_getJson('/api/git-push/npm-owned');
|
|
2304
|
+
this.npmOwned = (res && Array.isArray(res.results)) ? res.results : [];
|
|
2305
|
+
this.npmOwnedError = (res && res.error) || '';
|
|
2306
|
+
} catch (e) {
|
|
2307
|
+
this.npmOwned = [];
|
|
2308
|
+
this.npmOwnedError = String((e && e.message) || e);
|
|
2309
|
+
}
|
|
2310
|
+
this.npmOwnedLoading = false;
|
|
2311
|
+
this.publish();
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
/** 刷新账号信息(/account-check,读凭据文件真源;同时刷新凭据徽标)。 */
|
|
2315
|
+
/** 离线读账号状态(秒级,不触发任何网络):读 account-status.json 快照 + 凭据文件。
|
|
2316
|
+
* 插件启动 / push 后重读 / 账号卡片渲染全用它。「重新检测」才走在线(recheckAccount)。 */
|
|
2317
|
+
async refreshAccount({ silent = false } = {}) {
|
|
2318
|
+
if (!silent) { this.accountLoading = true; }
|
|
2319
|
+
this.publish();
|
|
2320
|
+
try {
|
|
2321
|
+
const accountRes = await dshgp_getJson('/api/git-push/account-status');
|
|
2322
|
+
this.accountBlock = (accountRes && accountRes.block) || '(无账号状态记录,点击「重新检测」在线校验)';
|
|
2323
|
+
this.accountLoggedIn = !!(accountRes && accountRes.loggedIn);
|
|
2324
|
+
this.tokenConfigured = !!(accountRes && accountRes.tokenConfigured);
|
|
2325
|
+
this.sshConfigured = !!(accountRes && accountRes.sshConfigured);
|
|
2326
|
+
this.tokenStatus = (accountRes && accountRes.tokenStatus) || null;
|
|
2327
|
+
this.sshStatus = (accountRes && accountRes.sshStatus) || null;
|
|
2328
|
+
this.apiQuota = (accountRes && accountRes.apiQuota) || null;
|
|
2329
|
+
} catch (e) {
|
|
2330
|
+
this.accountBlock = '读取失败: ' + (e && e.message || e);
|
|
2331
|
+
this.accountLoggedIn = false;
|
|
2332
|
+
}
|
|
2333
|
+
this.accountLoading = false;
|
|
2334
|
+
this.publish();
|
|
2335
|
+
// token 配额刷新(异步、不阻塞凭据显示):查 /api-quota(后端写回快照)→ 按
|
|
2336
|
+
// statusUpdated 标志重读 account-status,使凭据块 Token 行出现「(配额剩余 N/h)」。
|
|
2337
|
+
// 查询本身失败不影响凭据展示;落盘失败由 quotaError 记录(不再静默)。
|
|
2338
|
+
this.refreshApiQuota();
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
// 刷新 token 的 GitHub API 配额(异步):查 /api/git-push/api-quota → 按收口标志重读快照。
|
|
2342
|
+
// 后端 60 秒缓存 + 进行中防抖,避免打开设置页时反复打 GitHub。
|
|
2343
|
+
// 收口约定:后端写 account-status 成功后回 statusUpdated=true;命中缓存回 cached=true
|
|
2344
|
+
// (表示此前已落盘)——只有这两种情况才重读 account-status(不再无条件拉)。
|
|
2345
|
+
// 写失败回 statusError 时如实记到 quotaError,同时仍用本次返回值渲染(配额是增强信息,
|
|
2346
|
+
// 不因落盘失败就不显示,但也不再静默吞掉失败原因)。
|
|
2347
|
+
async refreshApiQuota() {
|
|
2348
|
+
if (this.quotaLoading) return;
|
|
2349
|
+
this.quotaLoading = true;
|
|
2350
|
+
try {
|
|
2351
|
+
const quotaResp = await dshgp_getJson('/api/git-push/api-quota');
|
|
2352
|
+
if (quotaResp && quotaResp.ok) {
|
|
2353
|
+
// 本次响应就是最新配额(落盘失败也照常展示)
|
|
2354
|
+
this.apiQuota = { core: quotaResp.core, search: quotaResp.search, graphql: quotaResp.graphql, codeSearch: quotaResp.codeSearch, checkedAt: quotaResp.fetchedAt };
|
|
2355
|
+
this.quotaError = quotaResp.statusError ? String(quotaResp.statusError) : '';
|
|
2356
|
+
if (quotaResp.statusUpdated || quotaResp.cached) {
|
|
2357
|
+
const res = await dshgp_getJson('/api/git-push/account-status');
|
|
2358
|
+
if (res && res.block) this.accountBlock = res.block;
|
|
2359
|
+
}
|
|
2360
|
+
this.publish();
|
|
2361
|
+
}
|
|
2362
|
+
} catch { /* 配额查询失败静默(凭据块仍正常显示) */ }
|
|
2363
|
+
this.quotaLoading = false;
|
|
2364
|
+
}
|
|
2365
|
+
|
|
2366
|
+
/** 「重新检测」:在线校验 token/SSH → 写 account-status.json → 再离线读回最新。
|
|
2367
|
+
* 仅手动点按钮触发(在线有网络耗时 1~4s),读取端仍走离线 refreshAccount。 */
|
|
2368
|
+
async recheckAccount() {
|
|
2369
|
+
// 防抖:连点会连发在线请求(GitHub /user 有速率限制),
|
|
2370
|
+
// 触发限流后反而更容易超时,表现为「点了没反应」。进行中直接忽略重复点击。
|
|
2371
|
+
if (this.accountLoading) return;
|
|
2372
|
+
this.accountLoading = true;
|
|
2373
|
+
this.publish();
|
|
2374
|
+
try {
|
|
2375
|
+
const res = await dshgp_postJson('/api/git-push/account-check', { checkSsh: true, confirm: false });
|
|
2376
|
+
// 超时 ≠ 失效:网络没测成时如实说明可重试,不写成「检测失败」吓人
|
|
2377
|
+
const ts = (res && res.tokenStatus) || {};
|
|
2378
|
+
const ss = (res && res.sshStatus) || {};
|
|
2379
|
+
if (!ts.valid && ts.timeout) {
|
|
2380
|
+
this.accountBlock = '⏳ 在线校验未完成(网络超时,可稍后重试);SSH 状态:' + (ss.valid ? '✅ 可用' : '未验证');
|
|
2381
|
+
}
|
|
2382
|
+
} catch (e) {
|
|
2383
|
+
this.accountBlock = '在线检测失败: ' + (e && e.message || e);
|
|
2384
|
+
}
|
|
2385
|
+
await this.refreshAccount(); // 离线读回在线校验落盘的 json
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
/** 扫描本地仓库(列表只从 dsh-repo-index.json 读取)。
|
|
2389
|
+
* rebuild=true:**离线重建索引**(扫描本地 .git,author 与离线账号 json 一致的登记,
|
|
2390
|
+
* 含本地新增,全程不联网)后再读回;缺省:直接读索引返回(不复扫、不联网)。 */
|
|
2391
|
+
async scanLocalRepos(path, rebuild, { silent = false } = {}) {
|
|
2392
|
+
if (!silent) { this.localLoading = true; }
|
|
2393
|
+
this.localMsg = '';
|
|
2394
|
+
this.publish();
|
|
2395
|
+
try {
|
|
2396
|
+
const p = String(path || '').trim();
|
|
2397
|
+
dshgp_localSet('dshgp-scan-path', p);
|
|
2398
|
+
const qs = '?rebuild=' + (rebuild ? '1' : '0') + (p ? '&path=' + encodeURIComponent(p) : '');
|
|
2399
|
+
const localRes = await dshgp_getJson('/api/git-push/repos-local' + qs);
|
|
2400
|
+
if (localRes && localRes.ok) {
|
|
2401
|
+
this.localPath = localRes.root || p;
|
|
2402
|
+
this.localRepos = Array.isArray(localRes.repos) ? localRes.repos : [];
|
|
2403
|
+
this.localMsg = this.localRepos.length
|
|
2404
|
+
? (rebuild ? '已重建索引,读取到 ' : '读取到 ') + this.localRepos.length + ' 个仓库(' + (localRes.root || '') + ')'
|
|
2405
|
+
: '索引中没有本账号仓库: ' + (localRes.root || '');
|
|
2406
|
+
} else {
|
|
2407
|
+
this.localRepos = [];
|
|
2408
|
+
this.localMsg = '❌ ' + ((localRes && localRes.error) || '读取失败');
|
|
2409
|
+
}
|
|
2410
|
+
} catch (e) {
|
|
2411
|
+
this.localRepos = [];
|
|
2412
|
+
this.localMsg = '❌ 读取失败: ' + (e && e.message || e);
|
|
2413
|
+
}
|
|
2414
|
+
this.localLoading = false;
|
|
2415
|
+
this.publish();
|
|
2416
|
+
// 读取/扫描收尾后**自动补查未知远端状态**——列表里 liveSkipped(本地列表预算/
|
|
2417
|
+
// 熔断导致 SSH 探测跳过)的仓库,串行向后端补查(SSH 真源),结果追加写回索引,
|
|
2418
|
+
// 同时刷新本地列表的远端状态(remoteHead/ahead/behind/remoteHeadAt/synced)。
|
|
2419
|
+
void this.refreshUnknownRemote();
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
/** 自动补查 liveSkipped(未知远端状态)仓库:串行走 /repos-local-refresh,更新列表条目。 */
|
|
2423
|
+
async refreshUnknownRemote() {
|
|
2424
|
+
if (this.refreshingRemote) return; // 防重入
|
|
2425
|
+
const skips = (this.localRepos || []).filter((r) => r.liveSkipped === true && r.path);
|
|
2426
|
+
if (!skips.length) return;
|
|
2427
|
+
this.refreshingRemote = true;
|
|
2428
|
+
try {
|
|
2429
|
+
const body = { repos: skips.map((r) => ({ name: r.name, path: r.path, branch: r.branch || '' })) };
|
|
2430
|
+
const res = await dshgp_postJson('/api/git-push/repos-local-refresh', body);
|
|
2431
|
+
const refreshed = (res && Array.isArray(res.refreshed)) ? res.refreshed : [];
|
|
2432
|
+
if (refreshed.length) {
|
|
2433
|
+
// 把补查结果合并进本地列表(按 name 匹配)
|
|
2434
|
+
const byName = new Map(refreshed.filter((r) => r.ok).map((r) => [r.name, r.remoteState || {}]));
|
|
2435
|
+
if (byName.size) {
|
|
2436
|
+
this.localRepos = (this.localRepos || []).map((r) => {
|
|
2437
|
+
const st = byName.get(r.name);
|
|
2438
|
+
if (!st) return r;
|
|
2439
|
+
return Object.assign({}, r, {
|
|
2440
|
+
remoteHead: st.remoteHead ?? r.remoteHead,
|
|
2441
|
+
ahead: st.ahead ?? r.ahead,
|
|
2442
|
+
behind: st.behind ?? r.behind,
|
|
2443
|
+
remoteHeadAt: st.remoteHeadAt ?? r.remoteHeadAt,
|
|
2444
|
+
synced: st.synced ?? r.synced,
|
|
2445
|
+
liveSkipped: false, // 补查完成,不再是未知
|
|
2446
|
+
});
|
|
2447
|
+
});
|
|
2448
|
+
this.publish();
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
} catch { /* 补查失败静默(下次读取再补) */ }
|
|
2452
|
+
this.refreshingRemote = false;
|
|
2453
|
+
}
|
|
2454
|
+
|
|
2455
|
+
/** 手动「扫描」= 独立进程后台离线扫描 + 只读新增 diff。
|
|
2456
|
+
* 流程:① POST repos-local-scan 让后端 spawn 独立进程(扫描中按钮禁用,不可重复点);
|
|
2457
|
+
* ② 循环 POST repos-local-scan-wait 等待「有新仓库」(非轮询,文件变化才唤醒);
|
|
2458
|
+
* ③ 每次只把新增仓库**追加**进列表(不全量重读),直到扫描 done;
|
|
2459
|
+
* ④ done 后恢复按钮,最后按索引读一次对齐(收尾)。 */
|
|
2460
|
+
async startScan(path) {
|
|
2461
|
+
if (this.localScanning) return; // 扫描中不可重复点
|
|
2462
|
+
const p = String(path || '').trim();
|
|
2463
|
+
dshgp_localSet('dshgp-scan-path', p);
|
|
2464
|
+
this.localScanning = true;
|
|
2465
|
+
this.localMsg = '⏳ 扫描中…(后台独立进程,扫到一个追加一个)';
|
|
2466
|
+
this.publish();
|
|
2467
|
+
let seen = this.localRepos.length;
|
|
2468
|
+
try {
|
|
2469
|
+
const started = await dshgp_postJson('/api/git-push/repos-local-scan', { path: p });
|
|
2470
|
+
if (started && started.running && started.ok === false) {
|
|
2471
|
+
this.localMsg = '⚠️ ' + (started.error || '扫描进行中,不能重复扫描');
|
|
2472
|
+
return;
|
|
2473
|
+
}
|
|
2474
|
+
// 循环等待新增:每次 wait 挂起直到独立进程写了新进度(非轮询)
|
|
2475
|
+
for (let i = 0; i < dshgp_SCAN_WAIT_MAX_ROUNDS; i += 1) {
|
|
2476
|
+
const waitRes = await dshgp_postJson('/api/git-push/repos-local-scan-wait', { from: seen });
|
|
2477
|
+
const newest = (waitRes && waitRes.newest) || [];
|
|
2478
|
+
if (newest.length) {
|
|
2479
|
+
// 只追加新增:从索引取这几条详情(不全量重读列表)
|
|
2480
|
+
await this.appendScannedRepos(newest);
|
|
2481
|
+
seen += newest.length;
|
|
2482
|
+
this.localMsg = '⏳ 扫描中… 已发现 ' + seen + ' 个仓库';
|
|
2483
|
+
this.publish();
|
|
2484
|
+
}
|
|
2485
|
+
if (waitRes && waitRes.done) break;
|
|
2486
|
+
if (!waitRes || waitRes.running === false) break;
|
|
2487
|
+
}
|
|
2488
|
+
} catch (e) {
|
|
2489
|
+
this.localMsg = '❌ 扫描失败: ' + (e && e.message || e);
|
|
2490
|
+
}
|
|
2491
|
+
this.localScanning = false;
|
|
2492
|
+
// 收尾:按索引读一次对齐(保证领先/落后等字段完整)
|
|
2493
|
+
await this.scanLocalRepos(p, false);
|
|
2494
|
+
this.localMsg = '✅ 扫描完成,读取到 ' + this.localRepos.length + ' 个仓库';
|
|
2495
|
+
this.publish();
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
/** 只把「新增仓库名」对应的条目追加进列表(增量,不全量重建)。 */
|
|
2499
|
+
async appendScannedRepos(names) {
|
|
2500
|
+
try {
|
|
2501
|
+
const indexRes = await dshgp_getJson('/api/git-push/repos-local');
|
|
2502
|
+
const all = (indexRes && Array.isArray(indexRes.repos)) ? indexRes.repos : [];
|
|
2503
|
+
const have = new Set(this.localRepos.map((r) => r.name));
|
|
2504
|
+
for (const n of names) {
|
|
2505
|
+
if (have.has(n)) continue;
|
|
2506
|
+
const hit = all.find((r) => r.name === n);
|
|
2507
|
+
if (hit) { this.localRepos = this.localRepos.concat([hit]); have.add(n); }
|
|
2508
|
+
}
|
|
2509
|
+
} catch { /* 读取失败保留已追加 */ }
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
/** 拉取云端仓库列表(/repos-cloud,token 列账号名下仓库)。 */
|
|
2513
|
+
async loadCloudRepos({ silent = false } = {}) {
|
|
2514
|
+
if (!silent) { this.cloudLoading = true; }
|
|
2515
|
+
this.cloudMsg = '';
|
|
2516
|
+
this.publish();
|
|
2517
|
+
try {
|
|
2518
|
+
const cloudRes = await dshgp_getJson('/api/git-push/repos-cloud');
|
|
2519
|
+
if (cloudRes && cloudRes.ok) {
|
|
2520
|
+
this.cloudRepos = Array.isArray(cloudRes.repos) ? cloudRes.repos : [];
|
|
2521
|
+
// 云端扫描同时写索引(后端 mergeCloudReposIntoIndex),提示已刷新条数
|
|
2522
|
+
const idxHint = cloudRes.indexUpdated ? ',索引已刷新 ' + cloudRes.indexUpdated + ' 条' : '';
|
|
2523
|
+
this.cloudMsg = '共 ' + this.cloudRepos.length + ' 个仓库(按最近更新排序)' + idxHint;
|
|
2524
|
+
// 云端获取后**重新读索引刷新本地列表**——后端已把云端仓库(含
|
|
2525
|
+
// defaultBranch/pushedAt/visibility 云端真源)写进 dsh-repo-index.json,
|
|
2526
|
+
// 侧边栏本地面板的远端状态(默认分支/云端更新/仅云端标记)随之更新。
|
|
2527
|
+
void this.scanLocalRepos(this.localPath, false);
|
|
2528
|
+
} else {
|
|
2529
|
+
this.cloudRepos = [];
|
|
2530
|
+
this.cloudMsg = '❌ ' + ((data && data.error) || '拉取失败');
|
|
2531
|
+
}
|
|
2532
|
+
} catch (e) {
|
|
2533
|
+
this.cloudRepos = [];
|
|
2534
|
+
this.cloudMsg = '❌ 拉取失败: ' + (e && e.message || e);
|
|
2535
|
+
}
|
|
2536
|
+
this.cloudLoading = false;
|
|
2537
|
+
this.publish();
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2540
|
+
/** 本地仓库手动 push(领先 + 工作树干净才允许,后端校验)。 */
|
|
2541
|
+
async pushLocalRepo(path) {
|
|
2542
|
+
this.repoBusy = dshgp_BUSY_PUSH + path;
|
|
2543
|
+
this.publish();
|
|
2544
|
+
let ok = false;
|
|
2545
|
+
let msg = '';
|
|
2546
|
+
try {
|
|
2547
|
+
const pushRes = await dshgp_postJson('/api/git-push/repo-push', { path, confirm: true });
|
|
2548
|
+
ok = !!(pushRes && pushRes.ok);
|
|
2549
|
+
if (ok) {
|
|
2550
|
+
msg = '✅ 推送成功 ' + path;
|
|
2551
|
+
} else {
|
|
2552
|
+
// 显示详细错误信息(含 ahead/behind)
|
|
2553
|
+
const err = (pushRes && (pushRes.error || (pushRes.push && pushRes.push.reason))) || '推送失败';
|
|
2554
|
+
const extra = [];
|
|
2555
|
+
if (pushRes && pushRes.ahead > 0) extra.push('领先 ' + pushRes.ahead);
|
|
2556
|
+
if (pushRes && pushRes.behind > 0) extra.push('落后 ' + pushRes.behind);
|
|
2557
|
+
msg = '⚠️ ' + err + (extra.length ? '(' + extra.join(',') + ')' : '');
|
|
2558
|
+
}
|
|
2559
|
+
this.localMsg = msg;
|
|
2560
|
+
} catch (e) {
|
|
2561
|
+
msg = '❌ 推送失败: ' + (e && e.message || e);
|
|
2562
|
+
this.localMsg = msg;
|
|
2563
|
+
}
|
|
2564
|
+
// push 反馈:行内绿/红醒目提示(成功/失败)
|
|
2565
|
+
this.repoFeedback = Object.assign({}, this.repoFeedback, { [path]: { ok, msg } });
|
|
2566
|
+
this.repoBusy = '';
|
|
2567
|
+
// 推送后自动刷新——本地仓库索引(后端维护 + 前列回读)与账号状态
|
|
2568
|
+
// (推送到云端后凭据有效性/登录关系可能变化,一并刷新)。
|
|
2569
|
+
void this.scanLocalRepos(this.localPath); // 刷新领先/落后状态
|
|
2570
|
+
if (ok) void this.refresh('account'); // push 后刷新账号信息
|
|
2571
|
+
this.publish();
|
|
2572
|
+
}
|
|
2573
|
+
|
|
2574
|
+
/** 本地仓库手动 commit(只提交不推送)——复用提交推送的本地提交审计。
|
|
2575
|
+
* 弹窗输入 commit message → POST /repo-commit → commitWithAudit(push:false)。
|
|
2576
|
+
* 精简返回:blocker → 「审计拦截」;warning → 附警告数;成功 → 「已提交 sha」。
|
|
2577
|
+
* @param {string} path 仓库绝对路径
|
|
2578
|
+
*/
|
|
2579
|
+
async commitLocalRepo(path) {
|
|
2580
|
+
const message = window.prompt('输入 commit message(本地提交;审计门禁通过才提交):', '');
|
|
2581
|
+
if (message === null || !String(message).trim()) return; // 用户取消
|
|
2582
|
+
this.repoBusy = 'commit:' + path;
|
|
2583
|
+
this.publish();
|
|
2584
|
+
let ok = false;
|
|
2585
|
+
let msg = '';
|
|
2586
|
+
try {
|
|
2587
|
+
const res = await dshgp_postJson('/api/git-push/repo-commit', { path, message: String(message).trim(), confirm: true });
|
|
2588
|
+
// post 封装返回 {data, msg...} 或直出 body;data.ok 为准
|
|
2589
|
+
const resp = (res && res.ok !== undefined) ? res : (res && res.data ? res.data : res);
|
|
2590
|
+
if (resp && resp.ok) {
|
|
2591
|
+
ok = true;
|
|
2592
|
+
const warnCount = resp.warningCount || 0;
|
|
2593
|
+
msg = '✅ 已提交' + (resp.commitSha ? ' ' + resp.commitSha : '') + (warnCount ? '(⚠️ ' + warnCount + ' 条 warning,见审计)' : '');
|
|
2594
|
+
} else if (resp && resp.blocked) {
|
|
2595
|
+
const list = (resp.blockers && resp.blockers.length ? resp.blockers.slice(0, 2).join(';') : (resp.error || '审计拦截'));
|
|
2596
|
+
msg = '🚫 审计拦截:' + list;
|
|
2597
|
+
} else {
|
|
2598
|
+
msg = '⚠️ ' + (resp && resp.error ? resp.error : '提交失败');
|
|
2599
|
+
}
|
|
2600
|
+
this.localMsg = msg;
|
|
2601
|
+
} catch (e) {
|
|
2602
|
+
msg = '❌ 提交失败: ' + (e && e.message || e);
|
|
2603
|
+
this.localMsg = msg;
|
|
2604
|
+
}
|
|
2605
|
+
this.repoFeedback = Object.assign({}, this.repoFeedback, { [path]: { ok, msg } });
|
|
2606
|
+
this.repoBusy = '';
|
|
2607
|
+
void this.scanLocalRepos(this.localPath); // 提交后未提交数变化,刷新列表
|
|
2608
|
+
this.publish();
|
|
2609
|
+
}
|
|
2610
|
+
|
|
2611
|
+
/**
|
|
2612
|
+
* 1.5.4:请求切换可见性——只记录待确认目标并弹**独立确认面板**(不直接调用后端)。
|
|
2613
|
+
* 真正切由 confirmVisSwitch 在用户点了「确认切换」后执行。
|
|
2614
|
+
* @param {string} fullName owner/repo
|
|
2615
|
+
* @param {string} target public | private
|
|
2616
|
+
*/
|
|
2617
|
+
requestVisSwitch(fullName, target) {
|
|
2618
|
+
if (this.repoBusy) return; // 已有交互(clone/push/切换)进行中,不弹
|
|
2619
|
+
const cur = this.cloudRepos.find((x) => String(x.fullName || '') === fullName);
|
|
2620
|
+
this.visConfirm = { fullName, target, cur: cur && cur.private ? 'private' : 'public' };
|
|
2621
|
+
this.publish();
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
/** 1.5.4:弹窗「确认切换」——按 visConfirm 记录执行切换,结束后关闭面板。 */
|
|
2625
|
+
async confirmVisSwitch() {
|
|
2626
|
+
const v = this.visConfirm;
|
|
2627
|
+
if (!v) return { ok: false, error: '无待确认的切换' };
|
|
2628
|
+
const res = await this.switchVisibility(v.fullName, v.target);
|
|
2629
|
+
this.visConfirm = null;
|
|
2630
|
+
this.publish();
|
|
2631
|
+
return res;
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
/** 1.5.4:弹窗「取消 / 关闭」——丢弃待确认目标。 */
|
|
2635
|
+
cancelVisSwitch() {
|
|
2636
|
+
if (this.visConfirm) {
|
|
2637
|
+
this.visConfirm = null;
|
|
2638
|
+
this.publish();
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
/**
|
|
2643
|
+
* 云端仓库私有/公开切换:POST repo-visibility(confirm 前置后端校验)。
|
|
2644
|
+
* 成功后就地更新列表该项(云端真源返回值)。
|
|
2645
|
+
* @param {string} fullName owner/repo
|
|
2646
|
+
* @param {string} target public | private
|
|
2647
|
+
* @returns {Promise<object>} 后端响应({ok, visibility} 或 {ok:false, error})
|
|
2648
|
+
*/
|
|
2649
|
+
async switchVisibility(fullName, target) {
|
|
2650
|
+
const parts = String(fullName || '').split('/');
|
|
2651
|
+
const owner = (parts[0] || '').trim();
|
|
2652
|
+
const repo = (parts[1] || '').trim();
|
|
2653
|
+
if (!owner || !repo) return { ok: false, error: '仓库名格式应为 owner/repo' };
|
|
2654
|
+
this.repoBusy = dshgp_BUSY_VIS + fullName;
|
|
2655
|
+
this.publish();
|
|
2656
|
+
let res;
|
|
2657
|
+
try {
|
|
2658
|
+
res = await dshgp_postJson('/api/git-push/repo-visibility', { owner, repo, visibility: target, confirm: true });
|
|
2659
|
+
} catch (e) {
|
|
2660
|
+
res = { ok: false, error: (e && e.message) || '请求失败' };
|
|
2661
|
+
}
|
|
2662
|
+
this.repoBusy = '';
|
|
2663
|
+
if (res && res.ok) {
|
|
2664
|
+
// 就地更新列表该项(新数组引用触发订阅重渲染)
|
|
2665
|
+
const arr = Array.isArray(this.cloudRepos) ? this.cloudRepos.slice() : [];
|
|
2666
|
+
for (const repo of arr) {
|
|
2667
|
+
if (String(repo.fullName || '') === fullName) repo.private = res.visibility === 'private';
|
|
2668
|
+
}
|
|
2669
|
+
this.cloudRepos = arr;
|
|
2670
|
+
this.cloudMsg = '✅ 已切换为' + (res.visibility === 'private' ? '私有' : '公开') + ':' + fullName;
|
|
2671
|
+
} else {
|
|
2672
|
+
this.cloudMsg = '❌ 切换失败:' + ((res && res.error) || '未知错误') + '(' + fullName + ')';
|
|
2673
|
+
}
|
|
2674
|
+
this.publish();
|
|
2675
|
+
return res;
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
/** 云端仓库 clone:先弹目录选择器选目标目录,再预览,确认后才真正开始。 */
|
|
2679
|
+
cloneFlow(repo) {
|
|
2680
|
+
dshgp_browseOpen(null, (dir) => { void this.cloneCloudRepo(repo, dir); });
|
|
2681
|
+
}
|
|
2682
|
+
|
|
2683
|
+
/**
|
|
2684
|
+
* 第一步:预览(不下载任何文件)。
|
|
2685
|
+
*
|
|
2686
|
+
* 此前点 clone 直接开下:用户既不知道总量(无从判断要等多久),也不知道
|
|
2687
|
+
* 体积守卫会跳过哪些文件。改为先预览、再确认。
|
|
2688
|
+
*/
|
|
2689
|
+
async cloneCloudRepo(repo, dir) {
|
|
2690
|
+
this.clonePending = { repo, dir };
|
|
2691
|
+
this.cloudMsg = '正在读取仓库信息…';
|
|
2692
|
+
this.repoBusy = dshgp_BUSY_CLONE + repo;
|
|
2693
|
+
this.publish();
|
|
2694
|
+
try {
|
|
2695
|
+
// 把目标目录一并交给后端:后端据此回报 partial(「已存在且不完整」= 有进行中标记且无有效提交),
|
|
2696
|
+
// 前端才能在确认框里提示「续传 / 重来」。不传 dir 时 partial 恒为 false(后端不猜目录)。
|
|
2697
|
+
const pv = await dshgp_postJson('/api/git-push/clone-preview', { target: repo, dir });
|
|
2698
|
+
if (pv && pv.ok) {
|
|
2699
|
+
this.cloudMsg = '';
|
|
2700
|
+
this.clonePreview = pv;
|
|
2701
|
+
} else {
|
|
2702
|
+
this.cloudMsg = '❌ ' + ((pv && pv.error) || '预览失败');
|
|
2703
|
+
this.clonePending = null;
|
|
2704
|
+
}
|
|
2705
|
+
} catch (e) {
|
|
2706
|
+
this.cloudMsg = '❌ 预览失败: ' + (e && e.message || e);
|
|
2707
|
+
this.clonePending = null;
|
|
2708
|
+
}
|
|
2709
|
+
this.repoBusy = '';
|
|
2710
|
+
this.publish();
|
|
2711
|
+
}
|
|
2712
|
+
|
|
2713
|
+
/** 第二步:点「开始克隆」后真正下载,并轮询进度直到结束。 */
|
|
2714
|
+
/**
|
|
2715
|
+
* 取消 clone 预览确认框(点「取消」)。
|
|
2716
|
+
*
|
|
2717
|
+
* 只清预览态与待办态,不做任何远端/磁盘操作——此时尚未开始下载。
|
|
2718
|
+
* 放在 Controller 而非组件里,是为了让「取消」也能顺带清 clonePending,
|
|
2719
|
+
* 否则残留的 clonePending 会让「确认其它仓库」拿到上一次的目标目录。
|
|
2720
|
+
*/
|
|
2721
|
+
cancelPreview() {
|
|
2722
|
+
this.clonePreview = null;
|
|
2723
|
+
this.clonePending = null;
|
|
2724
|
+
this.publish();
|
|
2725
|
+
}
|
|
2726
|
+
|
|
2727
|
+
async cloneConfirmed(restart = false) {
|
|
2728
|
+
const pend = this.clonePending;
|
|
2729
|
+
if (!pend) return;
|
|
2730
|
+
this.clonePreview = null;
|
|
2731
|
+
const { repo, dir } = pend;
|
|
2732
|
+
this.repoBusy = dshgp_BUSY_CLONE + repo;
|
|
2733
|
+
this.publish();
|
|
2734
|
+
// 克隆改为**后台 job**——repo-clone 立即返回 202 {async:true, jobId},
|
|
2735
|
+
// 下载在后端继续跑。故此处不再 await 整个克隆,而是:
|
|
2736
|
+
// ① 提交任务(拿 jobId;预检/互斥失败会同步回错,照实显示)
|
|
2737
|
+
// ② 轮询 /clone-progress 驱动进度,直到 state 变 done 取终态
|
|
2738
|
+
// 判「卡死」仍看进度是否停滞(大文件慢传不该被杀),不用绝对超时。
|
|
2739
|
+
let pollTimer = null;
|
|
2740
|
+
const stopPoll = () => { if (pollTimer) { clearInterval(pollTimer); pollTimer = null; } };
|
|
2741
|
+
// 终态收敛:把后端 cloneJobStatus() 的 done.result 转成用户文案。
|
|
2742
|
+
// 成败与成因仍由后端结构化给出(clone.js 的 cause/retriable),前端不猜文案。
|
|
2743
|
+
const renderResult = (res) => {
|
|
2744
|
+
if (res && res.ok) {
|
|
2745
|
+
// 如实报告被跳过的文件:否则用户以为克隆完整
|
|
2746
|
+
const skipped = res.skippedCount || 0;
|
|
2747
|
+
this.cloudMsg = '✅ 已克隆 ' + repo + ' → ' + (res.dest || dir)
|
|
2748
|
+
+ (skipped > 0 ? '(已跳过 ' + skipped + ' 个超大文件)' : '');
|
|
2749
|
+
} else {
|
|
2750
|
+
const msg = (res && res.error) || '克隆失败';
|
|
2751
|
+
const extra = res && res.cleaned && res.retriable === true
|
|
2752
|
+
? '(半成品已自动清理,可直接重试)'
|
|
2753
|
+
: '';
|
|
2754
|
+
this.cloudMsg = '❌ ' + msg + extra;
|
|
2755
|
+
}
|
|
2756
|
+
};
|
|
2757
|
+
// 轮询:① 更新进度条 ② 检测终态(running → done)后收尾。
|
|
2758
|
+
// consume=true 让后端取走终态,避免下次打开面板读到上次结果。
|
|
2759
|
+
const poll = async () => {
|
|
2760
|
+
try {
|
|
2761
|
+
const st = await dshgp_postJson('/api/git-push/clone-progress', {});
|
|
2762
|
+
if (st && st.state === 'running' && st.progress) {
|
|
2763
|
+
this.cloneProgress = st.progress;
|
|
2764
|
+
this.publish();
|
|
2765
|
+
} else if (st && st.state === 'done') {
|
|
2766
|
+
// 任务已结束:先取终态再 consume 清掉(顺序反了会读到空)
|
|
2767
|
+
const fin = await dshgp_postJson('/api/git-push/clone-progress', { consume: true });
|
|
2768
|
+
stopPoll();
|
|
2769
|
+
renderResult(fin && fin.result ? fin.result : (st.result || null));
|
|
2770
|
+
this.cloneProgress = null;
|
|
2771
|
+
this.clonePending = null;
|
|
2772
|
+
this.repoBusy = '';
|
|
2773
|
+
this.publish();
|
|
2774
|
+
} else if (st && st.state === 'idle') {
|
|
2775
|
+
// 既非 running 也非 done:任务已消失(进程重启等)——不能永远转圈
|
|
2776
|
+
stopPoll();
|
|
2777
|
+
this.cloudMsg = '⚠️ 克隆任务已不存在(可能插件进程重启过),请重新发起';
|
|
2778
|
+
this.cloneProgress = null;
|
|
2779
|
+
this.clonePending = null;
|
|
2780
|
+
this.repoBusy = '';
|
|
2781
|
+
this.publish();
|
|
2782
|
+
}
|
|
2783
|
+
} catch { /* 轮询失败不中断克隆本身 */ }
|
|
2784
|
+
};
|
|
2785
|
+
pollTimer = setInterval(() => { void poll(); }, 1000);
|
|
2786
|
+
void poll();
|
|
2787
|
+
try {
|
|
2788
|
+
// 提交即返回(很快);超时不必再放到 30 分钟——提交本身不下载。
|
|
2789
|
+
// SUBMIT_TIMEOUT_MS 是「提交请求」的超时(不是下载超时):提交只建后台任务,
|
|
2790
|
+
// 故远小于下载/轮询类超时;提取为命名常量以免被当作裸魔数。
|
|
2791
|
+
const SUBMIT_TIMEOUT_MS = 60_000;
|
|
2792
|
+
// history:勾选框的值(null=未表态则不传字段,跟随后端默认 true;取消勾选 ⇒ 显式传 false 退回整树快照)
|
|
2793
|
+
const submit = await dshgp_postJson('/api/git-push/repo-clone', { target: repo, dir, confirm: true, history: this.cloneHistory === false ? false : true, restart: restart === true }, SUBMIT_TIMEOUT_MS);
|
|
2794
|
+
if (submit && submit.async === true) {
|
|
2795
|
+
// 已转后台:进度与终态交给轮询,这里只提示「已开始」
|
|
2796
|
+
this.cloudMsg = '⏳ 克隆已在后台运行:' + repo + ' → ' + (submit.dest || dir);
|
|
2797
|
+
this.publish();
|
|
2798
|
+
} else {
|
|
2799
|
+
// 未转后台 = 提交阶段就失败(预检/互斥/参数)——同步回错,照实显示并收尾。
|
|
2800
|
+
// 兼容后端降级为同步返回(老版本/未来改动)的情形。
|
|
2801
|
+
stopPoll();
|
|
2802
|
+
renderResult(submit);
|
|
2803
|
+
this.cloneProgress = null;
|
|
2804
|
+
this.clonePending = null;
|
|
2805
|
+
this.repoBusy = '';
|
|
2806
|
+
this.publish();
|
|
2807
|
+
}
|
|
2808
|
+
} catch (e) {
|
|
2809
|
+
stopPoll();
|
|
2810
|
+
this.cloudMsg = '❌ 克隆失败: ' + (e && e.message || e) + '(可直接重试——半成品已自动清理)';
|
|
2811
|
+
this.cloneProgress = null;
|
|
2812
|
+
this.clonePending = null;
|
|
2813
|
+
this.repoBusy = '';
|
|
2814
|
+
this.publish();
|
|
2815
|
+
}
|
|
2816
|
+
}
|
|
2817
|
+
|
|
2818
|
+
/** 单击规则包行:切换禁用/启用(改为写 yml 顶层 disabled,不存 scope 变量)。 */
|
|
2819
|
+
async toggleDisabled(slot) {
|
|
2820
|
+
if (slot === 'nodejs' || slot === 'private') {
|
|
2821
|
+
this.setStatus('⚠️ nodejs/private 安全红线槽位不可禁用');
|
|
2822
|
+
return;
|
|
2823
|
+
}
|
|
2824
|
+
const meta = (this.slotMeta && this.slotMeta[slot]) || {};
|
|
2825
|
+
const nowDisabled = !!(meta.disabled);
|
|
2826
|
+
// 即时反馈:先本地翻转(行绿/红 + 顶部提示),不等后端响应
|
|
2827
|
+
this.slotMeta = { ...(this.slotMeta || {}), [slot]: { ...meta, disabled: !nowDisabled } };
|
|
2828
|
+
this.setStatus(!nowDisabled ? '✅ 已禁用 ' + slot + '(该槽位规则不再加载)' : '✅ 已启用 ' + slot);
|
|
2829
|
+
this.publish();
|
|
2830
|
+
try {
|
|
2831
|
+
const toggleRes = await dshgp_postJson('/api/git-push/toggle-rule', { slot, disabled: !nowDisabled });
|
|
2832
|
+
if (toggleRes && toggleRes.ok) {
|
|
2833
|
+
void this.loadSlots(); // 后台重载对账(yml 解析结果)
|
|
2834
|
+
} else {
|
|
2835
|
+
this.setStatus('❌ 切换失败:' + ((toggleRes && toggleRes.error) || '未知错误'));
|
|
2836
|
+
this.loadSlots();
|
|
2837
|
+
}
|
|
2838
|
+
} catch (e) {
|
|
2839
|
+
this.setStatus('❌ 切换失败:' + (e && e.message || e));
|
|
2840
|
+
void this.loadSlots(); // 恢复 yml 真实状态
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
|
|
2844
|
+
/** 审计 tab 顶部即时反馈(区别于设置 tab 的 flashSaved)。 */
|
|
2845
|
+
setStatus(msg) {
|
|
2846
|
+
this.statusMsg = String(msg || '');
|
|
2847
|
+
if (this.statusTimer) clearTimeout(this.statusTimer);
|
|
2848
|
+
this.statusTimer = setTimeout(() => {
|
|
2849
|
+
this.statusMsg = '';
|
|
2850
|
+
this.publish();
|
|
2851
|
+
}, dshgp_SAVED_MSG_MS);
|
|
2852
|
+
}
|
|
2853
|
+
|
|
2854
|
+
/** 上下调整规则包次序(下覆盖上)。 */
|
|
2855
|
+
moveSlot(slot, dir) {
|
|
2856
|
+
const arr = [...this.ruleOrder];
|
|
2857
|
+
const i = arr.indexOf(slot);
|
|
2858
|
+
const j = i + dir;
|
|
2859
|
+
if (i < 0 || j < 0 || j >= arr.length) return;
|
|
2860
|
+
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
2861
|
+
this.ruleOrder = arr;
|
|
2862
|
+
this.publish();
|
|
2863
|
+
// 次序持久化走 HTTP settings-set(写插件私有 config.json)。
|
|
2864
|
+
// 不再 scope.set——scope.set 会把 auditRuleOrder 写进公共 settings.yaml
|
|
2865
|
+
// (跨实例锁竞争 + isLoopback=memory 陷阱,见 settings-bridge.js 头部说明)。
|
|
2866
|
+
this.persistSetting('auditRuleOrder', arr);
|
|
2867
|
+
this.setStatus('✅ 规则包次序已保存:' + arr.join(' → '));
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
/**
|
|
2871
|
+
* 前端设置写入通用入口(抽公共函数消除 toggle 系列重复)。
|
|
2872
|
+
* 统一四件套:标记 editedKeys(防 loadSettingsFromHttp 异步 GET 旧值覆盖弹回)
|
|
2873
|
+
* → publish(UI 立即反映)→ persistSetting(HTTP 落盘 config.json + loopback scope 双通道)。
|
|
2874
|
+
* @param {string} key 设置键
|
|
2875
|
+
* @param {unknown} value 值
|
|
2876
|
+
* @param {string} okMsg flashSaved 成功文案(空=静默)
|
|
2877
|
+
*/
|
|
2878
|
+
commitSetting(key, value, okMsg = '') {
|
|
2879
|
+
this.editedKeys.add(key);
|
|
2880
|
+
this.publish();
|
|
2881
|
+
this.persistSetting(key, value, okMsg);
|
|
2882
|
+
}
|
|
2883
|
+
|
|
2884
|
+
/** 审计开关(写回 auditEnabled)。 */
|
|
2885
|
+
toggleAudit(checked) {
|
|
2886
|
+
this.auditEnabled = !!checked;
|
|
2887
|
+
// 交互修正:关闭父开关时**不再**把子开关的勾选抹掉。
|
|
2888
|
+
// 子开关的勾选是用户偏好,父开关只管「此刻生不生效」(host 侧注入由
|
|
2889
|
+
// cfg.auditEnabled && cfg.injectRequirements 门控)。原实现静默清勾选,
|
|
2890
|
+
// 用户重开父开关时还得再点一遍子开关,且看不出勾选是被谁清掉的。
|
|
2891
|
+
this.commitSetting('auditEnabled', this.auditEnabled, this.auditEnabled
|
|
2892
|
+
? '✅ 已开启:提交前自动审计'
|
|
2893
|
+
: '✅ 已关闭:提交前不审计');
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2896
|
+
/**
|
|
2897
|
+
* 设置持久化统一入口(**零 scope.set**,单通道走 host HTTP /settings-set → 写插件私有
|
|
2898
|
+
* config.json)。彻底移除 scope.set:
|
|
2899
|
+
* ① scope.set 会把设置写进公共 settings.yaml(跨实例写锁竞争 + isLoopback=memory 陷阱);
|
|
2900
|
+
* ② loopback 直连时 scope.set 会写公共 yaml、反代时 memory 不落盘——两条路都不对,
|
|
2901
|
+
* HTTP settings-set 与访问方式无关、无宿主锁竞争、重启从文件读回,是唯一可靠通道。
|
|
2902
|
+
* @param {string} key 设置键
|
|
2903
|
+
* @param {unknown} value 值
|
|
2904
|
+
* @param {string} okMsg flashSaved 成功文案(空=静默)
|
|
2905
|
+
*/
|
|
2906
|
+
persistSetting(key, value, okMsg = '') {
|
|
2907
|
+
// 凭据防线(第三层):凭据键**绝不发送脱敏值/空值**——防止把回显用的
|
|
2908
|
+
// 「ghp_…XYZ」这类打码串写回 config.json 覆盖真凭据(服务端 persistGithubToken/
|
|
2909
|
+
// persistSshPub 另有 isMaskedValue 拦截,这里是 UI 侧提前拦住不发请求)。
|
|
2910
|
+
if (key === 'githubToken' || key === 'sshPub') {
|
|
2911
|
+
const sv = String(value ?? '').trim();
|
|
2912
|
+
if (!sv) return; // 空值:不动该键(留空=保持不变)
|
|
2913
|
+
if (sv.includes('…') || sv.includes('****') || /^gh[pous]_…/.test(sv)) {
|
|
2914
|
+
this.failed = true;
|
|
2915
|
+
this.flashSaved('❌ 拒绝写入:这是脱敏显示值,请输入完整凭据');
|
|
2916
|
+
this.publish();
|
|
2917
|
+
return;
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
// UI 提交调试日志(浏览器控制台可见;服务端另有 settings-ui.log 持久留痕)
|
|
2921
|
+
if (typeof console !== 'undefined' && console.debug) {
|
|
2922
|
+
try { console.debug('[dsh-git-push] UI 提交', key, '=', String(value).slice(0, dshgp_LOG_TRUNCATE) + (String(value).length > dshgp_LOG_TRUNCATE ? '…' : '')); } catch { /* 控制台不可用时跳过调试输出 */ }
|
|
2923
|
+
}
|
|
2924
|
+
void dshgp_postJson('/api/git-push/settings-set', { key, value }).then((data) => {
|
|
2925
|
+
if (data && data.ok) {
|
|
2926
|
+
if (okMsg) this.flashSaved(okMsg);
|
|
2927
|
+
} else {
|
|
2928
|
+
this.failed = true;
|
|
2929
|
+
this.publish();
|
|
2930
|
+
}
|
|
2931
|
+
}).catch(() => {
|
|
2932
|
+
this.failed = true;
|
|
2933
|
+
this.publish();
|
|
2934
|
+
});
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
/**
|
|
2938
|
+
* 注入开发者要求清单开关(auditEnabled 的子开关)。
|
|
2939
|
+
* 父开关关闭时**仍可勾选**(保留偏好、只置灰、不注入)——原实现在这里直接 return,
|
|
2940
|
+
* 用户点了没任何反应,必须先开父开关再点一次(两遍)。
|
|
2941
|
+
*/
|
|
2942
|
+
toggleInjectRequirements(checked) {
|
|
2943
|
+
this.injectRequirements = !!checked;
|
|
2944
|
+
this.commitSetting('injectRequirements', this.injectRequirements, this.injectRequirements
|
|
2945
|
+
? (this.auditEnabled ? '✅ 已开启:注入开发者要求清单' : '✅ 已勾选:待开启「提交前自动审计」后生效')
|
|
2946
|
+
: '✅ 已关闭:不注入要求清单');
|
|
2947
|
+
}
|
|
2948
|
+
|
|
2949
|
+
/**
|
|
2950
|
+
* 注入总开关(写回 injectSystemPrompt;默认开)。
|
|
2951
|
+
* 关 = host 侧 systemPrompt 段全部返回空串 + 上下文注入不注入;
|
|
2952
|
+
* 开 = 功能用法/README 提醒/要求清单走系统提示词,环境(工作区/工具/skill 入口)走上下文首条注入。
|
|
2953
|
+
* 注入段里的「开发者要求清单」仍受 auditEnabled + injectRequirements 双重门控。
|
|
2954
|
+
*/
|
|
2955
|
+
toggleInjectSystemPrompt(checked) {
|
|
2956
|
+
this.injectSystemPrompt = !!checked;
|
|
2957
|
+
// 走 commitSetting 公共入口(自动含 editedKeys 标记 + publish + persistSetting);
|
|
2958
|
+
// 此前漏了 editedKeys 标记,loadSettingsFromHttp 异步 GET 可能用旧值把它覆盖回去
|
|
2959
|
+
this.commitSetting('injectSystemPrompt', this.injectSystemPrompt, this.injectSystemPrompt
|
|
2960
|
+
? '✅ 已开启:注入系统提示词/上下文'
|
|
2961
|
+
: '✅ 已关闭:不注入');
|
|
2962
|
+
}
|
|
2963
|
+
|
|
2964
|
+
/**
|
|
2965
|
+
* 审计扫描范围切换:diff=仅本次变动(auditChanged,默认)/ full=全量(auditFull)。
|
|
2966
|
+
* 按钮式单击切换;持久化走 host HTTP(persistence=memory 陷阱绕开方案,见 settings-bridge.js)。
|
|
2967
|
+
*/
|
|
2968
|
+
toggleAuditScanScope(scope) {
|
|
2969
|
+
const next = scope === 'full' ? 'full' : 'diff';
|
|
2970
|
+
if (this.auditScanScope === next) return;
|
|
2971
|
+
this.auditScanScope = next;
|
|
2972
|
+
this.commitSetting('auditScanScope', next, next === 'full'
|
|
2973
|
+
? '✅ 已切换:审计扫描范围 = 全量(auditFull)'
|
|
2974
|
+
: '✅ 已切换:审计扫描范围 = 部分(auditChanged,仅本次变动)');
|
|
2975
|
+
}
|
|
2976
|
+
|
|
2977
|
+
/** 权重维度编辑(合并写回 weightOverrides JSON)。 */
|
|
2978
|
+
editWeight(key, value) {
|
|
2979
|
+
this.weightValues = { ...(this.weightValues || {}), [key]: value };
|
|
2980
|
+
const json = JSON.stringify(this.weightValues);
|
|
2981
|
+
this.commitSetting('weightOverrides', json, '✅ 权重已保存(合计 ' + dshgp_DIMENSIONS.reduce((a, d) => a + (this.weightValues[d.key] != null ? this.weightValues[d.key] : d.def), 0) + '),下次审计生效');
|
|
2982
|
+
}
|
|
2983
|
+
|
|
2984
|
+
/**
|
|
2985
|
+
* 新增 / 收敛:审计进阶 / 推送通道设置项通用提交。
|
|
2986
|
+
* 更新本地镜像 → 走 commitSetting(HTTP settings-set → config.json)→ 即时反馈。
|
|
2987
|
+
* @param {string} key maxScanFiles|pushMethod
|
|
2988
|
+
* @param {unknown} value 新值
|
|
2989
|
+
*/
|
|
2990
|
+
setAdvanced(key, value) {
|
|
2991
|
+
const ok = /^(maxScanFiles|maxCloneFileMB|cloneConcurrency|pushMethod|pushGate|autoPushEnabled|autoPushTriggerText|autoPushScope)$/.test(key);
|
|
2992
|
+
if (!ok) { this.setStatus('❌ 未知设置键: ' + key); return; }
|
|
2993
|
+
const numKeys = { maxScanFiles: 1, maxCloneFileMB: 1, cloneConcurrency: 1 };
|
|
2994
|
+
const boolKeys = { pushGate: 1, autoPushEnabled: 1 };
|
|
2995
|
+
const enumKeys = { pushMethod: ['ssh', 'api', 'auto'], autoPushScope: ['session', 'all'] };
|
|
2996
|
+
let v = value;
|
|
2997
|
+
if (boolKeys[key]) v = value === true;
|
|
2998
|
+
else if (numKeys[key]) v = Number(value) || 0;
|
|
2999
|
+
else if (enumKeys[key]) {
|
|
3000
|
+
const allowed = enumKeys[key];
|
|
3001
|
+
v = allowed.includes(value) ? value : this[key];
|
|
3002
|
+
if (v !== value) { this.setStatus('❌ 非法取值: ' + value); return; }
|
|
3003
|
+
} else v = String(value ?? '');
|
|
3004
|
+
this[key] = v;
|
|
3005
|
+
this.commitSetting(key, v, '✅ ' + key + ' 已保存,下次生效');
|
|
3006
|
+
}
|
|
3007
|
+
|
|
3008
|
+
edit(text) { this.text = String(text || ''); this.failed = false; this.publish(); }
|
|
3009
|
+
editSsh(text) { this.sshPub = String(text || ''); this.failed = false; this.publish(); }
|
|
3010
|
+
editEmail(text) { this.sshEmail = String(text || ''); this.failed = false; this.publish(); }
|
|
3011
|
+
|
|
3012
|
+
/** 保存 token / 公钥到插件配置(settingsScope)。 */
|
|
3013
|
+
async save() {
|
|
3014
|
+
const raw = this.text.trim();
|
|
3015
|
+
const pub = this.sshPub.trim();
|
|
3016
|
+
if ((!raw && !pub) || this.saving) return;
|
|
3017
|
+
this.saving = true;
|
|
3018
|
+
this.failed = false;
|
|
3019
|
+
this.publish();
|
|
3020
|
+
try {
|
|
3021
|
+
// 凭据持久化走 persistSetting(纯 HTTP /settings-set → 服务端
|
|
3022
|
+
// writeSettingsKey 写 config.json + persistGithubToken/persistSshPub 落插件目录,
|
|
3023
|
+
// 不 scope.set——scope.set 会把凭据写进公共 settings.yaml 明文,反代下还不落盘)。
|
|
3024
|
+
if (raw) this.persistSetting('githubToken', raw);
|
|
3025
|
+
if (pub) this.persistSetting('sshPub', pub);
|
|
3026
|
+
this.text = '';
|
|
3027
|
+
this.sshPub = '';
|
|
3028
|
+
this.saving = false;
|
|
3029
|
+
// 保存后**刷新凭据与密钥的「已填写」状态**——此前只在写入 token 时本地置位
|
|
3030
|
+
// tokenConfigured、sshConfigured 从不置位(保存公钥后徽标仍显示未填写),且本地置位
|
|
3031
|
+
// 无法反映服务端规范化/落盘失败。统一走 refresh('account') 从 account-status 真源读回。
|
|
3032
|
+
// 顺序:先弹「已保存」提示,再异步读回状态(读回过程不遮挡保存成功的反馈)。
|
|
3033
|
+
this.flashSaved('✅ 凭据已保存');
|
|
3034
|
+
await this.refresh('account');
|
|
3035
|
+
} catch (_e) {
|
|
3036
|
+
this.saving = false;
|
|
3037
|
+
this.failed = true;
|
|
3038
|
+
}
|
|
3039
|
+
this.publish();
|
|
3040
|
+
}
|
|
3041
|
+
|
|
3042
|
+
discard() { this.text = ''; this.sshPub = ''; this.failed = false; this.publish(); }
|
|
3043
|
+
|
|
3044
|
+
/** 一键生成 SSH 密钥对(/gen-ssh-key):公钥保存到 sshkey 并复制。 */
|
|
3045
|
+
async genKey() {
|
|
3046
|
+
const email = this.sshEmail.trim();
|
|
3047
|
+
if (!email || this.genKeying) return;
|
|
3048
|
+
this.genKeying = true;
|
|
3049
|
+
this.genKeyError = '';
|
|
3050
|
+
this.publish();
|
|
3051
|
+
try {
|
|
3052
|
+
const genRes = await dshgp_postJson('/api/git-push/gen-ssh-key', { email });
|
|
3053
|
+
if (genRes && genRes.ok && genRes.pub) {
|
|
3054
|
+
this.sshPub = genRes.pub;
|
|
3055
|
+
this.publish();
|
|
3056
|
+
await dshgp_copyText(genRes.pub);
|
|
3057
|
+
this.genKeying = false;
|
|
3058
|
+
this.flashSaved('✅ 公钥已生成:已填入 SSH 公钥框并复制到剪贴板');
|
|
3059
|
+
} else {
|
|
3060
|
+
this.genKeying = false;
|
|
3061
|
+
this.genKeyError = (genRes && genRes.error) || '生成失败';
|
|
3062
|
+
this.publish();
|
|
3063
|
+
}
|
|
3064
|
+
} catch (e) {
|
|
3065
|
+
this.genKeying = false;
|
|
3066
|
+
this.genKeyError = '生成失败: ' + (e && e.message || e);
|
|
3067
|
+
this.publish();
|
|
3068
|
+
}
|
|
3069
|
+
}
|
|
3070
|
+
|
|
3071
|
+
/** 挂到槽系统的 hooks(供组件注入)。 */
|
|
3072
|
+
inject() {
|
|
3073
|
+
return {
|
|
3074
|
+
hooks: { gitPushCard: this.store },
|
|
3075
|
+
edit: (text) => this.edit(text),
|
|
3076
|
+
editSsh: (text) => this.editSsh(text),
|
|
3077
|
+
editEmail: (text) => this.editEmail(text),
|
|
3078
|
+
save: () => { void this.save(); },
|
|
3079
|
+
discard: () => this.discard(),
|
|
3080
|
+
genKey: () => { void this.genKey(); },
|
|
3081
|
+
toggleAudit: (checked) => this.toggleAudit(checked),
|
|
3082
|
+
// 子开关动作必须在这里暴露:页面 props 来自 inject(),漏了会让 onChange 调到 undefined
|
|
3083
|
+
toggleInjectRequirements: (checked) => this.toggleInjectRequirements(checked),
|
|
3084
|
+
toggleInjectSystemPrompt: (checked) => this.toggleInjectSystemPrompt(checked),
|
|
3085
|
+
toggleAuditScanScope: (scope) => this.toggleAuditScanScope(scope),
|
|
3086
|
+
editWeight: (key, value) => this.editWeight(key, value),
|
|
3087
|
+
setAdvanced: (key, value) => this.setAdvanced(key, value),
|
|
3088
|
+
moveSlot: (slot, dir) => this.moveSlot(slot, dir),
|
|
3089
|
+
toggleDisabled: (slot) => { void this.toggleDisabled(slot); },
|
|
3090
|
+
// 统一刷新入口(参数控制刷哪部分)——设置 / 账号 / 本地仓库 / 云端 / 槽位
|
|
3091
|
+
refresh: (parts, opts) => { void this.refresh(parts, opts); },
|
|
3092
|
+
refreshAccount: () => { void this.refresh('account'); }, // 离线读 json(启动/push后/渲染)
|
|
3093
|
+
recheckAccount: () => { void this.recheckAccount(); }, // 在线校验写 json(「重新检测」)
|
|
3094
|
+
// npm 账号:与 GitHub 账号**同一套注入与语义**(离线刷新 / 在线校验 / 名下包列表)
|
|
3095
|
+
refreshNpmAccount: () => { void this.refreshNpmAccount(); },
|
|
3096
|
+
recheckNpmAccount: () => { void this.recheckNpmAccount(); },
|
|
3097
|
+
refreshNpmOwned: () => { void this.loadNpmOwned(); },
|
|
3098
|
+
installNpmPackage: (opts) => { void this.installNpmPackage(opts); },
|
|
3099
|
+
// 安装交互四段(入口/选择/进度/回执)——与 GitHub 克隆同款注入
|
|
3100
|
+
openInstallFlow: (pkg) => this.openInstallFlow(pkg),
|
|
3101
|
+
chooseInstallDir: () => this.chooseInstallDir(),
|
|
3102
|
+
confirmInstallGlobal: () => this.confirmInstallGlobal(),
|
|
3103
|
+
cancelInstallDialog: () => this.cancelInstallDialog(),
|
|
3104
|
+
// 账号卡片:本地/云端 动作
|
|
3105
|
+
scanLocalRepos: (path, rebuild) => { void this.refresh('repos', { path, rebuild }); },
|
|
3106
|
+
startScan: (path) => { void this.startScan(path); }, // 扫描按钮:独立进程后台扫描 + 逐条追加
|
|
3107
|
+
loadCloudRepos: () => { void this.refresh('cloud'); },
|
|
3108
|
+
pushLocalRepo: (path) => { void this.pushLocalRepo(path); },
|
|
3109
|
+
commitLocalRepo: (path) => { void this.commitLocalRepo(path); }, // 本地 commit(复用提交审计)
|
|
3110
|
+
cloneFlow: (repo) => this.cloneFlow(repo),
|
|
3111
|
+
requestVisSwitch: (fullName, target) => this.requestVisSwitch(fullName, target), // 弹独立确认面板(1.5.4)
|
|
3112
|
+
confirmVisSwitch: () => { void this.confirmVisSwitch(); },
|
|
3113
|
+
cancelVisSwitch: () => { this.cancelVisSwitch(); },
|
|
3114
|
+
cloneConfirmed: () => { void this.cloneConfirmed(); }, // 预览确认框「开始克隆」
|
|
3115
|
+
// 预览框勾选「带真实历史」:只改本地选择并重绘,真正的参数在提交时随 history 一起发出
|
|
3116
|
+
setCloneHistory: (v) => { this.cloneHistory = (v === true); this.publish(); },
|
|
3117
|
+
cancelPreview: () => { this.cancelPreview(); }, // 预览确认框「取消」
|
|
3118
|
+
};
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
|
|
3122
|
+
const inject = ['slots'];
|
|
3123
|
+
|
|
3124
|
+
function apply(ctx) {
|
|
3125
|
+
// 【常驻诊断 · 前端接线失败可见化】apply 整体包一层 try/catch,把真实异常打到控制台。
|
|
3126
|
+
// 背景:cordis 只把失败的 client entry 标成 failed(页面仅显示
|
|
3127
|
+
// `web boot: 1 entry did not activate` / `dsh-git-push: failed`),真实异常既不进页面、
|
|
3128
|
+
// 也不进宿主日志——本次 0.2.0 适配就是靠这层 console.error 才定位到
|
|
3129
|
+
// `cannot get property "settingsScope" without inject`(读未 inject 的服务属性会抛)。
|
|
3130
|
+
// 保留为常驻诊断(不是临时探针):任何未来的接线异常都会直接出现在浏览器控制台。
|
|
3131
|
+
try {
|
|
3132
|
+
// 版本兼容自动切换(2.3.0):DSH 0.2.0 移除了 client 注入服务 settingsScope,
|
|
3133
|
+
// 声明依赖会导致 entry pending(waiting for service: settingsScope)→ 插件不激活。
|
|
3134
|
+
// git-push 设置/凭据真源早已全链路走 HTTP(settings-bridge → config.json),
|
|
3135
|
+
// scope 仅剩「订阅 + 初值兜底」(零 scope.set),故特性检测自动切换:
|
|
3136
|
+
// 有真 scope(0.1.6)用它;没有(0.2.0)用空 fallback(快照空 → 全走 HTTP,行为一致)。
|
|
3137
|
+
// 【2.3.0 修复】必须用 ctx.get() 防御式读取:cordis 里「读未 inject 的服务属性」会直接抛
|
|
3138
|
+
// `cannot get property "settingsScope" without inject`(实测:直接写 ctx.settingsScope
|
|
3139
|
+
// 会让 0.2.0 上 client entry 激活失败 → 页面报 web boot: dsh-git-push: failed)。
|
|
3140
|
+
// 外面再包一层 try/catch:ctx.get 本身在个别宿主实现里也可能抛(1.0.10 回归不变量:
|
|
3141
|
+
// 「ctx.get 抛错不崩」),两层防护保证任何宿主形态下 apply 都不因此中断。
|
|
3142
|
+
let settingsScope;
|
|
3143
|
+
try {
|
|
3144
|
+
settingsScope = typeof ctx.get === 'function' ? ctx.get('settingsScope') : undefined;
|
|
3145
|
+
} catch {
|
|
3146
|
+
settingsScope = undefined;
|
|
3147
|
+
}
|
|
3148
|
+
const scope = settingsScope
|
|
3149
|
+
? settingsScope.bind({ namespace: SETTINGS_NS })
|
|
3150
|
+
: { subscribe: () => () => {}, getSnapshot: () => ({ value: undefined }) };
|
|
3151
|
+
const controller = new dshgp_Controller(scope);
|
|
3152
|
+
const store = controller.store;
|
|
3153
|
+
// (修复「重启后不预读」):**每次进设置页都预读**账号信息 + 本地仓库列表
|
|
3154
|
+
// (读 account-status.json / dsh-repo-index.json,本地文件幂等便宜)——此前的模块级
|
|
3155
|
+
// `dshgp_startupLoaded` 标记在 DSH bundle 常驻(浏览器不刷新)时保持 true,
|
|
3156
|
+
// 导致「第一次预读后,重启/重进设置页不再预读」。改为每次 apply 都读,跟随最新 json。
|
|
3157
|
+
// 后续仍可手动「重新检测 / 扫描」在线刷新。
|
|
3158
|
+
// 读取复用「本地仓库列表选择的路径」(localStorage dshgp-scan-path,本地面板扫描时写入);
|
|
3159
|
+
// 没选过则空 → 后端自动识别 DSH 家根。
|
|
3160
|
+
let savedPath = dshgp_localGet('dshgp-scan-path');
|
|
3161
|
+
void controller.refreshAccount();
|
|
3162
|
+
void controller.scanLocalRepos(savedPath, false); // 只读索引(不重建,读 json)
|
|
3163
|
+
// uSES 桥:SnapshotStore 是裸 observable,用 useSyncExternalStore 自建 selector hook
|
|
3164
|
+
const useCardState = (selector) => {
|
|
3165
|
+
const snap = react.useSyncExternalStore(store.subscribe, store.getSnapshot);
|
|
3166
|
+
return selector ? selector(snap) : snap;
|
|
3167
|
+
};
|
|
3168
|
+
// 统一 props:组件层不感知 controller,全走 store + 动作注入
|
|
3169
|
+
const makeProps = (state) => Object.assign({ state, useGitPushCard: useCardState }, controller.inject());
|
|
3170
|
+
function SectionPage() {
|
|
3171
|
+
const state = useCardState((s) => s);
|
|
3172
|
+
if (!state.available) return null;
|
|
3173
|
+
const props = makeProps(state);
|
|
3174
|
+
return jsx.jsx(dshgp_GitPushPage, props);
|
|
3175
|
+
}
|
|
3176
|
+
// 只注册 settings.section(独立侧边栏页);settings.plugin.item(插件配置卡)已删除
|
|
3177
|
+
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
3178
|
+
name: 'settings.section',
|
|
3179
|
+
id: 'dsh-git-push',
|
|
3180
|
+
order: 40,
|
|
3181
|
+
label: () => 'Git 提交推送',
|
|
3182
|
+
}, () => react.createElement(SectionPage, null)));
|
|
3183
|
+
} catch (e) {
|
|
3184
|
+
// 【常驻诊断】真实异常进控制台(页面只显示 "dsh-git-push: failed",看不出原因)
|
|
3185
|
+
console.error('[dsh-git-push] client apply 失败:', (e && (e.stack || e.message)) || String(e));
|
|
3186
|
+
throw e;
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3189
|
+
|
|
3190
|
+
exports.NS = NS;
|
|
3191
|
+
exports.apply = apply;
|
|
3192
|
+
exports.inject = inject;
|
|
3193
|
+
return module.exports;
|
|
3194
|
+
},
|
|
3195
|
+
});
|