dsh-git-push 2.9.4 → 2.9.9
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/README.md +21 -25
- package/lib/app/apply.js +8 -1
- package/lib/app/audit-api.js +4 -1
- package/lib/app/command-registry.js +17 -11
- package/lib/app/handlers/meta.js +38 -0
- package/lib/app/handlers/repo-actions.js +3 -1
- package/lib/app/handlers/settings.js +0 -0
- package/lib/app/http-handlers.js +3 -1
- package/lib/app/schema.js +0 -0
- package/lib/app/settings-bridge.js +0 -0
- package/lib/app/tool-call.js +26 -21
- package/lib/ast/control-flow.js +12 -3
- package/lib/ast/size.js +5 -2
- package/lib/audit/audit-file.js +4 -2
- package/lib/audit/file-context.js +89 -0
- package/lib/audit/finding.js +16 -2
- package/lib/audit/index.js +2 -2
- package/lib/checks/button-bind.js +25 -2
- package/lib/commit-push.js +20 -2
- package/lib/core/exec.js +6 -4
- package/lib/exempt/tool.js +198 -0
- package/lib/git/clone-history-mode.js +24 -5
- package/lib/git/push.js +28 -13
- package/lib/git/transport.js +49 -17
- package/lib/git/visibility.js +93 -9
- package/lib/npm/publish.js +27 -0
- package/lib/npm/registry.js +5 -2
- package/lib/self/index.js +1 -1
- package/package.json +2 -4
- package/skills/dev/dsh-git-push.md +1 -2
- package/skills/guide/guide-cli-scripts.md +3 -3
- package/skills/guide/guide-inject-ui.md +4 -4
- package/assets/minihost.sh +0 -35
- package/assets/preview.html +0 -36703
- package/lib/fs/edit-after-read.js +0 -142
- package/scripts/frontend-preview-check.mjs +0 -124
- package/scripts/preview-gen.mjs +0 -489
- package/scripts/preview-local-runner.mjs +0 -55
- package/scripts/preview-server-direct.mjs +0 -116
- package/scripts/preview-server.mjs +0 -305
- package/scripts/preview-slot-data.mjs +0 -123
- package/scripts/sync-plugin-install.mjs +0 -286
- package/scripts/sync-plugin.mjs +0 -284
package/lib/git/push.js
CHANGED
|
@@ -10,7 +10,7 @@ import { existsSync } from 'node:fs';
|
|
|
10
10
|
import { join } from 'node:path';
|
|
11
11
|
import { autoTagDSHProject, ensureAuxSshRemote, readPkgVersion, updateRemoteTrackingRef } from './post-push.js';
|
|
12
12
|
import { loadRequirements } from './config.js';
|
|
13
|
-
import { resolveSshKeys } from './credentials.js';
|
|
13
|
+
import { resolveSshKeys, resolveToken } from './credentials.js';
|
|
14
14
|
import { runGit } from './exec.js';
|
|
15
15
|
import { buildWrappedGitEnv } from './wrapped-git.js';
|
|
16
16
|
import { buildCommitMessage } from './commit-message.js';
|
|
@@ -44,7 +44,7 @@ function resolveRepoIdentity(repoPath) {
|
|
|
44
44
|
import { fetchRemoteHeads, dispatchPush, liveRemoteHead } from './transport.js';
|
|
45
45
|
// 推送后「远端 sha 硬校验」用(假成功防线:远端空仓/未落地时必须判失败,见 enhanceAfterPushSuccess)
|
|
46
46
|
import { githubFetch } from './api.js';
|
|
47
|
-
import { resolveRepoVisibility } from './visibility.js';
|
|
47
|
+
import { resolveRepoVisibility, cachedVisibility } from './visibility.js';
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* 统一提交推送:预检 → 敏感文件 .gitignore → add → commit → push。
|
|
@@ -54,7 +54,7 @@ import { resolveRepoVisibility } from './visibility.js';
|
|
|
54
54
|
* customIgnorePatterns:逗号/换行分隔的 gitignore pattern,追加进 .gitignore(幂等)
|
|
55
55
|
* @returns {{ok, steps: string[], commitSha?, pushed?, push?, remoteHeads?, error?}}
|
|
56
56
|
*/
|
|
57
|
-
export async function commitAndPush({ repoPath = '', message = '', messageItems = null, push = true, dryRun = false, token = '', customIgnorePatterns = '', requirementsConfirmed = false, force = false, pushMethod = 'ssh', pushGate = false, pushConfirmed = false, paths = '' } = {}) {
|
|
57
|
+
export async function commitAndPush({ repoPath = '', message = '', messageItems = null, push = true, dryRun = false, token = '', customIgnorePatterns = '', requirementsConfirmed = false, force = false, pushMethod = 'ssh', pushGate = false, pushConfirmed = false, paths = '', remote = '' } = {}) {
|
|
58
58
|
const steps = [];
|
|
59
59
|
if (!repoPath || !existsSync(join(repoPath, '.git'))) return { ok: false, steps: ['预检'], error: `非 git 仓库: ${repoPath || '(空)'}` };
|
|
60
60
|
// message 支持三种形态(字符串 / 数组 / {subject,items}):在预检处**单点**组装成规范提交信息,
|
|
@@ -199,7 +199,7 @@ export async function commitAndPush({ repoPath = '', message = '', messageItems
|
|
|
199
199
|
steps.push('push');
|
|
200
200
|
// 通道由 dispatchPush 单点决策(默认 SSH:推本地 HEAD、远端 sha 与本地一致;无密钥才回落 API)。
|
|
201
201
|
// ⚠️ dispatchPush 是 async:必须 await(旧 bug:同步调用导致 pr.ok 恒 undefined,推送从未成功)
|
|
202
|
-
const pr = await dispatchPush({ repoPath, token, force, pushMethod });
|
|
202
|
+
const pr = await dispatchPush({ repoPath, token, force, pushMethod, remote });
|
|
203
203
|
if (pr.ok) {
|
|
204
204
|
// D24:pr.pushed=false(内容级短路「远端已是最新」)→ 如实 pushed:false(commitPushDoPush 语义)
|
|
205
205
|
// committed 必须如实带上:cleanSkipCommit 时本次**没有产生新提交**。
|
|
@@ -209,7 +209,7 @@ export async function commitAndPush({ repoPath = '', message = '', messageItems
|
|
|
209
209
|
// 原先只有 API 分支做这些,SSH 分支只拉 heads → 走 SSH 时本地 origin/<branch> 引用不更新,
|
|
210
210
|
// 下次 ahead/behind 判断就会错位。
|
|
211
211
|
steps.push(`pushed-via-${pr.method || 'unknown'}`);
|
|
212
|
-
const enhanced = await enhanceAfterPushSuccess({ repoPath, pr, token, steps, commitSha });
|
|
212
|
+
const enhanced = await enhanceAfterPushSuccess({ repoPath, pr, token, steps, commitSha, remote });
|
|
213
213
|
// 假成功防线(用户实测事故):远端为空仓时推送动作不报错,但提交根本没上去。
|
|
214
214
|
// verified===false 表示「API 查到了远端分支,但 sha 与本地提交不一致 / 查不到该分支」
|
|
215
215
|
// ⇒ 必须返回 ok:false,让调用方与用户看到真实状态,而不是「commit+push done」。
|
|
@@ -267,7 +267,7 @@ async function fetchRemoteBranchRef(repoPath, branch, owner, repo) {
|
|
|
267
267
|
* 结果记入 push.remoteRef / push.auxRemote / autoTag。
|
|
268
268
|
* @returns {Promise<{push, autoTag, heads?}>}
|
|
269
269
|
*/
|
|
270
|
-
async function enhanceAfterPushSuccess({ repoPath, pr, token, steps, commitSha }) {
|
|
270
|
+
async function enhanceAfterPushSuccess({ repoPath, pr, token, steps, commitSha, remote = '' }) {
|
|
271
271
|
const pushSlot = pr;
|
|
272
272
|
const branchRef = pr.branch;
|
|
273
273
|
const localHead = runGit(['rev-parse', 'HEAD'], { cwd: repoPath }).stdout;
|
|
@@ -289,13 +289,20 @@ async function enhanceAfterPushSuccess({ repoPath, pr, token, steps, commitSha }
|
|
|
289
289
|
} catch (e) {
|
|
290
290
|
pushSlot.auxRemote = `ensure-aux-remote 异常: ${e?.message || e}`;
|
|
291
291
|
}
|
|
292
|
+
// 核验用 token:调用方没显式传时从插件凭据兜底。
|
|
293
|
+
// 为什么必须有:pushViaSsh 成功时 pr.token 为空,若这里直接用 token(默认 ''),
|
|
294
|
+
// 后面的 API 核验会以空 token 请求 → 404/401 → 明明推成功了却报「未能核验远端」。
|
|
295
|
+
const verifyToken = String(token || '').trim() || resolveToken({ workspaceRoot: repoPath }).token;
|
|
296
|
+
// 统一前置判断:先确定仓库可见性并填缓存——后续 ls-remote 探针据此决定要不要试 origin(https):
|
|
297
|
+
// 私有库经 https/镜像必然失败,试它只会把「未核验」的原因带偏。
|
|
298
|
+
try { await resolveRepoVisibility(repoPath, verifyToken); } catch { /* 判定失败按 unknown 处理 */ }
|
|
292
299
|
let autoTag = null;
|
|
293
300
|
try {
|
|
294
|
-
autoTag = await autoTagDSHProject({ repoPath, version: readPkgVersion(repoPath), commitSha: pr.commitSha, owner: pr.owner, repo: pr.repo, token: pr.token ||
|
|
301
|
+
autoTag = await autoTagDSHProject({ repoPath, version: readPkgVersion(repoPath), commitSha: pr.commitSha, owner: pr.owner, repo: pr.repo, token: pr.token || verifyToken });
|
|
295
302
|
} catch (e) {
|
|
296
303
|
autoTag = { ok: false, skipped: 'auto-tag-error', error: String(e?.message || e) };
|
|
297
304
|
}
|
|
298
|
-
const heads = await fetchRemoteHeads({ owner: pr.owner, repo: pr.repo, branch: pr.branch, token: pr.token ||
|
|
305
|
+
const heads = await fetchRemoteHeads({ owner: pr.owner, repo: pr.repo, branch: pr.branch, token: pr.token || verifyToken }).catch(() => null);
|
|
299
306
|
// 推送成功后的**硬校验**:远端该分支的 sha 必须等于本次提交 sha。
|
|
300
307
|
// 事故(用户实测):远端仓库为空(API 409 Conflict)时插件仍回「commit+push done」——
|
|
301
308
|
// 成功判定只看「推送动作有没有报错」,没看「远端到底有没有这个提交」,属**假成功**。
|
|
@@ -321,6 +328,13 @@ async function enhanceAfterPushSuccess({ repoPath, pr, token, steps, commitSha }
|
|
|
321
328
|
*/
|
|
322
329
|
const lsRemoteProbe = () => {
|
|
323
330
|
try {
|
|
331
|
+
// 通道 1:SSH(与推送同源)。推送走 ssh:443 时核验也必须走同一条——
|
|
332
|
+
// origin 常是 https 而本机 https 通道不通,只跑 origin 会让探针永远「失明」,
|
|
333
|
+
// 于是明明推送成功却报「未能核验远端」(实测就是这个现象)。
|
|
334
|
+
const ssh = liveRemoteHead({ repoPath, branch: branchRef, remote });
|
|
335
|
+
if (ssh.ok && ssh.sha) return { ok: true, sha: ssh.sha, via: ssh.via };
|
|
336
|
+
// 通道 2:origin(https + 凭据 env)。私有库跳过——镜像/直连都看不到私有库,试了只会多一条失败。
|
|
337
|
+
if (cachedVisibility(repoPath) === 'private') return { ok: false, sha: '', err: '私有库跳过 origin(https) 通道(统一前置判断)' };
|
|
324
338
|
// ⚠️ 必须带**凭据 env**:私有库上不带凭据的 ls-remote 会静默返回空(HTTPS 下等同 404)——
|
|
325
339
|
// 那会让「第二路证据」失明。故这一路必须复用插件自己的凭据装配(SSH 私钥 / HTTPS askpass):
|
|
326
340
|
// exec.js 的 runGit 是裸 git,只有 wrapped-git.js 的 buildWrappedGitEnv 会注入凭据。
|
|
@@ -338,7 +352,7 @@ async function enhanceAfterPushSuccess({ repoPath, pr, token, steps, commitSha }
|
|
|
338
352
|
const lsRemoteSha = () => lsRemoteProbe().sha;
|
|
339
353
|
try {
|
|
340
354
|
const br = await githubFetch(`/repos/${pr.owner}/${pr.repo}/branches/${encodeURIComponent(branchRef)}`,
|
|
341
|
-
{ token: pr.token ||
|
|
355
|
+
{ token: pr.token || verifyToken, method: 'GET' });
|
|
342
356
|
const remoteSha = String(br?.json?.commit?.sha || '');
|
|
343
357
|
// 比对对象是**本次推送所报的 sha**(pr.commitSha):API 通道会在远端新建提交对象,
|
|
344
358
|
// 其 sha 与本地 HEAD 本来就不同(设计如此,见 fetchRemoteBranchRef 注释),
|
|
@@ -422,14 +436,15 @@ export function readmeCheckHint(repoPath) {
|
|
|
422
436
|
* @param {{repoPath?:string, pushMethod?:string}} opts
|
|
423
437
|
* @returns {{ok:boolean, branch?, ahead?, behind?, changed?, pushed?, push?, error?}}
|
|
424
438
|
*/
|
|
425
|
-
export async function pushCurrentBranch({ repoPath = '', pushMethod = 'ssh' } = {}) {
|
|
439
|
+
export async function pushCurrentBranch({ repoPath = '', pushMethod = 'ssh', remote = '' } = {}) {
|
|
426
440
|
if (!repoPath || !existsSync(join(repoPath, '.git'))) return { ok: false, error: `非 git 仓库: ${repoPath || '(空)'}` };
|
|
427
441
|
const branch = runGit(['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: repoPath }).stdout.trim() || '';
|
|
428
442
|
const status = runGit(['status', '--porcelain'], { cwd: repoPath }).stdout;
|
|
429
443
|
const changed = status ? status.split('\n').filter(Boolean).length : 0;
|
|
430
444
|
const up = runGit(['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'], { cwd: repoPath });
|
|
431
445
|
const upstream = up.ok && up.stdout.trim() ? up.stdout.trim() : '';
|
|
432
|
-
|
|
446
|
+
// 指定 remote 时以它为基准(多 remote / fork 场景);否则沿用 origin
|
|
447
|
+
const originUrl = runGit(['remote', 'get-url', remote || 'origin'], { cwd: repoPath }).stdout.trim();
|
|
433
448
|
// 放宽「必须已 -u 建立上游」——无 @{u} 但有远端同样可推
|
|
434
449
|
// (dispatchPush 走 `git push <远端> HEAD:refs/heads/<分支>`,不依赖上游跟踪)。
|
|
435
450
|
// 领先比较基准 = @{u},否则 origin/<当前分支>;本地无该 ref(未 fetch 过)时
|
|
@@ -438,7 +453,7 @@ export async function pushCurrentBranch({ repoPath = '', pushMethod = 'ssh' } =
|
|
|
438
453
|
let ahead = 0, behind = 0, remoteMissing = false, compareFailed = false;
|
|
439
454
|
// 优先 live ls-remote:origin 是 https 时本地 fetch 常失败,origin/<branch> 缓存过期
|
|
440
455
|
// 会把「远端已前走」显示成「领先 N」,点 push 才报分叉。
|
|
441
|
-
const live = originUrl ? liveRemoteHead({ repoPath, branch }) : { ok: false, sha: '' };
|
|
456
|
+
const live = originUrl ? liveRemoteHead({ repoPath, branch, remote }) : { ok: false, sha: '' };
|
|
442
457
|
if (live.ok && live.sha) {
|
|
443
458
|
const rcLive = runGit(['rev-list', '--left-right', '--count', `HEAD...${live.sha}`], { cwd: repoPath });
|
|
444
459
|
if (rcLive.ok) {
|
|
@@ -471,6 +486,6 @@ export async function pushCurrentBranch({ repoPath = '', pushMethod = 'ssh' } =
|
|
|
471
486
|
if (compareFailed) return { ok: false, ahead, behind, changed, error: '无法确认远端状态(本地未 fetch 且 ls-remote 失败)——请先 git fetch 或检查网络' };
|
|
472
487
|
if (ahead <= 0) return { ok: false, ahead, behind, changed, error: '当前分支未领先远端(没有可推送的新提交)' };
|
|
473
488
|
if (behind > 0) return { ok: false, ahead, behind, changed, error: `本地与远端分叉(本地领先 ${ahead},远端领先 ${behind})——先 pull 合并远端提交再推送` };
|
|
474
|
-
const push = await dispatchPush({ repoPath, branch, pushMethod });
|
|
489
|
+
const push = await dispatchPush({ repoPath, branch, pushMethod, remote });
|
|
475
490
|
return { ok: push.ok === true, branch, ahead, behind, changed, pushed: push.pushed, push, error: push.error || push.reason };
|
|
476
491
|
}
|
package/lib/git/transport.js
CHANGED
|
@@ -19,6 +19,7 @@ import { gitRaw, runGit, runGitAsync } from './exec.js';
|
|
|
19
19
|
import { resolveGithubRemote, parseGithubUrl } from './remote-resolve.js';
|
|
20
20
|
// 推送失败诊断(分类 + 置信度 + 下一步):把原文事实与推断分开返回
|
|
21
21
|
import { classifyPushFailure } from './push-diagnose.js';
|
|
22
|
+
import { cachedVisibility } from './visibility.js';
|
|
22
23
|
|
|
23
24
|
/* ───────── 推送通道常量 ───────── */
|
|
24
25
|
const COMMITS_FETCH_TIMEOUT_MS = 20_000; // 远端 commits 查询超时
|
|
@@ -74,12 +75,12 @@ export async function fetchRemoteHeads({ owner = '', repo = '', branch = '', tok
|
|
|
74
75
|
* @param {object} p { repoPath, branch?, token?, force?, pushMethod? }
|
|
75
76
|
* @returns {Promise<{ok, pushed, method?, reason?, fallbackReason?, key?, ...}>}
|
|
76
77
|
*/
|
|
77
|
-
export async function dispatchPush({ repoPath = '', branch = '', token = '', force = false, pushMethod = 'ssh' } = {}) {
|
|
78
|
+
export async function dispatchPush({ repoPath = '', branch = '', token = '', force = false, pushMethod = 'ssh', remote = '' } = {}) {
|
|
78
79
|
const mode = String(pushMethod || 'ssh').toLowerCase();
|
|
79
80
|
const hasKey = resolveSshKeys().length > 0;
|
|
80
81
|
|
|
81
|
-
const trySsh = () => pushViaSsh({ repoPath, branch, force });
|
|
82
|
-
const tryApi = () => pushViaApi({ repoPath, branch, token, force });
|
|
82
|
+
const trySsh = () => pushViaSsh({ repoPath, branch, force, remote });
|
|
83
|
+
const tryApi = () => pushViaApi({ repoPath, branch, token, force, remote });
|
|
83
84
|
|
|
84
85
|
if (mode === 'api') {
|
|
85
86
|
const apiRes = await tryApi();
|
|
@@ -100,7 +101,7 @@ export async function dispatchPush({ repoPath = '', branch = '', token = '', for
|
|
|
100
101
|
const localHead = runGit(['rev-parse', 'HEAD'], { cwd: repoPath }).stdout;
|
|
101
102
|
const cur = branch || runGit(['branch', '--show-current'], { cwd: repoPath }).stdout || 'master';
|
|
102
103
|
const cached = runGit(['rev-parse', `refs/remotes/origin/${cur}`], { cwd: repoPath }).stdout;
|
|
103
|
-
const live = liveRemoteHead({ repoPath, branch: cur });
|
|
104
|
+
const live = liveRemoteHead({ repoPath, branch: cur, remote });
|
|
104
105
|
const remoteHead = live.sha || cached || '';
|
|
105
106
|
return {
|
|
106
107
|
ok: false, pushed: false, method: 'ssh', diverged: true,
|
|
@@ -187,12 +188,17 @@ function buildLsRemoteSshCmd(keyPath, known, { mux = true } = {}) {
|
|
|
187
188
|
* origin 是 https 时本地 fetch 常失败,账号卡片会把「远端已前走」显示成「领先 N」。
|
|
188
189
|
* @returns {{ok:boolean, sha:string, via?:string}}
|
|
189
190
|
*/
|
|
190
|
-
export function liveRemoteHead({ repoPath = '', branch = '' } = {}) {
|
|
191
|
+
export function liveRemoteHead({ repoPath = '', branch = '', remote = '' } = {}) {
|
|
191
192
|
// 离线开关(单测/无外网)——直接失败,不触发 SSH/网络 ls-remote(防挂起)
|
|
192
193
|
if (process.env.DSH_GIT_PUSH_OFFLINE === '1') return { ok: false, sha: '', via: 'offline' };
|
|
193
|
-
// 自动指定正确的 remote(与推送同源判定:归属 + ssh:443 形态 +
|
|
194
|
+
// 自动指定正确的 remote(与推送同源判定:归属 + ssh:443 形态 + 名字优先级);
|
|
195
|
+
// 指定 remote 时以它为核验目标(与 pushViaSsh/pushViaApi 的 remote 同源)。
|
|
194
196
|
const rr = resolveGithubRemote({ repoPath });
|
|
195
|
-
|
|
197
|
+
let url = rr.ok && rr.url ? rr.url : '';
|
|
198
|
+
if (remote) {
|
|
199
|
+
url = String(runGit(['remote', 'get-url', remote], { cwd: repoPath }).stdout || '').trim() || url;
|
|
200
|
+
}
|
|
201
|
+
const pr = (url ? parseGithubUrl(url) : null)
|
|
196
202
|
|| parseGithubOwnerRepo(runGit(['remote', 'get-url', 'origin'], { cwd: repoPath }).stdout);
|
|
197
203
|
const target = branch || runGit(['branch', '--show-current'], { cwd: repoPath }).stdout;
|
|
198
204
|
if (!pr || !target) return { ok: false, sha: '' };
|
|
@@ -213,21 +219,38 @@ export function liveRemoteHead({ repoPath = '', branch = '' } = {}) {
|
|
|
213
219
|
if (sha) return { ok: true, sha, via: kind };
|
|
214
220
|
}
|
|
215
221
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
222
|
+
// 统一前置判断:私有库不试 origin(https) 回退——镜像/直连都看不到私有库,试了只会多一条失败。
|
|
223
|
+
// unknown 时保留回退(可能是公开库,https 直连/镜像仍有机会成功)。
|
|
224
|
+
if (cachedVisibility(repoPath) !== 'private') {
|
|
225
|
+
const lr = runGit(['ls-remote', rr.remote || 'origin', `${REFS_HEADS_PREFIX}${target}`], { cwd: repoPath, timeoutMs: LS_TIMEOUT });
|
|
226
|
+
if (lr.ok) {
|
|
227
|
+
const sha = (lr.stdout || '').trim().split(/\s+/)[0] || '';
|
|
228
|
+
if (sha) return { ok: true, sha, via: rr.remote || 'origin' };
|
|
229
|
+
}
|
|
220
230
|
}
|
|
221
231
|
return { ok: false, sha: '' };
|
|
222
232
|
}
|
|
223
233
|
|
|
224
234
|
/** SSH 回退:ssh.github.com:443(token 401 时)。force=true 时 --force(覆盖远端历史)。 */
|
|
225
|
-
|
|
235
|
+
/** 解析指定 remote 的目标(owner/repo);remote 不存在或不是 GitHub 地址返回 null。 */
|
|
236
|
+
export function resolveRemoteTarget(repoPath = '', remote = '') {
|
|
237
|
+
const url = String(runGit(['remote', 'get-url', remote], { cwd: repoPath }).stdout || '').trim();
|
|
238
|
+
if (!url) return null;
|
|
239
|
+
return parseGithubUrl(url) || parseGithubOwnerRepo(url) || null;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function pushViaSsh({ repoPath = '', branch = '', force = false, remote = '' }) {
|
|
226
243
|
const keys = resolveSshKeys();
|
|
227
244
|
if (!keys.length) return { ok: false, pushed: false, reason: '无 SSH 私钥(配置目录 id_rsa/id_ed25519/id_ecdsa)' };
|
|
228
245
|
// 自动指定正确的 remote(归属 + 本机可用形态 ssh:443 + 名字优先级;必要时 set-url)——不再写死 origin
|
|
246
|
+
// 指定 remote 时以它为推送目标(多 remote / fork 场景),核验同源(liveRemoteHead 同参数)。
|
|
229
247
|
const rr = resolveGithubRemote({ repoPath });
|
|
230
|
-
|
|
248
|
+
let picked = rr.ok && rr.url ? parseGithubUrl(rr.url) : null;
|
|
249
|
+
if (remote) {
|
|
250
|
+
const byRemote = resolveRemoteTarget(repoPath, remote);
|
|
251
|
+
if (!byRemote) return { ok: false, pushed: false, reason: `指定的 remote「${remote}」不存在或不是 GitHub 地址` };
|
|
252
|
+
picked = byRemote;
|
|
253
|
+
}
|
|
231
254
|
const originUrl = runGit(['remote', 'get-url', 'origin'], { cwd: repoPath }).stdout;
|
|
232
255
|
const pr = picked || parseGithubOwnerRepo(originUrl);
|
|
233
256
|
if (!pr) {
|
|
@@ -276,10 +299,16 @@ async function apiOrFallback(api, repoPath, branch, res) {
|
|
|
276
299
|
* token 401 → pushViaSsh 回退。
|
|
277
300
|
* @returns {{ok, pushed, method?, commitSha?, reason?, branchAdjusted?}}
|
|
278
301
|
*/
|
|
279
|
-
export async function pushViaApi({ repoPath = '', branch = '', token = '', force = false } = {}) {
|
|
302
|
+
export async function pushViaApi({ repoPath = '', branch = '', token = '', force = false, remote = '' } = {}) {
|
|
280
303
|
const rr = resolveGithubRemote({ repoPath });
|
|
281
304
|
const origin = runGit(['remote', 'get-url', 'origin'], { cwd: repoPath }).stdout;
|
|
282
|
-
|
|
305
|
+
let pr = (rr.ok && rr.url ? parseGithubUrl(rr.url) : null) || parseGithubOwnerRepo(origin);
|
|
306
|
+
// 指定 remote 时以它为准(多 remote / fork 场景):推送目标与核验目标同源
|
|
307
|
+
if (remote) {
|
|
308
|
+
const remoteUrl = String(runGit(['remote', 'get-url', remote], { cwd: repoPath }).stdout || '').trim();
|
|
309
|
+
const byRemote = remoteUrl ? (parseGithubUrl(remoteUrl) || parseGithubOwnerRepo(remoteUrl)) : null;
|
|
310
|
+
if (byRemote) pr = byRemote;
|
|
311
|
+
}
|
|
283
312
|
if (!pr) {
|
|
284
313
|
return {
|
|
285
314
|
ok: false, pushed: false,
|
|
@@ -401,9 +430,12 @@ async function uploadBlobsAndBuildTree({ repoPath, entries, remoteBlobShas, api
|
|
|
401
430
|
* (ControlMaster)把 N 仓总耗时压到接近单仓。
|
|
402
431
|
* @returns {Promise<{ok:boolean, sha:string, via?:string}>}
|
|
403
432
|
*/
|
|
404
|
-
export async function liveRemoteHeadAsync({ repoPath = '', branch = '' } = {}) {
|
|
433
|
+
export async function liveRemoteHeadAsync({ repoPath = '', branch = '', remote = '' } = {}) {
|
|
405
434
|
if (process.env.DSH_GIT_PUSH_OFFLINE === '1') return { ok: false, sha: '', via: 'offline' };
|
|
406
|
-
|
|
435
|
+
// 指定 remote 时核验它(与推送同源);否则沿用 origin
|
|
436
|
+
const origin = remote
|
|
437
|
+
? (await runGitAsync(['remote', 'get-url', remote], { cwd: repoPath })).stdout
|
|
438
|
+
: (await runGitAsync(['remote', 'get-url', 'origin'], { cwd: repoPath })).stdout;
|
|
407
439
|
const pr = parseGithubOwnerRepo(origin);
|
|
408
440
|
const target = branch || (await runGitAsync(['branch', '--show-current'], { cwd: repoPath })).stdout;
|
|
409
441
|
if (!pr || !target) return { ok: false, sha: '' };
|
package/lib/git/visibility.js
CHANGED
|
@@ -3,32 +3,116 @@
|
|
|
3
3
|
// 抽出原因:同一职责(可见性判定)此前在
|
|
4
4
|
// push.js 与 commit-push.js 各写一份,违反「同一职责单一入口」的设计,故抽成独立模块。
|
|
5
5
|
//
|
|
6
|
-
//
|
|
6
|
+
// 为什么独立成模块:可见性判定有**多个消费方**,各自实现(`resolveToken` +
|
|
7
7
|
// `detectRepoVisibility` 两处复制)会造成口径漂移(token 来源、探测失败兜底不一致):
|
|
8
8
|
// ① `lib/git/push.js` —— 私有库敏感文件豁免(private → 只扫描报告、不写 .gitignore)
|
|
9
9
|
// ② `lib/commit-push.js` —— 审计门禁豁免(private → 审计只报告不拦截)
|
|
10
|
-
//
|
|
11
|
-
|
|
10
|
+
// ③ 克隆 / ls-remote 探针 / 推送核验 —— 私有库**不走第三方镜像**(见 accessPlan)
|
|
11
|
+
// 统一走本入口后,各消费方拿到同一形状、同一兜底口径。
|
|
12
|
+
import { detectRepoVisibility, parseGithubOwnerRepo, githubFetch } from './api.js';
|
|
12
13
|
import { resolveToken } from './credentials.js';
|
|
14
|
+
import { runGit } from '../core/exec.js';
|
|
13
15
|
|
|
14
|
-
//
|
|
16
|
+
// 可见性缓存:按 repoPath 键化,默认 5 分钟——避免每次 git 操作都多打一次 API
|
|
17
|
+
const cache = new Map();
|
|
18
|
+
const DEFAULT_TTL_MS = 5 * 60 * 1000;
|
|
19
|
+
|
|
20
|
+
/** 清空缓存(测试用,或凭据变化后强制重查)。 */
|
|
21
|
+
export function clearVisibilityCache() {
|
|
22
|
+
cache.clear();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 读缓存(同步;未命中返回 'unknown')。 */
|
|
26
|
+
export function cachedVisibility(repoPath = '') {
|
|
27
|
+
const hit = cache.get(repoPath);
|
|
28
|
+
return hit ? hit.value.visibility : 'unknown';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 访问计划:把可见性翻译成「走哪条通道」。
|
|
33
|
+
* public → 可以走镜像(gh-proxy 加速)
|
|
34
|
+
* private / unknown / 其他 → 不走镜像,改 SSH(本机 ssh.github.com:443 可用)
|
|
35
|
+
* 为什么 unknown 也当私有:镜像对私有库无意义(必然 404/认证失败),
|
|
36
|
+
* 而「失败后才发现」正是过去克隆失败、探针失明、核验未完成的根因。
|
|
37
|
+
* @returns {{visibility:string, useMirror:boolean, transport:'https'|'ssh'}}
|
|
38
|
+
*/
|
|
39
|
+
export function accessPlan(visibility = 'unknown') {
|
|
40
|
+
if (visibility === 'public') return { visibility, useMirror: true, transport: 'https' };
|
|
41
|
+
return { visibility, useMirror: false, transport: 'ssh' };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** SSH 形态的仓库 URL(走 ssh.github.com:443,绕开本机不通的 github.com:443)。 */
|
|
45
|
+
export function sshGitUrl(owner = '', repo = '') {
|
|
46
|
+
return `ssh://git@ssh.github.com:443/${owner}/${repo}.git`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 从仓库路径解析 GitHub 坐标(解析不到返回 null)。 */
|
|
50
|
+
export function ownerRepoOf(repoPath = '') {
|
|
51
|
+
try {
|
|
52
|
+
const url = runGit(['remote', 'get-url', 'origin'], { cwd: repoPath }).stdout;
|
|
53
|
+
return parseGithubOwnerRepo(url);
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 按 owner/repo 判断可见性(克隆场景用:目标目录还是空的,没有 origin 可解析)。
|
|
61
|
+
* 与 resolveRepoVisibility 共用缓存(键前缀 gh: 区分)。
|
|
62
|
+
* @returns {Promise<{visibility:'private'|'public'|'unknown', owner?:string, repo?:string, reason?:string, cached?:boolean}>}
|
|
63
|
+
*/
|
|
64
|
+
export async function resolveOwnerVisibility({ owner = '', repo = '', token = '', ttlMs = DEFAULT_TTL_MS } = {}) {
|
|
65
|
+
if (!owner || !repo) return { visibility: 'unknown', reason: '缺少 owner/repo' };
|
|
66
|
+
const key = `gh:${owner}/${repo}`;
|
|
67
|
+
const hit = cache.get(key);
|
|
68
|
+
if (hit && Date.now() - hit.at < ttlMs) return { ...hit.value, cached: true };
|
|
69
|
+
|
|
70
|
+
let tok = token;
|
|
71
|
+
if (!tok) {
|
|
72
|
+
try { tok = resolveToken({}).token; } catch { tok = ''; }
|
|
73
|
+
}
|
|
74
|
+
if (!tok) return { visibility: 'unknown', reason: '无可用 token' };
|
|
75
|
+
try {
|
|
76
|
+
const r = await githubFetch(`/repos/${owner}/${repo}`, { token: tok, timeout: 10_000 });
|
|
77
|
+
if (r.status === 200) {
|
|
78
|
+
const j = r.json || {};
|
|
79
|
+
const value = { visibility: j.private ? 'private' : 'public', owner, repo };
|
|
80
|
+
cache.set(key, { value, at: Date.now() });
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
// 404:GitHub 对「私有但无权限」与「不存在」返回同一个码 ⇒ 按私有处理(不走镜像更安全)
|
|
84
|
+
const value = { visibility: r.status === 404 ? 'private' : 'unknown', owner, repo, reason: `API ${r.status}` };
|
|
85
|
+
if (r.status === 404) cache.set(key, { value, at: Date.now() });
|
|
86
|
+
return value;
|
|
87
|
+
} catch (e) {
|
|
88
|
+
return { visibility: 'unknown', reason: String((e && e.message) || e) };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 解析仓库远端可见性(统一收口,带缓存)。
|
|
15
93
|
//
|
|
16
94
|
// 兜底口径:token 缺失 / 非 GitHub origin / API 失败 → 一律 `unknown`
|
|
17
|
-
// (调用方对 unknown 按保守处理:push
|
|
95
|
+
// (调用方对 unknown 按保守处理:push 不豁免、审计门禁仍拦截、不走镜像)。
|
|
18
96
|
// 边界:resolveToken 自身抛错也吞成「无 token」(探测失败不该中断调用方流程)。
|
|
19
97
|
//
|
|
20
98
|
// @param {string} repoPath 仓库绝对路径
|
|
21
99
|
// @param {string} [token] 显式 token(缺省按仓库解析:仓库 token 文件 → 插件配置)
|
|
22
|
-
// @
|
|
23
|
-
//
|
|
24
|
-
export async function resolveRepoVisibility(repoPath, token = '') {
|
|
100
|
+
// @param {{ttlMs?:number}} [opts] 缓存有效期
|
|
101
|
+
// @returns {Promise<{visibility: 'private'|'public'|'unknown', owner?: string, repo?: string, reason?: string, cached?: boolean}>}
|
|
102
|
+
export async function resolveRepoVisibility(repoPath, token = '', { ttlMs = DEFAULT_TTL_MS } = {}) {
|
|
103
|
+
const hit = cache.get(repoPath);
|
|
104
|
+
if (hit && Date.now() - hit.at < ttlMs) return { ...hit.value, cached: true };
|
|
105
|
+
|
|
25
106
|
let tok = token;
|
|
26
107
|
if (!tok) {
|
|
27
108
|
try { tok = resolveToken({ repoPath }).token; } catch { tok = ''; }
|
|
28
109
|
}
|
|
29
110
|
if (!tok) return { visibility: 'unknown', reason: '无可用 token' };
|
|
30
111
|
try {
|
|
31
|
-
|
|
112
|
+
const r = await detectRepoVisibility({ repoPath, token: tok });
|
|
113
|
+
// 只缓存确定结果:unknown 可能是临时网络失败,缓存它会让后续操作一直走 SSH
|
|
114
|
+
if (r.visibility !== 'unknown') cache.set(repoPath, { value: r, at: Date.now() });
|
|
115
|
+
return r;
|
|
32
116
|
} catch (e) {
|
|
33
117
|
return { visibility: 'unknown', reason: String((e && e.message) || e) };
|
|
34
118
|
}
|
package/lib/npm/publish.js
CHANGED
|
@@ -16,6 +16,14 @@ import { npmArgs, writeNpmrc } from './npmrc.js';
|
|
|
16
16
|
|
|
17
17
|
export const PUBLISH_LOG_FILE = 'npm-publish.log';
|
|
18
18
|
export const PUBLISH_TIMEOUT_MS = 300_000;
|
|
19
|
+
/** 真发后轮询 registry 确认版本可见:每分钟 1 次、最多 5 次(远端更新即返回,超时输出原结果)。 */
|
|
20
|
+
export const PUBLISH_POLL_MAX = 5;
|
|
21
|
+
export const PUBLISH_POLL_INTERVAL_MS = 60_000;
|
|
22
|
+
|
|
23
|
+
/** 等待(轮询间隔)。 */
|
|
24
|
+
function sleep(ms) {
|
|
25
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
26
|
+
}
|
|
19
27
|
/** tag 白名单(防把非法值透传给 npm)。 */
|
|
20
28
|
export const PUBLISH_TAGS = ['latest', 'beta', 'next', 'alpha', 'rc', 'dev', 'canary'];
|
|
21
29
|
|
|
@@ -148,6 +156,20 @@ export async function publishPackage({
|
|
|
148
156
|
// 否则会去发布宿主 cwd 下的包(或不存在的包)—— 这是发包类操作里最危险的一种错。
|
|
149
157
|
const r = runNpm(args, { timeoutMs, env: { NO_UPDATE_NOTIFIER: '1' }, cwd: info.dir });
|
|
150
158
|
appendPublishLog(`publish END dryRun=${dryRun} ok=${r.ok} code=${r.code} err=${String(r.error || '').slice(0, 200)}`, { workspaceRoot });
|
|
159
|
+
// 真发成功后轮询 registry 确认版本可见(每分钟 1 次、最多 5 分钟;远端更新即返回,超时输出原结果)
|
|
160
|
+
let verified = false;
|
|
161
|
+
let polled = 0;
|
|
162
|
+
let pollTimeout = false;
|
|
163
|
+
if (r.ok && !dryRun) {
|
|
164
|
+
for (let i = 0; i < PUBLISH_POLL_MAX; i += 1) {
|
|
165
|
+
await sleep(PUBLISH_POLL_INTERVAL_MS);
|
|
166
|
+
polled += 1;
|
|
167
|
+
const now = await fetchPublishedVersions({ name: info.name, registry: reg, timeoutMs: NPM_TIMEOUT_MS });
|
|
168
|
+
if (now.ok && now.versions.includes(info.version)) { verified = true; break; }
|
|
169
|
+
}
|
|
170
|
+
pollTimeout = !verified;
|
|
171
|
+
appendPublishLog(`publish POLL verified=${verified} polled=${polled} timeout=${pollTimeout}`, { workspaceRoot });
|
|
172
|
+
}
|
|
151
173
|
return {
|
|
152
174
|
ok: !!r.ok,
|
|
153
175
|
dryRun: !!dryRun,
|
|
@@ -159,6 +181,11 @@ export async function publishPackage({
|
|
|
159
181
|
packSize: pack.size,
|
|
160
182
|
tarball: pack.filename,
|
|
161
183
|
published: !dryRun && !!r.ok,
|
|
184
|
+
// 轮询结果:verified=true 表示 registry 已能看到新版本;pollTimeout=true 表示 5 分钟未出现(以 npm 返回为准)
|
|
185
|
+
verified,
|
|
186
|
+
polled,
|
|
187
|
+
pollTimeout,
|
|
188
|
+
pollNote: pollTimeout ? '5 分钟内未在 registry 看到新版本(可能 CDN 延迟;结果以 npm 返回为准)' : '',
|
|
162
189
|
registryQuery: { ok: pub.ok, error: pub.error || '' },
|
|
163
190
|
stdout: String(r.stdout || '').slice(-4000),
|
|
164
191
|
stderr: String(r.stderr || '').slice(-4000),
|
package/lib/npm/registry.js
CHANGED
|
@@ -75,9 +75,12 @@ export function runNpm(args = [], { timeoutMs = NPM_TIMEOUT_MS, env = {}, cwd =
|
|
|
75
75
|
const merged = { ...process.env, ...env };
|
|
76
76
|
// 关键:npm 的入口是 `#!/usr/bin/env node` 脚本 ⇒ 子进程 PATH 里必须有 node,
|
|
77
77
|
// 否则即使找到 npm 也会报「env: 'node': No such file or directory」(最小 PATH 宿主实测)。
|
|
78
|
-
//
|
|
78
|
+
// 插到 PATH **末尾**:既保证 node 可找到,又不覆盖调用方/测试注入的 PATH 优先级
|
|
79
|
+
// (插最前会在 GitHub runner 上让 nodeDir 自带的真 npm 抢先于测试注入的假 npm)。
|
|
79
80
|
const nodeDir = dirname(String(process.execPath || ''));
|
|
80
|
-
if (nodeDir
|
|
81
|
+
if (nodeDir && !String(merged.PATH || '').split(delimiter).includes(nodeDir)) {
|
|
82
|
+
merged.PATH = `${merged.PATH || ''}${delimiter}${nodeDir}`;
|
|
83
|
+
}
|
|
81
84
|
const bin = resolveNpmBin({ env: merged });
|
|
82
85
|
// maxBuffer 可注入:默认 16MB;测试传极小值(如 1)即可**确定性触发** ENOBUFS 走重试分支 ✓
|
|
83
86
|
const runNpmBuf = (buf) => spawnSync(bin, args, {
|
package/lib/self/index.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
export const VERSION = '2.9.
|
|
12
|
+
export const VERSION = '2.9.9'; // 2.9.9:npm_publish 真发后轮询 registry 确认版本可见——每分钟 1 次、最多 5 分钟;远端更新即返回(verified=true),超时输出原结果(verified=false + pollTimeout + pollNote),轮询过程写 npm-publish.log。历史:2.9.8:①git_commit_push 支持 remote 参数(多 remote / fork:推送与核验同源);②新增 exempt 注释豁免工具(add/remove/list/check)。
|
|
13
13
|
// 实测后果:该目录有 package.json ⇒ npm 去打包整棵 DSH 树、输出 2.1MB > spawnSync 默认 maxBuffer 1MB ⇒ ENOBUFS(npm_publish 的体检与真发全部失败);
|
|
14
14
|
// 该目录没有 package.json 时报 ENOENT。现 publish 的两个调用点显式传 cwd=目标包目录,并给 runNpm 加 16MB maxBuffer。
|
|
15
15
|
// 2.8.3:文案修正——「零改动 / 无新提交」明确为**正常成功路径**(注入用法、工具描述、README、skill 同批改),并修 job 输出自相矛盾(cleanSkipCommit 路径补 committed:false,不再显示「已提交,未推送」)
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-git-push",
|
|
3
|
-
"version": "2.9.
|
|
4
|
-
|
|
3
|
+
"version": "2.9.9",
|
|
5
4
|
"description": "DSH git 自动提交推送插件——统一函数入口架构(规则/审计/git/自身/侧边栏/评分/豁免/上下文/HTTP/测试十大总入口)",
|
|
6
5
|
"type": "module",
|
|
7
6
|
"main": "lib/index.js",
|
|
@@ -92,7 +91,6 @@
|
|
|
92
91
|
"test": "node test/run-tests.mjs",
|
|
93
92
|
"check": "node scripts/check.mjs",
|
|
94
93
|
"scan-version": "node scripts/scan-version.mjs",
|
|
95
|
-
"check:drift": "node scripts/doc-drift.mjs"
|
|
96
|
-
"sync-plugin": "node scripts/sync-plugin.mjs"
|
|
94
|
+
"check:drift": "node scripts/doc-drift.mjs"
|
|
97
95
|
}
|
|
98
96
|
}
|
|
@@ -24,7 +24,6 @@ generatedBy: deepseek-official/deepseek-v4-flash · EIGHTfs 2026-10-02
|
|
|
24
24
|
| `link_check` | `repo?`, `paths?` | 检查文档链接:404/403→-3、DNS→-2、超时/5xx→-1;只 warning,永不 blocker |
|
|
25
25
|
| `io_scan` | `repo?`, `writeOnly?` | I/O 风险扫描(AST 四级分级 high/medium/low/safe,与审计 io-risk 同标准) |
|
|
26
26
|
| `git_clone_preview` | `target`, `branch?` | clone 预演(不落盘,报告将拉取什么) |
|
|
27
|
-
| `edit_after_read` | `path`/`file_path`, `old`/`old_string`, `new`/`new_string`, `all?` | 读改合一编辑(读后文件被改动则拒绝;old 默认必须唯一匹配;字面匹配不做正则解释) |
|
|
28
27
|
| `git_identity_rewrite` | `paths?`, `root?`, `dryRun?`, `push?` | 提交身份历史改写(默认 dryRun 只报告;真改写先建备份引用 + 自检,通过才 force-with-lease) |
|
|
29
28
|
| `module_splitter` | `command`, `file`/`plan`, `dryRun?` | 巨型单文件拆分:analyze(先看依赖)→ split → verify(校验导出一致) |
|
|
30
29
|
| `git_account_check` | `token?`, `sshPub?` | 校验 GitHub 账号与凭据(登录态/用户名/公钥数/套餐;token 不传自动解析) |
|
|
@@ -313,7 +312,7 @@ node scripts/readme-gen.mjs <repoPath> [--write <path>] [--template <path>]
|
|
|
313
312
|
|
|
314
313
|
| 现象 | 原因 / 处理 |
|
|
315
314
|
|------|-------------|
|
|
316
|
-
| 插件改动刷新看不到 | 真实加载源是 `<profile>/local-plugins/<插件名>`,只同步 `node_modules/` 无效;用 `
|
|
315
|
+
| 插件改动刷新看不到 | 真实加载源是 `<profile>/local-plugins/<插件名>`,只同步 `node_modules/` 无效;用 ``sync_plugin` 工具(write:true)` 同步两处(多 profile 时加 `--profile <名>`) |
|
|
317
316
|
| 改插件代码必须重启才生效 | 免重启热重载要同时满足两条:① profile 的 `cordis.patch.yml` 里 `id: hmr` 显式配 `base` + `root`(默认 `root: []` = module roots are opt-in,一个模块目录都不 watch);② 插件本体在 `local-plugins/`(`node_modules/**` 被默认 `ignored` 整棵剪枝,想只放行其下某插件的否定写法无效)。`sync-plugin.mjs` 会直接报告该插件能否热重载,`--fix` 可修部署形态(改完形态需重启一次让解析路径生效) |
|
|
318
317
|
| 规则不生效 | 槽位动态发现,确认文件名 `audit-rules-<名>.yml` 且在 `lib/audit-rules/` |
|
|
319
318
|
| 统计数字矛盾(0 blocker 0 warning 但 total > 0) | error 级计入拦截级,看 findings 的 `severity` |
|
|
@@ -71,10 +71,10 @@ git-sluice self-check
|
|
|
71
71
|
| `scripts/scan-version.mjs` | 版本一致性校验(三处版本号是否同步) |
|
|
72
72
|
| `scripts/doc-func.mjs` / `doc-tree.mjs` / `doc-version.mjs` | 函数列表 / 目录树 / 版本记录 三份文档与代码同步(`check` 查漂移、`apply` 写回) |
|
|
73
73
|
| `scripts/readme-gen.mjs` | README 生成 |
|
|
74
|
-
| `
|
|
74
|
+
| (已迁移)dsh-useful-tools 的 `preview` 工具(action=gen / 只更数据段 / check` 漂移门禁 / `--watch` 监听) / ``preview` 工具 action=serve(dsh-useful-tools)`(默认反代真后端 / `--direct` 直连插件 / `--local` 免重启) | 界面预览页生成与漂移门禁、本地真实后端测试服务 |
|
|
75
75
|
| `scripts/browser-page-probe.mjs` | 无头浏览器探针:读页面真实渲染文本 + 抓前端运行时错误(零硬编码路径,自动探测环境) |
|
|
76
|
-
| `
|
|
77
|
-
| `
|
|
76
|
+
| ``sync_plugin` 工具(dsh-useful-tools)` | 同步(工作区 → 安装副本;**安装位置 = local-plugins 真源**)+ 部署形态与免重启热重载自检:`--profile <名>` 指定 profile(多 profile 必给)、`--fix` 只修 local-plugins 侧形态(解软链 / 建真实目录)。node_modules 入口由 DSH 安装流程生成,本脚本不建链;若那里的副本**内容与真源不一致**会报警(实测会顶掉真源;同 inode 硬链接副本不报) |
|
|
77
|
+
| ``sync_plugin` 工具的实现(dsh-useful-tools/lib/core/plugin-sync/install.mjs)` | 安装形态 / HMR 自检的实现模块(`sync-plugin.mjs` 引用,非独立入口) |
|
|
78
78
|
| `scripts/verify-prestep.mjs` | 上下文注入自检(真实触发 pre-step 校验注入内容) |
|
|
79
79
|
| `scripts/rename-locator.mjs` | 变量重命名位置定位(按作用域聚合) |
|
|
80
80
|
| `scripts/rules-solo-audit.mjs` | 单条 yml 规则的控制变量评估 |
|
|
@@ -19,7 +19,7 @@ generatedBy: deepseek-official/deepseek-v4-flash · EIGHTfs 2026-10-02
|
|
|
19
19
|
| 改插件配置/开关 | 只改插件私有 `config.json`(侧边栏保存即写它);不要写公共 `settings.yaml` |
|
|
20
20
|
| 看界面上的真实数据 | 用 `assets/start.sh` 起预览反代(默认真实后端),不要只看静态 HTML 文件 |
|
|
21
21
|
| 刷新账号信息 / 本地仓库列表 | 只在三种时机读取;不轮询、不监听索引文件,页面切 tab 不会刷新 |
|
|
22
|
-
| 改了前端界面代码 |
|
|
22
|
+
| 改了前端界面代码 | 先用 dsh-useful-tools 的 `preview` 工具(`action=gen`)重生成预览页再看,否则看的是旧界面 |
|
|
23
23
|
|
|
24
24
|
## 二、怎么做 / 命令 / 实例
|
|
25
25
|
|
|
@@ -115,7 +115,7 @@ generatedBy: deepseek-official/deepseek-v4-flash · EIGHTfs 2026-10-02
|
|
|
115
115
|
|
|
116
116
|
### 2.6 界面预览页(assets/preview.html,真实后端数据)
|
|
117
117
|
|
|
118
|
-
预览页由 `
|
|
118
|
+
预览页由 **dsh-useful-tools** 的 `preview` 工具生成(`action=gen`)(内联真实前端代码,只垫片宿主环境),界面与真实插件一致;用 `assets/start.sh` 起本地反代服务访问:
|
|
119
119
|
|
|
120
120
|
```bash
|
|
121
121
|
./assets/start.sh start [--port 31000] # 默认 30999;端口被别的项目占用时用 --port 错开
|
|
@@ -123,11 +123,11 @@ generatedBy: deepseek-official/deepseek-v4-flash · EIGHTfs 2026-10-02
|
|
|
123
123
|
```
|
|
124
124
|
|
|
125
125
|
- 访问 `http://<本机IP>:30999`(默认端口)。反代把 `/api/git-push/*` 全部转发到真实 DSH 后端(默认 `http://<本机IP>:30800`),并自动完成 token 认证——账号信息 / 本地仓库 / 云端仓库 / 规则包 / 审计结果 / 设置全部来自真实后端,读取与写入都真实。
|
|
126
|
-
- 指定后端或直接跑:`
|
|
126
|
+
- 指定后端或直接跑:`preview` 工具 `action=serve`(port / backend 参数)(同一入口还有 `--direct` 直连插件 handleHttp、`--local` 每请求 fork 子进程跑工作区最新代码);token 解析顺序:`--token` > 环境变量 `DSH_PREVIEW_TOKEN` > 解析 `dsh-proxy.log` 兜底。
|
|
127
127
|
- 离线调试:URL 加 `?mock=1` 切内置假数据(改动只留页面内、不写文件);跨后端实测:URL 加 `?backend=http://<本机IP>:端口`。
|
|
128
128
|
- 全部可点:三选项卡切换、审计开关、注入系统提示词开关、注入要求清单子开关(含置灰联动)、规则包启停与调序、权重编辑、token/SSH 保存、邮箱一键生成 SSH 并回填。
|
|
129
129
|
- 健康检查 `GET /preview-ping`;PID 落 `dsh-git-push.pid`(插件根);日志 `assets/preview-server.log`(超 10 MB 轮转)。
|
|
130
|
-
- 改了前端代码后同步预览:`
|
|
130
|
+
- 改了前端代码后同步预览:`preview` 工具 `action=gen`。
|
|
131
131
|
|
|
132
132
|
### 2.7 配置持久化位置
|
|
133
133
|
|
package/assets/minihost.sh
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# dsh-plugin mini-host 一键启动 —— 本地跑本插件服务端代码,**改完代码刷新页面即生效**,
|
|
3
|
-
# 既不用重启 DSH 宿主、也不用重启本服务(每个请求 fork 一次性子进程,插件模块天然新鲜)。
|
|
4
|
-
#
|
|
5
|
-
# 依赖通用工具:dsh-plugin-minihost.mjs(+ dsh-plugin-minihost-child.mjs)
|
|
6
|
-
# 位置:技能仓库 ai-work-archive/skills/,或运行时目录 <DSH_HOME>/skills/
|
|
7
|
-
# 用法:
|
|
8
|
-
# bash assets/minihost.sh # 默认端口 31100
|
|
9
|
-
# bash assets/minihost.sh --port 31200 # 换端口(其余参数透传给 mini-host)
|
|
10
|
-
# 环境变量:
|
|
11
|
-
# DSH_SKILLS_DIR 指定含通用工具的 skills 目录(默认 $DSH_HOME/skills 或 ~/.dsh/skills)
|
|
12
|
-
# PORT 默认端口(默认 31100)
|
|
13
|
-
# NODE_BIN 指定 node(默认 PATH 里的 node)
|
|
14
|
-
set -uo pipefail
|
|
15
|
-
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
16
|
-
SKILLS_DIR="${DSH_SKILLS_DIR:-${DSH_HOME:-$HOME/.dsh}/skills}"
|
|
17
|
-
TOOL="$SKILLS_DIR/dsh-plugin-minihost.mjs"
|
|
18
|
-
if [ ! -f "$TOOL" ]; then
|
|
19
|
-
echo "找不到通用工具:$TOOL"
|
|
20
|
-
echo "请设置 DSH_SKILLS_DIR 指向含 dsh-plugin-minihost.mjs 的 skills 目录"
|
|
21
|
-
exit 2
|
|
22
|
-
fi
|
|
23
|
-
ARGS=(--plugin "$ROOT" --port "${PORT:-31100}")
|
|
24
|
-
# 预览页是**生成产物**(.gitignore 已忽略,不入库):缺失时先自动生成一次,
|
|
25
|
-
# 否则 --preview 分支会**静默跳过**(页面打开是 404/无预览页,且没有任何报错)。
|
|
26
|
-
PREVIEW_HTML="$ROOT/assets/preview.html"
|
|
27
|
-
PREVIEW_GEN="$ROOT/scripts/preview-gen.mjs"
|
|
28
|
-
if [ ! -f "$PREVIEW_HTML" ] && [ -f "$PREVIEW_GEN" ]; then
|
|
29
|
-
echo "[minihost] 预览页缺失,先生成一次:node scripts/preview-gen.mjs"
|
|
30
|
-
"${NODE_BIN:-node}" "$PREVIEW_GEN" >/dev/null 2>&1 \
|
|
31
|
-
|| echo "[minihost] 预览页生成失败(继续启动,但不带预览页)"
|
|
32
|
-
fi
|
|
33
|
-
[ -f "$PREVIEW_HTML" ] && ARGS+=(--preview "$PREVIEW_HTML")
|
|
34
|
-
[ -d "$ROOT/lib" ] && ARGS+=(--static "$ROOT/lib")
|
|
35
|
-
exec "${NODE_BIN:-node}" "$TOOL" "${ARGS[@]}" "$@"
|