dsh-config-manager 0.4.1 → 0.4.2
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/cli/actions.js +2 -3
- package/lib/cli/import-source.js +2 -6
- package/lib/cli/index.js +2 -3
- package/lib/client.d.ts +0 -5
- package/lib/client.js +26116 -25801
- package/lib/core/exporter.js +2 -4
- package/lib/core/host-schedulers/cache-cleanup.d.ts +41 -0
- package/lib/core/host-schedulers/cache-cleanup.js +45 -0
- package/lib/core/host-schedulers/lifecycle-hooks.d.ts +51 -0
- package/lib/core/host-schedulers/lifecycle-hooks.js +78 -0
- package/lib/core/host-schedulers/market-cache.d.ts +40 -0
- package/lib/core/host-schedulers/market-cache.js +92 -0
- package/lib/core/model-tools.js +2 -6
- package/lib/core/restore.d.ts +0 -2
- package/lib/core/restore.js +16 -18
- package/lib/core/verify-recovery.js +4 -7
- package/lib/index.d.ts +3 -22
- package/lib/index.js +69 -325
- package/lib/profiles/dsh-profile-manager.d.ts +23 -1
- package/lib/profiles/dsh-profile-manager.js +70 -2
- package/lib/routes/kit.d.ts +21 -0
- package/lib/routes/kit.js +29 -0
- package/lib/routes/prefs.js +6 -6
- package/lib/routes/recovery.js +25 -41
- package/lib/routes/route-support.d.ts +23 -1
- package/lib/routes/route-support.js +185 -0
- package/lib/routes/snapshots.js +4 -11
- package/lib/routes/sync.js +5 -7
- package/lib/security/redaction.d.ts +5 -1
- package/lib/security/redaction.js +26 -23
- package/lib/sync/backup-scheduler.js +2 -6
- package/lib/ui/backup-inspect.d.ts +1 -1
- package/lib/ui/dsh-profiles-view.d.ts +0 -10
- package/lib/ui/dsh-profiles-view.js +3 -7
- package/lib/ui/snapshots-view.d.ts +0 -14
- package/lib/ui/snapshots-view.js +16 -2
- package/lib/utils/paths.d.ts +20 -4
- package/lib/utils/paths.js +22 -6
- package/lib/utils/time.d.ts +31 -0
- package/lib/utils/time.js +54 -0
- package/package.json +1 -1
- package/src/cli/actions.ts +2 -3
- package/src/cli/import-source.ts +2 -7
- package/src/cli/index.ts +2 -3
- package/src/client/about/AboutPanel.tsx +1 -1
- package/src/client/about/ReleaseBody.tsx +22 -52
- package/src/client/about/ReleaseNotesDialog.tsx +15 -69
- package/src/client/about/release-notes-view.ts +4 -11
- package/src/client/common/info-hint-guard.test.ts +11 -5
- package/src/client/common/ui.tsx +23 -0
- package/src/client/config-manager.module.css +201 -32
- package/src/client/css-token-guard.test.ts +135 -1
- package/src/client/import/ConflictList.tsx +3 -3
- package/src/client/import/ImportWizardView.tsx +1 -1
- package/src/client/library/ArtifactRow.tsx +2 -2
- package/src/client/library/RestorePlanView.tsx +21 -9
- package/src/client/library/report-dismiss.test.ts +5 -3
- package/src/client/locales/about.ts +97 -0
- package/src/client/locales/backup.ts +141 -0
- package/src/client/locales/common.ts +113 -0
- package/src/client/locales/export.ts +184 -0
- package/src/client/locales/foreign.ts +184 -0
- package/src/client/locales/import-compat.ts +32 -0
- package/src/client/locales/import.ts +192 -0
- package/src/client/locales/next-steps.ts +25 -0
- package/src/client/locales/overview-control.ts +32 -0
- package/src/client/locales/overview.ts +145 -0
- package/src/client/locales/profiles.ts +263 -0
- package/src/client/locales/report.ts +17 -0
- package/src/client/locales/restore.ts +132 -0
- package/src/client/locales/sessions.ts +257 -0
- package/src/client/locales/shell.ts +149 -0
- package/src/client/locales.ts +49 -1783
- package/src/client/market/MarketImportReview.tsx +2 -2
- package/src/client/market/MarketPanel.tsx +1 -1
- package/src/client/market/market-view.ts +3 -5
- package/src/client/recovery/RecoveryPanel.tsx +62 -1054
- package/src/client/recovery/SessionHealthCard.tsx +134 -0
- package/src/client/recovery/SessionHealthDialog.tsx +665 -0
- package/src/client/recovery/SessionLayoutSection.tsx +284 -0
- package/src/client/recovery/recovery-api.ts +10 -1
- package/src/client/recovery/recovery-panel-layout.test.ts +20 -5
- package/src/client/recovery/session-dialog-mount.test.ts +16 -9
- package/src/client/recovery/use-recovery-write.test.ts +90 -0
- package/src/client/recovery/use-recovery-write.ts +53 -0
- package/src/client/run-store.ts +57 -2
- package/src/client/sync/PushPreviewCard.tsx +2 -2
- package/src/client/sync/SyncConfirmView.tsx +5 -5
- package/src/client/sync/SyncLogList.tsx +2 -2
- package/src/client/sync/history-model.ts +4 -5
- package/src/client/sync/sync-view.ts +3 -4
- package/src/core/exporter.ts +2 -4
- package/src/core/host-schedulers/cache-cleanup.test.ts +84 -0
- package/src/core/host-schedulers/cache-cleanup.ts +74 -0
- package/src/core/host-schedulers/lifecycle-hooks.test.ts +111 -0
- package/src/core/host-schedulers/lifecycle-hooks.ts +118 -0
- package/src/core/host-schedulers/market-cache.test.ts +93 -0
- package/src/core/host-schedulers/market-cache.ts +116 -0
- package/src/core/model-tools.ts +2 -7
- package/src/core/restore-failure-state.test.ts +210 -0
- package/src/core/restore.ts +16 -18
- package/src/core/verify-recovery.ts +4 -7
- package/src/index.ts +76 -330
- package/src/profiles/dsh-profile-copy-rollback.test.ts +156 -0
- package/src/profiles/dsh-profile-manager.ts +71 -3
- package/src/routes/kit.ts +37 -0
- package/src/routes/prefs.ts +6 -6
- package/src/routes/recovery.ts +25 -42
- package/src/routes/route-support.ts +208 -1
- package/src/routes/snapshots.ts +4 -9
- package/src/routes/sync.ts +4 -7
- package/src/security/redaction.ts +29 -23
- package/src/sync/backup-scheduler.ts +3 -6
- package/src/sync/sync-config.test.ts +24 -13
- package/src/ui/backup-inspect.ts +1 -1
- package/src/ui/dsh-profiles-view.ts +3 -5
- package/src/ui/i18n.test.ts +8 -3
- package/src/ui/snapshots-view.ts +2 -2
- package/src/utils/paths.test.ts +36 -1
- package/src/utils/paths.ts +30 -6
- package/src/utils/time.test.ts +46 -0
- package/src/utils/time.ts +55 -0
package/lib/index.js
CHANGED
|
@@ -44,11 +44,15 @@ import { homedir } from 'node:os';
|
|
|
44
44
|
import { promisify } from 'node:util';
|
|
45
45
|
import * as dshSettings from '@deepseek-ai/dsh-settings';
|
|
46
46
|
import { dshHomePath, resolveDshHome } from '@deepseek-ai/dsh-home-paths';
|
|
47
|
-
import { endpoint, registerRoutes, requireJsonObject, writeJson, readJsonBody, errorMessage } from './routes/kit.js';
|
|
47
|
+
import { endpoint, registerRoutes, requireJsonObject, writeJson, readJsonBody, errorMessage, writeMutationError } from './routes/kit.js';
|
|
48
48
|
import { buildRoutes } from './routes/index.js';
|
|
49
49
|
import { Exporter, FileSnapshotStore, Importer, verifySnapshot } from './core/index.js';
|
|
50
50
|
import { DshProfileLauncher, DshProfileManager, DshProfileRuntimeRegistry } from './profiles/index.js';
|
|
51
51
|
import { cleanupCaches } from './core/cache-cleaner.js';
|
|
52
|
+
// tech-debt #23:宿主调度器下沉(纯调度语义可单测,index.ts 只留一次装配)。
|
|
53
|
+
import { createCacheCleanupScheduler } from './core/host-schedulers/cache-cleanup.js';
|
|
54
|
+
import { createHostLifecycle } from './core/host-schedulers/lifecycle-hooks.js';
|
|
55
|
+
import { createMarketCacheLayout, marketItemCached, pruneStagedMarketZips as pruneMarketStagedZips, readMarketCacheIndexText, writeMarketItemCache, } from './core/host-schedulers/market-cache.js';
|
|
52
56
|
import { isValidSnapshotId, planRestore } from './core/restore.js';
|
|
53
57
|
import { rollback as performRollback } from './core/rollback.js';
|
|
54
58
|
// Phase 1 P0-1/P0-2:配置生命周期(自动快照 / 撤销 / 重做)与 P0-5 崩溃归因。
|
|
@@ -86,10 +90,10 @@ import { probeSessionFormats, resolveSessionFormatVersion } from './utils/sessio
|
|
|
86
90
|
import { describePatchYamlError, dumpPatchDocument, loadPatchDocument } from './utils/patch-yaml.js';
|
|
87
91
|
import { atomicCopyFile, atomicWriteFile } from './utils/atomic-write.js';
|
|
88
92
|
import { isENOENT } from './utils/guards.js';
|
|
89
|
-
import { EnvironmentLockManager, runWithMutationLock
|
|
93
|
+
import { EnvironmentLockManager, runWithMutationLock } from './utils/env-lock.js';
|
|
90
94
|
import { activeProxySummary } from './utils/proxy.js';
|
|
91
95
|
import { listRecursiveFollowingLinks } from './utils/recursive-walk.js';
|
|
92
|
-
import { Phase3Recovery,
|
|
96
|
+
import { Phase3Recovery, mapLockStateForStartup } from './core/phase3-host.js';
|
|
93
97
|
import { classifyStartup, FAIL_CLOSED_STARTUP, resolveStartupSafeMode } from './core/startup-barrier.js';
|
|
94
98
|
import { GitTransport } from './sync/git/git-transport.js';
|
|
95
99
|
import { WebDavTransport } from './sync/webdav/webdav-transport.js';
|
|
@@ -108,7 +112,7 @@ import { selectPruneCandidates } from './core/backup.js';
|
|
|
108
112
|
import { appendAutosyncEntry } from './sync/sync-history.js';
|
|
109
113
|
import { MigrationStore, historyResultFromAutosyncStatus, MIGRATION_HISTORY_DIR } from './core/migration-history.js';
|
|
110
114
|
import { createHistoryPruner } from './core/history-prune.js';
|
|
111
|
-
import {
|
|
115
|
+
import { isWebDavConfig, isS3Config, isGistConfig, channelOf, SYNC_CHANNELS, GIST_PROVIDER, cloudSecretRef } from './sync/sync-config.js';
|
|
112
116
|
import { resolveSessionFormatDisposition, sessionFormatAbortResponse, } from './routes/session-format.js';
|
|
113
117
|
import { createPrepareSync } from './sync/config-issue-reporting.js';
|
|
114
118
|
import { AUTO_SYNC_OPT_IN_SECTIONS, defaultSyncSelection, effectiveSections, OPT_IN_SYNC_SECTIONS, readAllSyncSelections, readSyncSelection } from './sync/sync-selection.js';
|
|
@@ -121,17 +125,17 @@ import { createGitFileWriter } from './market/git-file-writer.js';
|
|
|
121
125
|
import { parseGitHubRepoUrl } from './market/repo-url.js';
|
|
122
126
|
import { StarCache } from './market/star-cache.js';
|
|
123
127
|
import { createConfiguredSecretScanner } from './security/secret-scanner.js';
|
|
124
|
-
import { sha256Hex } from './utils/hashing.js';
|
|
125
128
|
import { createTtlAsyncCache } from './utils/ttl-cache.js';
|
|
126
129
|
import { isFileSection, SECTION_IDS } from './schema/config.js';
|
|
127
130
|
import { stringifyJsonSafe } from './utils/json.js';
|
|
128
131
|
import { isSameOrChild } from './utils/paths.js';
|
|
132
|
+
import { formatDateOnly } from './utils/time.js';
|
|
129
133
|
import { isRecord } from './utils/guards.js';
|
|
130
134
|
import { createLogger, parseLogLevel } from './utils/logger.js';
|
|
131
135
|
// 与 HTTP 路径**同一份**「运行中对话」判据(命令入口绝不能各写一套)
|
|
132
136
|
import { sessionActiveDenied, sessionActiveGateApplies } from './routes/recovery.js';
|
|
133
137
|
// P4:路由组共享的纯工具已下沉到 routes/route-support.ts —— 组文件不再反向 import 本文件。
|
|
134
|
-
import { ROUTE_TIMEOUT_MS, SYNC_CREDENTIAL_REF, SYNC_WEBDAV_CREDENTIAL_REF,
|
|
138
|
+
import { ROUTE_TIMEOUT_MS, SYNC_CREDENTIAL_REF, SYNC_WEBDAV_CREDENTIAL_REF, credentialRef, decryptErrorText, executeRestorePlan, isControlledPath, makeRestoreExecutor, safeCredentialRef, syncPasswordRef, tryDecryptCredentials, withTimeout } from './routes/route-support.js';
|
|
135
139
|
export { ROUTE_TIMEOUT_MS, REVIEW_KINDS, SYNC_CREDENTIAL_REF, SYNC_ENCRYPT_PASSWORD_REF_PREFIX, SYNC_DECRYPT_PASSWORD_REF_PREFIX, SYNC_WEBDAV_CREDENTIAL_REF, SyncRouteError, buildAutosyncStatus, buildAutosyncStatusByChannel, buildFileDiffBody, buildRestoreBody, credentialRef, decryptErrorText, executeRestorePlan, extractSyncSections, extractSyncSessions, isAutosyncInterval, isControlledPath, isGitHubAuthMissing, isToolchainChangeItem, makeRestoreExecutor, parseMeForm, planToConfirmItems, safeCredentialRef, sessionHealthNextSteps, syncPasswordRef, tryDecryptCredentials, withTimeout, writeProfileError, writeRequestBodyToFile, writeSyncRouteError } from './routes/route-support.js';
|
|
136
140
|
/* ---------------------------------------------------------------- identity */
|
|
137
141
|
/** Stable cordis plugin name — must match the cordis.patch.yml row id. */
|
|
@@ -139,7 +143,7 @@ export const name = 'config-manager';
|
|
|
139
143
|
/** Services required before the engine can mount (present in every profile). */
|
|
140
144
|
export const inject = ['settings', 'credentials'];
|
|
141
145
|
/** Plugin version, kept in sync with package.json ("version"). */
|
|
142
|
-
export const PLUGIN_VERSION = '0.4.
|
|
146
|
+
export const PLUGIN_VERSION = '0.4.2';
|
|
143
147
|
/** Plugin own package name — excluded from its own exported plugins list. */
|
|
144
148
|
const PLUGIN_NAME = 'dsh-config-manager';
|
|
145
149
|
/**
|
|
@@ -1906,12 +1910,6 @@ export class ConfigManagerHostContext {
|
|
|
1906
1910
|
}
|
|
1907
1911
|
}
|
|
1908
1912
|
/* ---------------------------------------------------------------- routes */
|
|
1909
|
-
function dateStamp(d = new Date()) {
|
|
1910
|
-
const y = d.getFullYear();
|
|
1911
|
-
const m = String(d.getMonth() + 1).padStart(2, '0');
|
|
1912
|
-
const day = String(d.getDate()).padStart(2, '0');
|
|
1913
|
-
return `${y}-${m}-${day}`;
|
|
1914
|
-
}
|
|
1915
1913
|
/** Minimal real dependency check (MCP §15): `which`/`where` probe. */
|
|
1916
1914
|
async function dependencyAvailable(command) {
|
|
1917
1915
|
const probe = process.platform === 'win32' ? 'where' : 'which';
|
|
@@ -1926,190 +1924,11 @@ async function dependencyAvailable(command) {
|
|
|
1926
1924
|
/** WebDAV 单请求超时(ms):慢速 WebDAV(如坚果云限速)上传大快照/读写索引
|
|
1927
1925
|
* 需要比 git 通道更宽裕的窗口;错误消息会带上实际 ms,便于用户判断。 */
|
|
1928
1926
|
const WEBDAV_TIMEOUT_MS = 120_000;
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
* - webdav: { transport:'webdav', url, username?, password? } —— password 非空写 SYNC_WEBDAV_CREDENTIAL_REF。
|
|
1935
|
-
* 返回值不含任何 secret(password/token 只进 credentials,永不回传/落同步文件)。
|
|
1936
|
-
*/
|
|
1937
|
-
export async function parseSyncBody(body, deps) {
|
|
1938
|
-
const rawTransport = body['transport'];
|
|
1939
|
-
// 通道值解析:接受通道名(s3/gist);也接受**具体兼容商**(oss/cos/minio/kodo)直接落到 s3 通道
|
|
1940
|
-
const transport = parseSyncChannel(rawTransport) ?? (isS3CompatProvider(rawTransport) ? 's3' : 'git');
|
|
1941
|
-
if (transport === 's3')
|
|
1942
|
-
return parseCloudS3Body(body, rawTransport, deps);
|
|
1943
|
-
if (transport === 'gist')
|
|
1944
|
-
return parseCloudGistBody(body, deps);
|
|
1945
|
-
if (transport === 'webdav') {
|
|
1946
|
-
const url = typeof body['url'] === 'string' ? body['url'].trim() : '';
|
|
1947
|
-
if (url === '')
|
|
1948
|
-
throw new SyncRouteError('url is required for webdav');
|
|
1949
|
-
const urlError = validateWebDavUrl(url);
|
|
1950
|
-
if (urlError !== null)
|
|
1951
|
-
throw new SyncRouteError(urlError);
|
|
1952
|
-
const username = typeof body['username'] === 'string' && body['username'] !== '' ? body['username'] : undefined;
|
|
1953
|
-
const password = typeof body['password'] === 'string' && body['password'] !== '' ? body['password'] : undefined;
|
|
1954
|
-
if (password !== undefined) {
|
|
1955
|
-
try {
|
|
1956
|
-
await deps.credentials.set(credentialRef(SYNC_WEBDAV_CREDENTIAL_REF), password);
|
|
1957
|
-
}
|
|
1958
|
-
catch (error) {
|
|
1959
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
1960
|
-
throw new SyncRouteError(engineMsg('host.syncWebdavPasswordWriteFailed', { reason, ref: SYNC_WEBDAV_CREDENTIAL_REF }));
|
|
1961
|
-
}
|
|
1962
|
-
}
|
|
1963
|
-
return {
|
|
1964
|
-
schemaVersion: 2,
|
|
1965
|
-
transport: 'webdav',
|
|
1966
|
-
webdav: { url, ...(username !== undefined ? { username } : {}) },
|
|
1967
|
-
};
|
|
1968
|
-
}
|
|
1969
|
-
// git 通道(沿用现有逻辑)
|
|
1970
|
-
const repoUrl = typeof body['repoUrl'] === 'string' ? body['repoUrl'].trim() : '';
|
|
1971
|
-
if (repoUrl === '')
|
|
1972
|
-
throw new SyncRouteError('repoUrl is required');
|
|
1973
|
-
const urlError = validateRepoUrl(repoUrl);
|
|
1974
|
-
if (urlError !== null)
|
|
1975
|
-
throw new SyncRouteError(urlError);
|
|
1976
|
-
const token = typeof body['token'] === 'string' && body['token'] !== '' ? body['token'] : undefined;
|
|
1977
|
-
if (token !== undefined) {
|
|
1978
|
-
try {
|
|
1979
|
-
await deps.credentials.set(credentialRef(SYNC_CREDENTIAL_REF), token);
|
|
1980
|
-
}
|
|
1981
|
-
catch (error) {
|
|
1982
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
1983
|
-
throw new SyncRouteError(engineMsg('host.syncTokenWriteFailed', { reason, ref: SYNC_CREDENTIAL_REF }));
|
|
1984
|
-
}
|
|
1985
|
-
}
|
|
1986
|
-
return {
|
|
1987
|
-
schemaVersion: 2,
|
|
1988
|
-
transport: 'git',
|
|
1989
|
-
git: { repoUrl },
|
|
1990
|
-
};
|
|
1991
|
-
}
|
|
1992
|
-
/** 请求体字段 → 去空白字符串(非字符串 = 空)。 */
|
|
1993
|
-
function syncStr(value) {
|
|
1994
|
-
return typeof value === 'string' ? value.trim() : '';
|
|
1995
|
-
}
|
|
1996
|
-
/** 云端点密钥写入失败 → 可操作错误(**含 ref 名、绝不含密钥值**)。 */
|
|
1997
|
-
function cloudCredentialWriteError(ref, kind, error) {
|
|
1998
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
1999
|
-
return new SyncRouteError(engineMsg('host.syncCredentialWriteFailed', { kind, reason, ref }), 400, 'cloud.credentialsWriteFailed');
|
|
2000
|
-
}
|
|
2001
|
-
/**
|
|
2002
|
-
* s3 通道请求体 → SyncConfig(provider 必填或由 transport 直接给出)。
|
|
2003
|
-
* 非密字段按 validateCloudChannelInput 校验(错误码 = HTTP body.code,由 UI 映射字典);
|
|
2004
|
-
* 密钥**只写**进 DSH credentials 的 cloudSecretRef(provider) 槽位,绝不进返回值 / 文件 / 日志。
|
|
2005
|
-
*/
|
|
2006
|
-
async function parseCloudS3Body(body, rawTransport, deps) {
|
|
2007
|
-
const provider = isS3CompatProvider(body['provider'])
|
|
2008
|
-
? body['provider']
|
|
2009
|
-
: (isS3CompatProvider(rawTransport) ? rawTransport : null);
|
|
2010
|
-
if (provider === null) {
|
|
2011
|
-
throw new SyncRouteError('provider is required for s3 (s3/oss/cos/minio/kodo)', 400, 'cloud.providerUnknown');
|
|
2012
|
-
}
|
|
2013
|
-
const endpoint = syncStr(body['endpoint']).replace(/\/+$/, '');
|
|
2014
|
-
const region = syncStr(body['region']);
|
|
2015
|
-
const bucket = syncStr(body['bucket']);
|
|
2016
|
-
const accessKeyId = syncStr(body['accessKeyId']);
|
|
2017
|
-
const prefix = syncStr(body['prefix']);
|
|
2018
|
-
const pathStyle = typeof body['pathStyle'] === 'boolean' ? body['pathStyle'] : undefined;
|
|
2019
|
-
const dialectId = body['dialectId'] === 'aws4' || body['dialectId'] === 'oss4' ? body['dialectId'] : undefined;
|
|
2020
|
-
const issue = validateCloudChannelInput(provider, {
|
|
2021
|
-
endpoint,
|
|
2022
|
-
region,
|
|
2023
|
-
bucket,
|
|
2024
|
-
accessKeyId,
|
|
2025
|
-
...(prefix === '' ? {} : { prefix }),
|
|
2026
|
-
...(pathStyle === undefined ? {} : { pathStyle }),
|
|
2027
|
-
...(dialectId === undefined ? {} : { dialectId }),
|
|
2028
|
-
});
|
|
2029
|
-
if (issue !== null)
|
|
2030
|
-
throw new SyncRouteError(issue, 400, issue);
|
|
2031
|
-
const secret = typeof body['secret'] === 'string' && body['secret'] !== '' ? body['secret'] : undefined;
|
|
2032
|
-
if (secret !== undefined) {
|
|
2033
|
-
const ref = cloudSecretRef(provider);
|
|
2034
|
-
try {
|
|
2035
|
-
await deps.credentials.set(credentialRef(ref), secret);
|
|
2036
|
-
}
|
|
2037
|
-
catch (error) {
|
|
2038
|
-
throw cloudCredentialWriteError(ref, engineMsg('host.syncKindS3Secret'), error);
|
|
2039
|
-
}
|
|
2040
|
-
}
|
|
2041
|
-
return {
|
|
2042
|
-
schemaVersion: 2,
|
|
2043
|
-
transport: 's3',
|
|
2044
|
-
s3: {
|
|
2045
|
-
provider,
|
|
2046
|
-
endpoint,
|
|
2047
|
-
region,
|
|
2048
|
-
bucket,
|
|
2049
|
-
accessKeyId,
|
|
2050
|
-
...(prefix === '' ? {} : { prefix }),
|
|
2051
|
-
...(pathStyle === undefined ? {} : { pathStyle }),
|
|
2052
|
-
...(dialectId === undefined ? {} : { dialectId }),
|
|
2053
|
-
},
|
|
2054
|
-
};
|
|
2055
|
-
}
|
|
2056
|
-
/**
|
|
2057
|
-
* gist 通道请求体 → SyncConfig。token 只写进 cloudSecretRef('gist') 槽位
|
|
2058
|
-
* (请求体字段名 token 或 secret 都接受;值绝不进返回值 / 文件 / 日志)。
|
|
2059
|
-
*/
|
|
2060
|
-
async function parseCloudGistBody(body, deps) {
|
|
2061
|
-
const gistId = syncStr(body['gistId']);
|
|
2062
|
-
const apiBaseUrl = syncStr(body['apiBaseUrl']);
|
|
2063
|
-
const filePrefix = syncStr(body['filePrefix']);
|
|
2064
|
-
const issue = validateCloudChannelInput(GIST_PROVIDER, {
|
|
2065
|
-
gistId,
|
|
2066
|
-
...(apiBaseUrl === '' ? {} : { apiBaseUrl }),
|
|
2067
|
-
...(filePrefix === '' ? {} : { filePrefix }),
|
|
2068
|
-
});
|
|
2069
|
-
if (issue !== null)
|
|
2070
|
-
throw new SyncRouteError(issue, 400, issue);
|
|
2071
|
-
const token = typeof body['token'] === 'string' && body['token'] !== ''
|
|
2072
|
-
? body['token']
|
|
2073
|
-
: (typeof body['secret'] === 'string' && body['secret'] !== '' ? body['secret'] : undefined);
|
|
2074
|
-
if (token !== undefined) {
|
|
2075
|
-
const ref = cloudSecretRef(GIST_PROVIDER);
|
|
2076
|
-
try {
|
|
2077
|
-
await deps.credentials.set(credentialRef(ref), token);
|
|
2078
|
-
}
|
|
2079
|
-
catch (error) {
|
|
2080
|
-
throw cloudCredentialWriteError(ref, 'Gist token', error);
|
|
2081
|
-
}
|
|
2082
|
-
}
|
|
2083
|
-
return {
|
|
2084
|
-
schemaVersion: 2,
|
|
2085
|
-
transport: 'gist',
|
|
2086
|
-
gist: {
|
|
2087
|
-
gistId,
|
|
2088
|
-
...(apiBaseUrl === '' ? {} : { apiBaseUrl }),
|
|
2089
|
-
...(filePrefix === '' ? {} : { filePrefix }),
|
|
2090
|
-
},
|
|
2091
|
-
};
|
|
2092
|
-
}
|
|
2093
|
-
/** 由 SyncConfig 合成 WebDAV 通道 baseUrl(webdav.url,尾部规范化带 '/';git 通道返回 '')。 */
|
|
2094
|
-
export function webdavBaseUrl(cfg) {
|
|
2095
|
-
if (!isWebDavConfig(cfg))
|
|
2096
|
-
return '';
|
|
2097
|
-
return cfg.webdav.url.replace(/\/+$/, '') + '/';
|
|
2098
|
-
}
|
|
2099
|
-
/**
|
|
2100
|
-
* 补全 webdav 配置缺失的 username(从持久化配置回填;纯函数,不修改入参)。
|
|
2101
|
-
* 语义与 password 一致:请求未带 username(表单留空/挂载自动加载)→ 沿用已保存的值;
|
|
2102
|
-
* 请求显式带 username → 原样保留(用户新输入优先)。非 webdav / 无持久化 → 原样返回。
|
|
2103
|
-
*/
|
|
2104
|
-
export function mergePersistedWebDavUsername(cfg, persisted) {
|
|
2105
|
-
if (!isWebDavConfig(cfg) || (cfg.webdav.username !== undefined && cfg.webdav.username !== ''))
|
|
2106
|
-
return cfg;
|
|
2107
|
-
if (persisted !== null && isWebDavConfig(persisted)
|
|
2108
|
-
&& typeof persisted.webdav.username === 'string' && persisted.webdav.username !== '') {
|
|
2109
|
-
return { ...cfg, webdav: { ...cfg.webdav, username: persisted.webdav.username } };
|
|
2110
|
-
}
|
|
2111
|
-
return cfg;
|
|
2112
|
-
}
|
|
1927
|
+
/* -------------------------------------------------- sync 路由(m-sync-ui) */
|
|
1928
|
+
// 请求体解析下沉到 routes/route-support.ts(tech-debt #23:组合根只留装配)。
|
|
1929
|
+
// 组合根继续导出这些符号,`src/index.sync.test.ts` 与既有调用方口径不变。
|
|
1930
|
+
import { mergePersistedWebDavUsername, parseSyncBody, webdavBaseUrl } from './routes/route-support.js';
|
|
1931
|
+
export { mergePersistedWebDavUsername, parseSyncBody, webdavBaseUrl } from './routes/route-support.js';
|
|
2113
1932
|
/**
|
|
2114
1933
|
* 读取插件诊断信息(issue #28):把「插件到底读了哪个目录 / 哪个 profile / 看到什么」变成
|
|
2115
1934
|
* 用户可自查的数据——此前只存在于宿主内部,导致「装了插件却识别不到」无从定位。
|
|
@@ -2438,18 +2257,10 @@ function makeRoutes(deps) {
|
|
|
2438
2257
|
});
|
|
2439
2258
|
}
|
|
2440
2259
|
catch (error) {
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
host.log.warn(`mutation lock blocked: op=${error.op} reason=${error.reason}${error.detail !== undefined ? ` detail=${error.detail}` : ''}`);
|
|
2445
|
-
writeJson(res, 423, { error: error.message, code: 'mutation-locked' });
|
|
2446
|
-
return;
|
|
2447
|
-
}
|
|
2448
|
-
// 非 423:若已由 runJournaled 置 SAFE MODE/失败,保持既有错误语义(400/500)
|
|
2449
|
-
if (error instanceof TransactionRecoveryRequiredError) {
|
|
2450
|
-
writeJson(res, 423, { error: error.message, code: 'transaction-recovery-required' });
|
|
2260
|
+
// 423 家族(SAFE MODE / 环境锁 / 未收敛事务)的唯一映射在 routes/kit.ts 的 writeMutationError;
|
|
2261
|
+
// 其余错误**必须 rethrow** —— endpoint() 的出口与救急台的 errorRenderer 都依赖这条抛出。
|
|
2262
|
+
if (writeMutationError(res, host, error))
|
|
2451
2263
|
return;
|
|
2452
|
-
}
|
|
2453
2264
|
throw error;
|
|
2454
2265
|
}
|
|
2455
2266
|
};
|
|
@@ -2695,12 +2506,11 @@ function makeRoutes(deps) {
|
|
|
2695
2506
|
// ------------------------------------------------ market 辅助(m-market)
|
|
2696
2507
|
// 目录:<marketDir>/cache/<url-hash>/(index/条目缓存)
|
|
2697
2508
|
// + <marketDir>/work/<url-hash>/(git 只读工作副本,--depth 1)。无任何凭据。
|
|
2698
|
-
|
|
2699
|
-
const
|
|
2700
|
-
const
|
|
2701
|
-
const
|
|
2702
|
-
const
|
|
2703
|
-
const marketWorkDir = (url) => join(marketWorkRoot, urlHash(url));
|
|
2509
|
+
// 布局与暂存 GC 的下沉实现见 core/host-schedulers/market-cache.ts(可单测)。
|
|
2510
|
+
const marketCache = createMarketCacheLayout(marketDir);
|
|
2511
|
+
const marketCacheIndex = marketCache.cacheIndex;
|
|
2512
|
+
const marketCacheItemDir = marketCache.itemDir;
|
|
2513
|
+
const marketWorkDir = marketCache.workDir;
|
|
2704
2514
|
/**
|
|
2705
2515
|
* 进程生命周期标记:本次 dsh 启动后市场是否已成功刷新过一次(内存态,dsh 重启后自动归零)。
|
|
2706
2516
|
* 供「首次打开市场页自动更新一次市场」:MarketPanel 挂载时读 status 返回的
|
|
@@ -2725,14 +2535,11 @@ function makeRoutes(deps) {
|
|
|
2725
2535
|
});
|
|
2726
2536
|
/** 读缓存的 index.json(结构校验通过才返回,否则 null)。 */
|
|
2727
2537
|
async function readCachedIndexObj(url) {
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
const res = parseMarketIndex(raw);
|
|
2731
|
-
return res.ok ? res.index : null;
|
|
2732
|
-
}
|
|
2733
|
-
catch {
|
|
2538
|
+
const raw = await readMarketCacheIndexText(marketCache, url);
|
|
2539
|
+
if (raw === null)
|
|
2734
2540
|
return null;
|
|
2735
|
-
|
|
2541
|
+
const res = parseMarketIndex(raw);
|
|
2542
|
+
return res.ok ? res.index : null;
|
|
2736
2543
|
}
|
|
2737
2544
|
/** 由配置条目构建市场摘要(name/itemCount/lastFetchedAt 来自缓存 index,可空)。 */
|
|
2738
2545
|
async function buildMarketSummary(e) {
|
|
@@ -2751,53 +2558,14 @@ function makeRoutes(deps) {
|
|
|
2751
2558
|
return s;
|
|
2752
2559
|
}
|
|
2753
2560
|
/** 条目是否已有完整缓存(manifest + config.zip)。 */
|
|
2754
|
-
|
|
2755
|
-
try {
|
|
2756
|
-
await fs.access(join(marketCacheItemDir(url), itemId, 'config.zip'));
|
|
2757
|
-
await fs.access(join(marketCacheItemDir(url), itemId, 'manifest.json'));
|
|
2758
|
-
return true;
|
|
2759
|
-
}
|
|
2760
|
-
catch {
|
|
2761
|
-
return false;
|
|
2762
|
-
}
|
|
2763
|
-
}
|
|
2561
|
+
const itemCached = (url, itemId) => marketItemCached(marketCache, url, itemId);
|
|
2764
2562
|
/** 写条目缓存(manifest + config.zip)供离线重复查看。内容始终视为不可信。 */
|
|
2765
|
-
|
|
2766
|
-
const dir = join(marketCacheItemDir(url), itemId);
|
|
2767
|
-
await fs.mkdir(dir, { recursive: true });
|
|
2768
|
-
await fs.writeFile(join(dir, 'manifest.json'), manifestRaw, 'utf8');
|
|
2769
|
-
await fs.writeFile(join(dir, 'config.zip'), zipBytes);
|
|
2770
|
-
}
|
|
2563
|
+
const writeItemCache = (url, itemId, manifestRaw, zipBytes) => writeMarketItemCache(marketCache, url, itemId, manifestRaw, zipBytes);
|
|
2771
2564
|
/**
|
|
2772
|
-
* 清理滞留在 tmpDir 的过期市场暂存 zip(market-*.zip)。
|
|
2773
|
-
* market/download 每次暂存新 zip 前调用(懒 GC
|
|
2774
|
-
* 后立即执行的 /execute 消费),清理更旧的 —— 防止未确认导入的暂存文件无限堆积。
|
|
2775
|
-
* 一次性尽力而为:任何读取/删除失败不影响主流程。
|
|
2565
|
+
* 清理滞留在 tmpDir 的过期市场暂存 zip(market-*.zip / publish-*.zip)。
|
|
2566
|
+
* market/download 每次暂存新 zip 前调用(懒 GC);保留期与尽力而为语义见 market-cache.ts。
|
|
2776
2567
|
*/
|
|
2777
|
-
const
|
|
2778
|
-
async function pruneStagedMarketZips() {
|
|
2779
|
-
try {
|
|
2780
|
-
const names = await fs.readdir(tmpDir);
|
|
2781
|
-
const now = Date.now();
|
|
2782
|
-
for (const name of names) {
|
|
2783
|
-
// market-*.zip(未确认导入的暂存)与 publish-*.zip(发布向导产物)都纳入保留策略
|
|
2784
|
-
if ((!name.startsWith('market-') && !name.startsWith('publish-')) || !name.endsWith('.zip'))
|
|
2785
|
-
continue;
|
|
2786
|
-
const p = join(tmpDir, name);
|
|
2787
|
-
try {
|
|
2788
|
-
const st = await fs.stat(p);
|
|
2789
|
-
if (now - st.mtimeMs > MARKET_TMP_RETENTION_MS)
|
|
2790
|
-
await fs.rm(p, { force: true, recursive: true });
|
|
2791
|
-
}
|
|
2792
|
-
catch {
|
|
2793
|
-
// 单文件 stat/删除失败 → 跳过(尽力而为)
|
|
2794
|
-
}
|
|
2795
|
-
}
|
|
2796
|
-
}
|
|
2797
|
-
catch {
|
|
2798
|
-
// tmpDir 读取失败 → 跳过(尽力而为)
|
|
2799
|
-
}
|
|
2800
|
-
}
|
|
2568
|
+
const pruneStagedMarketZips = async () => { await pruneMarketStagedZips(tmpDir); };
|
|
2801
2569
|
// -------------------------------------------------- me 装配(m-my-configs)
|
|
2802
2570
|
// 「一键上传 / 我的配置」:GitHub REST 客户端 + 上传编排。
|
|
2803
2571
|
// token 只经 credentials.resolve(SYNC_CREDENTIAL_REF) 在宿主内部读取(与 git 同步共用
|
|
@@ -3106,7 +2874,7 @@ function makeRoutes(deps) {
|
|
|
3106
2874
|
}
|
|
3107
2875
|
const desiredName = customFileName !== null
|
|
3108
2876
|
? customFileName
|
|
3109
|
-
: `dsh-config-${
|
|
2877
|
+
: `dsh-config-${formatDateOnly(new Date())}-${randomBytes(3).toString('hex')}.zip`;
|
|
3110
2878
|
const finalFileName = resolveNonCollidingExportName(desiredName, existingExportNames);
|
|
3111
2879
|
const outPath = join(exportsDir, finalFileName);
|
|
3112
2880
|
// m1:执行开始注册 run(同 kind 已有进行中任务 → 409 拒绝,防止重复导出)
|
|
@@ -3629,11 +3397,11 @@ export function apply(ctx, config) {
|
|
|
3629
3397
|
host.log.warn('Phase 3 SAFE MODE 激活:存在未恢复的 transaction,destructive 操作被阻断(如需恢复请先显式处理)');
|
|
3630
3398
|
}
|
|
3631
3399
|
// P1-B:启动 recovery 分类 barrier。调度器(AutoSync/Backup)只在分类完成且 state=NORMAL 时启动。
|
|
3632
|
-
//
|
|
3633
|
-
//
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3400
|
+
// 启停 / 退出兜底释放锁 / 实例心跳的装配下沉到 core/host-schedulers/lifecycle-hooks.ts:
|
|
3401
|
+
// 这里只把分类结论投给它,arm 与 classify 谁先到都收敛到同一结果。
|
|
3402
|
+
// fail-closed:分类抛错 → 结论 BLOCKED(终态)→ 调度器不启动。
|
|
3403
|
+
const lifecycleRef = { current: null };
|
|
3404
|
+
const startupVerdictRef = { value: null };
|
|
3637
3405
|
void (async () => {
|
|
3638
3406
|
try {
|
|
3639
3407
|
await phase3Recovery.initFingerprint();
|
|
@@ -3654,7 +3422,6 @@ export function apply(ctx, config) {
|
|
|
3654
3422
|
lockState: mapLockStateForStartup(lockInsp.state),
|
|
3655
3423
|
});
|
|
3656
3424
|
const { state } = await startupState.classify();
|
|
3657
|
-
startupStateResolved = true;
|
|
3658
3425
|
// 残留锁自愈(可证 stale 回收 + 孤儿心跳清理),判定与理由见 core/env-lock-lifecycle.ts。
|
|
3659
3426
|
const effectiveLockState = await reclaimStaleLockAtStartup({ kind: state.kind, inspected: lockInsp.state, lock: envLockManager, log: host.log });
|
|
3660
3427
|
// issue #87:分类结论才是本轮权威。NORMAL 且没有活锁者 ⇒ 上一轮留下的 durable SAFE MODE 是**陈旧标记**
|
|
@@ -3670,13 +3437,12 @@ export function apply(ctx, config) {
|
|
|
3670
3437
|
await phase3Recovery.clearSafeMode().catch(() => undefined);
|
|
3671
3438
|
host.log.info('Phase 3 启动分类 NORMAL:上一轮遗留的 SAFE MODE 标记已复位(无未决事务、无活锁者)');
|
|
3672
3439
|
}
|
|
3673
|
-
|
|
3440
|
+
const verdict = state.kind === 'NORMAL' ? 'NORMAL' : 'BLOCKED';
|
|
3441
|
+
startupVerdictRef.value = verdict;
|
|
3674
3442
|
if (state.kind === 'RECOVERY_REQUIRED' || state.kind === 'NEEDS_ATTENTION') {
|
|
3675
3443
|
host.log.warn(`Phase 3 ${state.kind}:上次 destructive operation 崩溃残留,需显式恢复;destructive 调度器未启动(read-only host 存活)`);
|
|
3676
3444
|
}
|
|
3677
|
-
|
|
3678
|
-
schedulerGate.start();
|
|
3679
|
-
}
|
|
3445
|
+
lifecycleRef.current?.onStartupClassified(verdict);
|
|
3680
3446
|
// Phase 1 P0-5:启动分类已得出结论 → 本次启动判定为成功(推进 lastGoodAt)。
|
|
3681
3447
|
// 灾备总开关关闭时不写 boot-state。
|
|
3682
3448
|
try {
|
|
@@ -3691,8 +3457,8 @@ export function apply(ctx, config) {
|
|
|
3691
3457
|
// fail-open —— 此刻无法证明环境干净,destructive 路由必须一并被阻断:置内存 SAFE MODE
|
|
3692
3458
|
// (isBlocked 谓词立即生效)+ 写 durable 标记(下次启动不判 NORMAL),与 phase3-host.ts
|
|
3693
3459
|
// runJournaled 异常分支的姿态一致。清理通道仍是用户显式 recovery(clearSafeMode)。
|
|
3694
|
-
|
|
3695
|
-
|
|
3460
|
+
// 分类抛错时保留 null:接线期若仍无结论,lifecycle 不会启动调度器(fail-closed 的第一道)。
|
|
3461
|
+
startupVerdictRef.value = FAIL_CLOSED_STARTUP.startSchedulers ? 'NORMAL' : 'BLOCKED';
|
|
3696
3462
|
if (FAIL_CLOSED_STARTUP.safeModeRequired) {
|
|
3697
3463
|
phase3Recovery.safeModeActive = true;
|
|
3698
3464
|
await phase3Recovery.store.writeSafeMode(true).catch(() => undefined);
|
|
@@ -3707,12 +3473,11 @@ export function apply(ctx, config) {
|
|
|
3707
3473
|
});
|
|
3708
3474
|
}
|
|
3709
3475
|
})();
|
|
3710
|
-
// 缓存自动清理:启动即清一次 + 每 24h
|
|
3476
|
+
// 缓存自动清理:启动即清一次 + 每 24h 定时清一次(调度语义见 core/host-schedulers/cache-cleanup.ts)。
|
|
3711
3477
|
// 只清「可重建/一次性」缓存与临时文件(tmp 暂存、exports 导出副本、market cache/work),
|
|
3712
3478
|
// 保留期内的文件不删(供刷新恢复导入/下载等窗口继续消费);snapshots 与 sync 属用户数据/安全网不动。
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
void cleanupCaches({
|
|
3479
|
+
const cacheCleanup = createCacheCleanupScheduler({
|
|
3480
|
+
cleanup: () => cleanupCaches({
|
|
3716
3481
|
tmpDir,
|
|
3717
3482
|
exportsDir,
|
|
3718
3483
|
// 定时备份产物(dsh-config-auto-*)豁免按天回收:保留策略归 BackupScheduler
|
|
@@ -3720,20 +3485,12 @@ export function apply(ctx, config) {
|
|
|
3720
3485
|
exportsExemptPrefix: AUTO_BACKUP_PREFIX,
|
|
3721
3486
|
marketCacheRoot: join(marketDir, 'cache'),
|
|
3722
3487
|
marketWorkRoot: join(marketDir, 'work'),
|
|
3723
|
-
})
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
.catch((error) => {
|
|
3730
|
-
host.log.warn('缓存自动清理失败', { error: error instanceof Error ? error.message : String(error) });
|
|
3731
|
-
});
|
|
3732
|
-
};
|
|
3733
|
-
runCacheCleanup();
|
|
3734
|
-
const cacheCleanupTimer = setInterval(runCacheCleanup, CACHE_CLEANUP_INTERVAL_MS);
|
|
3735
|
-
ctx.effect(() => () => clearInterval(cacheCleanupTimer), 'config-manager: cache cleanup scheduler');
|
|
3736
|
-
// self 分区目录(相对 ~/.dsh 根):dataDir 在 homeDir 下 → 用相对路径挂载 self adapter;
|
|
3488
|
+
}),
|
|
3489
|
+
intervalMs: CACHE_CLEANUP_INTERVAL_MS,
|
|
3490
|
+
log: host.log,
|
|
3491
|
+
});
|
|
3492
|
+
cacheCleanup.start();
|
|
3493
|
+
ctx.effect(() => () => cacheCleanup.dispose(), 'config-manager: cache cleanup scheduler');
|
|
3737
3494
|
// 自定义 dataDir 位于 ~/.dsh 之外时 Host fs 门面无法覆盖(confined to home root),
|
|
3738
3495
|
// 不挂 self 分区并告警(其余分区不受影响)。
|
|
3739
3496
|
const selfRel = relative(homeDir, dataDir);
|
|
@@ -3836,35 +3593,22 @@ export function apply(ctx, config) {
|
|
|
3836
3593
|
// M1:与 HTTP 导出路由同一个 scanner(G-09 文件类分区凭据告警在两条路径上一致)。
|
|
3837
3594
|
scanner: secretScanner,
|
|
3838
3595
|
});
|
|
3839
|
-
// P1-B:backupScheduler
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
}
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
process.once('exit', releaseLockOnExit);
|
|
3856
|
-
ctx.effect(() => () => {
|
|
3857
|
-
process.removeListener('exit', releaseLockOnExit);
|
|
3858
|
-
releaseLockOnExit();
|
|
3859
|
-
}, 'config-manager: environment lock exit release');
|
|
3860
|
-
// m-profiles:实例心跳(自报 + 定期刷新);dispose 时撤回自己的心跳文件,别让别人把死实例当成活的。
|
|
3861
|
-
ctx.effect(() => {
|
|
3862
|
-
const stopHeartbeat = profileRuntime.startHeartbeat();
|
|
3863
|
-
return () => {
|
|
3864
|
-
stopHeartbeat();
|
|
3865
|
-
profileRuntime.withdraw();
|
|
3866
|
-
};
|
|
3867
|
-
}, 'config-manager: profile runtime heartbeat');
|
|
3596
|
+
// P1-B:backupScheduler 与 autosync scheduler 都不在构造期启动 —— 由启动分类结论驱动(仅 NORMAL)。
|
|
3597
|
+
// 启停顺序、卸载清理、退出兜底释放环境锁、实例心跳统一在 lifecycle-hooks 里装配(可单测)。
|
|
3598
|
+
const lifecycle = createHostLifecycle({
|
|
3599
|
+
scheduler,
|
|
3600
|
+
backupScheduler,
|
|
3601
|
+
releaseLockOnExit: createExitLockReleaser(envLockManager),
|
|
3602
|
+
profileRuntime,
|
|
3603
|
+
effect: (label, setup) => { ctx.effect(setup, label); },
|
|
3604
|
+
});
|
|
3605
|
+
lifecycle.mount();
|
|
3606
|
+
lifecycleRef.current = lifecycle;
|
|
3607
|
+
lifecycle.arm();
|
|
3608
|
+
// 分类结论若已先到(异步 barrier 抢在接线前跑完),补投一次;重复投递无副作用。
|
|
3609
|
+
const pendingVerdict = startupVerdictRef.value;
|
|
3610
|
+
if (pendingVerdict !== null)
|
|
3611
|
+
lifecycle.onStartupClassified(pendingVerdict);
|
|
3868
3612
|
// ------------------------------------------- S1:回合自动留点(宿主真接线)
|
|
3869
3613
|
//
|
|
3870
3614
|
// 订阅 `session/event`(@deepseek-ai/dsh-session 的 post-commit fire-and-forget feed)。
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DshProfileCopyWarning, type DshProfileDetail, type DshProfileErrorCode, type DshProfileIncompleteCopy, type DshProfileMeta } from './dsh-profile-shared.ts';
|
|
1
|
+
import { type DshProfileCopyMarker, type DshProfileCopyWarning, type DshProfileDetail, type DshProfileErrorCode, type DshProfileIncompleteCopy, type DshProfileMeta } from './dsh-profile-shared.ts';
|
|
2
2
|
/** DSH home 下的 profile 根目录名(与 dsh-app-boot 的 PROFILES_DIR 一致)。 */
|
|
3
3
|
export declare const PROFILES_DIR = "profiles";
|
|
4
4
|
/** profile 的用户 patch 层文件名(与 dsh-app-boot 的 PROFILE_PATCH_FILENAME 一致)。 */
|
|
@@ -25,6 +25,28 @@ export interface DshProfileIncompleteCopiesScan {
|
|
|
25
25
|
}
|
|
26
26
|
/** t89:profiles 根目录枚举失败的原因码(诊断/日志用)。 */
|
|
27
27
|
export declare const PROFILES_ROOT_UNREADABLE = "profiles-root-unreadable";
|
|
28
|
+
/**
|
|
29
|
+
* 复制失败时回滚目标目录(cross-F3 收尾 / tech-debt #5)。
|
|
30
|
+
*
|
|
31
|
+
* **顺序即不变量:先删内容,标记留到最后。** 标记(`.dcm-copy-in-progress.json`)是「这个目录是半截副本」
|
|
32
|
+
* 的唯一证据 —— `listIncompleteCopies()` 只认它,`requireManagedDir` 也只认它,没有 package.json
|
|
33
|
+
* 又没有标记的目录既不进列表、删除还报 notFound(孤儿)。
|
|
34
|
+
*
|
|
35
|
+
* 此前 catch 里是一把 `rm(recursive)` 加一句注释:rm 先删掉标记再失败(例如某个只读子目录让它中途放弃),
|
|
36
|
+
* 残留目录恰好落进那个「看不见也删不掉」的形态。这里两道保险:
|
|
37
|
+
* ① 逐条删顶层内容,标记不参与删除批次 —— 中途失败时标记必然还在;
|
|
38
|
+
* ② 收尾时若目录仍存在而标记没了(rm 部分生效 / 外部工具删过),**按原样重写标记**再放手。
|
|
39
|
+
*
|
|
40
|
+
* 因此只要返回,残留(若还在)**必然**能被 `listIncompleteCopies()` / `listIncompleteCopiesScan()`
|
|
41
|
+
* 扫到,并能经 `remove()`(UI 的 diskApi.profileDelete)删除。
|
|
42
|
+
*
|
|
43
|
+
* @param remove 删除实现(缺省递归强制删除),仅供测试注入「部分失败」的 fs。
|
|
44
|
+
*/
|
|
45
|
+
export declare function rollbackCopiedProfileDir(destDir: string, marker: DshProfileCopyMarker, remove?: (target: string) => Promise<void>): Promise<{
|
|
46
|
+
removed: boolean;
|
|
47
|
+
failedEntries: string[];
|
|
48
|
+
markerRestored: boolean;
|
|
49
|
+
}>;
|
|
28
50
|
/** 「档案」= DSH profile 的读写引擎(同步 fs;profile 数量级为个位数,无需异步)。 */
|
|
29
51
|
export declare class DshProfileManager {
|
|
30
52
|
private readonly homeDir;
|