dsh-git-push 2.9.9 → 2.10.4
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 +26 -15
- package/assets/tree-sitter/LICENSE +0 -0
- package/assets/tree-sitter/README.md +0 -0
- package/assets/tree-sitter/tree-sitter-javascript.wasm +0 -0
- package/assets/tree-sitter/tree-sitter-python.wasm +0 -0
- package/assets/tree-sitter/tree-sitter-typescript.wasm +0 -0
- package/assets/tree-sitter/tree-sitter.js +0 -0
- package/assets/tree-sitter/tree-sitter.wasm +0 -0
- package/lib/ARCHITECTURE.md +27 -0
- package/lib/app/apply.js +0 -0
- package/lib/app/command-registry.js +1 -0
- package/lib/app/handlers/repos.js +18 -2
- package/lib/app/handlers/settings.js +0 -0
- package/lib/app/handlers/workspace-paths.js +0 -0
- package/lib/app/schema.js +0 -0
- package/lib/app/settings-bridge.js +0 -0
- package/lib/app/tool-call.js +6 -2
- package/lib/ast/brace.js +15 -0
- package/lib/ast/code-lines.js +0 -0
- package/lib/ast/fs-hotspots.js +0 -0
- package/lib/ast/index.js +0 -0
- package/lib/ast/size.js +68 -1
- package/lib/ast/tokenizer.js +0 -0
- package/lib/ast/treesitter.js +0 -0
- package/lib/audit/collector.js +13 -4
- package/lib/audit/ignore-blind.js +5 -4
- package/lib/audit/orchestrate.js +2 -1
- package/lib/audit-rules/audit-rules-frontend.yml +4 -4
- package/lib/checks/button-bind.js +61 -13
- package/lib/checks/dispatch.js +1 -1
- package/lib/checks/fs-scanner.js +0 -0
- package/lib/checks/private.js +2 -1
- package/lib/checks/regex.js +0 -0
- package/lib/checks/structural.js +10 -3
- package/lib/client-parts/{10-account.js → account.js} +1 -1
- package/lib/client-parts/{41-actions.js → actions.js} +3 -2
- package/lib/client-parts/{99-apply.js → apply.js} +2 -1
- package/lib/client-parts/{21-audit.js → audit.js} +5 -5
- package/lib/client-parts/{11-browser.js → browser.js} +15 -4
- package/lib/client-parts/{01-const.js → const.js} +11 -5
- package/lib/client-parts/{40-controller.js → controller.js} +4 -4
- package/lib/client-parts/{03-icons.js → icons.js} +1 -1
- package/lib/client-parts/{00-loader.js → loader.js} +1 -0
- package/lib/client-parts/{23-npm.js → npm.js} +3 -2
- package/lib/client-parts/{30-page.js → page.js} +1 -1
- package/lib/client-parts/{20-repo.js → repo.js} +2 -2
- package/lib/client-parts/{22-settings.js → settings.js} +1 -1
- package/lib/client-parts/{02-utils.js → utils.js} +1 -1
- package/lib/client.js +51 -30
- package/lib/context/index.js +2 -1
- package/lib/core/atomic-json.js +1 -1
- package/lib/core/workspace-paths.js +0 -0
- package/lib/exempt/index.js +7 -2
- package/lib/exempt/tool.js +0 -0
- package/lib/git/clone-history-mode.js +22 -9
- package/lib/git/clone-replay-io.js +10 -4
- package/lib/git/clone.js +8 -2
- package/lib/git/commit-message.js +0 -0
- package/lib/git/index-format.js +182 -0
- package/lib/git/index.js +1 -0
- package/lib/git/init-compat.js +118 -0
- package/lib/git/push-diagnose.js +0 -0
- package/lib/git/repo-index.js +41 -30
- package/lib/git/scan-runner.js +1 -1
- package/lib/npm/publish.js +14 -12
- package/lib/self/index.js +1 -1
- package/package.json +1 -1
- package/scripts/build-client.mjs +19 -14
- package/scripts/check.mjs +68 -0
- package/scripts/cpu-sample.mjs +0 -0
- package/scripts/picker-repro.mjs +115 -0
- package/scripts/scan-fs-hotspots.mjs +0 -0
- package/skills/dsh-repo-index.md +1 -1
- package/skills/guide/guide-audit.md +106 -3
- package/skills/guide/guide-cli-scripts.md +1 -1
- package/skills/guide/guide-clone-repos.md +2 -2
- package/skills/guide/guide-inject-ui.md +2 -2
- package/skills/workflow/README.md +1 -1
package/lib/exempt/index.js
CHANGED
|
@@ -75,13 +75,18 @@ export const EXEMPT_MARKERS = {
|
|
|
75
75
|
// 能豁免这些 kind,而规则自身却提示用 dsh-skip-quality ⇒ 写了不生效;
|
|
76
76
|
// ② regex —— 兜底覆盖**非安全类**的 regex finding(安全类由 excludeRules 排除,
|
|
77
77
|
// 仍必须写 dsh-skip-sensitive,避免用质量标记顺手静默掉安全问题 ✗)。
|
|
78
|
+
// 2026-10-24 补齐(外部项目实测反馈):button-bind 此前**不在任何标记的 blocked 里**,
|
|
79
|
+
// 而 button/unbound 与 button/create-element-binding 两条规则都提示 dsh-skip-quality
|
|
80
|
+
// ⇒ 用户按提示写文件头标记**完全不生效**,且找不到别的标记可用(同一类「提示写了
|
|
81
|
+
// 不生效」缺陷)。按钮绑定判定是启发式的(事件委托/封装函数/原生 label 触发都可能
|
|
82
|
+
// 合法),必须留一条可豁免路径。
|
|
78
83
|
blocked: ['func-lines', 'empty-catch', 'sync-fs', 'magic-number-smart', 'blacklist',
|
|
79
|
-
'comment-density', 'file-health',
|
|
84
|
+
'comment-density', 'file-health', 'button-bind',
|
|
80
85
|
'semantic', 'dataflow', 'duplicate-const', 'repeated-string', 'regex'],
|
|
81
86
|
// regex 兜底时**排除**安全类规则名(这些必须走 dsh-skip-sensitive,不能靠质量标记吞掉)
|
|
82
87
|
excludeRules: ['security', 'credential', 'credref', 'credfile', 'secret', 'password', 'hardcoded'],
|
|
83
88
|
lineLevel: false,
|
|
84
|
-
hint: '文件头=整文件免质量评分(func-lines/empty-catch/sync-fs/magic-number-smart/blacklist 措辞/comment-density/file-health
|
|
89
|
+
hint: '文件头=整文件免质量评分(func-lines/empty-catch/sync-fs/magic-number-smart/blacklist 措辞/comment-density/file-health/button-bind 按钮绑定)',
|
|
85
90
|
},
|
|
86
91
|
'dsh-skip-residue': {
|
|
87
92
|
dimensions: ['可读性', '可维护性'],
|
package/lib/exempt/tool.js
CHANGED
|
File without changes
|
|
@@ -16,6 +16,7 @@ import { fetchCommitChain } from './clone-history.js';
|
|
|
16
16
|
import { replayHistory } from './clone-replay.js';
|
|
17
17
|
import { createReplayIo } from './clone-replay-io.js';
|
|
18
18
|
import { runGit } from './exec.js';
|
|
19
|
+
import { initRepoCompat } from './init-compat.js';
|
|
19
20
|
import { resolveOwnerVisibility, accessPlan, sshGitUrl } from './visibility.js';
|
|
20
21
|
import { resolveSshKeys } from './credentials.js';
|
|
21
22
|
|
|
@@ -134,15 +135,27 @@ export async function cloneWithGitFetch({
|
|
|
134
135
|
};
|
|
135
136
|
|
|
136
137
|
const n = Number(depth) > 0 ? Number(depth) : 0;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
//
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
138
|
+
// 初始化 + origin 一步做完:本地盘走 git init + remote add;不支持 chmod 的卷
|
|
139
|
+
// (CIFS/SMB nounix)走手工 .git 结构降级 —— 那些卷上 git init / git config /
|
|
140
|
+
// git remote add 全都要写 .git/config,而写 config 时的 chmod(config.lock) 必然
|
|
141
|
+
// EPERM,git 直接 fatal。降级路径把 remote 段一并手写进 config(见 init-compat.js)
|
|
142
|
+
const initRes = initRepoCompat(repoPath, {
|
|
143
|
+
branch: branch || 'master',
|
|
144
|
+
remoteUrl,
|
|
145
|
+
chmodOk: deps.chmodOk,
|
|
146
|
+
gitInit: (args, o) => git(args, { ...gitOpts, ...o }),
|
|
147
|
+
});
|
|
148
|
+
steps.push({ cmd: `init (${initRes.via})`, ok: !!initRes.ok });
|
|
149
|
+
if (!initRes.ok) return fail(`git init 失败:${initRes.stderr || '未知'}`);
|
|
150
|
+
if (initRes.filemode) {
|
|
151
|
+
// 权限噪音抑制(只对本地盘有意义;降级路径已把 filemode=false 写进手工 config)
|
|
152
|
+
run(['config', 'core.fileMode', 'false']);
|
|
153
|
+
if (!git(['remote', 'get-url', 'origin'], gitOpts)?.ok) {
|
|
154
|
+
run(['remote', 'add', 'origin', remoteUrl]);
|
|
155
|
+
} else {
|
|
156
|
+
// 已存在 origin(续跑):按本次判断纠正,避免上次留下的 https 形态继续走镜像
|
|
157
|
+
run(['remote', 'set-url', 'origin', remoteUrl]);
|
|
158
|
+
}
|
|
146
159
|
}
|
|
147
160
|
|
|
148
161
|
// 显式 refspec:同时写入 refs/remotes/origin/<branch>,后续可据此建本地分支并设上游
|
|
@@ -22,9 +22,10 @@ import { existsSync, readFileSync, writeFileSync, renameSync, rmSync } from 'nod
|
|
|
22
22
|
|
|
23
23
|
import { githubFetch } from './api.js';
|
|
24
24
|
import { runGit } from './exec.js';
|
|
25
|
+
import { initRepoCompat } from './init-compat.js';
|
|
25
26
|
import { downloadBlobs } from './clone-download.js';
|
|
26
27
|
import {
|
|
27
|
-
blobEntriesOf,
|
|
28
|
+
blobEntriesOf, setRemoteArgs, configFileModeArgs, addAllArgs, writeTreeArgs,
|
|
28
29
|
commitTreeArgs, updateRefArgs, setUpstreamArgs, localBranchRef, remoteTrackingRef, markerJson,
|
|
29
30
|
} from './clone-replay.js';
|
|
30
31
|
|
|
@@ -145,13 +146,18 @@ export function createReplayIo({
|
|
|
145
146
|
|
|
146
147
|
/** 重放前准备:init → 显式写 core.fileMode=false → 设 origin(已有 origin 则不覆盖)。 */
|
|
147
148
|
async prepare() {
|
|
148
|
-
|
|
149
|
-
|
|
149
|
+
// 不支持 chmod 的卷(CIFS/SMB nounix)上 git init / git config / git remote add
|
|
150
|
+
// 全都要写 .git/config,而写 config 时的 chmod(config.lock) 必然 EPERM ⇒ fatal。
|
|
151
|
+
// 改走手工 .git 结构降级:HEAD + config(filemode=false) + remote 段一次写好
|
|
152
|
+
const url = `https://github.com/${owner}/${repo}.git`;
|
|
153
|
+
const initRes = initRepoCompat(gitOpts.cwd, { remoteUrl: url, chmodOk: deps.chmodOk, gitInit: (args, o) => git(args, { ...gitOpts, ...o }) });
|
|
154
|
+
if (!initRes.ok) return { ok: false, error: `git init 失败:${initRes.stderr || '未知'}` };
|
|
155
|
+
// 降级路径:filemode 与 origin 都已写进 config,无需再执行 git config / remote add
|
|
156
|
+
if (!initRes.filemode) return { ok: true, fileModeSet: true, originSet: true, via: initRes.via };
|
|
150
157
|
const cfg = git(configFileModeArgs(false), gitOpts);
|
|
151
158
|
const hasOrigin = git(['remote', 'get-url', 'origin'], gitOpts);
|
|
152
159
|
let originSet = true;
|
|
153
160
|
if (!hasOrigin?.ok) {
|
|
154
|
-
const url = `https://github.com/${owner}/${repo}.git`;
|
|
155
161
|
const add = git(setRemoteArgs('origin', url), gitOpts);
|
|
156
162
|
originSet = !!add?.ok;
|
|
157
163
|
}
|
package/lib/git/clone.js
CHANGED
|
@@ -18,6 +18,7 @@ import { resolveToken } from './credentials.js';
|
|
|
18
18
|
import { downloadBlobs, partitionBySize, DEFAULT_MAX_FILE_MB, DEFAULT_CONCURRENCY, removeDirForce, PARTS_DIR } from './clone-download.js';
|
|
19
19
|
import { cloneAbortSignal, cloneLog } from './clone-jobs.js';
|
|
20
20
|
import { runGit } from './exec.js';
|
|
21
|
+
import { initRepoCompat } from './init-compat.js';
|
|
21
22
|
|
|
22
23
|
/* ───────────────────────── clone / 建仓 / 可见性 ───────────────────────── */
|
|
23
24
|
|
|
@@ -322,12 +323,17 @@ export async function cloneViaApi({
|
|
|
322
323
|
// 先删「进行中」标记:与 history 模式同理,它若留在目录里会被 git add -A 一并提交,
|
|
323
324
|
// 使快照提交多出一个本不该存在的文件(此前实测残留在仓库里,需人工清理)。
|
|
324
325
|
try { unlinkSync(join(targetDir, CLONE_MARKER)); } catch { /* 标记本就不在则忽略 */ }
|
|
326
|
+
// 初始化:本地盘走 git init;不支持 chmod 的卷(CIFS/SMB nounix)走手工 .git 结构,
|
|
327
|
+
// origin 一并手写进 config —— 那些卷上 `git remote add` 同样要写 .git/config 而失败
|
|
328
|
+
const apiRemoteUrl = `${GH_API}/repos/${owner}/${repo}`;
|
|
329
|
+
const initRes = initRepoCompat(targetDir, { branch: useBranch, remoteUrl: apiRemoteUrl });
|
|
330
|
+
if (!initRes.ok) return { ok: false, error: `git init 失败:${initRes.stderr || '未知'}`, dest: targetDir };
|
|
325
331
|
for (const args of [
|
|
326
|
-
['
|
|
332
|
+
['add', '-A'], ['-c', 'user.email=v2-clone@local', '-c', 'user.name=v2-clone', 'commit', '-q', '-m', `clone from ${owner}/${repo}@${useBranch}`],
|
|
327
333
|
]) {
|
|
328
334
|
runGit(args, { cwd: targetDir });
|
|
329
335
|
}
|
|
330
|
-
runGit(['remote', 'add', 'origin',
|
|
336
|
+
if (initRes.filemode) runGit(['remote', 'add', 'origin', apiRemoteUrl], { cwd: targetDir });
|
|
331
337
|
|
|
332
338
|
// 成功:移除进行中标记,此后该目录不再被当作「可清理的残留」
|
|
333
339
|
try { unlinkSync(join(targetDir, CLONE_MARKER)); } catch { /* 标记本就不在则忽略 */ }
|
|
File without changes
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-repo-index 的 JSONL 存储格式(读写 + 旧 JSON 兼容)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么改 JSONL(原为单份 pretty-print JSON 对象):
|
|
5
|
+
* ① **流式读写**:JSONL 每行一个独立对象,写入可以按条目逐行生成、读取可以逐行解析,
|
|
6
|
+
* 不必把整份文档拼成一个结构再 parse/stringify——索引随仓库数增长时这一点更重要;
|
|
7
|
+
* ② **损坏容错**:单份 JSON 只要有一处截断就整份不可用(parse 直接抛),
|
|
8
|
+
* 而 JSONL 可以跳过坏行、保留其余条目,索引不会因为一次半截写而全废;
|
|
9
|
+
* ③ **可增量**:单仓远端状态更新只需重写它自己那一行,语义上不再绑定「整份文档」。
|
|
10
|
+
*
|
|
11
|
+
* 文件形态(每行一个 JSON 对象,UTF-8,LF 结尾):
|
|
12
|
+
* {"_t":"meta","name":…,"description":…,"version":…,"generatedAt":…,"owner":…,"note":…}
|
|
13
|
+
* {"_t":"repo","name":…,"path":…,"repoUrl":…,"visibility":…,…} ← 每个仓库一行
|
|
14
|
+
* {"_t":"localOnly","path":"…"} ← 顶层无远端的目录
|
|
15
|
+
* {"_t":"recovery","text":"多行恢复说明"} ← 收尾(文本整体占一行)
|
|
16
|
+
*
|
|
17
|
+
* 兼容策略:
|
|
18
|
+
* - 读:优先 `dsh-repo-index.jsonl`;不存在则回退旧 `dsh-repo-index.json`(整份 JSON);
|
|
19
|
+
* 两种都能解析成同一个内存对象,调用方无感;
|
|
20
|
+
* - 写:一律写 `.jsonl`;首次写入时把旧的 `.json` 移入同级 `.trash/`(保留可恢复,
|
|
21
|
+
* 避免两份同源索引并存造成漂移)。
|
|
22
|
+
*
|
|
23
|
+
* 不变量:解析结果的对象形状与旧格式**完全一致**(name/description/version/generatedAt/
|
|
24
|
+
* owner/note/repos/localOnly/recovery),保证前端与其它读取方零改动。
|
|
25
|
+
*/
|
|
26
|
+
import { existsSync, readFileSync, mkdirSync, renameSync, readdirSync } from 'node:fs';
|
|
27
|
+
import { join, dirname } from 'node:path';
|
|
28
|
+
|
|
29
|
+
import { writeTextAtomic } from '../core/atomic-json.js';
|
|
30
|
+
|
|
31
|
+
/** 新格式文件名(JSONL)。 */
|
|
32
|
+
export const INDEX_FILE = 'dsh-repo-index.jsonl';
|
|
33
|
+
/** 旧格式文件名(整份 JSON,仅读与迁移用)。 */
|
|
34
|
+
export const LEGACY_INDEX_FILE = 'dsh-repo-index.json';
|
|
35
|
+
|
|
36
|
+
/** 把索引对象序列化成 JSONL 文本(meta → repos → localOnly → recovery)。 */
|
|
37
|
+
export function serializeIndex(index) {
|
|
38
|
+
const o = index && typeof index === 'object' ? index : {};
|
|
39
|
+
const lines = [];
|
|
40
|
+
const meta = {
|
|
41
|
+
_t: 'meta',
|
|
42
|
+
name: o.name || '',
|
|
43
|
+
description: o.description || '',
|
|
44
|
+
version: o.version || '',
|
|
45
|
+
generatedAt: o.generatedAt || '',
|
|
46
|
+
owner: o.owner || '',
|
|
47
|
+
note: o.note || '',
|
|
48
|
+
};
|
|
49
|
+
lines.push(JSON.stringify(meta));
|
|
50
|
+
for (const r of Array.isArray(o.repos) ? o.repos : []) {
|
|
51
|
+
if (!r || typeof r !== 'object') continue;
|
|
52
|
+
lines.push(JSON.stringify({ _t: 'repo', ...r }));
|
|
53
|
+
}
|
|
54
|
+
for (const p of Array.isArray(o.localOnly) ? o.localOnly : []) {
|
|
55
|
+
lines.push(JSON.stringify({ _t: 'localOnly', path: String(p || '') }));
|
|
56
|
+
}
|
|
57
|
+
// recovery 是给人看的多行命令说明:整体作为一个字段,换行由 JSON 转义承载,仍只占一行
|
|
58
|
+
if (o.recovery !== undefined && o.recovery !== null && o.recovery !== '') {
|
|
59
|
+
lines.push(JSON.stringify({ _t: 'recovery', text: String(o.recovery) }));
|
|
60
|
+
}
|
|
61
|
+
return lines.join('\n') + '\n';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** JSONL 文本 → 索引对象;坏行跳过并计数(不因单行损坏丢弃整份)。 */
|
|
65
|
+
export function parseIndex(text) {
|
|
66
|
+
const s = String(text || '');
|
|
67
|
+
const trimmed = s.trim();
|
|
68
|
+
if (!trimmed) return null;
|
|
69
|
+
// 旧格式(整份 JSON):以 { 或 [ 开头且能整体 parse —— 其中的行不是独立对象
|
|
70
|
+
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
|
71
|
+
try {
|
|
72
|
+
const whole = JSON.parse(trimmed);
|
|
73
|
+
// 带 _t 的顶层对象不是旧格式(极少见),继续走 JSONL 分支
|
|
74
|
+
if (!(whole && typeof whole === 'object' && whole._t)) {
|
|
75
|
+
return Array.isArray(whole) ? { repos: whole } : whole;
|
|
76
|
+
}
|
|
77
|
+
} catch { /* 不是整份 JSON → 按 JSONL 解析 */ }
|
|
78
|
+
}
|
|
79
|
+
const out = { name: '', description: '', version: '', generatedAt: '', owner: '', note: '', repos: [], localOnly: [], recovery: '' };
|
|
80
|
+
let skipped = 0;
|
|
81
|
+
for (const raw of s.split('\n')) {
|
|
82
|
+
const line = raw.trim();
|
|
83
|
+
if (!line) continue;
|
|
84
|
+
let obj;
|
|
85
|
+
try { obj = JSON.parse(line); } catch { skipped += 1; continue; }
|
|
86
|
+
if (!obj || typeof obj !== 'object') { skipped += 1; continue; }
|
|
87
|
+
const t = obj._t;
|
|
88
|
+
if (t === 'meta') {
|
|
89
|
+
out.name = obj.name || out.name;
|
|
90
|
+
out.description = obj.description || out.description;
|
|
91
|
+
out.version = obj.version || out.version;
|
|
92
|
+
out.generatedAt = obj.generatedAt || out.generatedAt;
|
|
93
|
+
out.owner = obj.owner || out.owner;
|
|
94
|
+
out.note = obj.note || out.note;
|
|
95
|
+
} else if (t === 'repo') {
|
|
96
|
+
const { _t, ...rest } = obj;
|
|
97
|
+
out.repos.push(rest);
|
|
98
|
+
} else if (t === 'localOnly') {
|
|
99
|
+
if (obj.path) out.localOnly.push(String(obj.path));
|
|
100
|
+
} else if (t === 'recovery') {
|
|
101
|
+
out.recovery = String(obj.text || '');
|
|
102
|
+
} else {
|
|
103
|
+
skipped += 1;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (skipped) out._skippedLines = skipped;
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 读索引文件(JSONL 优先,旧 JSON 回退)。
|
|
112
|
+
* @returns {{index: object|null, path: string, format: 'jsonl'|'json'|'none'}}
|
|
113
|
+
*/
|
|
114
|
+
export function readIndexFile(dir) {
|
|
115
|
+
const jsonlPath = join(dir, INDEX_FILE);
|
|
116
|
+
if (existsSync(jsonlPath)) {
|
|
117
|
+
try { return { index: parseIndex(readFileSync(jsonlPath, 'utf8')), path: jsonlPath, format: 'jsonl' }; } catch { /* 落到旧格式 */ }
|
|
118
|
+
}
|
|
119
|
+
const legacyPath = join(dir, LEGACY_INDEX_FILE);
|
|
120
|
+
if (existsSync(legacyPath)) {
|
|
121
|
+
try { return { index: parseIndex(readFileSync(legacyPath, 'utf8')), path: legacyPath, format: 'json' }; } catch { /* 无可用索引 */ }
|
|
122
|
+
}
|
|
123
|
+
return { index: null, path: '', format: 'none' };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 写入索引(一律 JSONL)。
|
|
128
|
+
*
|
|
129
|
+
* 旧 `.json` 的处理:首次成功写入 `.jsonl` 后,把旧文件移入同级 `.trash/<时间戳>-<名>`
|
|
130
|
+
* (可恢复),避免「两份同源索引并存」——两者不一致时无法判断哪份是真源。
|
|
131
|
+
* @returns {{ok:boolean, path:string, migratedFrom?:string}}
|
|
132
|
+
*/
|
|
133
|
+
export function writeIndexFile(dir, index) {
|
|
134
|
+
const target = join(dir, INDEX_FILE);
|
|
135
|
+
const wr = writeTextAtomic(target, serializeIndex(index));
|
|
136
|
+
if (!wr.ok) return { ok: false, path: target };
|
|
137
|
+
const legacyPath = join(dir, LEGACY_INDEX_FILE);
|
|
138
|
+
let migratedFrom = '';
|
|
139
|
+
if (existsSync(legacyPath)) {
|
|
140
|
+
try {
|
|
141
|
+
const trashDir = join(dir, '.trash');
|
|
142
|
+
mkdirSync(trashDir, { recursive: true });
|
|
143
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
144
|
+
let dest = join(trashDir, `${stamp}-${LEGACY_INDEX_FILE}`);
|
|
145
|
+
if (existsSync(dest)) dest = join(trashDir, `${stamp}-${process.pid}-${LEGACY_INDEX_FILE}`);
|
|
146
|
+
renameSync(legacyPath, dest);
|
|
147
|
+
migratedFrom = dest;
|
|
148
|
+
} catch { /* 移不动就留着(不影响 JSONL 读取优先级) */ }
|
|
149
|
+
}
|
|
150
|
+
return { ok: true, path: target, ...(migratedFrom ? { migratedFrom } : {}) };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** 目录里是否存在任一格式的索引文件。 */
|
|
154
|
+
export function indexFileExists(dir) {
|
|
155
|
+
return existsSync(join(dir, INDEX_FILE)) || existsSync(join(dir, LEGACY_INDEX_FILE));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** 找目录下的索引文件路径(JSONL 优先);都没有返回 null。 */
|
|
159
|
+
export function findIndexPath(dir) {
|
|
160
|
+
const jsonlPath = join(dir, INDEX_FILE);
|
|
161
|
+
if (existsSync(jsonlPath)) return jsonlPath;
|
|
162
|
+
const legacyPath = join(dir, LEGACY_INDEX_FILE);
|
|
163
|
+
if (existsSync(legacyPath)) return legacyPath;
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** 兼容旧调用:整份 JSON 文本(部分调用方只做正则扫描,JSONL 每行也是合法 JSON 片段)。 */
|
|
168
|
+
export function indexAsJsonText(index) {
|
|
169
|
+
return serializeIndex(index);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** 列出目录里残留的索引文件(自检用:正常只有一个)。 */
|
|
173
|
+
export function listIndexFiles(dir) {
|
|
174
|
+
try {
|
|
175
|
+
return readdirSync(dir).filter((f) => f === INDEX_FILE || f === LEGACY_INDEX_FILE);
|
|
176
|
+
} catch { return []; }
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** 索引文件所在目录(便于测试与调试定位)。 */
|
|
180
|
+
export function indexDirOf(filePath) {
|
|
181
|
+
return dirname(String(filePath || ''));
|
|
182
|
+
}
|
package/lib/git/index.js
CHANGED
|
@@ -38,4 +38,5 @@ export { listCloudRepos } from './cloud.js';
|
|
|
38
38
|
export { checkGithubAccount, formatGithubAccountBlock, fetchApiQuota } from './account.js';
|
|
39
39
|
export { writeAccountStatusFromResult, accountStatusFile, readAccountStatus, refreshAccountStatus, buildAccountStatus, updateAccountStatusQuota } from './account-status.js';
|
|
40
40
|
export { locateRepoIndex, readRepoIndexMap, indexEntryForRepo, buildRepoIndex, maintainRepoIndex, updateRepoIndex, mergeCloudReposIntoIndex, updateRepoRemoteStateInIndex } from './repo-index.js';
|
|
41
|
+
export { INDEX_FILE, LEGACY_INDEX_FILE, serializeIndex, parseIndex, readIndexFile, writeIndexFile, indexFileExists, findIndexPath, listIndexFiles } from './index-format.js';
|
|
41
42
|
export { scanRunner, runScan, waitScanDelta, readScanLive, resetScanLive, scanLiveFile, stopScanWatch } from './scan-runner.js';
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* git 仓库初始化兼容层(CIFS/SMB 等不支持 chmod 的文件系统)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要(实测根因,2026-10-28):
|
|
5
|
+
* `git init` 末尾要把探测到的 `core.filemode` **写入** `.git/config`。写 config 走的是
|
|
6
|
+
* `config.lock` → chmod(继承原权限) → rename,而 CIFS 挂载带 `nounix` 时 chmod 一律
|
|
7
|
+
* `EPERM`,于是 git 直接 fatal:
|
|
8
|
+
* `error: chmod on .../.git/config.lock failed: Operation not permitted`
|
|
9
|
+
* `fatal: could not set 'core.filemode' to 'false'`
|
|
10
|
+
* 结果是在目标目录留下一个**未初始化的空 .git**,后续 add/commit 还会向上命中父仓库
|
|
11
|
+
* (把父仓库整棵树写进错误的历史,历史事故)。
|
|
12
|
+
* 同样的 chmod 也会让 `git config core.fileMode false` 失效——所以「先 git init 再关
|
|
13
|
+
* filemode」这条自救路线在 CIFS 上根本不成立。
|
|
14
|
+
*
|
|
15
|
+
* 实测结论(这三条是设计依据,改动前请重跑确认):
|
|
16
|
+
* ① `git init` / `git config` 写 config → 必然失败(chmod);
|
|
17
|
+
* ② **手工搭最小 .git 结构**后,`git add -A` / `git commit` / `git log` / `git reset`
|
|
18
|
+
* 全部正常——index.lock 与 refs 的写入不受影响,只有 config 的 chmod 是死穴;
|
|
19
|
+
* ③ `core.filemode = false` 写进 config 后,`git status` 才不再把所有文件报成 M
|
|
20
|
+
* (CIFS 上文件 mode 恒为 777,与 index 里记录的 100644 不符)。
|
|
21
|
+
*
|
|
22
|
+
* 因此降级路径 = 手写 `.git/{HEAD,config}` + 空 `objects/refs/info` 目录,绕开 git 的
|
|
23
|
+
* config 写入流程;config 里预先写死 `filemode = false`。
|
|
24
|
+
*/
|
|
25
|
+
import { existsSync, mkdirSync, writeFileSync, chmodSync, rmSync } from 'node:fs';
|
|
26
|
+
import { join } from 'node:path';
|
|
27
|
+
import { runGit } from './exec.js';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 探测目录所在文件系统是否支持 chmod。
|
|
31
|
+
*
|
|
32
|
+
* 判据就是真去 chmod 一个临时文件——比看 mount 类型可靠(同类挂载的选项可能不同,
|
|
33
|
+
* 而且同一台机器上 NFS/CIFS/本地盘混合)。用完即删,不留残余。
|
|
34
|
+
* @param {string} dir 目标目录(不存在会先创建——clone 的目标目录本来就是新建的)
|
|
35
|
+
* @returns {boolean} true = 支持 chmod(可走标准 git init)
|
|
36
|
+
*/
|
|
37
|
+
export function fsSupportsChmod(dir) {
|
|
38
|
+
const probe = join(dir, `.dshgp-chmod-probe-${process.pid}-${Date.now()}`);
|
|
39
|
+
try {
|
|
40
|
+
// 先确保目录存在:目标目录可能还没建,此时 writeFile 会 ENOENT,
|
|
41
|
+
// 若把 ENOENT 误判成「不支持 chmod」就会让所有全新目标目录都走降级分支(实测踩过)
|
|
42
|
+
mkdirSync(dir, { recursive: true });
|
|
43
|
+
writeFileSync(probe, '');
|
|
44
|
+
chmodSync(probe, 0o600);
|
|
45
|
+
return true;
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
} finally {
|
|
49
|
+
try { rmSync(probe, { force: true }); } catch { /* 探测文件残留无所谓 */ }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 手工搭最小可用的 .git 结构(不经 git init)。
|
|
55
|
+
*
|
|
56
|
+
* 只写 git 真正必需的四样:HEAD(指分支)、config(含 filemode=false)、
|
|
57
|
+
* objects/(对象库)、refs/heads(提交后放分支引用);info/ 是配套惯例目录。
|
|
58
|
+
* 不写 index —— 交给首次 `git add` 自动生成(实测可行)。
|
|
59
|
+
* @param {string} dir 仓库工作树目录
|
|
60
|
+
* @param {{branch?: string, remoteName?: string, remoteUrl?: string}} [opts]
|
|
61
|
+
* branch 为目标分支名(HEAD 指向它);给了 remoteUrl 就把 remote 段一并写进 config
|
|
62
|
+
* —— 因为 `git remote add` 同样是写 config,在 CIFS 上一样会 chmod 失败
|
|
63
|
+
*/
|
|
64
|
+
export function writeMinimalGitDir(dir, { branch = 'master', remoteName = 'origin', remoteUrl = '' } = {}) {
|
|
65
|
+
const g = join(dir, '.git');
|
|
66
|
+
for (const d of ['objects', 'refs/heads', 'refs/tags', 'info']) {
|
|
67
|
+
mkdirSync(join(g, d), { recursive: true });
|
|
68
|
+
}
|
|
69
|
+
// HEAD 指向分支名而不是具体 sha:首次 commit 后 git 会把 refs/heads/<branch> 建好
|
|
70
|
+
writeFileSync(join(g, 'HEAD'), `ref: refs/heads/${branch}\n`);
|
|
71
|
+
// filemode=false 是关键项:不加则 CIFS 上所有文件因 777 vs 100644 恒被报为已修改
|
|
72
|
+
const lines = [
|
|
73
|
+
'[core]',
|
|
74
|
+
'\trepositoryformatversion = 0',
|
|
75
|
+
'\tfilemode = false',
|
|
76
|
+
'\tbare = false',
|
|
77
|
+
'\tlogallrefupdates = true',
|
|
78
|
+
];
|
|
79
|
+
if (remoteUrl) {
|
|
80
|
+
lines.push(`[remote "${remoteName}"]`, `\turl = ${remoteUrl}`, `\tfetch = +refs/heads/*:refs/remotes/${remoteName}/*`);
|
|
81
|
+
}
|
|
82
|
+
writeFileSync(join(g, 'config'), lines.join('\n') + '\n');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 初始化 git 仓库(自动适配不支持 chmod 的文件系统)。
|
|
87
|
+
*
|
|
88
|
+
* 能 chmod → 走标准 `git init -q`(行为与之前完全一致);
|
|
89
|
+
* 不能 chmod → 手写最小 .git 结构,等价于「已 init 完成」的仓库。
|
|
90
|
+
* @param {string} dir 目标目录(必须已存在)
|
|
91
|
+
* @param {{branch?: string, remoteUrl?: string, chmodOk?: boolean, gitInit?: (args: string[], opts: object) => object}} [opts]
|
|
92
|
+
* branch: 目标分支(降级路径写进 HEAD);remoteUrl: 降级路径一并写进 config 的 remote 段;
|
|
93
|
+
* chmodOk: 强制指定 chmod 能力(测试用,省略则真去探测目标卷);
|
|
94
|
+
* gitInit: 可注入的 git 执行器(测试用,缺省走 runGit)
|
|
95
|
+
* @returns {{ok: boolean, via: 'git-init'|'manual', filemode: boolean, stderr?: string}}
|
|
96
|
+
*/
|
|
97
|
+
export function initRepoCompat(dir, { branch = 'master', remoteUrl = '', chmodOk, gitInit } = {}) {
|
|
98
|
+
const exec = typeof gitInit === 'function' ? gitInit : (args, opts) => runGit(args, opts);
|
|
99
|
+
const canChmod = typeof chmodOk === 'boolean' ? chmodOk : fsSupportsChmod(dir);
|
|
100
|
+
if (canChmod) {
|
|
101
|
+
const r = exec(['init', '-q'], { cwd: dir });
|
|
102
|
+
return { ok: !!r?.ok, via: 'git-init', filemode: true, stderr: r?.stderr };
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
writeMinimalGitDir(dir, { branch, remoteUrl });
|
|
106
|
+
// 自检:结构搭好后 git 必须能识别出工作树,否则等于静默失败(历史事故的形态)
|
|
107
|
+
const rc = exec(['rev-parse', '--git-dir'], { cwd: dir });
|
|
108
|
+
if (!rc?.ok) return { ok: false, via: 'manual', filemode: false, stderr: rc?.stderr || '自检失败:git 未识别出新仓库' };
|
|
109
|
+
return { ok: true, via: 'manual', filemode: false };
|
|
110
|
+
} catch (e) {
|
|
111
|
+
return { ok: false, via: 'manual', filemode: false, stderr: String((e && e.message) || e) };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** .git 目录是否已存在(续跑判断:已 init 过就不再重复写)。 */
|
|
116
|
+
export function hasGitDir(dir) {
|
|
117
|
+
return existsSync(join(dir, '.git'));
|
|
118
|
+
}
|
package/lib/git/push-diagnose.js
CHANGED
|
File without changes
|
package/lib/git/repo-index.js
CHANGED
|
@@ -16,15 +16,17 @@
|
|
|
16
16
|
* 自持、不入 git;与 dsh-repo-index skill 权威位置一致)。失败全部静默降级,
|
|
17
17
|
* 不阻塞扫描/推送。
|
|
18
18
|
*/
|
|
19
|
-
import {
|
|
19
|
+
import { existsSync } from 'node:fs';
|
|
20
20
|
import { readFile, readdir, stat, access } from 'node:fs/promises';
|
|
21
21
|
import { join, basename, dirname } from 'node:path';
|
|
22
22
|
|
|
23
23
|
import { scanRepos, parseGithubOwnerRepo, githubFetch } from './index.js';
|
|
24
24
|
import { credentialsDir } from './credentials.js';
|
|
25
|
-
import { writeTextAtomic
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
import { writeTextAtomic } from './atomic-json.js';
|
|
26
|
+
import {
|
|
27
|
+
INDEX_FILE, serializeIndex, parseIndex,
|
|
28
|
+
readIndexFile, writeIndexFile, findIndexPath,
|
|
29
|
+
} from './index-format.js';
|
|
28
30
|
const VIS_CHECK_TIMEOUT_MS = 10_000; // GitHub 可见性查询超时
|
|
29
31
|
const AUTO_GEN_NOTE = 'auto-generated by dsh-git-push: DO NOT EDIT MANUALLY'; // 索引文件防手工编辑标记
|
|
30
32
|
|
|
@@ -36,8 +38,8 @@ const AUTO_GEN_NOTE = 'auto-generated by dsh-git-push: DO NOT EDIT MANUALLY'; //
|
|
|
36
38
|
* 凭据/索引收敛插件自持;workspaceRoot 保留作兼容入参,不再参与路径解析)。
|
|
37
39
|
*/
|
|
38
40
|
export function locateRepoIndex(workspaceRoot) {
|
|
39
|
-
|
|
40
|
-
return
|
|
41
|
+
// JSONL 优先,旧 .json 回退(迁移期两种都在时以 .jsonl 为准;写侧会把旧文件移入 .trash)
|
|
42
|
+
return findIndexPath(credentialsDir({ workspaceRoot: workspaceRoot || '' }));
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
/** 读索引:{ name → {owner, repo, repoUrl, visibility} };无索引/损坏 → null。 */
|
|
@@ -45,7 +47,7 @@ export function readRepoIndexMap(workspaceRoot) {
|
|
|
45
47
|
const p = locateRepoIndex(workspaceRoot);
|
|
46
48
|
if (!p) return null;
|
|
47
49
|
try {
|
|
48
|
-
const parsed =
|
|
50
|
+
const parsed = readIndexFile(dirname(p)).index;
|
|
49
51
|
const map = {};
|
|
50
52
|
for (const r of Array.isArray(parsed.repos) ? parsed.repos : []) {
|
|
51
53
|
if (!r || !r.name) continue;
|
|
@@ -256,7 +258,8 @@ export async function buildRepoIndex({ workspaceRoot, depth = 20, extraRepos = [
|
|
|
256
258
|
'# 3) 恢复后按插件安装三要素装回主环境(测试实例先行 + 接管式重启)',
|
|
257
259
|
].join('\n'),
|
|
258
260
|
};
|
|
259
|
-
|
|
261
|
+
// 输出 JSONL(每仓一行):流式可读、单行损坏不废整份
|
|
262
|
+
return serializeIndex(index);
|
|
260
263
|
}
|
|
261
264
|
|
|
262
265
|
/**
|
|
@@ -268,20 +271,25 @@ export function syncRepoIndex({ content, workspaceRoot = '', owner = 'EIGHTfs',
|
|
|
268
271
|
// 不变量「索引只存本地仓库」:写入前**剔除云端-only 残留条目**(cloudOnly=true 或
|
|
269
272
|
// path 为空的旧数据)——此前 merge 曾把本地无副本的云仓库登记进索引,这些条目既违反新语义,
|
|
270
273
|
// 又让前端列表出现空 path 行(React 同 key 警告)。写侧统一过滤,读到的旧索引入口即自愈。
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
274
|
+
// 调用方可能传 JSONL(buildRepoIndex 的输出),也可能传旧整份 JSON(历史调用方未全部收敛)
|
|
275
|
+
const parsed = parseIndex(content);
|
|
276
|
+
if (!parsed || !Array.isArray(parsed.repos)) {
|
|
277
|
+
// 无法解析 = 调用方传了非索引文本:原样落盘(保持旧行为,不静默丢内容)
|
|
278
|
+
const wr = writeTextAtomic(target, content);
|
|
279
|
+
return wr.ok ? { ok: true, written: [target] } : { ok: false, written: [] };
|
|
280
|
+
}
|
|
281
|
+
// 不变量「索引只存本地仓库」:写入前剔除云端-only 残留(cloudOnly=true 或 path 为空),
|
|
282
|
+
// 这些条目既违反语义,又让前端列表出现空 path 行(React 同 key 警告)。
|
|
283
|
+
parsed.repos = parsed.repos.filter((r) => r && !r.cloudOnly && String(r.path || '').trim());
|
|
284
|
+
// 显式 syncTarget 时按该路径写;否则统一走 writeIndexFile(写 .jsonl + 迁移旧 .json)
|
|
285
|
+
if (syncTarget) {
|
|
286
|
+
const wr = writeTextAtomic(syncTarget, serializeIndex(parsed));
|
|
287
|
+
return wr.ok ? { ok: true, written: [syncTarget] } : { ok: false, written: [] };
|
|
288
|
+
}
|
|
289
|
+
const wr = writeIndexFile(dirname(target), parsed);
|
|
290
|
+
return wr.ok
|
|
291
|
+
? { ok: true, written: [wr.path], ...(wr.migratedFrom ? { legacyMoved: wr.migratedFrom } : {}) }
|
|
292
|
+
: { ok: false, written: [] };
|
|
285
293
|
}
|
|
286
294
|
|
|
287
295
|
/**
|
|
@@ -299,7 +307,7 @@ export function syncRepoIndex({ content, workspaceRoot = '', owner = 'EIGHTfs',
|
|
|
299
307
|
*/
|
|
300
308
|
function mergeFreshIntoExisting(existing, freshContent) {
|
|
301
309
|
let fresh = null;
|
|
302
|
-
try { fresh =
|
|
310
|
+
try { fresh = parseIndex(freshContent); } catch { fresh = null; }
|
|
303
311
|
if (!fresh || !Array.isArray(fresh.repos)) {
|
|
304
312
|
// 新结果不可用(损坏/空)→ 保留现有索引原样
|
|
305
313
|
return { index: existing || { name: 'dsh-repo-index', version: 1, generatedAt: new Date().toISOString(), repos: [], localOnly: [] }, updated: 0 };
|
|
@@ -374,8 +382,11 @@ export async function updateRepoIndex({ workspaceRoot = '', token = '', owner =
|
|
|
374
382
|
// rebuild(默认):全量重建 → 与现有索引合并(不全量覆盖)
|
|
375
383
|
const target = syncTarget || locateRepoIndex(workspaceRoot) || join(credentialsDir({ workspaceRoot: workspaceRoot || '' }), INDEX_FILE);
|
|
376
384
|
let existing = null;
|
|
377
|
-
try {
|
|
378
|
-
|
|
385
|
+
try {
|
|
386
|
+
if (existsSync(target)) existing = readIndexFile(dirname(target)).index;
|
|
387
|
+
} catch { existing = null; }
|
|
388
|
+
// parseManualVisibility 入参是「索引文本」:统一用 JSONL 序列化(每行仍是合法 JSON 片段)
|
|
389
|
+
const manualVisibility = parseManualVisibility(existing ? serializeIndex(existing) : '');
|
|
379
390
|
// offline=true(账号卡片「扫描」)时纯离线重建——owner 过滤来自本地 remote
|
|
380
391
|
// 解析(不联网),可见性回退既有标注,不给 buildRepoIndex 传 token 即不触发可见性网络。
|
|
381
392
|
const fresh = await buildRepoIndex({
|
|
@@ -383,7 +394,7 @@ export async function updateRepoIndex({ workspaceRoot = '', token = '', owner =
|
|
|
383
394
|
token: offline ? '' : token, manualVisibility, owner, offline, maxRepos,
|
|
384
395
|
});
|
|
385
396
|
const { index, updated } = mergeFreshIntoExisting(existing, fresh);
|
|
386
|
-
const sync = syncRepoIndex({ content:
|
|
397
|
+
const sync = syncRepoIndex({ content: serializeIndex(index), workspaceRoot, owner, syncTarget });
|
|
387
398
|
return { ok: sync.ok, target: sync.written[0] || '', indexUpdated: sync.ok === true, updated };
|
|
388
399
|
} catch (e) {
|
|
389
400
|
return { ok: false, error: String(e?.message || e) };
|
|
@@ -418,7 +429,7 @@ export function mergeCloudReposIntoIndex({ workspaceRoot = '', owner = 'EIGHTfs'
|
|
|
418
429
|
const target = syncTarget || locateRepoIndex(workspaceRoot) || join(credentialsDir({ workspaceRoot: workspaceRoot || '' }), INDEX_FILE);
|
|
419
430
|
let existing = null;
|
|
420
431
|
try {
|
|
421
|
-
if (existsSync(target)) existing =
|
|
432
|
+
if (existsSync(target)) existing = readIndexFile(dirname(target)).index;
|
|
422
433
|
} catch { existing = null; }
|
|
423
434
|
// 保底结构:老索引/坏 JSON → 空容器,合并后写回
|
|
424
435
|
const index = existing && typeof existing === 'object' && Array.isArray(existing.repos) ? existing : {
|
|
@@ -461,7 +472,7 @@ export function mergeCloudReposIntoIndex({ workspaceRoot = '', owner = 'EIGHTfs'
|
|
|
461
472
|
index.repos = [...byName.values()].sort((a, b) => String(a.name).localeCompare(String(b.name)));
|
|
462
473
|
index.generatedAt = new Date().toISOString();
|
|
463
474
|
index.owner = owner;
|
|
464
|
-
const written = syncRepoIndex({ content:
|
|
475
|
+
const written = syncRepoIndex({ content: serializeIndex(index), workspaceRoot, owner, syncTarget });
|
|
465
476
|
return { ok: true, updated, ...written };
|
|
466
477
|
} catch (e) {
|
|
467
478
|
return { ok: false, error: String(e?.message || e) };
|
|
@@ -488,7 +499,7 @@ export function updateRepoRemoteStateInIndex({ workspaceRoot = '', repoName = ''
|
|
|
488
499
|
const target = syncTarget || locateRepoIndex(workspaceRoot) || join(credentialsDir({ workspaceRoot: workspaceRoot || '' }), INDEX_FILE);
|
|
489
500
|
let index = null;
|
|
490
501
|
try {
|
|
491
|
-
if (existsSync(target)) index =
|
|
502
|
+
if (existsSync(target)) index = readIndexFile(dirname(target)).index;
|
|
492
503
|
} catch { index = null; }
|
|
493
504
|
if (!index || !Array.isArray(index.repos) || !repoName) return { ok: false, error: '索引缺失/仓库名缺失' };
|
|
494
505
|
const hit = index.repos.find((r) => r.name === repoName);
|
|
@@ -504,7 +515,7 @@ export function updateRepoRemoteStateInIndex({ workspaceRoot = '', repoName = ''
|
|
|
504
515
|
if (visibility) hit.visibility = visibility;
|
|
505
516
|
hit.remoteStateAt = new Date().toISOString();
|
|
506
517
|
index.generatedAt = new Date().toISOString();
|
|
507
|
-
const written = syncRepoIndex({ content:
|
|
518
|
+
const written = syncRepoIndex({ content: serializeIndex(index), workspaceRoot, owner: index.owner || 'EIGHTfs', syncTarget });
|
|
508
519
|
return { ok: true, ...written };
|
|
509
520
|
} catch (e) {
|
|
510
521
|
return { ok: false, error: String(e?.message || e) };
|
package/lib/git/scan-runner.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* 三要素:
|
|
8
8
|
* 1) spawn 独立进程跑 scripts/scan-repos.mjs(系统级后台,不卡宿主/主进程);
|
|
9
9
|
* 2) 进程每扫到一个 author(owner) 一致的仓库 → 增量写 scan-live.json
|
|
10
|
-
* (version 递增 + found 追加),并同步把该仓库并入 dsh-repo-index.
|
|
10
|
+
* (version 递增 + found 追加),并同步把该仓库并入 dsh-repo-index.jsonl;
|
|
11
11
|
* 3) 宿主用 fs.watchFile 监听 scan-live.json 变化,变化即唤醒 waiters——
|
|
12
12
|
* 前端「等待新版本」请求挂起,直到 version > 已见数或扫描结束才返回新增
|
|
13
13
|
* (非轮询:有新数据才返回,前端只追加变化部分,不全量重读)。
|