dsh-config-manager 0.5.0 → 0.6.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.
Files changed (42) hide show
  1. package/lib/client.d.ts +3 -0
  2. package/lib/client.js +709 -602
  3. package/lib/core/messages.d.ts +4 -0
  4. package/lib/core/messages.js +8 -0
  5. package/lib/core/migration-history.d.ts +40 -0
  6. package/lib/core/migration-history.js +55 -0
  7. package/lib/core/plugin-cli.d.ts +5 -0
  8. package/lib/core/plugin-cli.js +11 -3
  9. package/lib/index.d.ts +5 -1
  10. package/lib/index.js +13 -14
  11. package/lib/profiles/dsh-profile-manager.d.ts +1 -1
  12. package/lib/profiles/dsh-profile-manager.js +26 -7
  13. package/lib/profiles/dsh-profile-shared.d.ts +3 -1
  14. package/lib/ui/sync-repository-picker.d.ts +21 -0
  15. package/lib/ui/sync-repository-picker.js +18 -0
  16. package/lib/utils/remove-tree.d.ts +7 -0
  17. package/lib/utils/remove-tree.js +265 -0
  18. package/package.json +1 -1
  19. package/src/client/config-manager.module.css +21 -1
  20. package/src/client/environment/EnvironmentPanel.tsx +2 -2
  21. package/src/client/locales/profiles.ts +2 -0
  22. package/src/client/sync/ChannelConfigDialog.tsx +32 -1
  23. package/src/client/sync/SyncPanel.tsx +11 -30
  24. package/src/client/sync/SyncRepositoryPicker.tsx +34 -13
  25. package/src/client/sync/SyncSettingsView.test.ts +32 -0
  26. package/src/client/sync/config-save-state.test.ts +99 -0
  27. package/src/client/sync/config-save-state.ts +69 -0
  28. package/src/client/sync/sync-locales.ts +4 -0
  29. package/src/core/engine-locale.test.ts +4 -0
  30. package/src/core/messages.ts +8 -0
  31. package/src/core/migration-history.test.ts +65 -0
  32. package/src/core/migration-history.ts +70 -0
  33. package/src/core/plugin-cli.fs.test.ts +30 -3
  34. package/src/core/plugin-cli.ts +11 -3
  35. package/src/index.ts +12 -14
  36. package/src/profiles/dsh-profile-manager.test.ts +20 -0
  37. package/src/profiles/dsh-profile-manager.ts +25 -7
  38. package/src/profiles/dsh-profile-shared.ts +2 -0
  39. package/src/ui/sync-repository-picker.test.ts +34 -1
  40. package/src/ui/sync-repository-picker.ts +24 -0
  41. package/src/utils/remove-tree.test.ts +120 -0
  42. package/src/utils/remove-tree.ts +239 -0
