dsh-config-manager 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- 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 +5 -5
- package/lib/client.js +26250 -25872
- package/lib/core/access-mode.d.ts +25 -0
- package/lib/core/access-mode.js +28 -0
- 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 +74 -330
- 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 +61 -1
- package/lib/routes/kit.js +72 -3
- package/lib/routes/prefs.js +6 -6
- package/lib/routes/recovery.js +25 -41
- package/lib/routes/request-trust.d.ts +28 -0
- package/lib/routes/request-trust.js +65 -0
- 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 +8 -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/access-mode.ts +21 -0
- 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/home/HomePanel.tsx +31 -6
- 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 +103 -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 +153 -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/access-mode.ts +37 -0
- 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 +81 -335
- 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 +106 -3
- package/src/routes/prefs.ts +6 -6
- package/src/routes/recovery.ts +25 -42
- package/src/routes/request-trust.ts +97 -0
- 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/src/index.ts
CHANGED
|
@@ -55,13 +55,25 @@ import { dshHomePath, resolveDshHome } from '@deepseek-ai/dsh-home-paths'
|
|
|
55
55
|
import type { WebRoute, WebServer } from '@deepseek-ai/dsh-host-webserver'
|
|
56
56
|
import type { WorkspaceId } from '@deepseek-ai/dsh-workspace'
|
|
57
57
|
|
|
58
|
-
import { endpoint, registerRoutes, requireJsonObject, writeJson, readJsonBody, errorMessage } from './routes/kit.ts'
|
|
58
|
+
import { endpoint, registerRoutes, requireJsonObject, writeJson, readJsonBody, errorMessage, writeMutationError } from './routes/kit.ts'
|
|
59
|
+
import { installHostRequestTrust } from './routes/request-trust.ts'
|
|
59
60
|
import { buildRoutes } from './routes/index.ts'
|
|
60
61
|
import type { RecoveryOrchestrator } from './core/recovery-orchestrator.ts'
|
|
61
62
|
import type { Portability } from './core/types.ts'
|
|
62
63
|
import { Exporter, FileSnapshotStore, Importer, verifySnapshot } from './core/index.ts'
|
|
63
64
|
import { DshProfileLauncher, DshProfileManager, DshProfileRuntimeRegistry } from './profiles/index.ts'
|
|
64
65
|
import { cleanupCaches } from './core/cache-cleaner.ts'
|
|
66
|
+
// tech-debt #23:宿主调度器下沉(纯调度语义可单测,index.ts 只留一次装配)。
|
|
67
|
+
import { createCacheCleanupScheduler } from './core/host-schedulers/cache-cleanup.ts'
|
|
68
|
+
import { createHostLifecycle } from './core/host-schedulers/lifecycle-hooks.ts'
|
|
69
|
+
import {
|
|
70
|
+
createMarketCacheLayout,
|
|
71
|
+
marketItemCached,
|
|
72
|
+
pruneStagedMarketZips as pruneMarketStagedZips,
|
|
73
|
+
readMarketCacheIndexText,
|
|
74
|
+
writeMarketItemCache,
|
|
75
|
+
} from './core/host-schedulers/market-cache.ts'
|
|
76
|
+
import type { HostLifecycle, StartupVerdict } from './core/host-schedulers/lifecycle-hooks.ts'
|
|
65
77
|
import { isValidSnapshotId, planRestore } from './core/restore.ts'
|
|
66
78
|
import { rollback as performRollback } from './core/rollback.ts'
|
|
67
79
|
// Phase 1 P0-1/P0-2:配置生命周期(自动快照 / 撤销 / 重做)与 P0-5 崩溃归因。
|
|
@@ -106,10 +118,10 @@ import { probeSessionFormats, resolveSessionFormatVersion } from './utils/sessio
|
|
|
106
118
|
import { describePatchYamlError, dumpPatchDocument, loadPatchDocument } from './utils/patch-yaml.ts'
|
|
107
119
|
import { atomicCopyFile, atomicWriteFile } from './utils/atomic-write.ts'
|
|
108
120
|
import { isENOENT } from './utils/guards.ts'
|
|
109
|
-
import { EnvironmentLockManager, runWithMutationLock,
|
|
121
|
+
import { EnvironmentLockManager, runWithMutationLock, type MutationLockContext } from './utils/env-lock.ts'
|
|
110
122
|
import { activeProxySummary } from './utils/proxy.ts'
|
|
111
123
|
import { listRecursiveFollowingLinks } from './utils/recursive-walk.ts'
|
|
112
|
-
import { Phase3Recovery,
|
|
124
|
+
import { Phase3Recovery, mapLockStateForStartup } from './core/phase3-host.ts'
|
|
113
125
|
import type { JournalRunContext } from './core/phase3-host.ts'
|
|
114
126
|
import { classifyStartup, FAIL_CLOSED_STARTUP, resolveStartupSafeMode } from './core/startup-barrier.ts'
|
|
115
127
|
import type { MutationLockPort } from './utils/env-lock.ts'
|
|
@@ -134,7 +146,7 @@ import { selectPruneCandidates } from './core/backup.ts'
|
|
|
134
146
|
import { appendAutosyncEntry } from './sync/sync-history.ts'
|
|
135
147
|
import { MigrationStore, type MigrationKind, type MigrationResult, historyResultFromAutosyncStatus, MIGRATION_HISTORY_DIR } from './core/migration-history.ts'
|
|
136
148
|
import { createHistoryPruner } from './core/history-prune.ts'
|
|
137
|
-
import {
|
|
149
|
+
import { isWebDavConfig, isS3Config, isGistConfig, channelOf, SYNC_CHANNELS, GIST_PROVIDER, cloudSecretRef } from './sync/sync-config.ts'
|
|
138
150
|
import {
|
|
139
151
|
resolveSessionFormatDisposition,
|
|
140
152
|
sessionFormatAbortResponse,
|
|
@@ -158,19 +170,19 @@ import { StarCache } from './market/star-cache.ts'
|
|
|
158
170
|
import { createConfiguredSecretScanner } from './security/secret-scanner.ts'
|
|
159
171
|
import type { ConfiguredSecretPatterns } from './security/secret-scanner.ts'
|
|
160
172
|
import type { SecretScanner } from './core/types.ts'
|
|
161
|
-
import { sha256Hex } from './utils/hashing.ts'
|
|
162
173
|
import { createTtlAsyncCache } from './utils/ttl-cache.ts'
|
|
163
174
|
import { isFileSection, SECTION_IDS } from './schema/config.ts'
|
|
164
175
|
import { stringifyJsonSafe } from './utils/json.ts'
|
|
165
176
|
import type { SectionId, WorkspaceRecord } from './schema/types.ts'
|
|
166
177
|
import { isSameOrChild } from './utils/paths.ts'
|
|
178
|
+
import { formatDateOnly } from './utils/time.ts'
|
|
167
179
|
import { isRecord } from './utils/guards.ts'
|
|
168
180
|
import { createLogger, parseLogLevel, type Logger } from './utils/logger.ts'
|
|
169
181
|
// 与 HTTP 路径**同一份**「运行中对话」判据(命令入口绝不能各写一套)
|
|
170
182
|
import { sessionActiveDenied, sessionActiveGateApplies } from './routes/recovery.ts'
|
|
171
183
|
|
|
172
184
|
// P4:路由组共享的纯工具已下沉到 routes/route-support.ts —— 组文件不再反向 import 本文件。
|
|
173
|
-
import { ROUTE_TIMEOUT_MS, SYNC_CREDENTIAL_REF, SYNC_WEBDAV_CREDENTIAL_REF,
|
|
185
|
+
import { ROUTE_TIMEOUT_MS, SYNC_CREDENTIAL_REF, SYNC_WEBDAV_CREDENTIAL_REF, credentialRef, decryptErrorText, executeRestorePlan, isControlledPath, makeRestoreExecutor, safeCredentialRef, syncPasswordRef, tryDecryptCredentials, withTimeout } from './routes/route-support.ts'
|
|
174
186
|
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.ts'
|
|
175
187
|
export type { AutosyncStatusResponse, BuildFileDiffBodyResult, BuildRestoreBodyResult, RestoreExecutor, SyncConfirmItem } from './routes/route-support.ts'
|
|
176
188
|
|
|
@@ -183,7 +195,7 @@ export const name = 'config-manager'
|
|
|
183
195
|
export const inject = ['settings', 'credentials']
|
|
184
196
|
|
|
185
197
|
/** Plugin version, kept in sync with package.json ("version"). */
|
|
186
|
-
export const PLUGIN_VERSION = '0.4.
|
|
198
|
+
export const PLUGIN_VERSION = '0.4.3'
|
|
187
199
|
|
|
188
200
|
/** Plugin own package name — excluded from its own exported plugins list. */
|
|
189
201
|
const PLUGIN_NAME = 'dsh-config-manager'
|
|
@@ -2136,13 +2148,6 @@ export class ConfigManagerHostContext implements HostContext {
|
|
|
2136
2148
|
/* ---------------------------------------------------------------- routes */
|
|
2137
2149
|
|
|
2138
2150
|
|
|
2139
|
-
function dateStamp(d: Date = new Date()): string {
|
|
2140
|
-
const y = d.getFullYear()
|
|
2141
|
-
const m = String(d.getMonth() + 1).padStart(2, '0')
|
|
2142
|
-
const day = String(d.getDate()).padStart(2, '0')
|
|
2143
|
-
return `${y}-${m}-${day}`
|
|
2144
|
-
}
|
|
2145
|
-
|
|
2146
2151
|
/** Minimal real dependency check (MCP §15): `which`/`where` probe. */
|
|
2147
2152
|
async function dependencyAvailable(command: string): Promise<boolean> {
|
|
2148
2153
|
const probe = process.platform === 'win32' ? 'where' : 'which'
|
|
@@ -2219,202 +2224,12 @@ interface RoutesDeps {
|
|
|
2219
2224
|
/* -------------------------------------------------- sync 路由(m-sync-ui) */
|
|
2220
2225
|
|
|
2221
2226
|
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
}
|
|
2226
|
-
|
|
2227
|
-
/**
|
|
2228
|
-
* 解析同步请求体,按 transport 分支返回归一化的 SyncConfig(可辨识联合,schemaVersion=2)。
|
|
2229
|
-
* 请求体形状(flat,M4 契约):
|
|
2230
|
-
* - git: { transport:'git', repoUrl, token? } —— token 非空写 SYNC_CREDENTIAL_REF;
|
|
2231
|
-
* git 可执行文件固定使用系统 PATH 中的 git(不再接受自定义 gitBin)。
|
|
2232
|
-
* - webdav: { transport:'webdav', url, username?, password? } —— password 非空写 SYNC_WEBDAV_CREDENTIAL_REF。
|
|
2233
|
-
* 返回值不含任何 secret(password/token 只进 credentials,永不回传/落同步文件)。
|
|
2234
|
-
*/
|
|
2235
|
-
export async function parseSyncBody(
|
|
2236
|
-
body: Record<string, unknown>,
|
|
2237
|
-
deps: ParseSyncBodyDeps,
|
|
2238
|
-
): Promise<SyncConfig> {
|
|
2239
|
-
const rawTransport = body['transport']
|
|
2240
|
-
// 通道值解析:接受通道名(s3/gist);也接受**具体兼容商**(oss/cos/minio/kodo)直接落到 s3 通道
|
|
2241
|
-
const transport = parseSyncChannel(rawTransport) ?? (isS3CompatProvider(rawTransport) ? 's3' : 'git')
|
|
2242
|
-
if (transport === 's3') return parseCloudS3Body(body, rawTransport, deps)
|
|
2243
|
-
if (transport === 'gist') return parseCloudGistBody(body, deps)
|
|
2244
|
-
if (transport === 'webdav') {
|
|
2245
|
-
const url = typeof body['url'] === 'string' ? body['url'].trim() : ''
|
|
2246
|
-
if (url === '') throw new SyncRouteError('url is required for webdav')
|
|
2247
|
-
const urlError = validateWebDavUrl(url)
|
|
2248
|
-
if (urlError !== null) throw new SyncRouteError(urlError)
|
|
2249
|
-
const username = typeof body['username'] === 'string' && body['username'] !== '' ? body['username'] : undefined
|
|
2250
|
-
const password = typeof body['password'] === 'string' && body['password'] !== '' ? body['password'] : undefined
|
|
2251
|
-
if (password !== undefined) {
|
|
2252
|
-
try {
|
|
2253
|
-
await deps.credentials.set(credentialRef(SYNC_WEBDAV_CREDENTIAL_REF), password)
|
|
2254
|
-
} catch (error) {
|
|
2255
|
-
const reason = error instanceof Error ? error.message : String(error)
|
|
2256
|
-
throw new SyncRouteError(
|
|
2257
|
-
engineMsg('host.syncWebdavPasswordWriteFailed', { reason, ref: SYNC_WEBDAV_CREDENTIAL_REF }),
|
|
2258
|
-
)
|
|
2259
|
-
}
|
|
2260
|
-
}
|
|
2261
|
-
return {
|
|
2262
|
-
schemaVersion: 2,
|
|
2263
|
-
transport: 'webdav',
|
|
2264
|
-
webdav: { url, ...(username !== undefined ? { username } : {}) },
|
|
2265
|
-
}
|
|
2266
|
-
}
|
|
2267
|
-
// git 通道(沿用现有逻辑)
|
|
2268
|
-
const repoUrl = typeof body['repoUrl'] === 'string' ? body['repoUrl'].trim() : ''
|
|
2269
|
-
if (repoUrl === '') throw new SyncRouteError('repoUrl is required')
|
|
2270
|
-
const urlError = validateRepoUrl(repoUrl)
|
|
2271
|
-
if (urlError !== null) throw new SyncRouteError(urlError)
|
|
2272
|
-
const token = typeof body['token'] === 'string' && body['token'] !== '' ? body['token'] : undefined
|
|
2273
|
-
if (token !== undefined) {
|
|
2274
|
-
try {
|
|
2275
|
-
await deps.credentials.set(credentialRef(SYNC_CREDENTIAL_REF), token)
|
|
2276
|
-
} catch (error) {
|
|
2277
|
-
const reason = error instanceof Error ? error.message : String(error)
|
|
2278
|
-
throw new SyncRouteError(
|
|
2279
|
-
engineMsg('host.syncTokenWriteFailed', { reason, ref: SYNC_CREDENTIAL_REF }),
|
|
2280
|
-
)
|
|
2281
|
-
}
|
|
2282
|
-
}
|
|
2283
|
-
return {
|
|
2284
|
-
schemaVersion: 2,
|
|
2285
|
-
transport: 'git',
|
|
2286
|
-
git: { repoUrl },
|
|
2287
|
-
}
|
|
2288
|
-
}
|
|
2289
|
-
|
|
2290
|
-
/** 请求体字段 → 去空白字符串(非字符串 = 空)。 */
|
|
2291
|
-
function syncStr(value: unknown): string {
|
|
2292
|
-
return typeof value === 'string' ? value.trim() : ''
|
|
2293
|
-
}
|
|
2294
|
-
|
|
2295
|
-
/** 云端点密钥写入失败 → 可操作错误(**含 ref 名、绝不含密钥值**)。 */
|
|
2296
|
-
function cloudCredentialWriteError(ref: string, kind: string, error: unknown): SyncRouteError {
|
|
2297
|
-
const reason = error instanceof Error ? error.message : String(error)
|
|
2298
|
-
return new SyncRouteError(
|
|
2299
|
-
engineMsg('host.syncCredentialWriteFailed', { kind, reason, ref }),
|
|
2300
|
-
400,
|
|
2301
|
-
'cloud.credentialsWriteFailed',
|
|
2302
|
-
)
|
|
2303
|
-
}
|
|
2227
|
+
// 请求体解析下沉到 routes/route-support.ts(tech-debt #23:组合根只留装配)。
|
|
2228
|
+
// 组合根继续导出这些符号,`src/index.sync.test.ts` 与既有调用方口径不变。
|
|
2229
|
+
import { mergePersistedWebDavUsername, parseSyncBody, webdavBaseUrl } from './routes/route-support.ts'
|
|
2304
2230
|
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
* 非密字段按 validateCloudChannelInput 校验(错误码 = HTTP body.code,由 UI 映射字典);
|
|
2308
|
-
* 密钥**只写**进 DSH credentials 的 cloudSecretRef(provider) 槽位,绝不进返回值 / 文件 / 日志。
|
|
2309
|
-
*/
|
|
2310
|
-
async function parseCloudS3Body(
|
|
2311
|
-
body: Record<string, unknown>,
|
|
2312
|
-
rawTransport: unknown,
|
|
2313
|
-
deps: ParseSyncBodyDeps,
|
|
2314
|
-
): Promise<SyncConfig> {
|
|
2315
|
-
const provider = isS3CompatProvider(body['provider'])
|
|
2316
|
-
? body['provider']
|
|
2317
|
-
: (isS3CompatProvider(rawTransport) ? rawTransport : null)
|
|
2318
|
-
if (provider === null) {
|
|
2319
|
-
throw new SyncRouteError('provider is required for s3 (s3/oss/cos/minio/kodo)', 400, 'cloud.providerUnknown')
|
|
2320
|
-
}
|
|
2321
|
-
const endpoint = syncStr(body['endpoint']).replace(/\/+$/, '')
|
|
2322
|
-
const region = syncStr(body['region'])
|
|
2323
|
-
const bucket = syncStr(body['bucket'])
|
|
2324
|
-
const accessKeyId = syncStr(body['accessKeyId'])
|
|
2325
|
-
const prefix = syncStr(body['prefix'])
|
|
2326
|
-
const pathStyle = typeof body['pathStyle'] === 'boolean' ? body['pathStyle'] : undefined
|
|
2327
|
-
const dialectId = body['dialectId'] === 'aws4' || body['dialectId'] === 'oss4' ? body['dialectId'] : undefined
|
|
2328
|
-
const issue = validateCloudChannelInput(provider, {
|
|
2329
|
-
endpoint,
|
|
2330
|
-
region,
|
|
2331
|
-
bucket,
|
|
2332
|
-
accessKeyId,
|
|
2333
|
-
...(prefix === '' ? {} : { prefix }),
|
|
2334
|
-
...(pathStyle === undefined ? {} : { pathStyle }),
|
|
2335
|
-
...(dialectId === undefined ? {} : { dialectId }),
|
|
2336
|
-
})
|
|
2337
|
-
if (issue !== null) throw new SyncRouteError(issue, 400, issue)
|
|
2338
|
-
const secret = typeof body['secret'] === 'string' && body['secret'] !== '' ? body['secret'] : undefined
|
|
2339
|
-
if (secret !== undefined) {
|
|
2340
|
-
const ref = cloudSecretRef(provider)
|
|
2341
|
-
try {
|
|
2342
|
-
await deps.credentials.set(credentialRef(ref), secret)
|
|
2343
|
-
} catch (error) {
|
|
2344
|
-
throw cloudCredentialWriteError(ref, engineMsg('host.syncKindS3Secret'), error)
|
|
2345
|
-
}
|
|
2346
|
-
}
|
|
2347
|
-
return {
|
|
2348
|
-
schemaVersion: 2,
|
|
2349
|
-
transport: 's3',
|
|
2350
|
-
s3: {
|
|
2351
|
-
provider,
|
|
2352
|
-
endpoint,
|
|
2353
|
-
region,
|
|
2354
|
-
bucket,
|
|
2355
|
-
accessKeyId,
|
|
2356
|
-
...(prefix === '' ? {} : { prefix }),
|
|
2357
|
-
...(pathStyle === undefined ? {} : { pathStyle }),
|
|
2358
|
-
...(dialectId === undefined ? {} : { dialectId }),
|
|
2359
|
-
},
|
|
2360
|
-
}
|
|
2361
|
-
}
|
|
2362
|
-
|
|
2363
|
-
/**
|
|
2364
|
-
* gist 通道请求体 → SyncConfig。token 只写进 cloudSecretRef('gist') 槽位
|
|
2365
|
-
* (请求体字段名 token 或 secret 都接受;值绝不进返回值 / 文件 / 日志)。
|
|
2366
|
-
*/
|
|
2367
|
-
async function parseCloudGistBody(body: Record<string, unknown>, deps: ParseSyncBodyDeps): Promise<SyncConfig> {
|
|
2368
|
-
const gistId = syncStr(body['gistId'])
|
|
2369
|
-
const apiBaseUrl = syncStr(body['apiBaseUrl'])
|
|
2370
|
-
const filePrefix = syncStr(body['filePrefix'])
|
|
2371
|
-
const issue = validateCloudChannelInput(GIST_PROVIDER, {
|
|
2372
|
-
gistId,
|
|
2373
|
-
...(apiBaseUrl === '' ? {} : { apiBaseUrl }),
|
|
2374
|
-
...(filePrefix === '' ? {} : { filePrefix }),
|
|
2375
|
-
})
|
|
2376
|
-
if (issue !== null) throw new SyncRouteError(issue, 400, issue)
|
|
2377
|
-
const token = typeof body['token'] === 'string' && body['token'] !== ''
|
|
2378
|
-
? body['token']
|
|
2379
|
-
: (typeof body['secret'] === 'string' && body['secret'] !== '' ? body['secret'] : undefined)
|
|
2380
|
-
if (token !== undefined) {
|
|
2381
|
-
const ref = cloudSecretRef(GIST_PROVIDER)
|
|
2382
|
-
try {
|
|
2383
|
-
await deps.credentials.set(credentialRef(ref), token)
|
|
2384
|
-
} catch (error) {
|
|
2385
|
-
throw cloudCredentialWriteError(ref, 'Gist token', error)
|
|
2386
|
-
}
|
|
2387
|
-
}
|
|
2388
|
-
return {
|
|
2389
|
-
schemaVersion: 2,
|
|
2390
|
-
transport: 'gist',
|
|
2391
|
-
gist: {
|
|
2392
|
-
gistId,
|
|
2393
|
-
...(apiBaseUrl === '' ? {} : { apiBaseUrl }),
|
|
2394
|
-
...(filePrefix === '' ? {} : { filePrefix }),
|
|
2395
|
-
},
|
|
2396
|
-
}
|
|
2397
|
-
}
|
|
2398
|
-
|
|
2399
|
-
/** 由 SyncConfig 合成 WebDAV 通道 baseUrl(webdav.url,尾部规范化带 '/';git 通道返回 '')。 */
|
|
2400
|
-
export function webdavBaseUrl(cfg: SyncConfig): string {
|
|
2401
|
-
if (!isWebDavConfig(cfg)) return ''
|
|
2402
|
-
return cfg.webdav.url.replace(/\/+$/, '') + '/'
|
|
2403
|
-
}
|
|
2404
|
-
|
|
2405
|
-
/**
|
|
2406
|
-
* 补全 webdav 配置缺失的 username(从持久化配置回填;纯函数,不修改入参)。
|
|
2407
|
-
* 语义与 password 一致:请求未带 username(表单留空/挂载自动加载)→ 沿用已保存的值;
|
|
2408
|
-
* 请求显式带 username → 原样保留(用户新输入优先)。非 webdav / 无持久化 → 原样返回。
|
|
2409
|
-
*/
|
|
2410
|
-
export function mergePersistedWebDavUsername(cfg: SyncConfig, persisted: SyncConfig | null): SyncConfig {
|
|
2411
|
-
if (!isWebDavConfig(cfg) || (cfg.webdav.username !== undefined && cfg.webdav.username !== '')) return cfg
|
|
2412
|
-
if (persisted !== null && isWebDavConfig(persisted)
|
|
2413
|
-
&& typeof persisted.webdav.username === 'string' && persisted.webdav.username !== '') {
|
|
2414
|
-
return { ...cfg, webdav: { ...cfg.webdav, username: persisted.webdav.username } }
|
|
2415
|
-
}
|
|
2416
|
-
return cfg
|
|
2417
|
-
}
|
|
2231
|
+
export { mergePersistedWebDavUsername, parseSyncBody, webdavBaseUrl } from './routes/route-support.ts'
|
|
2232
|
+
export type { ParseSyncBodyDeps } from './routes/route-support.ts'
|
|
2418
2233
|
|
|
2419
2234
|
/** /status 的插件诊断位(issue #28)。仅回非敏感元信息:目录、profile 名、计数。 */
|
|
2420
2235
|
export interface PluginDiagnostics {
|
|
@@ -2759,18 +2574,9 @@ function makeRoutes(deps: RoutesDeps): { routes: WebRoute[]; scheduler: AutoSync
|
|
|
2759
2574
|
}
|
|
2760
2575
|
})
|
|
2761
2576
|
} catch (error) {
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
host.log.warn(`mutation lock blocked: op=${error.op} reason=${error.reason}${error.detail !== undefined ? ` detail=${error.detail}` : ''}`)
|
|
2766
|
-
writeJson(res, 423, { error: error.message, code: 'mutation-locked' })
|
|
2767
|
-
return
|
|
2768
|
-
}
|
|
2769
|
-
// 非 423:若已由 runJournaled 置 SAFE MODE/失败,保持既有错误语义(400/500)
|
|
2770
|
-
if (error instanceof TransactionRecoveryRequiredError) {
|
|
2771
|
-
writeJson(res, 423, { error: error.message, code: 'transaction-recovery-required' })
|
|
2772
|
-
return
|
|
2773
|
-
}
|
|
2577
|
+
// 423 家族(SAFE MODE / 环境锁 / 未收敛事务)的唯一映射在 routes/kit.ts 的 writeMutationError;
|
|
2578
|
+
// 其余错误**必须 rethrow** —— endpoint() 的出口与救急台的 errorRenderer 都依赖这条抛出。
|
|
2579
|
+
if (writeMutationError(res, host, error)) return
|
|
2774
2580
|
throw error
|
|
2775
2581
|
}
|
|
2776
2582
|
}
|
|
@@ -3023,12 +2829,11 @@ function makeRoutes(deps: RoutesDeps): { routes: WebRoute[]; scheduler: AutoSync
|
|
|
3023
2829
|
// ------------------------------------------------ market 辅助(m-market)
|
|
3024
2830
|
// 目录:<marketDir>/cache/<url-hash>/(index/条目缓存)
|
|
3025
2831
|
// + <marketDir>/work/<url-hash>/(git 只读工作副本,--depth 1)。无任何凭据。
|
|
3026
|
-
|
|
3027
|
-
const
|
|
3028
|
-
const
|
|
3029
|
-
const
|
|
3030
|
-
const
|
|
3031
|
-
const marketWorkDir = (url: string) => join(marketWorkRoot, urlHash(url))
|
|
2832
|
+
// 布局与暂存 GC 的下沉实现见 core/host-schedulers/market-cache.ts(可单测)。
|
|
2833
|
+
const marketCache = createMarketCacheLayout(marketDir)
|
|
2834
|
+
const marketCacheIndex = marketCache.cacheIndex
|
|
2835
|
+
const marketCacheItemDir = marketCache.itemDir
|
|
2836
|
+
const marketWorkDir = marketCache.workDir
|
|
3032
2837
|
|
|
3033
2838
|
/**
|
|
3034
2839
|
* 进程生命周期标记:本次 dsh 启动后市场是否已成功刷新过一次(内存态,dsh 重启后自动归零)。
|
|
@@ -3056,13 +2861,10 @@ function makeRoutes(deps: RoutesDeps): { routes: WebRoute[]; scheduler: AutoSync
|
|
|
3056
2861
|
|
|
3057
2862
|
/** 读缓存的 index.json(结构校验通过才返回,否则 null)。 */
|
|
3058
2863
|
async function readCachedIndexObj(url: string): Promise<MarketIndex | null> {
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
} catch {
|
|
3064
|
-
return null
|
|
3065
|
-
}
|
|
2864
|
+
const raw = await readMarketCacheIndexText(marketCache, url)
|
|
2865
|
+
if (raw === null) return null
|
|
2866
|
+
const res = parseMarketIndex(raw)
|
|
2867
|
+
return res.ok ? res.index : null
|
|
3066
2868
|
}
|
|
3067
2869
|
|
|
3068
2870
|
/** 由配置条目构建市场摘要(name/itemCount/lastFetchedAt 来自缓存 index,可空)。 */
|
|
@@ -3081,50 +2883,17 @@ function makeRoutes(deps: RoutesDeps): { routes: WebRoute[]; scheduler: AutoSync
|
|
|
3081
2883
|
}
|
|
3082
2884
|
|
|
3083
2885
|
/** 条目是否已有完整缓存(manifest + config.zip)。 */
|
|
3084
|
-
|
|
3085
|
-
try {
|
|
3086
|
-
await fs.access(join(marketCacheItemDir(url), itemId, 'config.zip'))
|
|
3087
|
-
await fs.access(join(marketCacheItemDir(url), itemId, 'manifest.json'))
|
|
3088
|
-
return true
|
|
3089
|
-
} catch {
|
|
3090
|
-
return false
|
|
3091
|
-
}
|
|
3092
|
-
}
|
|
2886
|
+
const itemCached = (url: string, itemId: string): Promise<boolean> => marketItemCached(marketCache, url, itemId)
|
|
3093
2887
|
|
|
3094
2888
|
/** 写条目缓存(manifest + config.zip)供离线重复查看。内容始终视为不可信。 */
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
await fs.mkdir(dir, { recursive: true })
|
|
3098
|
-
await fs.writeFile(join(dir, 'manifest.json'), manifestRaw, 'utf8')
|
|
3099
|
-
await fs.writeFile(join(dir, 'config.zip'), zipBytes)
|
|
3100
|
-
}
|
|
2889
|
+
const writeItemCache = (url: string, itemId: string, manifestRaw: string, zipBytes: Uint8Array): Promise<void> =>
|
|
2890
|
+
writeMarketItemCache(marketCache, url, itemId, manifestRaw, zipBytes)
|
|
3101
2891
|
|
|
3102
2892
|
/**
|
|
3103
|
-
* 清理滞留在 tmpDir 的过期市场暂存 zip(market-*.zip)。
|
|
3104
|
-
* market/download 每次暂存新 zip 前调用(懒 GC
|
|
3105
|
-
* 后立即执行的 /execute 消费),清理更旧的 —— 防止未确认导入的暂存文件无限堆积。
|
|
3106
|
-
* 一次性尽力而为:任何读取/删除失败不影响主流程。
|
|
2893
|
+
* 清理滞留在 tmpDir 的过期市场暂存 zip(market-*.zip / publish-*.zip)。
|
|
2894
|
+
* market/download 每次暂存新 zip 前调用(懒 GC);保留期与尽力而为语义见 market-cache.ts。
|
|
3107
2895
|
*/
|
|
3108
|
-
const
|
|
3109
|
-
async function pruneStagedMarketZips(): Promise<void> {
|
|
3110
|
-
try {
|
|
3111
|
-
const names = await fs.readdir(tmpDir)
|
|
3112
|
-
const now = Date.now()
|
|
3113
|
-
for (const name of names) {
|
|
3114
|
-
// market-*.zip(未确认导入的暂存)与 publish-*.zip(发布向导产物)都纳入保留策略
|
|
3115
|
-
if ((!name.startsWith('market-') && !name.startsWith('publish-')) || !name.endsWith('.zip')) continue
|
|
3116
|
-
const p = join(tmpDir, name)
|
|
3117
|
-
try {
|
|
3118
|
-
const st = await fs.stat(p)
|
|
3119
|
-
if (now - st.mtimeMs > MARKET_TMP_RETENTION_MS) await fs.rm(p, { force: true, recursive: true })
|
|
3120
|
-
} catch {
|
|
3121
|
-
// 单文件 stat/删除失败 → 跳过(尽力而为)
|
|
3122
|
-
}
|
|
3123
|
-
}
|
|
3124
|
-
} catch {
|
|
3125
|
-
// tmpDir 读取失败 → 跳过(尽力而为)
|
|
3126
|
-
}
|
|
3127
|
-
}
|
|
2896
|
+
const pruneStagedMarketZips = async (): Promise<void> => { await pruneMarketStagedZips(tmpDir) }
|
|
3128
2897
|
|
|
3129
2898
|
// -------------------------------------------------- me 装配(m-my-configs)
|
|
3130
2899
|
// 「一键上传 / 我的配置」:GitHub REST 客户端 + 上传编排。
|
|
@@ -3427,7 +3196,7 @@ function makeRoutes(deps: RoutesDeps): { routes: WebRoute[]; scheduler: AutoSync
|
|
|
3427
3196
|
}
|
|
3428
3197
|
const desiredName = customFileName !== null
|
|
3429
3198
|
? customFileName
|
|
3430
|
-
: `dsh-config-${
|
|
3199
|
+
: `dsh-config-${formatDateOnly(new Date())}-${randomBytes(3).toString('hex')}.zip`
|
|
3431
3200
|
const finalFileName = resolveNonCollidingExportName(desiredName, existingExportNames)
|
|
3432
3201
|
const outPath = join(exportsDir, finalFileName)
|
|
3433
3202
|
// m1:执行开始注册 run(同 kind 已有进行中任务 → 409 拒绝,防止重复导出)
|
|
@@ -3928,11 +3697,11 @@ export function apply(ctx: Context, config?: Config): void {
|
|
|
3928
3697
|
host.log.warn('Phase 3 SAFE MODE 激活:存在未恢复的 transaction,destructive 操作被阻断(如需恢复请先显式处理)')
|
|
3929
3698
|
}
|
|
3930
3699
|
// P1-B:启动 recovery 分类 barrier。调度器(AutoSync/Backup)只在分类完成且 state=NORMAL 时启动。
|
|
3931
|
-
//
|
|
3932
|
-
//
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3700
|
+
// 启停 / 退出兜底释放锁 / 实例心跳的装配下沉到 core/host-schedulers/lifecycle-hooks.ts:
|
|
3701
|
+
// 这里只把分类结论投给它,arm 与 classify 谁先到都收敛到同一结果。
|
|
3702
|
+
// fail-closed:分类抛错 → 结论 BLOCKED(终态)→ 调度器不启动。
|
|
3703
|
+
const lifecycleRef: { current: HostLifecycle | null } = { current: null }
|
|
3704
|
+
const startupVerdictRef: { value: StartupVerdict | null } = { value: null }
|
|
3936
3705
|
void (async () => {
|
|
3937
3706
|
try {
|
|
3938
3707
|
await phase3Recovery.initFingerprint()
|
|
@@ -3953,7 +3722,6 @@ export function apply(ctx: Context, config?: Config): void {
|
|
|
3953
3722
|
lockState: mapLockStateForStartup(lockInsp.state),
|
|
3954
3723
|
})
|
|
3955
3724
|
const { state } = await startupState.classify()
|
|
3956
|
-
startupStateResolved = true
|
|
3957
3725
|
// 残留锁自愈(可证 stale 回收 + 孤儿心跳清理),判定与理由见 core/env-lock-lifecycle.ts。
|
|
3958
3726
|
const effectiveLockState = await reclaimStaleLockAtStartup({ kind: state.kind, inspected: lockInsp.state, lock: envLockManager, log: host.log })
|
|
3959
3727
|
// issue #87:分类结论才是本轮权威。NORMAL 且没有活锁者 ⇒ 上一轮留下的 durable SAFE MODE 是**陈旧标记**
|
|
@@ -3969,12 +3737,12 @@ export function apply(ctx: Context, config?: Config): void {
|
|
|
3969
3737
|
await phase3Recovery.clearSafeMode().catch(() => undefined)
|
|
3970
3738
|
host.log.info('Phase 3 启动分类 NORMAL:上一轮遗留的 SAFE MODE 标记已复位(无未决事务、无活锁者)')
|
|
3971
3739
|
}
|
|
3972
|
-
|
|
3740
|
+
const verdict: StartupVerdict = state.kind === 'NORMAL' ? 'NORMAL' : 'BLOCKED'
|
|
3741
|
+
startupVerdictRef.value = verdict
|
|
3973
3742
|
if (state.kind === 'RECOVERY_REQUIRED' || state.kind === 'NEEDS_ATTENTION') {
|
|
3974
3743
|
host.log.warn(`Phase 3 ${state.kind}:上次 destructive operation 崩溃残留,需显式恢复;destructive 调度器未启动(read-only host 存活)`)
|
|
3975
|
-
} else if (shouldStartSchedulers && schedulerGate.start !== null) {
|
|
3976
|
-
schedulerGate.start()
|
|
3977
3744
|
}
|
|
3745
|
+
lifecycleRef.current?.onStartupClassified(verdict)
|
|
3978
3746
|
// Phase 1 P0-5:启动分类已得出结论 → 本次启动判定为成功(推进 lastGoodAt)。
|
|
3979
3747
|
// 灾备总开关关闭时不写 boot-state。
|
|
3980
3748
|
try {
|
|
@@ -3987,8 +3755,8 @@ export function apply(ctx: Context, config?: Config): void {
|
|
|
3987
3755
|
// fail-open —— 此刻无法证明环境干净,destructive 路由必须一并被阻断:置内存 SAFE MODE
|
|
3988
3756
|
// (isBlocked 谓词立即生效)+ 写 durable 标记(下次启动不判 NORMAL),与 phase3-host.ts
|
|
3989
3757
|
// runJournaled 异常分支的姿态一致。清理通道仍是用户显式 recovery(clearSafeMode)。
|
|
3990
|
-
|
|
3991
|
-
|
|
3758
|
+
// 分类抛错时保留 null:接线期若仍无结论,lifecycle 不会启动调度器(fail-closed 的第一道)。
|
|
3759
|
+
startupVerdictRef.value = FAIL_CLOSED_STARTUP.startSchedulers ? 'NORMAL' : 'BLOCKED'
|
|
3992
3760
|
if (FAIL_CLOSED_STARTUP.safeModeRequired) {
|
|
3993
3761
|
phase3Recovery.safeModeActive = true
|
|
3994
3762
|
await phase3Recovery.store.writeSafeMode(true).catch(() => undefined)
|
|
@@ -4002,12 +3770,11 @@ export function apply(ctx: Context, config?: Config): void {
|
|
|
4002
3770
|
})
|
|
4003
3771
|
}
|
|
4004
3772
|
})()
|
|
4005
|
-
// 缓存自动清理:启动即清一次 + 每 24h
|
|
3773
|
+
// 缓存自动清理:启动即清一次 + 每 24h 定时清一次(调度语义见 core/host-schedulers/cache-cleanup.ts)。
|
|
4006
3774
|
// 只清「可重建/一次性」缓存与临时文件(tmp 暂存、exports 导出副本、market cache/work),
|
|
4007
3775
|
// 保留期内的文件不删(供刷新恢复导入/下载等窗口继续消费);snapshots 与 sync 属用户数据/安全网不动。
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
void cleanupCaches({
|
|
3776
|
+
const cacheCleanup = createCacheCleanupScheduler({
|
|
3777
|
+
cleanup: () => cleanupCaches({
|
|
4011
3778
|
tmpDir,
|
|
4012
3779
|
exportsDir,
|
|
4013
3780
|
// 定时备份产物(dsh-config-auto-*)豁免按天回收:保留策略归 BackupScheduler
|
|
@@ -4015,20 +3782,12 @@ export function apply(ctx: Context, config?: Config): void {
|
|
|
4015
3782
|
exportsExemptPrefix: AUTO_BACKUP_PREFIX,
|
|
4016
3783
|
marketCacheRoot: join(marketDir, 'cache'),
|
|
4017
3784
|
marketWorkRoot: join(marketDir, 'work'),
|
|
4018
|
-
})
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
.catch((error) => {
|
|
4025
|
-
host.log.warn('缓存自动清理失败', { error: error instanceof Error ? error.message : String(error) })
|
|
4026
|
-
})
|
|
4027
|
-
}
|
|
4028
|
-
runCacheCleanup()
|
|
4029
|
-
const cacheCleanupTimer = setInterval(runCacheCleanup, CACHE_CLEANUP_INTERVAL_MS)
|
|
4030
|
-
ctx.effect(() => () => clearInterval(cacheCleanupTimer), 'config-manager: cache cleanup scheduler')
|
|
4031
|
-
// self 分区目录(相对 ~/.dsh 根):dataDir 在 homeDir 下 → 用相对路径挂载 self adapter;
|
|
3785
|
+
}),
|
|
3786
|
+
intervalMs: CACHE_CLEANUP_INTERVAL_MS,
|
|
3787
|
+
log: host.log,
|
|
3788
|
+
})
|
|
3789
|
+
cacheCleanup.start()
|
|
3790
|
+
ctx.effect(() => () => cacheCleanup.dispose(), 'config-manager: cache cleanup scheduler')
|
|
4032
3791
|
// 自定义 dataDir 位于 ~/.dsh 之外时 Host fs 门面无法覆盖(confined to home root),
|
|
4033
3792
|
// 不挂 self 分区并告警(其余分区不受影响)。
|
|
4034
3793
|
const selfRel = relative(homeDir, dataDir)
|
|
@@ -4133,33 +3892,21 @@ export function apply(ctx: Context, config?: Config): void {
|
|
|
4133
3892
|
// M1:与 HTTP 导出路由同一个 scanner(G-09 文件类分区凭据告警在两条路径上一致)。
|
|
4134
3893
|
scanner: secretScanner,
|
|
4135
3894
|
})
|
|
4136
|
-
// P1-B:backupScheduler
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
//
|
|
4149
|
-
const
|
|
4150
|
-
|
|
4151
|
-
ctx.effect(() => () => {
|
|
4152
|
-
process.removeListener('exit', releaseLockOnExit)
|
|
4153
|
-
releaseLockOnExit()
|
|
4154
|
-
}, 'config-manager: environment lock exit release')
|
|
4155
|
-
// m-profiles:实例心跳(自报 + 定期刷新);dispose 时撤回自己的心跳文件,别让别人把死实例当成活的。
|
|
4156
|
-
ctx.effect(() => {
|
|
4157
|
-
const stopHeartbeat = profileRuntime.startHeartbeat()
|
|
4158
|
-
return () => {
|
|
4159
|
-
stopHeartbeat()
|
|
4160
|
-
profileRuntime.withdraw()
|
|
4161
|
-
}
|
|
4162
|
-
}, 'config-manager: profile runtime heartbeat')
|
|
3895
|
+
// P1-B:backupScheduler 与 autosync scheduler 都不在构造期启动 —— 由启动分类结论驱动(仅 NORMAL)。
|
|
3896
|
+
// 启停顺序、卸载清理、退出兜底释放环境锁、实例心跳统一在 lifecycle-hooks 里装配(可单测)。
|
|
3897
|
+
const lifecycle = createHostLifecycle({
|
|
3898
|
+
scheduler,
|
|
3899
|
+
backupScheduler,
|
|
3900
|
+
releaseLockOnExit: createExitLockReleaser(envLockManager),
|
|
3901
|
+
profileRuntime,
|
|
3902
|
+
effect: (label, setup) => { ctx.effect(setup, label) },
|
|
3903
|
+
})
|
|
3904
|
+
lifecycle.mount()
|
|
3905
|
+
lifecycleRef.current = lifecycle
|
|
3906
|
+
lifecycle.arm()
|
|
3907
|
+
// 分类结论若已先到(异步 barrier 抢在接线前跑完),补投一次;重复投递无副作用。
|
|
3908
|
+
const pendingVerdict = startupVerdictRef.value
|
|
3909
|
+
if (pendingVerdict !== null) lifecycle.onStartupClassified(pendingVerdict)
|
|
4163
3910
|
// ------------------------------------------- S1:回合自动留点(宿主真接线)
|
|
4164
3911
|
//
|
|
4165
3912
|
// 订阅 `session/event`(@deepseek-ai/dsh-session 的 post-commit fire-and-forget feed)。
|
|
@@ -4373,13 +4120,12 @@ export function apply(ctx: Context, config?: Config): void {
|
|
|
4373
4120
|
}
|
|
4374
4121
|
// 端口就绪 → 重新自报一次心跳(其它实例的「运行中」徽章与端口信息靠它;token 永不落盘)。
|
|
4375
4122
|
webPort.value = webServer.port
|
|
4376
|
-
// F-2:宿主自请求走这个端口(探测/代理 DSH 自己的 /api/session.export
|
|
4377
|
-
//
|
|
4378
|
-
//
|
|
4379
|
-
// routeEnv 的 sessionExportPort 是**活 getter**(读 host.webPort),因此这里赋值对已构造好的
|
|
4380
|
-
// 路由表同样生效 —— 不需要重建路由。
|
|
4123
|
+
// F-2:宿主自请求走这个端口(探测/代理 DSH 自己的 /api/session.export);routeEnv 的
|
|
4124
|
+
// sessionExportPort 是**活 getter**(读 host.webPort),所以这里赋值对已构造好的路由表同样生效、
|
|
4125
|
+
// 无需重建;但必须早于注册(否则首次探测拿到 undefined 会如实降级)。端口变化只有重启才会发生。
|
|
4381
4126
|
host.webPort = webServer.port
|
|
4382
4127
|
profileRuntime.announce()
|
|
4128
|
+
installHostRequestTrust(ctx, host.log)
|
|
4383
4129
|
ctx.effect(() => {
|
|
4384
4130
|
const disposers = registerRoutes(webServer, routes)
|
|
4385
4131
|
return () => {
|