dsh-config-manager 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.d.ts +8 -0
- package/lib/client.js +748 -602
- package/lib/core/local-plugin-host.d.ts +9 -0
- package/lib/core/local-plugin-host.js +174 -1
- package/lib/core/messages.d.ts +7 -0
- package/lib/core/messages.js +16 -0
- package/lib/core/migration-history.d.ts +40 -0
- package/lib/core/migration-history.js +55 -0
- package/lib/core/plugin-cli.d.ts +5 -0
- package/lib/core/plugin-cli.js +11 -3
- package/lib/core/run-registry.d.ts +10 -0
- package/lib/core/run-registry.js +17 -0
- package/lib/index.d.ts +7 -2
- package/lib/index.js +20 -19
- package/lib/profiles/dsh-profile-manager.d.ts +1 -1
- package/lib/profiles/dsh-profile-manager.js +26 -7
- package/lib/profiles/dsh-profile-shared.d.ts +3 -1
- package/lib/routes/import.js +6 -1
- package/lib/routes/route-support.d.ts +2 -1
- package/lib/routes/route-support.js +8 -3
- package/lib/routes/sync.js +5 -2
- package/lib/sync/autosync-config.d.ts +9 -1
- package/lib/sync/autosync-config.js +10 -2
- package/lib/sync/autosync-scheduler.js +18 -6
- package/lib/sync/git/git-transport.d.ts +31 -1
- package/lib/sync/git/git-transport.js +119 -23
- package/lib/sync/sync-config.d.ts +34 -3
- package/lib/sync/sync-config.js +38 -5
- package/lib/ui/sync-repository-picker.d.ts +21 -0
- package/lib/ui/sync-repository-picker.js +18 -0
- package/lib/ui/sync-settings-view.d.ts +4 -0
- package/lib/ui/sync-settings-view.js +3 -0
- package/lib/utils/remove-tree.d.ts +7 -0
- package/lib/utils/remove-tree.js +265 -0
- package/package.json +1 -1
- package/src/client/config-manager.module.css +21 -1
- package/src/client/environment/EnvironmentPanel.tsx +2 -2
- package/src/client/locales/profiles.ts +2 -0
- package/src/client/run-store.test.ts +1 -1
- package/src/client/run-store.ts +5 -0
- package/src/client/sync/ChannelConfigDialog.tsx +47 -2
- package/src/client/sync/SyncPanel.tsx +17 -30
- package/src/client/sync/SyncRepositoryPicker.tsx +34 -13
- package/src/client/sync/SyncSettingsView.test.ts +32 -0
- package/src/client/sync/config-save-state.test.ts +99 -0
- package/src/client/sync/config-save-state.ts +69 -0
- package/src/client/sync/sync-api.ts +2 -0
- package/src/client/sync/sync-locales.ts +10 -0
- package/src/core/engine-locale.test.ts +4 -0
- package/src/core/local-plugin-host.test.ts +31 -2
- package/src/core/local-plugin-host.ts +175 -2
- package/src/core/messages.ts +16 -0
- package/src/core/migration-history.test.ts +65 -0
- package/src/core/migration-history.ts +70 -0
- package/src/core/plugin-cli.fs.test.ts +30 -3
- package/src/core/plugin-cli.ts +11 -3
- package/src/core/run-registry-runs.test.ts +26 -1
- package/src/core/run-registry.ts +18 -0
- package/src/index.sync.test.ts +27 -0
- package/src/index.ts +21 -21
- package/src/profiles/dsh-profile-manager.test.ts +20 -0
- package/src/profiles/dsh-profile-manager.ts +25 -7
- package/src/profiles/dsh-profile-shared.ts +2 -0
- package/src/routes/import.ts +6 -1
- package/src/routes/route-support.ts +7 -3
- package/src/routes/sync.ts +5 -2
- package/src/sync/autosync-config.ts +10 -2
- package/src/sync/autosync-scheduler.test.ts +61 -1
- package/src/sync/autosync-scheduler.ts +17 -5
- package/src/sync/git/git-transport.test.ts +117 -0
- package/src/sync/git/git-transport.ts +131 -23
- package/src/sync/sync-config.test.ts +59 -1
- package/src/sync/sync-config.ts +51 -5
- package/src/ui/sync-repository-picker.test.ts +34 -1
- package/src/ui/sync-repository-picker.ts +24 -0
- package/src/ui/sync-settings-view.test.ts +1 -0
- package/src/ui/sync-settings-view.ts +7 -0
- package/src/utils/remove-tree.test.ts +120 -0
- package/src/utils/remove-tree.ts +239 -0
|
@@ -31,6 +31,15 @@ export interface LocalPluginPackHookOptions {
|
|
|
31
31
|
sourceFingerprint?: (absPath: string) => Promise<string | null>;
|
|
32
32
|
/** tarball 体积上限(缺省 MAX_LOCAL_TARBALL_BYTES;测试用小值验证超限负缓存) */
|
|
33
33
|
maxTarballBytes?: number;
|
|
34
|
+
/**
|
|
35
|
+
* 内容缓存上限(字节;缺省 PACKED_CACHE_MAX_BYTES,**0 = 关闭**)。
|
|
36
|
+
* 命中判据 = 源目录的**内容指纹**(递归 rel/size/mtime)未变:命中即复用上次的 tarball 字节,跳过 npm pack。
|
|
37
|
+
*/
|
|
38
|
+
packedCacheMaxBytes?: number;
|
|
39
|
+
/** 内容缓存条目上限(缺省 PACKED_CACHE_MAX_ENTRIES)。 */
|
|
40
|
+
packedCacheMaxEntries?: number;
|
|
41
|
+
/** 内容指纹(测试注入;缺省 deepSourceFingerprint)。 */
|
|
42
|
+
contentFingerprint?: (absPath: string) => Promise<string | null>;
|
|
34
43
|
}
|
|
35
44
|
export declare function createLocalPluginPackHook(opts: LocalPluginPackHookOptions): LocalPluginPackHook;
|
|
36
45
|
/** 供其他模块复用(避免重复实现 npm 输出解析) */
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import fsp from 'node:fs/promises';
|
|
11
11
|
import path from 'node:path';
|
|
12
|
+
import { createHash } from 'node:crypto';
|
|
12
13
|
import { spawn } from 'node:child_process';
|
|
13
14
|
import { packLocalPlugins, parsePackOutput, resolveLocalPluginPath } from './local-plugin-pack.js';
|
|
14
15
|
import { quoteCmdArg } from './plugin-cli.js';
|
|
@@ -102,6 +103,74 @@ async function defaultSourceFingerprint(absPath) {
|
|
|
102
103
|
return null;
|
|
103
104
|
}
|
|
104
105
|
}
|
|
106
|
+
/** 内容缓存上限(缺省 128 MiB):只缓存真的打过的 tarball 字节。 */
|
|
107
|
+
const PACKED_CACHE_MAX_BYTES = 128 * 1024 * 1024;
|
|
108
|
+
/** 内容缓存条目上限(防「一堆小插件」把 Map 撑大)。 */
|
|
109
|
+
const PACKED_CACHE_MAX_ENTRIES = 64;
|
|
110
|
+
/** 内容指纹的遍历上限:超过就不缓存(宁可不省,也不拿可能过期的字节去备份)。 */
|
|
111
|
+
const CONTENT_FP_MAX_ENTRIES = 20_000;
|
|
112
|
+
/**
|
|
113
|
+
* 内容指纹(**正缓存**用):递归列出目录内每个文件的相对路径 + 字节数 + mtime。
|
|
114
|
+
*
|
|
115
|
+
* 为什么不用上面的 defaultSourceFingerprint:它只取「目录 mtime + package.json」,
|
|
116
|
+
* 在 lib/ 里改一行**不会**改目录 mtime —— 拿它做正缓存,会把旧 tarball 当成当前内容上传进备份。
|
|
117
|
+
* 负缓存能容忍这种粗糙(最坏是少备份一次、30 分钟内重试),正缓存不能容忍(最坏是备份里是旧代码)。
|
|
118
|
+
*
|
|
119
|
+
* 成本实测(2026-11-07,真机):8810 文件 3.6 s、51502 文件 14.9 s —— 仍比一次 210 MB 插件的
|
|
120
|
+
* 44.7 s npm pack 便宜一个量级;超过 CONTENT_FP_MAX_ENTRIES 或遇到链接/特殊文件一律返回 null
|
|
121
|
+
* (调用方据此**不缓存**,直接照常打包)。
|
|
122
|
+
*/
|
|
123
|
+
async function deepSourceFingerprint(absPath) {
|
|
124
|
+
let st;
|
|
125
|
+
try {
|
|
126
|
+
st = await fsp.stat(absPath);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
if (st.isFile())
|
|
132
|
+
return 'file:' + st.size + ':' + Math.trunc(st.mtimeMs);
|
|
133
|
+
if (!st.isDirectory())
|
|
134
|
+
return null;
|
|
135
|
+
const hash = createHash('sha256');
|
|
136
|
+
let entries = 0;
|
|
137
|
+
const walk = async (dir, rel) => {
|
|
138
|
+
let list;
|
|
139
|
+
try {
|
|
140
|
+
list = await fsp.readdir(dir, { withFileTypes: true });
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
list.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
146
|
+
for (const entry of list) {
|
|
147
|
+
// 与 npm pack 同口径:node_modules 不进产物;.git 不参与内容身份
|
|
148
|
+
if (entry.name === 'node_modules' || entry.name === '.git')
|
|
149
|
+
continue;
|
|
150
|
+
const abs = path.join(dir, entry.name);
|
|
151
|
+
const relPath = rel === '' ? entry.name : rel + '/' + entry.name;
|
|
152
|
+
if (entry.isDirectory()) {
|
|
153
|
+
if (!(await walk(abs, relPath)))
|
|
154
|
+
return false;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (!entry.isFile())
|
|
158
|
+
return false; // 链接 / 设备文件:不猜它指向什么,放弃缓存
|
|
159
|
+
const s = await fsp.stat(abs).catch(() => null);
|
|
160
|
+
if (s === null)
|
|
161
|
+
return false;
|
|
162
|
+
entries += 1;
|
|
163
|
+
if (entries > CONTENT_FP_MAX_ENTRIES)
|
|
164
|
+
return false;
|
|
165
|
+
hash.update(relPath + '\u0000' + s.size + '\u0000' + Math.trunc(s.mtimeMs) + '\n');
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
};
|
|
169
|
+
if (!(await walk(absPath, '')))
|
|
170
|
+
return null;
|
|
171
|
+
hash.update('entries:' + entries);
|
|
172
|
+
return 'deep:' + hash.digest('hex');
|
|
173
|
+
}
|
|
105
174
|
export function createLocalPluginPackHook(opts) {
|
|
106
175
|
const exec = opts.exec ?? defaultExec;
|
|
107
176
|
const oversizeTtlMs = opts.oversizeTtlMs ?? OVERSIZE_NEGATIVE_TTL_MS;
|
|
@@ -113,6 +182,42 @@ export function createLocalPluginPackHook(opts) {
|
|
|
113
182
|
* 要省的只是那几十秒的 npm pack。键用绝对源路径(同一插件在 link:/file: 两种写法下同键)。
|
|
114
183
|
*/
|
|
115
184
|
const oversizeCache = new Map();
|
|
185
|
+
/**
|
|
186
|
+
* 内容缓存(正缓存):解析后的源路径 → 上次打出的 tarball 字节 + 当时的内容指纹。
|
|
187
|
+
*
|
|
188
|
+
* 与超限负缓存的区别:负缓存存「结论」,这里存**产物本身**,命中即跳过 npm pack。
|
|
189
|
+
* 命中判据是 deepSourceFingerprint(文件级 rel/size/mtime),不是目录 mtime —— 见该函数注释。
|
|
190
|
+
* 上限双保险:总字节数 + 条目数,超出按「最久未用」淘汰;单条超过上限则根本不入缓存。
|
|
191
|
+
*/
|
|
192
|
+
const packedMaxBytes = opts.packedCacheMaxBytes ?? PACKED_CACHE_MAX_BYTES;
|
|
193
|
+
const packedMaxEntries = opts.packedCacheMaxEntries ?? PACKED_CACHE_MAX_ENTRIES;
|
|
194
|
+
const contentFp = opts.contentFingerprint ?? deepSourceFingerprint;
|
|
195
|
+
const packedCache = new Map();
|
|
196
|
+
let packedCacheBytes = 0;
|
|
197
|
+
const evictPacked = () => {
|
|
198
|
+
while (packedCache.size > packedMaxEntries || packedCacheBytes > packedMaxBytes) {
|
|
199
|
+
let oldestKey = null;
|
|
200
|
+
let oldestAt = Number.POSITIVE_INFINITY;
|
|
201
|
+
for (const [key, value] of packedCache) {
|
|
202
|
+
if (value.usedAt < oldestAt) {
|
|
203
|
+
oldestAt = value.usedAt;
|
|
204
|
+
oldestKey = key;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (oldestKey === null)
|
|
208
|
+
return;
|
|
209
|
+
const removed = packedCache.get(oldestKey);
|
|
210
|
+
if (removed !== undefined)
|
|
211
|
+
packedCacheBytes -= removed.bytes;
|
|
212
|
+
packedCache.delete(oldestKey);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
/** 按入参顺序输出打包结果(缓存命中与本轮打包混在一起时,保持确定性顺序)。 */
|
|
216
|
+
const orderPacked = (input, packed) => {
|
|
217
|
+
const byName = new Map(packed.map((p) => [p.packageName, p]));
|
|
218
|
+
return input.map((p) => byName.get(p.name)).filter((p) => p !== undefined);
|
|
219
|
+
};
|
|
220
|
+
const rewrittenOf = (packed) => Object.fromEntries(packed.map((p) => [p.packageName, p.rewrittenSpec]));
|
|
116
221
|
const hasLocalSpec = (p) => p.spec !== undefined && /^\s*(link|file):/i.test(p.spec);
|
|
117
222
|
return async (plugins, ctx) => {
|
|
118
223
|
// 无本地源插件时零开销返回(不建目录、不 spawn)。
|
|
@@ -165,6 +270,45 @@ export function createLocalPluginPackHook(opts) {
|
|
|
165
270
|
if (!kept.some(hasLocalSpec)) {
|
|
166
271
|
return { packed: [], rewritten: {}, warnings: cacheWarnings, oversize: cacheOversize };
|
|
167
272
|
}
|
|
273
|
+
// —— 内容缓存命中分流:源内容没变的那几个直接复用上次的 tarball,其余才真的打包 ——
|
|
274
|
+
const hitPacked = [];
|
|
275
|
+
const toPack = [];
|
|
276
|
+
if (packedMaxBytes > 0) {
|
|
277
|
+
for (const p of kept) {
|
|
278
|
+
const spec = p.spec;
|
|
279
|
+
if (spec === undefined || !hasLocalSpec(p)) {
|
|
280
|
+
toPack.push(p);
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
const abs = resolveLocalPluginPath(spec, { homeDir: opts.homeDir, profileDir });
|
|
284
|
+
const hit = packedCache.get(abs);
|
|
285
|
+
if (hit === undefined) {
|
|
286
|
+
toPack.push(p);
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
const fp = await contentFp(abs).catch(() => null);
|
|
290
|
+
if (fp === null || fp !== hit.fingerprint) {
|
|
291
|
+
packedCacheBytes -= hit.bytes;
|
|
292
|
+
packedCache.delete(abs);
|
|
293
|
+
toPack.push(p);
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
hit.usedAt = Date.now();
|
|
297
|
+
hitPacked.push(hit.entry);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
toPack.push(...kept);
|
|
302
|
+
}
|
|
303
|
+
if (!toPack.some(hasLocalSpec)) {
|
|
304
|
+
// 全部命中:不建临时目录、不 spawn 一次 npm。
|
|
305
|
+
return {
|
|
306
|
+
packed: orderPacked(plugins, hitPacked),
|
|
307
|
+
rewritten: rewrittenOf(hitPacked),
|
|
308
|
+
warnings: cacheWarnings,
|
|
309
|
+
oversize: cacheOversize,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
168
312
|
const tmpRoot = path.join(opts.dataDir, 'tmp');
|
|
169
313
|
let packDir;
|
|
170
314
|
try {
|
|
@@ -183,8 +327,13 @@ export function createLocalPluginPackHook(opts) {
|
|
|
183
327
|
};
|
|
184
328
|
}
|
|
185
329
|
try {
|
|
330
|
+
const specOfName = new Map();
|
|
331
|
+
for (const p of toPack) {
|
|
332
|
+
if (p.spec !== undefined && hasLocalSpec(p))
|
|
333
|
+
specOfName.set(p.name, p.spec);
|
|
334
|
+
}
|
|
186
335
|
const result = await packLocalPlugins({
|
|
187
|
-
plugins:
|
|
336
|
+
plugins: toPack.map((p) => ({ name: p.name, version: p.version, spec: p.spec })),
|
|
188
337
|
homeDir: opts.homeDir,
|
|
189
338
|
profileDir,
|
|
190
339
|
packDir,
|
|
@@ -213,8 +362,32 @@ export function createLocalPluginPackHook(opts) {
|
|
|
213
362
|
}
|
|
214
363
|
}
|
|
215
364
|
}
|
|
365
|
+
// 内容缓存记账:本轮真打出来的 tarball 按「源内容指纹」入缓存;超限/算不出指纹的跳过(不猜)。
|
|
366
|
+
if (packedMaxBytes > 0) {
|
|
367
|
+
for (const entry of result.packed) {
|
|
368
|
+
const spec = specOfName.get(entry.packageName);
|
|
369
|
+
if (spec === undefined)
|
|
370
|
+
continue;
|
|
371
|
+
const bytes = entry.data.byteLength;
|
|
372
|
+
if (bytes > packedMaxBytes)
|
|
373
|
+
continue;
|
|
374
|
+
const abs = resolveLocalPluginPath(spec, { homeDir: opts.homeDir, profileDir });
|
|
375
|
+
const fp = await contentFp(abs).catch(() => null);
|
|
376
|
+
if (fp === null)
|
|
377
|
+
continue;
|
|
378
|
+
const prev = packedCache.get(abs);
|
|
379
|
+
if (prev !== undefined)
|
|
380
|
+
packedCacheBytes -= prev.bytes;
|
|
381
|
+
packedCache.set(abs, { fingerprint: fp, entry, bytes, usedAt: Date.now() });
|
|
382
|
+
packedCacheBytes += bytes;
|
|
383
|
+
}
|
|
384
|
+
evictPacked();
|
|
385
|
+
}
|
|
386
|
+
const allPacked = [...hitPacked, ...result.packed];
|
|
216
387
|
return {
|
|
217
388
|
...result,
|
|
389
|
+
packed: orderPacked(plugins, allPacked),
|
|
390
|
+
rewritten: { ...result.rewritten, ...rewrittenOf(hitPacked) },
|
|
218
391
|
oversize: [...cacheOversize, ...result.oversize],
|
|
219
392
|
warnings: [...cacheWarnings, ...result.warnings],
|
|
220
393
|
};
|
package/lib/core/messages.d.ts
CHANGED
|
@@ -201,6 +201,10 @@ export declare const zh: {
|
|
|
201
201
|
readonly 'host.snapshotPruneSummary': '自动保留清理删除 {count} 个旧快照';
|
|
202
202
|
readonly 'host.autosyncSummary': '自动同步 {direction}{transportSuffix}';
|
|
203
203
|
readonly 'host.autosyncTransportSuffix': '({transport})';
|
|
204
|
+
readonly 'host.autosyncDirectionPush': '上传';
|
|
205
|
+
readonly 'host.autosyncDirectionPull': '下载';
|
|
206
|
+
readonly 'host.autosyncDirectionBoth': '双向';
|
|
207
|
+
readonly 'host.autosyncDirectionNone': '检查';
|
|
204
208
|
readonly 'host.githubMissingClientId': '未配置 GitHub OAuth client_id:请在插件配置中设置 githubClientId(GitHub → Settings → Developer settings → OAuth Apps 注册应用获取)';
|
|
205
209
|
readonly 'host.githubFlowGone': 'GitHub 登录流程不存在或已过期,请重新开始';
|
|
206
210
|
readonly 'host.restoreBlobEscape': 'blob 路径越界: {blob}';
|
|
@@ -409,6 +413,9 @@ export declare const zh: {
|
|
|
409
413
|
readonly 'sync.git.adoptNotSyncRepo': '远端仓库顶层出现了快照布局以外的内容({entries}):它看起来不是本插件的同步仓库,已拒绝合并(不会把别的仓库内容搬进工作副本)。';
|
|
410
414
|
readonly 'sync.git.adoptMergeConflict': '合并远端 {branch} 时发生冲突:已撤销这次合并(merge --abort),工作副本回到操作前的状态。请手工解决冲突后重试,或改用「重新克隆工作副本」。';
|
|
411
415
|
readonly 'sync.workdirModeInvalidFull': '重建工作副本的模式非法: {mode}(只允许 relink(重指向地址)、adopt(采纳远端历史)或 reclone(重新克隆))';
|
|
416
|
+
readonly 'sync.git.subdirInvalid': '同步子目录前缀不合法:{subdir}(不得以 / 开头或结尾,不得含反斜杠、空段、. 段、.. 段或 .git 段)';
|
|
417
|
+
readonly 'sync.git.subdirRoot': '仓库根';
|
|
418
|
+
readonly 'sync.git.subdirChanged': '工作副本的同步布局是「{stored}」,当前配置是「{expected}」:sparse-checkout 只在首次克隆时生效,旧工作副本里没有新前缀的目录树 —— 照常同步会表现为「远端没有快照」。请在「同步 → 通道配置」里重建工作副本(重新克隆)后再同步。';
|
|
412
419
|
readonly 'sync.git.cmdFailed': 'git {args} 失败 (exit {code}): {err}';
|
|
413
420
|
readonly 'sync.git.identityMissing': 'git 在这台机器上没有可用的提交身份(user.name / user.email 未配置),本次操作被本机 git 拒绝(exit 128,与网络和远端无关)。插件会为同步工作副本自动补写仓库级身份;若仍失败,请在本机执行 git config --global user.name "<名字>" 与 git config --global user.email "<邮箱>" 后重试。原始错误:{err}';
|
|
414
421
|
readonly 'sync.git.pushTokenRequired': '推送需要访问令牌:远端是 http(s) 仓库,但本机没有可用的令牌(拉取公开仓库可以匿名完成,推送必须认证)。请在「同步 → 通道配置」里登录 GitHub 或填入访问令牌后重试。';
|
package/lib/core/messages.js
CHANGED
|
@@ -190,6 +190,10 @@ export const zh = {
|
|
|
190
190
|
'host.snapshotPruneSummary': '自动保留清理删除 {count} 个旧快照',
|
|
191
191
|
'host.autosyncSummary': '自动同步 {direction}{transportSuffix}',
|
|
192
192
|
'host.autosyncTransportSuffix': '({transport})',
|
|
193
|
+
'host.autosyncDirectionPush': '上传',
|
|
194
|
+
'host.autosyncDirectionPull': '下载',
|
|
195
|
+
'host.autosyncDirectionBoth': '双向',
|
|
196
|
+
'host.autosyncDirectionNone': '检查',
|
|
193
197
|
'host.githubMissingClientId': '未配置 GitHub OAuth client_id:请在插件配置中设置 githubClientId(GitHub → Settings → Developer settings → OAuth Apps 注册应用获取)',
|
|
194
198
|
'host.githubFlowGone': 'GitHub 登录流程不存在或已过期,请重新开始',
|
|
195
199
|
'host.restoreBlobEscape': 'blob 路径越界: {blob}',
|
|
@@ -407,6 +411,10 @@ export const zh = {
|
|
|
407
411
|
'sync.git.adoptNotSyncRepo': '远端仓库顶层出现了快照布局以外的内容({entries}):它看起来不是本插件的同步仓库,已拒绝合并(不会把别的仓库内容搬进工作副本)。',
|
|
408
412
|
'sync.git.adoptMergeConflict': '合并远端 {branch} 时发生冲突:已撤销这次合并(merge --abort),工作副本回到操作前的状态。请手工解决冲突后重试,或改用「重新克隆工作副本」。',
|
|
409
413
|
'sync.workdirModeInvalidFull': '重建工作副本的模式非法: {mode}(只允许 relink(重指向地址)、adopt(采纳远端历史)或 reclone(重新克隆))',
|
|
414
|
+
// issue #131:git 通道的仓库内子目录前缀(多工具共用一个备份仓库时各占一个目录)。
|
|
415
|
+
'sync.git.subdirInvalid': '同步子目录前缀不合法:{subdir}(不得以 / 开头或结尾,不得含反斜杠、空段、. 段、.. 段或 .git 段)',
|
|
416
|
+
'sync.git.subdirRoot': '仓库根',
|
|
417
|
+
'sync.git.subdirChanged': '工作副本的同步布局是「{stored}」,当前配置是「{expected}」:sparse-checkout 只在首次克隆时生效,旧工作副本里没有新前缀的目录树 —— 照常同步会表现为「远端没有快照」。请在「同步 → 通道配置」里重建工作副本(重新克隆)后再同步。',
|
|
410
418
|
'sync.git.cmdFailed': 'git {args} 失败 (exit {code}): {err}',
|
|
411
419
|
// 本机提交身份缺失(真机 issue:commit exit 128 ⇒ 交易 NEEDS_ATTENTION ⇒ 被误升 SAFE MODE)。
|
|
412
420
|
// 文案必须点名「本机配置」,并把「远端/网络/令牌」这三种常见误判方向明确排除。
|
|
@@ -690,6 +698,10 @@ export const en = {
|
|
|
690
698
|
'host.snapshotPruneSummary': 'Automatic retention cleanup removed {count} old snapshot(s)',
|
|
691
699
|
'host.autosyncSummary': 'Autosync {direction}{transportSuffix}',
|
|
692
700
|
'host.autosyncTransportSuffix': ' ({transport})',
|
|
701
|
+
'host.autosyncDirectionPush': 'upload',
|
|
702
|
+
'host.autosyncDirectionPull': 'download',
|
|
703
|
+
'host.autosyncDirectionBoth': 'two-way',
|
|
704
|
+
'host.autosyncDirectionNone': 'check',
|
|
693
705
|
'host.githubMissingClientId': 'GitHub OAuth client_id is not configured: set githubClientId in the plugin config (GitHub → Settings → Developer settings → OAuth Apps → register an app)',
|
|
694
706
|
'host.githubFlowGone': 'The GitHub sign-in flow does not exist or has expired; please start over',
|
|
695
707
|
'host.restoreBlobEscape': 'Blob path outside snapshot directory: {blob}',
|
|
@@ -906,6 +918,10 @@ export const en = {
|
|
|
906
918
|
'sync.git.adoptNotSyncRepo': 'The remote repository root contains entries outside the snapshot layout ({entries}): it does not look like this plugin\'s sync repository, so the merge was refused (another repository\'s content is never pulled into the working copy).',
|
|
907
919
|
'sync.git.adoptMergeConflict': 'Merging remote {branch} produced conflicts: the merge was aborted (merge --abort) and the working copy is back to its previous state. Resolve the conflicts manually and retry, or use "clone the working copy again".',
|
|
908
920
|
'sync.workdirModeInvalidFull': 'Invalid working-copy rebuild mode: {mode} (only relink (re-point the address), adopt (merge the remote history) or reclone (clone again) are allowed).',
|
|
921
|
+
// issue #131: in-repo subdirectory prefix for the git channel (several tools sharing one backup repository).
|
|
922
|
+
'sync.git.subdirInvalid': 'Invalid sync subdirectory prefix: {subdir} (must not start or end with /, and must not contain a backslash, an empty segment, a . segment, a .. segment, or a .git segment)',
|
|
923
|
+
'sync.git.subdirRoot': 'repository root',
|
|
924
|
+
'sync.git.subdirChanged': 'This working copy uses the sync layout "{stored}" but the current config is "{expected}": sparse-checkout only applies on the first clone, so the old working copy has no tree for the new prefix — syncing would look like "the remote has no snapshots". Rebuild the working copy (clone again) under Sync → Channel configuration, then sync again.',
|
|
909
925
|
'sync.git.cmdFailed': 'git {args} failed (exit {code}): {err}',
|
|
910
926
|
// Missing local commit identity (real-world issue: commit exit 128 → NEEDS_ATTENTION → wrongly escalated to SAFE MODE).
|
|
911
927
|
// Name the local config and rule out the three usual suspects (remote, network, token).
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MsgFunc } from './msg-types.ts';
|
|
1
2
|
export declare const MIGRATION_HISTORY_SCHEMA_VERSION = 1;
|
|
2
3
|
export declare const MIGRATION_HISTORY_DIR = "migration-history";
|
|
3
4
|
/** 默认保留上限(retention 删最旧)。 */
|
|
@@ -37,6 +38,45 @@ export type MigrationResult = 'success' | 'failed' | 'skipped' | 'pending';
|
|
|
37
38
|
* 用户据此去查网络/凭据,方向完全错。
|
|
38
39
|
*/
|
|
39
40
|
export declare function historyResultFromAutosyncStatus(status: 'success' | 'skipped' | 'partial' | 'failed'): MigrationResult;
|
|
41
|
+
/**
|
|
42
|
+
* 自动同步「空检查轮」判定:这一轮既没上传也没下行、更没应用任何分区(sections 恒空),
|
|
43
|
+
* 它只是 realtime 通道缺省每 60s 一次(remoteCheckMs)的远端探测 —— 是**轮询**,不是活动。
|
|
44
|
+
*
|
|
45
|
+
* 为什么必须挡在统一历史之外(2026-11-08 真机实测,desktop 档案):
|
|
46
|
+
* ① 1 条/分钟把首页「最近活动」刷成与真推**完全同形**的 success 行(用户据此报告
|
|
47
|
+
* 「每隔 1 分钟都在推送」,而同期 git 工作副本只有 4 次真实 add/deletes);
|
|
48
|
+
* ② 统一历史保留额度(缺省 1000 条)被空轮吃满:实测 1009 条里 934 条是 autosync,
|
|
49
|
+
* 其中 688 条正是 upToDate 空轮,真实事件(备份 22 / 档案操作 40)被最旧淘汰;
|
|
50
|
+
* ③ /history 是目录全量扫描(条目越多首页越慢),空轮只会让它线性变慢。
|
|
51
|
+
*
|
|
52
|
+
* 不丢诊断:sync-history.json 仍逐轮记录(含 upToDate),同步页「上次运行 / 跳过原因」照常显示。
|
|
53
|
+
*/
|
|
54
|
+
export declare function isAutosyncIdleRound(entry: {
|
|
55
|
+
status: string;
|
|
56
|
+
skipReason?: string;
|
|
57
|
+
}): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* 自动同步方向 → 字典键(`both`/`push`/`pull`/`none` 是机器 token,不得直接铺到界面上)。
|
|
60
|
+
* 未知方向返回 null,由调用方原样回显(不猜、不吞)。
|
|
61
|
+
*/
|
|
62
|
+
export declare function autosyncDirectionMessageKey(direction: unknown): string | null;
|
|
63
|
+
/** 自动同步一轮 → 统一历史条目的载荷(不写则为 null)。 */
|
|
64
|
+
export type AutosyncHistoryInput = Pick<MigrationHistoryEntry, 'result' | 'sections' | 'source' | 'summary' | 'error'>;
|
|
65
|
+
/**
|
|
66
|
+
* 自动同步一轮 → 统一历史条目;空检查轮返回 null(调用方直接 return,不写)。
|
|
67
|
+
*
|
|
68
|
+
* 规则落在 core 而不是宿主闭包里:宿主 src/index.ts 有体量棘轮(tests/file-size-ratchet.test.ts),
|
|
69
|
+
* 且这几条判断本身要能单测(空轮不写 / 方向本地化 / failed 带原因)。
|
|
70
|
+
* msg 由调用方注入(宿主传 engineMsg),本模块只管查表不引入新状态。
|
|
71
|
+
*/
|
|
72
|
+
export declare function autosyncUnifiedHistoryInput(entry: {
|
|
73
|
+
status: 'success' | 'skipped' | 'partial' | 'failed';
|
|
74
|
+
direction?: unknown;
|
|
75
|
+
skipReason?: string;
|
|
76
|
+
transport?: string;
|
|
77
|
+
error?: string;
|
|
78
|
+
appliedSections?: string[];
|
|
79
|
+
}, msg?: MsgFunc): AutosyncHistoryInput | null;
|
|
40
80
|
/** 触发来源(常量)。 */
|
|
41
81
|
export type MigrationSource = 'api' | 'autosync' | 'backup-scheduler' | 'recovery' | 'cli' | 'internal';
|
|
42
82
|
/** 一条不可变的迁移历史记录(磁盘形态;schemaVersion 内联)。 */
|
|
@@ -80,6 +80,61 @@ export function historyResultFromAutosyncStatus(status) {
|
|
|
80
80
|
return 'skipped';
|
|
81
81
|
return status === 'partial' ? 'pending' : 'failed';
|
|
82
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* 自动同步「空检查轮」判定:这一轮既没上传也没下行、更没应用任何分区(sections 恒空),
|
|
85
|
+
* 它只是 realtime 通道缺省每 60s 一次(remoteCheckMs)的远端探测 —— 是**轮询**,不是活动。
|
|
86
|
+
*
|
|
87
|
+
* 为什么必须挡在统一历史之外(2026-11-08 真机实测,desktop 档案):
|
|
88
|
+
* ① 1 条/分钟把首页「最近活动」刷成与真推**完全同形**的 success 行(用户据此报告
|
|
89
|
+
* 「每隔 1 分钟都在推送」,而同期 git 工作副本只有 4 次真实 add/deletes);
|
|
90
|
+
* ② 统一历史保留额度(缺省 1000 条)被空轮吃满:实测 1009 条里 934 条是 autosync,
|
|
91
|
+
* 其中 688 条正是 upToDate 空轮,真实事件(备份 22 / 档案操作 40)被最旧淘汰;
|
|
92
|
+
* ③ /history 是目录全量扫描(条目越多首页越慢),空轮只会让它线性变慢。
|
|
93
|
+
*
|
|
94
|
+
* 不丢诊断:sync-history.json 仍逐轮记录(含 upToDate),同步页「上次运行 / 跳过原因」照常显示。
|
|
95
|
+
*/
|
|
96
|
+
export function isAutosyncIdleRound(entry) {
|
|
97
|
+
return entry.status === 'success' && entry.skipReason === 'upToDate';
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 自动同步方向 → 字典键(`both`/`push`/`pull`/`none` 是机器 token,不得直接铺到界面上)。
|
|
101
|
+
* 未知方向返回 null,由调用方原样回显(不猜、不吞)。
|
|
102
|
+
*/
|
|
103
|
+
export function autosyncDirectionMessageKey(direction) {
|
|
104
|
+
switch (direction) {
|
|
105
|
+
case 'push': return 'host.autosyncDirectionPush';
|
|
106
|
+
case 'pull': return 'host.autosyncDirectionPull';
|
|
107
|
+
case 'both': return 'host.autosyncDirectionBoth';
|
|
108
|
+
case 'none': return 'host.autosyncDirectionNone';
|
|
109
|
+
default: return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 自动同步一轮 → 统一历史条目;空检查轮返回 null(调用方直接 return,不写)。
|
|
114
|
+
*
|
|
115
|
+
* 规则落在 core 而不是宿主闭包里:宿主 src/index.ts 有体量棘轮(tests/file-size-ratchet.test.ts),
|
|
116
|
+
* 且这几条判断本身要能单测(空轮不写 / 方向本地化 / failed 带原因)。
|
|
117
|
+
* msg 由调用方注入(宿主传 engineMsg),本模块只管查表不引入新状态。
|
|
118
|
+
*/
|
|
119
|
+
export function autosyncUnifiedHistoryInput(entry, msg = engineMsg) {
|
|
120
|
+
if (isAutosyncIdleRound(entry))
|
|
121
|
+
return null;
|
|
122
|
+
const directionKey = autosyncDirectionMessageKey(entry.direction);
|
|
123
|
+
const transport = entry.transport;
|
|
124
|
+
const input = {
|
|
125
|
+
result: historyResultFromAutosyncStatus(entry.status),
|
|
126
|
+
sections: entry.appliedSections === undefined ? [] : [...entry.appliedSections],
|
|
127
|
+
source: 'autosync',
|
|
128
|
+
summary: msg('host.autosyncSummary', {
|
|
129
|
+
direction: directionKey === null ? String(entry.direction ?? '') : msg(directionKey),
|
|
130
|
+
transportSuffix: transport === undefined || transport === '' ? '' : msg('host.autosyncTransportSuffix', { transport }),
|
|
131
|
+
}),
|
|
132
|
+
};
|
|
133
|
+
const error = entry.status === 'failed' ? (entry.error ?? entry.skipReason) : undefined;
|
|
134
|
+
if (error !== undefined)
|
|
135
|
+
input.error = error;
|
|
136
|
+
return input;
|
|
137
|
+
}
|
|
83
138
|
const defaultIo = {
|
|
84
139
|
async mkdir(d, o) { await fs.mkdir(d, o); },
|
|
85
140
|
async readdirNames(d) { try {
|
package/lib/core/plugin-cli.d.ts
CHANGED
|
@@ -118,6 +118,11 @@ export declare function reconcileBundles(profileDir: string): boolean;
|
|
|
118
118
|
* 直接启动 DSH 会因缺包而失败。本函数把 manifest 恢复为「该插件未安装」的一致状态,
|
|
119
119
|
* 消除「声明了依赖但没装全」的启动风险。pnpm-lock.yaml 不触碰(运行时不被读取,
|
|
120
120
|
* 下次安装 pnpm 自行对齐)。尽力而为:任何失败不抛错,由调用方记录告警。
|
|
121
|
+
*
|
|
122
|
+
* 删包目录必须走 removeTreeSync 而不是 fs.rmSync(recursive):包目录常是**链接**(DSH 把
|
|
123
|
+
* node_modules/<pkg> 链到 .dsh-module-fallback),链接目标消失后就是悬空链接,rmSync 遇到
|
|
124
|
+
* 这种树会静默空转(不抛错、一个都不删),于是「跳过当前插件」留下半装残留,下次安装撞缺包。
|
|
125
|
+
* removeTreeSync 只删链接本身(绝不跟进去删 fallback 里的实体)并在删不净时抛错。
|
|
121
126
|
*/
|
|
122
127
|
export declare function cleanupAbortedInstall(profileDir: string, pkg: string): void;
|
|
123
128
|
/**
|
package/lib/core/plugin-cli.js
CHANGED
|
@@ -17,9 +17,10 @@
|
|
|
17
17
|
import { engineMsg } from './messages-core.js';
|
|
18
18
|
import { isConcreteVersion } from './validator.js';
|
|
19
19
|
import { spawn } from 'node:child_process';
|
|
20
|
-
import { readFileSync
|
|
20
|
+
import { readFileSync } from 'node:fs';
|
|
21
21
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
22
22
|
import { atomicWriteFileSync } from '../utils/atomic-write.js';
|
|
23
|
+
import { removeTreeSync } from '../utils/remove-tree.js';
|
|
23
24
|
import { isDesktopProfile, resolveDesktopCarrier } from '../utils/desktop-carrier.js';
|
|
24
25
|
import { isRescueActiveSync } from './boot-rescue.js';
|
|
25
26
|
/* ------------------------------------------------------------ profile 文件 */
|
|
@@ -287,6 +288,11 @@ function isRescueActiveForProfileDir(profileDir) {
|
|
|
287
288
|
* 直接启动 DSH 会因缺包而失败。本函数把 manifest 恢复为「该插件未安装」的一致状态,
|
|
288
289
|
* 消除「声明了依赖但没装全」的启动风险。pnpm-lock.yaml 不触碰(运行时不被读取,
|
|
289
290
|
* 下次安装 pnpm 自行对齐)。尽力而为:任何失败不抛错,由调用方记录告警。
|
|
291
|
+
*
|
|
292
|
+
* 删包目录必须走 removeTreeSync 而不是 fs.rmSync(recursive):包目录常是**链接**(DSH 把
|
|
293
|
+
* node_modules/<pkg> 链到 .dsh-module-fallback),链接目标消失后就是悬空链接,rmSync 遇到
|
|
294
|
+
* 这种树会静默空转(不抛错、一个都不删),于是「跳过当前插件」留下半装残留,下次安装撞缺包。
|
|
295
|
+
* removeTreeSync 只删链接本身(绝不跟进去删 fallback 里的实体)并在删不净时抛错。
|
|
290
296
|
*/
|
|
291
297
|
export function cleanupAbortedInstall(profileDir, pkg) {
|
|
292
298
|
const manifest = readProfileManifest(profileDir);
|
|
@@ -301,10 +307,12 @@ export function cleanupAbortedInstall(profileDir, pkg) {
|
|
|
301
307
|
reconcileBundles(profileDir);
|
|
302
308
|
}
|
|
303
309
|
try {
|
|
304
|
-
|
|
310
|
+
removeTreeSync(join(profileDir, 'node_modules', pkg));
|
|
305
311
|
}
|
|
306
312
|
catch {
|
|
307
|
-
//
|
|
313
|
+
// 尽力而为:目录可能本来就不存在(正常情况下 removeTreeSync 对缺失目标是不抛的),
|
|
314
|
+
// 剩下的失败只有「真被占用 / 权限不足」——这里仍不打断「用户跳过」的流程,
|
|
315
|
+
// 但绝不再让悬空链接这种可修的形态走到这里。
|
|
308
316
|
}
|
|
309
317
|
}
|
|
310
318
|
/**
|
|
@@ -86,6 +86,16 @@ export interface RunRegistryOptions {
|
|
|
86
86
|
* 内存 run 注册表。Node 单线程 + 同步 Map 读写,无并发竞争;
|
|
87
87
|
* 所有公开读方法返回状态副本,防止外部直接篡改内部状态。
|
|
88
88
|
*/
|
|
89
|
+
/**
|
|
90
|
+
* 自动同步「空转」run:60s 一次的远端探测拿到 upToDate —— 本轮既没上传也没下行、没应用任何分区。
|
|
91
|
+
*
|
|
92
|
+
* 为什么要过滤(2026-11-09 真机):realtime 通道每轮都会 register('autosync'),于是运行中心每分钟
|
|
93
|
+
* 多一张「自动同步 · 已完成」卡片,与「迁移历史」同一种噪音(那边已由 isAutosyncIdleRound 挡住)。
|
|
94
|
+
* 轮询不是活动;真干活(push/pull/冲突/失败)的卡片必须留着 —— 它们才解释「刚才发生了什么」。
|
|
95
|
+
*
|
|
96
|
+
* 判定只认 run 自己的 result.idle(由调度器收尾时写入),不在 UI 猜 skipReason。
|
|
97
|
+
*/
|
|
98
|
+
export declare function isIdleAutosyncRun(state: Pick<RunState, 'kind' | 'status' | 'result'>): boolean;
|
|
89
99
|
export declare class RunRegistry {
|
|
90
100
|
private readonly runs;
|
|
91
101
|
private readonly retentionMs;
|
package/lib/core/run-registry.js
CHANGED
|
@@ -65,6 +65,23 @@ export const DEFAULT_RUN_STALLED_MS = 6 * 60 * 60 * 1000;
|
|
|
65
65
|
* 内存 run 注册表。Node 单线程 + 同步 Map 读写,无并发竞争;
|
|
66
66
|
* 所有公开读方法返回状态副本,防止外部直接篡改内部状态。
|
|
67
67
|
*/
|
|
68
|
+
/**
|
|
69
|
+
* 自动同步「空转」run:60s 一次的远端探测拿到 upToDate —— 本轮既没上传也没下行、没应用任何分区。
|
|
70
|
+
*
|
|
71
|
+
* 为什么要过滤(2026-11-09 真机):realtime 通道每轮都会 register('autosync'),于是运行中心每分钟
|
|
72
|
+
* 多一张「自动同步 · 已完成」卡片,与「迁移历史」同一种噪音(那边已由 isAutosyncIdleRound 挡住)。
|
|
73
|
+
* 轮询不是活动;真干活(push/pull/冲突/失败)的卡片必须留着 —— 它们才解释「刚才发生了什么」。
|
|
74
|
+
*
|
|
75
|
+
* 判定只认 run 自己的 result.idle(由调度器收尾时写入),不在 UI 猜 skipReason。
|
|
76
|
+
*/
|
|
77
|
+
export function isIdleAutosyncRun(state) {
|
|
78
|
+
if (state.kind !== 'autosync' || state.status === 'running')
|
|
79
|
+
return false;
|
|
80
|
+
const result = state.result;
|
|
81
|
+
if (result === null || typeof result !== 'object')
|
|
82
|
+
return false;
|
|
83
|
+
return result.idle === true;
|
|
84
|
+
}
|
|
68
85
|
export class RunRegistry {
|
|
69
86
|
runs = new Map();
|
|
70
87
|
retentionMs;
|
package/lib/index.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export declare const name = "config-manager";
|
|
|
75
75
|
/** Services required before the engine can mount (present in every profile). */
|
|
76
76
|
export declare const inject: string[];
|
|
77
77
|
/** Plugin version, kept in sync with package.json ("version"). */
|
|
78
|
-
export declare const PLUGIN_VERSION = "0.
|
|
78
|
+
export declare const PLUGIN_VERSION = "0.7.0";
|
|
79
79
|
/**
|
|
80
80
|
* Star 引导弹窗指向的 GitHub 仓库(用户引导点 Star 的目标)。
|
|
81
81
|
* 与 package.json 的 repository 字段保持一致;界面不可改(硬编码,参照
|
|
@@ -581,6 +581,10 @@ export declare class DshFileSystemFacade implements FileSystemFacade {
|
|
|
581
581
|
writeFile(relPath: string, data: Uint8Array): Promise<void>;
|
|
582
582
|
exists(relPath: string): Promise<boolean>;
|
|
583
583
|
copy(from: string, to: string): Promise<void>;
|
|
584
|
+
/**
|
|
585
|
+
* 递归删除(home 内,缺失目标视为成功)。**不用 fs.rm(recursive)**:目录里有悬空链接时它静默
|
|
586
|
+
* 空转(报告写「已还原」而磁盘原样在)。removeTree 逐条删、只删链接本身、删不净就抛错。
|
|
587
|
+
*/
|
|
584
588
|
remove(relPath: string): Promise<void>;
|
|
585
589
|
/** 仅路径列表(既有契约):委托 listRecursiveDetailed,丢弃诊断。 */
|
|
586
590
|
listRecursive(dir: string): Promise<string[]>;
|
|
@@ -814,12 +818,13 @@ export type RouteEnvInferred = {
|
|
|
814
818
|
syncWorkDir: {
|
|
815
819
|
inspect: (repoUrl: string, opts?: {
|
|
816
820
|
detail?: boolean;
|
|
821
|
+
subdir?: string;
|
|
817
822
|
}) => Promise<{
|
|
818
823
|
facts: GitWorkDirFacts;
|
|
819
824
|
} | {
|
|
820
825
|
error: string;
|
|
821
826
|
}>;
|
|
822
|
-
rebuild: (repoUrl: string, mode: 'relink' | 'adopt' | 'reclone') => Promise<GitWorkDirFacts>;
|
|
827
|
+
rebuild: (repoUrl: string, mode: 'relink' | 'adopt' | 'reclone', subdir?: string) => Promise<GitWorkDirFacts>;
|
|
823
828
|
};
|
|
824
829
|
syncSectionCatalog: {
|
|
825
830
|
id: SectionId;
|