@@ -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}';
@@ -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}',
@@ -690,6 +694,10 @@ export const en = {
690
694
  'host.snapshotPruneSummary': 'Automatic retention cleanup removed {count} old snapshot(s)',
691
695
  'host.autosyncSummary': 'Autosync {direction}{transportSuffix}',
692
696
  'host.autosyncTransportSuffix': ' ({transport})',
697
+ 'host.autosyncDirectionPush': 'upload',
698
+ 'host.autosyncDirectionPull': 'download',
699
+ 'host.autosyncDirectionBoth': 'two-way',
700
+ 'host.autosyncDirectionNone': 'check',
693
701
  '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
702
  'host.githubFlowGone': 'The GitHub sign-in flow does not exist or has expired; please start over',
695
703
  'host.restoreBlobEscape': 'Blob path outside snapshot directory: {blob}',
@@ -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 {
@@ -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
  /**
@@ -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, rmSync } from 'node:fs';
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
- rmSync(join(profileDir, 'node_modules', pkg), { recursive: true, force: true });
310
+ removeTreeSync(join(profileDir, 'node_modules', pkg));
305
311
  }
306
312
  catch {
307
- // 尽力而为:目录可能不存在或正被占用,忽略
313
+ // 尽力而为:目录可能本来就不存在(正常情况下 removeTreeSync 对缺失目标是不抛的),
314
+ // 剩下的失败只有「真被占用 / 权限不足」——这里仍不打断「用户跳过」的流程,
315
+ // 但绝不再让悬空链接这种可修的形态走到这里。
308
316
  }
309
317
  }
310
318
  /**
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.5.0";
78
+ export declare const PLUGIN_VERSION = "0.6.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[]>;
package/lib/index.js CHANGED
@@ -90,6 +90,7 @@ import { PROJECT_KEY_RE, readLogCwdFromBytes, rewriteSessionLogDir } from './uti
90
90
  import { probeSessionFormats, resolveSessionFormatVersion } from './utils/session-format.js';
91
91
  import { describePatchYamlError, dumpPatchDocument, loadPatchDocument } from './utils/patch-yaml.js';
92
92
  import { atomicCopyFile, atomicWriteFile } from './utils/atomic-write.js';
93
+ import { removeTree } from './utils/remove-tree.js';
93
94
  import { isENOENT } from './utils/guards.js';
94
95
  import { EnvironmentLockManager, runWithMutationLock } from './utils/env-lock.js';
95
96
  import { activeProxySummary } from './utils/proxy.js';
@@ -111,7 +112,7 @@ import { AUTO_BACKUP_PREFIX, isValidExportFileName, resolveNonCollidingExportNam
111
112
  import { DEFAULT_RETENTION_POLICY, selectPruneCandidatesByPolicy } from './sync/retention-policy.js';
112
113
  import { selectPruneCandidates } from './core/backup.js';
113
114
  import { appendAutosyncEntry } from './sync/sync-history.js';
114
- import { MigrationStore, historyResultFromAutosyncStatus, MIGRATION_HISTORY_DIR } from './core/migration-history.js';
115
+ import { MigrationStore, autosyncUnifiedHistoryInput, MIGRATION_HISTORY_DIR } from './core/migration-history.js';
115
116
  import { createHistoryPruner } from './core/history-prune.js';
116
117
  import { isWebDavConfig, isS3Config, isGistConfig, channelOf, SYNC_CHANNELS, GIST_PROVIDER, cloudSecretRef } from './sync/sync-config.js';
117
118
  import { resolveSessionFormatDisposition, sessionFormatAbortResponse, } from './routes/session-format.js';
@@ -147,7 +148,7 @@ export const name = 'config-manager';
147
148
  /** Services required before the engine can mount (present in every profile). */
148
149
  export const inject = ['settings', 'credentials'];
149
150
  /** Plugin version, kept in sync with package.json ("version"). */
150
- export const PLUGIN_VERSION = '0.5.0';
151
+ export const PLUGIN_VERSION = '0.6.0';
151
152
  /** Plugin own package name — excluded from its own exported plugins list. */
152
153
  const PLUGIN_NAME = 'dsh-config-manager';
153
154
  /**
@@ -1605,8 +1606,12 @@ export class DshFileSystemFacade {
1605
1606
  async copy(from, to) {
1606
1607
  await atomicCopyFile(this.abs(from), this.abs(to));
1607
1608
  }
1609
+ /**
1610
+ * 递归删除(home 内,缺失目标视为成功)。**不用 fs.rm(recursive)**:目录里有悬空链接时它静默
1611
+ * 空转(报告写「已还原」而磁盘原样在)。removeTree 逐条删、只删链接本身、删不净就抛错。
1612
+ */
1608
1613
  async remove(relPath) {
1609
- await fs.rm(this.abs(relPath), { recursive: true, force: true });
1614
+ await removeTree(this.abs(relPath));
1610
1615
  }
1611
1616
  /** 仅路径列表(既有契约):委托 listRecursiveDetailed,丢弃诊断。 */
1612
1617
  async listRecursive(dir) {
@@ -2476,17 +2481,11 @@ function makeRoutes(deps) {
2476
2481
  // Phase 6:autosync 既写 sync-history.json(既有语义),也写统一迁移历史(COMPLETE 不变量)。
2477
2482
  appendHistoryFn: async (entry) => {
2478
2483
  await appendAutosyncEntry(syncDir, entry).catch(() => undefined);
2479
- await history.append({
2480
- kind: 'autosync',
2481
- result: historyResultFromAutosyncStatus(entry.status),
2482
- sections: entry.appliedSections ?? [],
2483
- source: 'autosync',
2484
- summary: engineMsg('host.autosyncSummary', {
2485
- direction: entry.direction,
2486
- transportSuffix: entry.transport !== undefined ? engineMsg('host.autosyncTransportSuffix', { transport: entry.transport }) : '',
2487
- }),
2488
- error: entry.status === 'failed' ? (entry.error ?? entry.skipReason) : undefined,
2489
- }).catch(() => undefined);
2484
+ // 空检查轮(每 60s 一次的远端探测,什么都没传)不进统一历史;payload 组装与判据见 core。
2485
+ const input = autosyncUnifiedHistoryInput(entry, engineMsg);
2486
+ if (input === null)
2487
+ return;
2488
+ await history.append({ kind: 'autosync', ...input }).catch(() => undefined);
2490
2489
  },
2491
2490
  });
2492
2491
  // P1-B:调度器不再在 makeRoutes 内同步 start —— 由 apply() 在「启动 recovery 分类完成后、仅 NORMAL」时启动。
@@ -109,7 +109,7 @@ export declare class DshProfileManager {
109
109
  /** 单个链接的重指向(失败保持原样:源档案还在时仍旧可用,不让整次复制失败)。 */
110
110
  private relinkCopiedEntry;
111
111
  /**
112
- * 物理删除 profile 目录(rmSync recursive;目录内 junction 只删链接本身)。
112
+ * 物理删除 profile 目录(removeTreeSync;目录内 junction 只删链接本身,删不干净报 deleteFailed)。
113
113
  * 当前运行中的 profile 需要 allowCurrent=true 显式确认(删除会让重启后的实例直接失败)。
114
114
  *
115
115
  * Desktop 独占档案(desktop)**一律拒绝**(连 allowCurrent 也不行):它由桌面端应用自己
@@ -18,14 +18,17 @@
18
18
  * 历史上这里还有一个 `<dataDir>/next-profile`「下次启动」标记——DSH 根本没有消费者,
19
19
  * 只会误导用户(2026-09 按产品决策整体移除,连同前端按钮)。
20
20
  *
21
- * 物理删除:remove() 走 rmSync(recursive),profile 目录内的 junction(pnpm 链接)
22
- * 只删链接本身,不会跟随进 pnpm store。
21
+ * 物理删除:remove() 走 utils/remove-tree 的 removeTreeSync —— 不能用 fs.rmSync(recursive):
22
+ * 目录里只要有一个**悬空链接**(DSH 的 node_modules/<pkg> → 已消失的 .dsh-module-fallback),
23
+ * rmSync 会不报错也不删任何东西(实测),于是「删除成功」而档案原样留在磁盘上。
24
+ * profile 目录内的 junction(pnpm 链接)只删链接本身,不会跟随进 pnpm store。
23
25
  */
24
26
  import { existsSync, mkdirSync, readdirSync, renameSync, rmSync, statSync } from 'node:fs';
25
27
  // 复制走 async fs(整档案上万个文件,cpSync 会把宿主事件循环卡住二十多秒)
26
- import { copyFile, cp, mkdir, readdir, readlink, rm, stat, symlink, unlink } from 'node:fs/promises';
28
+ import { copyFile, cp, mkdir, readdir, readlink, stat, symlink, unlink } from 'node:fs/promises';
27
29
  import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
28
30
  import { atomicWriteFileSync } from '../utils/atomic-write.js';
31
+ import { removeTree, removeTreeSync } from '../utils/remove-tree.js';
29
32
  import { isRecord } from '../utils/guards.js';
30
33
  import { resolveProfileDir, validateProfileName } from '../core/plugin-cli.js';
31
34
  import { readTextSafe } from './dsh-profile-io.js';
@@ -74,9 +77,15 @@ function isInsideDir(root, candidate) {
74
77
  }
75
78
  /** t89:profiles 根目录枚举失败的原因码(诊断/日志用)。 */
76
79
  export const PROFILES_ROOT_UNREADABLE = 'profiles-root-unreadable';
77
- /** 回滚复制目标目录的缺省删除实现(递归强制;不存在不算错)。 */
80
+ /**
81
+ * 回滚复制目标目录的缺省删除实现(不存在不算错)。
82
+ *
83
+ * 必须走 removeTree 而不是 fs.rm(recursive):半截副本里可能已经有指向
84
+ * `.dsh-module-fallback` 的悬空 junction,fs.rm 会「成功」却一个字节都不删,
85
+ * 回滚于是无声失败。
86
+ */
78
87
  const defaultProfileRemove = async (target) => {
79
- await rm(target, { recursive: true, force: true });
88
+ await removeTree(target);
80
89
  };
81
90
  /**
82
91
  * 复制失败时回滚目标目录(cross-F3 收尾 / tech-debt #5)。
@@ -398,7 +407,7 @@ export class DshProfileManager {
398
407
  }
399
408
  }
400
409
  /**
401
- * 物理删除 profile 目录(rmSync recursive;目录内 junction 只删链接本身)。
410
+ * 物理删除 profile 目录(removeTreeSync;目录内 junction 只删链接本身,删不干净报 deleteFailed)。
402
411
  * 当前运行中的 profile 需要 allowCurrent=true 显式确认(删除会让重启后的实例直接失败)。
403
412
  *
404
413
  * Desktop 独占档案(desktop)**一律拒绝**(连 allowCurrent 也不行):它由桌面端应用自己
@@ -414,7 +423,17 @@ export class DshProfileManager {
414
423
  if (name === this.currentProfile() && opts.allowCurrent !== true) {
415
424
  throw new DshProfileError('currentProfile');
416
425
  }
417
- rmSync(dir, { recursive: true, force: true });
426
+ // 不用 rmSync(recursive):悬空 junction 会让它静默空转(见 utils/remove-tree.ts 头注)。
427
+ // 删不掉必须变成可见错误码,绝不回 200 —— 那正是「点了删除、档案还在」的成因。
428
+ try {
429
+ removeTreeSync(dir);
430
+ }
431
+ catch (error) {
432
+ throw new DshProfileError('deleteFailed', error instanceof Error ? error.message : String(error));
433
+ }
434
+ if (existsSync(dir)) {
435
+ throw new DshProfileError('deleteFailed', `profile directory still exists after removal: ${dir}`);
436
+ }
418
437
  }
419
438
  /**
420
439
  * cross-F3:目标目录 = **正常 profile(有 package.json)** 或 **中断的复制残留(有进行中标记)**;
@@ -241,7 +241,9 @@ export type DshProfileErrorCode = 'invalidName' | 'reservedName' | 'exists' | 'n
241
241
  /** 复制档案中途失败(目标目录已回滚,磁盘上不留半套副本) */
242
242
  | 'copyFailed'
243
243
  /** 该档案由 Desktop 应用独占管理(启动 / 删除 / 改名一律拒绝,操作它会让桌面端起不来) */
244
- | 'managedProfile';
244
+ | 'managedProfile'
245
+ /** 目录删不干净(被占用 / 权限不足;message 里附底层原因)—— 绝不是「删成功」 */
246
+ | 'deleteFailed';
245
247
  /** 复制档案的非致命告警码(UI 按码映射文案,绝不静默)。 */
246
248
  export type DshProfileCopyWarning =
247
249
  /** 副本没有 node_modules 却声明了依赖:直接启动会解析不到 bundle,必须先装依赖 */
@@ -96,3 +96,24 @@ export declare function repoCreateBody(name: string, description: string): {
96
96
  * `Invalid Date`);与 src/ui/snapshots-view.ts:170 同一口径(`toLocaleString()`)。
97
97
  */
98
98
  export declare function formatRepoUpdatedAt(iso: string, locale?: string): string;
99
+ /**
100
+ * 仓库列表是否该**自动加载**(不要求用户先点开下拉)。
101
+ *
102
+ * 用户反馈(2026-11-08):GitHub 登录成功后界面没有任何提示,列表也不会自己出现 ——
103
+ * 必须手动点一下「从我的仓库中选择」才知道成功了。这里把「该拉列表」的判定收成一条纯函数,
104
+ * 三个触发点共用:弹窗打开、登录状态由「未登录」变「已登录」、表单里已经有地址。
105
+ *
106
+ * 规则:
107
+ * - 弹窗没打开 / 已加载过 / 正在加载 → 不重复发请求;
108
+ * - `failed` 为真 → 不自动重试(否则每次重渲染都会打一次必然失败的请求;重试由「刷新列表」或
109
+ * 登录状态变化后的复位负责)。
110
+ * - 未登录且地址为空 → 保持惰性(此时拉列表必然 401,白跑一次网络)。
111
+ */
112
+ export declare function shouldAutoLoadRepos(input: {
113
+ open: boolean;
114
+ signedIn: boolean | null;
115
+ loaded: boolean;
116
+ loading: boolean;
117
+ failed: boolean;
118
+ repoUrl: string;
119
+ }): boolean;
@@ -142,4 +142,22 @@ export function formatRepoUpdatedAt(iso, locale) {
142
142
  const date = new Date(ms);
143
143
  return locale === undefined ? date.toLocaleString() : date.toLocaleString(locale);
144
144
  }
145
+ /**
146
+ * 仓库列表是否该**自动加载**(不要求用户先点开下拉)。
147
+ *
148
+ * 用户反馈(2026-11-08):GitHub 登录成功后界面没有任何提示,列表也不会自己出现 ——
149
+ * 必须手动点一下「从我的仓库中选择」才知道成功了。这里把「该拉列表」的判定收成一条纯函数,
150
+ * 三个触发点共用:弹窗打开、登录状态由「未登录」变「已登录」、表单里已经有地址。
151
+ *
152
+ * 规则:
153
+ * - 弹窗没打开 / 已加载过 / 正在加载 → 不重复发请求;
154
+ * - `failed` 为真 → 不自动重试(否则每次重渲染都会打一次必然失败的请求;重试由「刷新列表」或
155
+ * 登录状态变化后的复位负责)。
156
+ * - 未登录且地址为空 → 保持惰性(此时拉列表必然 401,白跑一次网络)。
157
+ */
158
+ export function shouldAutoLoadRepos(input) {
159
+ if (!input.open || input.loaded || input.loading || input.failed)
160
+ return false;
161
+ return input.signedIn === true || input.repoUrl.trim() !== '';
162
+ }
145
163
  //# sourceMappingURL=sync-repository-picker.js.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 同步严格删除:目标不存在算成功;链接只删链接本身;删不掉抛底层错误;
3
+ * 结束时目标**仍然存在**也抛错(rm 静默失效的兜底判据)。
4
+ */
5
+ export declare function removeTreeSync(target: string): void;
6
+ /** 异步版本(大批量目录不阻塞事件循环);语义与 removeTreeSync 完全一致。 */
7
+ export declare function removeTree(target: string): Promise<void>;