dsh-config-manager 0.4.3 → 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.
- package/README.md +10 -0
- package/README.zh-CN.md +10 -0
- package/lib/adapters/mcp.d.ts +9 -0
- package/lib/adapters/mcp.js +37 -0
- package/lib/adapters/plugins.js +10 -2
- package/lib/adapters/pnpm-workspace.js +1 -1
- package/lib/adapters/self.d.ts +2 -0
- package/lib/adapters/self.js +18 -2
- package/lib/adapters/workspaces.js +1 -1
- package/lib/cli/restore-resume.js +1 -1
- package/lib/cli/web/page.js +2 -2
- package/lib/client.d.ts +17 -41
- package/lib/client.js +946 -761
- package/lib/core/backup.d.ts +11 -0
- package/lib/core/backup.js +27 -0
- package/lib/core/env-lock-lifecycle.d.ts +17 -3
- package/lib/core/env-lock-lifecycle.js +38 -0
- package/lib/core/external-failure.d.ts +9 -0
- package/lib/core/external-failure.js +50 -0
- package/lib/core/local-plugin-host.d.ts +9 -7
- package/lib/core/local-plugin-host.js +109 -15
- package/lib/core/local-plugin-pack.d.ts +20 -0
- package/lib/core/local-plugin-pack.js +18 -3
- package/lib/core/mcp-connector-store.d.ts +13 -0
- package/lib/core/mcp-connector-store.js +16 -1
- package/lib/core/messages-core.d.ts +45 -0
- package/lib/core/messages-core.js +92 -0
- package/lib/core/messages.d.ts +5 -0
- package/lib/core/messages.js +14 -0
- package/lib/core/migration-history.d.ts +40 -0
- package/lib/core/migration-history.js +55 -0
- package/lib/core/model-tool-plans.d.ts +66 -0
- package/lib/core/model-tool-plans.js +128 -0
- package/lib/core/model-tools.d.ts +96 -8
- package/lib/core/model-tools.js +568 -31
- package/lib/core/phase3-host.js +10 -2
- package/lib/core/plugin-cli.d.ts +5 -0
- package/lib/core/plugin-cli.js +11 -3
- package/lib/core/plugin-data-registry.d.ts +1 -1
- package/lib/core/plugin-data-registry.js +1 -1
- package/lib/core/restore-plan-fingerprint.d.ts +2 -0
- package/lib/core/restore-plan-fingerprint.js +18 -0
- package/lib/core/restore-resume.d.ts +1 -1
- package/lib/core/restore-resume.js +1 -1
- package/lib/core/restore.d.ts +5 -0
- package/lib/core/restore.js +4 -1
- package/lib/core/types.d.ts +12 -0
- package/lib/foreign/claude-sessions.d.ts +1 -1
- package/lib/foreign/claude-sessions.js +1 -1
- package/lib/foreign/registry.js +1 -1
- package/lib/foreign/types.d.ts +1 -1
- package/lib/index.d.ts +19 -15
- package/lib/index.js +72 -80
- package/lib/market/git-file-writer.js +1 -1
- package/lib/market/github-repos.js +1 -1
- package/lib/market/market-config.js +1 -1
- package/lib/market/messages-market.js +1 -1
- package/lib/market/my-repo.js +1 -1
- package/lib/market/prepare.js +1 -1
- package/lib/market/reader.js +2 -2
- package/lib/market/repo-url.d.ts +1 -1
- package/lib/market/security.js +2 -2
- package/lib/market/star-cache.d.ts +1 -1
- package/lib/market/types.d.ts +1 -1
- package/lib/market/types.js +1 -1
- package/lib/market/url.js +1 -1
- package/lib/profiles/dsh-profile-manager.d.ts +1 -1
- package/lib/profiles/dsh-profile-manager.js +26 -7
- package/lib/profiles/dsh-profile-shared.d.ts +3 -1
- package/lib/routes/backup.js +17 -9
- package/lib/routes/index.d.ts +1 -1
- package/lib/routes/kit.d.ts +2 -2
- package/lib/routes/market.d.ts +1 -1
- package/lib/routes/market.js +3 -60
- package/lib/routes/model-tools-deps.d.ts +41 -0
- package/lib/routes/model-tools-deps.js +18 -0
- package/lib/routes/recovery.js +5 -3
- package/lib/routes/route-support.d.ts +18 -26
- package/lib/routes/route-support.js +19 -32
- package/lib/routes/snapshots.d.ts +1 -1
- package/lib/routes/snapshots.js +4 -40
- package/lib/routes/sync.js +40 -28
- package/lib/schema/index.d.ts +2 -2
- package/lib/schema/index.js +2 -2
- package/lib/schema/section-registry.d.ts +5 -3
- package/lib/schema/section-registry.js +7 -3
- package/lib/security/secret-scanner.js +1 -1
- package/lib/sync/apply-bundle.d.ts +50 -0
- package/lib/sync/apply-bundle.js +60 -0
- package/lib/sync/autosync-scheduler.d.ts +9 -0
- package/lib/sync/autosync-scheduler.js +118 -89
- package/lib/sync/backup-scheduler.js +5 -4
- package/lib/sync/blob-store.d.ts +2 -2
- package/lib/sync/git/git-transport.d.ts +12 -0
- package/lib/sync/git/git-transport.js +50 -2
- package/lib/sync/merge.d.ts +2 -0
- package/lib/sync/merge.js +28 -0
- package/lib/sync/messages.d.ts +4 -0
- package/lib/sync/messages.js +9 -2
- package/lib/sync/s3/s3-transport.d.ts +1 -1
- package/lib/sync/s3/s3-transport.js +1 -1
- package/lib/sync/sync-engine.d.ts +4 -4
- package/lib/sync/sync-engine.js +25 -26
- package/lib/sync/sync-scope-boot.d.ts +34 -0
- package/lib/sync/sync-scope-boot.js +71 -0
- package/lib/sync/sync-scope.d.ts +103 -0
- package/lib/sync/sync-scope.js +229 -0
- package/lib/sync/sync-selection.d.ts +17 -4
- package/lib/sync/sync-selection.js +40 -14
- package/lib/sync/transport.d.ts +4 -1
- package/lib/sync/transport.js +6 -0
- package/lib/sync/webdav/webdav-transport.js +1 -1
- package/lib/sync/workspace-merge.d.ts +36 -0
- package/lib/sync/workspace-merge.js +152 -0
- package/lib/ui/backup-schedule.d.ts +13 -2
- package/lib/ui/backup-schedule.js +3 -0
- package/lib/ui/snapshots-view.d.ts +16 -0
- package/lib/ui/snapshots-view.js +21 -0
- package/lib/ui/sync-repository-picker.d.ts +21 -0
- package/lib/ui/sync-repository-picker.js +18 -0
- package/lib/utils/env-lock.d.ts +96 -0
- package/lib/utils/env-lock.js +332 -111
- package/lib/utils/messages-utils.d.ts +6 -0
- package/lib/utils/messages-utils.js +17 -1
- package/lib/utils/patch-yaml.js +1 -1
- package/lib/utils/remove-tree.d.ts +7 -0
- package/lib/utils/remove-tree.js +265 -0
- package/lib/utils/zip.js +1 -1
- package/package.json +3 -2
- package/src/adapters/mcp.test.ts +28 -0
- package/src/adapters/mcp.ts +33 -0
- package/src/adapters/plugins.test.ts +49 -0
- package/src/adapters/plugins.ts +9 -1
- package/src/adapters/pnpm-workspace.ts +1 -1
- package/src/adapters/self.test.ts +39 -1
- package/src/adapters/self.ts +20 -2
- package/src/adapters/workspaces.ts +1 -1
- package/src/cli/restore-resume.ts +1 -1
- package/src/cli/web/page.ts +2 -2
- package/src/client/about/AboutPanel.tsx +1 -1
- package/src/client/about/about-view.test.ts +1 -1
- package/src/client/about/about-view.ts +1 -1
- package/src/client/api.ts +1 -6
- package/src/client/chat/chat-entry-view.test.ts +1 -1
- package/src/client/chat/chat-slots.ts +1 -1
- package/src/client/chat/rollback-diff-tab.ts +1 -1
- package/src/client/client-types.ts +1 -1
- package/src/client/common/routes.ts +1 -5
- package/src/client/config-manager.module.css +21 -1
- package/src/client/css-scale-guard.test.ts +1 -1
- package/src/client/environment/EnvironmentPanel.tsx +2 -2
- package/src/client/home/HomePanel.tsx +3 -0
- package/src/client/library/ArtifactRow.tsx +14 -2
- package/src/client/library/LibraryPanel.tsx +44 -0
- package/src/client/locales/overview.ts +10 -2
- package/src/client/locales/profiles.ts +2 -0
- package/src/client/locales/sessions.ts +3 -0
- package/src/client/market/MyConfigsView.tsx +1 -1
- package/src/client/market/market-api.ts +2 -14
- package/src/client/market/market-locales.ts +1 -1
- package/src/client/market/market-view.ts +3 -3
- package/src/client/market/my-configs-api.ts +1 -1
- package/src/client/market/my-configs-view.ts +1 -1
- package/src/client/recovery/recovery-locales.test.ts +1 -1
- package/src/client/run-store.ts +1 -1
- package/src/client/sync/ChannelConfigDialog.tsx +32 -1
- package/src/client/sync/SyncPanel.tsx +11 -30
- package/src/client/sync/SyncRepositoryPicker.tsx +34 -13
- package/src/client/sync/SyncSectionPickerDialog.tsx +0 -5
- package/src/client/sync/SyncSettingsView.test.ts +32 -0
- package/src/client/sync/config-save-state.test.ts +99 -0
- package/src/client/sync/config-save-state.ts +69 -0
- package/src/client/sync/history-model.test.ts +28 -7
- package/src/client/sync/history-model.ts +6 -3
- package/src/client/sync/sync-locales.ts +14 -4
- package/src/client/sync/sync-view.ts +1 -1
- package/src/core/analyzer-cache.test.ts +1 -1
- package/src/core/backup.test.ts +45 -1
- package/src/core/backup.ts +25 -0
- package/src/core/disk-usage.test.ts +2 -0
- package/src/core/engine-locale.test.ts +4 -0
- package/src/core/env-lock-lifecycle.ts +33 -3
- package/src/core/external-failure.test.ts +60 -0
- package/src/core/external-failure.ts +54 -0
- package/src/core/integrity-extra-entries.test.ts +1 -1
- package/src/core/local-plugin-host.test.ts +134 -0
- package/src/core/local-plugin-host.ts +122 -17
- package/src/core/local-plugin-pack.ts +39 -3
- package/src/core/mcp-connector-store.ts +26 -1
- package/src/core/messages-core.ts +94 -0
- package/src/core/messages.ts +14 -0
- package/src/core/migration-history.test.ts +65 -0
- package/src/core/migration-history.ts +70 -0
- package/src/core/model-tool-plans.test.ts +111 -0
- package/src/core/model-tool-plans.ts +170 -0
- package/src/core/model-tools.test.ts +212 -12
- package/src/core/model-tools.ts +710 -38
- package/src/core/phase3-host.ts +10 -2
- package/src/core/phase3-production-integration.test.ts +43 -0
- package/src/core/plugin-cli.fs.test.ts +30 -3
- package/src/core/plugin-cli.ts +11 -3
- package/src/core/plugin-data-registry.ts +1 -1
- package/src/core/restore-plan-fingerprint.ts +19 -0
- package/src/core/restore-resume.ts +1 -1
- package/src/core/restore.ts +9 -1
- package/src/core/types.ts +12 -0
- package/src/foreign/claude-sessions.ts +3 -3
- package/src/foreign/registry.ts +1 -1
- package/src/foreign/types.ts +1 -1
- package/src/index.ts +102 -111
- package/src/market/git-file-writer.ts +1 -1
- package/src/market/github-repos.test.ts +1 -1
- package/src/market/github-repos.ts +1 -1
- package/src/market/market-config.ts +1 -1
- package/src/market/messages-market.ts +1 -1
- package/src/market/my-repo.test.ts +1 -1
- package/src/market/my-repo.ts +1 -1
- package/src/market/prepare.test.ts +1 -1
- package/src/market/prepare.ts +1 -1
- package/src/market/reader.ts +2 -2
- package/src/market/repo-url.ts +1 -1
- package/src/market/security.ts +2 -2
- package/src/market/star-cache.ts +1 -1
- package/src/market/types.ts +1 -1
- package/src/market/url.test.ts +1 -1
- package/src/market/url.ts +1 -1
- package/src/profiles/dsh-profile-copy-rollback.test.ts +1 -1
- package/src/profiles/dsh-profile-manager.test.ts +20 -0
- package/src/profiles/dsh-profile-manager.ts +25 -7
- package/src/profiles/dsh-profile-shared.ts +2 -0
- package/src/routes/backup.ts +16 -9
- package/src/routes/index.ts +1 -1
- package/src/routes/kit.ts +2 -2
- package/src/routes/market.ts +2 -59
- package/src/routes/model-tools-deps.ts +56 -0
- package/src/routes/recovery.ts +5 -3
- package/src/routes/route-support.ts +49 -36
- package/src/routes/snapshots.ts +4 -40
- package/src/routes/sync.ts +39 -27
- package/src/schema/index.ts +2 -2
- package/src/schema/manifest-schema.test.ts +2 -2
- package/src/schema/registry.test.ts +1 -1
- package/src/schema/section-registry.ts +9 -4
- package/src/security/redaction.test.ts +1 -1
- package/src/security/secret-scanner.test.ts +2 -2
- package/src/security/secret-scanner.ts +1 -1
- package/src/sync/apply-bundle.ts +104 -0
- package/src/sync/autosync-scheduler.test.ts +180 -6
- package/src/sync/autosync-scheduler.ts +132 -92
- package/src/sync/backup-scheduler.test.ts +11 -4
- package/src/sync/backup-scheduler.ts +5 -4
- package/src/sync/blob-store.ts +2 -2
- package/src/sync/git/git-transport.test.ts +62 -0
- package/src/sync/git/git-transport.ts +54 -3
- package/src/sync/merge.ts +29 -0
- package/src/sync/messages.ts +9 -2
- package/src/sync/s3/s3-transport.ts +1 -1
- package/src/sync/sync-engine.test.ts +238 -2
- package/src/sync/sync-engine.ts +25 -26
- package/src/sync/sync-preview-push.test.ts +2 -1
- package/src/sync/sync-scope-boot.ts +87 -0
- package/src/sync/sync-scope.test.ts +154 -0
- package/src/sync/sync-scope.ts +256 -0
- package/src/sync/sync-selection.test.ts +76 -2
- package/src/sync/sync-selection.ts +40 -13
- package/src/sync/transport.test.ts +21 -1
- package/src/sync/transport.ts +12 -0
- package/src/sync/webdav/webdav-delete-index-unreadable.test.ts +2 -2
- package/src/sync/webdav/webdav-transport.ts +1 -1
- package/src/sync/workspace-merge.test.ts +110 -0
- package/src/sync/workspace-merge.ts +180 -0
- package/src/ui/backup-schedule.test.ts +5 -0
- package/src/ui/backup-schedule.ts +21 -2
- package/src/ui/session-issue-labels.ts +1 -1
- package/src/ui/snapshots-view.test.ts +32 -0
- package/src/ui/snapshots-view.ts +34 -0
- package/src/ui/sync-repository-picker.test.ts +34 -1
- package/src/ui/sync-repository-picker.ts +24 -0
- package/src/utils/env-lock.test.ts +242 -9
- package/src/utils/env-lock.ts +247 -13
- package/src/utils/messages-utils.ts +17 -1
- package/src/utils/patch-yaml.ts +1 -1
- package/src/utils/remove-tree.test.ts +120 -0
- package/src/utils/remove-tree.ts +239 -0
- package/src/utils/zip.ts +1 -1
- package/src/client/CLIENT_DEPENDENCIES.md +0 -94
package/src/routes/snapshots.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 路由组:快照与恢复(快照列表 / 恢复 / 删除 /
|
|
2
|
+
* 路由组:快照与恢复(快照列表 / 恢复 / 删除 / 逐文件差异)。
|
|
3
3
|
*
|
|
4
4
|
* W1(host-entry#F-02/#F-03):路由只在这里声明一次 —— endpoint({ path, methods }, handler) 的
|
|
5
5
|
* path/methods 就是唯一声明处;围栏、方法判定与顶层异常处理由 src/routes/kit.ts 在注册点统一提供。
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
import { endpoint, readJsonBody, writeJson, writeMutationError } from './kit.ts'
|
|
9
9
|
import type { WebRoute } from './kit.ts'
|
|
10
10
|
import type { RoutesEnv } from './context.ts'
|
|
11
|
-
import { deleteSnapshot, isValidSnapshotId, listSnapshots, planRestore
|
|
11
|
+
import { deleteSnapshot, isValidSnapshotId, listSnapshots, planRestore } from '../core/restore.ts'
|
|
12
|
+
// 预览-执行一致性指纹:与 agent 工具(config_restore)共用同一实现,口径分叉会让防呆失效。
|
|
13
|
+
import { restorePlanFingerprint } from '../core/restore-plan-fingerprint.ts'
|
|
12
14
|
import type { RunState } from '../core/run-registry.ts'
|
|
13
15
|
import { snapshotFileDiff, summarizeRestoreChanges } from '../core/snapshot-diff.ts'
|
|
14
16
|
import { buildFileDiffBody, buildRestoreBody, executeRestorePlan, makeRestoreExecutor } from './route-support.ts'
|
|
@@ -16,19 +18,7 @@ import type { RestoreJournalPort } from '../core/restore-wal.ts'
|
|
|
16
18
|
import { probeRestoreResume, runRestoreWithResume } from '../core/restore-resume.ts'
|
|
17
19
|
import type { RestoreResumeHint } from '../core/restore-resume.ts'
|
|
18
20
|
import { runWithMutationLock } from '../utils/env-lock.ts'
|
|
19
|
-
import { isENOENT } from '../utils/guards.ts'
|
|
20
21
|
import { join } from 'node:path'
|
|
21
|
-
import { createHash } from 'node:crypto'
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 恢复计划指纹(预览-执行一致性):只取「动作类型 + 目标 + blob」三列 —— 描述文案、详情、顺序无关的
|
|
25
|
-
* 易变字段一律不进,保证同一份快照 + 同一磁盘状态下指纹稳定。内容变化不会改变指纹(同 kind/target),
|
|
26
|
-
* 只有**动作集合真的变了**(文件出现/消失、插件增删)才会不同 —— 那正是需要用户重新确认的情况。
|
|
27
|
-
*/
|
|
28
|
-
function restorePlanFingerprint(plan: Awaited<ReturnType<typeof planRestore>>): string {
|
|
29
|
-
const lines = plan.actions.map((action) => [action.kind, action.target ?? '', action.blobPath ?? ''].join('\u0000'))
|
|
30
|
-
return createHash('sha256').update(lines.join('\n')).digest('hex')
|
|
31
|
-
}
|
|
32
22
|
|
|
33
23
|
export function snapshotRoutes(env: RoutesEnv): WebRoute[] {
|
|
34
24
|
const {
|
|
@@ -255,32 +245,6 @@ export function snapshotRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
255
245
|
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) })
|
|
256
246
|
}
|
|
257
247
|
})),
|
|
258
|
-
// --------------------------------------------- snapshots/pin(P1-⑧)
|
|
259
|
-
// 置顶/取消置顶快照:置顶快照豁免「最多保留 N 个」的自动清理(只能手动删除)。
|
|
260
|
-
// 纯元数据写(重写 snapshot.json 的 pinned 字段);loopback fence 必备。
|
|
261
|
-
endpoint({ path: '/api/dsh-config-manager/snapshots/pin', methods: ['POST'] }, withMutationGate('snapshot-pin', async (req, res) => {
|
|
262
|
-
try {
|
|
263
|
-
const body = await readJsonBody(req)
|
|
264
|
-
const id = typeof body === 'object' && body !== null
|
|
265
|
-
? (body as Record<string, unknown>)['snapshotId']
|
|
266
|
-
: undefined
|
|
267
|
-
const pinned = (body as Record<string, unknown> | undefined)?.['pinned'] === true
|
|
268
|
-
if (!isValidSnapshotId(id)) {
|
|
269
|
-
writeJson(res, 400, { error: 'snapshotId is required and must be a valid snapshot id' })
|
|
270
|
-
return
|
|
271
|
-
}
|
|
272
|
-
await setSnapshotPinned(snapshotsDir, id, pinned)
|
|
273
|
-
writeJson(res, 200, { ok: true, pinned })
|
|
274
|
-
} catch (error) {
|
|
275
|
-
// e2e-F4:快照不存在时**不得**把 fs 原始错误(含服务端绝对路径)回给浏览器 ——
|
|
276
|
-
// 结构化 404 + 机器可读码,文案由界面按码映射;其余失败也不再回显原始 message。
|
|
277
|
-
if (isENOENT(error)) {
|
|
278
|
-
writeJson(res, 404, { error: 'snapshot not found', code: 'snapshot-not-found' })
|
|
279
|
-
return
|
|
280
|
-
}
|
|
281
|
-
writeJson(res, 500, { error: 'failed to update snapshot pin' })
|
|
282
|
-
}
|
|
283
|
-
})),
|
|
284
248
|
// --------------------------------------- snapshots/file-diff(git 风格预览)
|
|
285
249
|
// 单个文件的逐行差异(只读):before = 当前磁盘文件 / after = 快照 blob。
|
|
286
250
|
// 点开某个文件才请求(列表阶段只做轻量统计),避免会话类快照几百个文件时拖死弹窗。
|
package/src/routes/sync.ts
CHANGED
|
@@ -41,7 +41,7 @@ function extractPathMappings(body: Record<string, unknown>): PathMapping[] {
|
|
|
41
41
|
}
|
|
42
42
|
return out
|
|
43
43
|
}
|
|
44
|
-
import { REVIEW_KINDS, ROUTE_TIMEOUT_MS,
|
|
44
|
+
import { REVIEW_KINDS, ROUTE_TIMEOUT_MS, SyncRouteError, buildAutosyncStatus, buildAutosyncStatusByChannel, credentialRef, extractSyncSections, extractSyncSessions, isAutosyncInterval, isGitHubAuthMissing, isToolchainChangeItem, planToConfirmItems, syncScopeOrDefault, withTimeout, writeSyncRouteError } from './route-support.ts'
|
|
45
45
|
import { GitHubApiError } from '../market/github-repos.ts'
|
|
46
46
|
import type { SectionId } from '../schema/types.ts'
|
|
47
47
|
import { redact } from '../security/redaction.ts'
|
|
@@ -81,14 +81,16 @@ interface CredentialDescriber {
|
|
|
81
81
|
async function cloudChannelViews(
|
|
82
82
|
full: FullSyncConfig | null,
|
|
83
83
|
credentials: CredentialDescriber,
|
|
84
|
+
/** 通道密钥槽位(已按档案作用域;默认档案 = 历史槽位名)。 */
|
|
85
|
+
cloudSecret: (provider: Parameters<typeof cloudSecretRef>[0]) => string,
|
|
84
86
|
): Promise<{ s3?: CloudS3ChannelView; gist?: CloudGistChannelView }> {
|
|
85
87
|
const out: { s3?: CloudS3ChannelView; gist?: CloudGistChannelView } = {}
|
|
86
88
|
if (full?.s3 !== undefined) {
|
|
87
|
-
const info = await credentials.describe(credentialRef(
|
|
89
|
+
const info = await credentials.describe(credentialRef(cloudSecret(full.s3.provider)))
|
|
88
90
|
out.s3 = s3ChannelView(full.s3.provider, full.s3, info.configured)
|
|
89
91
|
}
|
|
90
92
|
if (full?.gist !== undefined) {
|
|
91
|
-
const info = await credentials.describe(credentialRef(
|
|
93
|
+
const info = await credentials.describe(credentialRef(cloudSecret(GIST_PROVIDER)))
|
|
92
94
|
out.gist = gistChannelView(full.gist, info.configured)
|
|
93
95
|
}
|
|
94
96
|
return out
|
|
@@ -133,6 +135,16 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
133
135
|
tryAppendHistory,
|
|
134
136
|
withMutationGate,
|
|
135
137
|
} = env
|
|
138
|
+
/**
|
|
139
|
+
* 凭据槽位一律按**档案作用域**取(见 src/sync/sync-scope.ts):
|
|
140
|
+
* 默认档案(web)沿用历史槽位名,零迁移;其它档案追加 `__<PROFILE>` 后缀 ——
|
|
141
|
+
* 于是不同 profile 可以各自绑定不同的 GitHub 账号 / 仓库而不互相覆盖。
|
|
142
|
+
*/
|
|
143
|
+
const syncScope = syncScopeOrDefault(syncDir, env.syncScope)
|
|
144
|
+
const tokenRef = syncScope.tokenRef
|
|
145
|
+
const webdavPasswordRef = syncScope.webdavPasswordRef
|
|
146
|
+
const passwordRef = (kind: 'ENCRYPT' | 'DECRYPT', channel: string): string => syncScope.passwordRef(kind, channel)
|
|
147
|
+
const cloudSecret = (provider: Parameters<typeof cloudSecretRef>[0]): string => syncScope.scopeRef(cloudSecretRef(provider))
|
|
136
148
|
/** 云端点密钥「只写」端口:值只进 DSH credentials,绝不落盘 / 日志 / 回传(cloudSecretRef 槽位)。 */
|
|
137
149
|
const cloudSecrets: CloudSecretWriter = {
|
|
138
150
|
set: async (ref, value) => { await credentials.set(credentialRef(ref), value) },
|
|
@@ -142,7 +154,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
142
154
|
* T-ui-merge:合并预览 / 合并执行共用的引擎选项。
|
|
143
155
|
*
|
|
144
156
|
* 解密密码口径与 /sync/sync 完全一致:请求体优先,其次已保存的 DECRYPT 凭据
|
|
145
|
-
* (
|
|
157
|
+
* (passwordRef('DECRYPT', channel),已按档案作用域)。密码只存在于内存,绝不写进响应 / 日志 / 同步文件;
|
|
146
158
|
* 明文快照根本不会被解密(引擎只在 manifest.encrypted 时才用密码)。
|
|
147
159
|
*/
|
|
148
160
|
const mergeEngineOptions = async (
|
|
@@ -150,7 +162,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
150
162
|
syncCfg: SyncConfig,
|
|
151
163
|
): Promise<{ snapshotId?: string; password?: string; pathMappings?: PathMapping[] }> => {
|
|
152
164
|
const snapshotId = typeof body['snapshotId'] === 'string' && body['snapshotId'] !== '' ? body['snapshotId'] : undefined
|
|
153
|
-
const savedDecryptPassword = await resolveSyncPassword(
|
|
165
|
+
const savedDecryptPassword = await resolveSyncPassword(passwordRef('DECRYPT', channelOf(syncCfg)))
|
|
154
166
|
const decryptPassword = typeof body['decryptPassword'] === 'string' && body['decryptPassword'] !== ''
|
|
155
167
|
? body['decryptPassword']
|
|
156
168
|
: savedDecryptPassword
|
|
@@ -206,8 +218,8 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
206
218
|
const full = await readFullSyncConfig(syncDir, configIssues)
|
|
207
219
|
const state = await loadSyncState(syncDir)
|
|
208
220
|
const [cred, webdavCred] = await Promise.all([
|
|
209
|
-
credentials.describe(credentialRef(
|
|
210
|
-
credentials.describe(credentialRef(
|
|
221
|
+
credentials.describe(credentialRef(tokenRef)),
|
|
222
|
+
credentials.describe(credentialRef(webdavPasswordRef)),
|
|
211
223
|
])
|
|
212
224
|
const transport: SyncConfig['transport'] = parseSyncChannel(full?.transport) ?? 'git'
|
|
213
225
|
// m-self:插件 UI 偏好(上次选择的同步通道;ui-prefs.json,随 self 分区进备份)
|
|
@@ -223,7 +235,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
223
235
|
}
|
|
224
236
|
: undefined
|
|
225
237
|
// 云端点配置视图(只回 secretStored 布尔;与当前通道无关,配置过即回填)
|
|
226
|
-
const cloud = await cloudChannelViews(full, credentials)
|
|
238
|
+
const cloud = await cloudChannelViews(full, credentials, cloudSecret)
|
|
227
239
|
// issue #79 / #104 建议 3:git 工作副本是否已跟随 repoUrl,外加「领先远端提交数 /
|
|
228
240
|
// 远端快照数」(只读自检;后者是「本地一直没真正备份」的预警依据)。
|
|
229
241
|
// 读不出来时**如实回传错误**(workDirError),不让状态接口静默少一块信息。
|
|
@@ -353,15 +365,15 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
353
365
|
if (channel === 's3') {
|
|
354
366
|
// s3 通道断开 → 清掉**全部**兼容商的密钥槽位(该通道不再指向任何一家;幂等)
|
|
355
367
|
for (const provider of S3_COMPAT_PROVIDERS) {
|
|
356
|
-
await credentials.unset(credentialRef(
|
|
368
|
+
await credentials.unset(credentialRef(cloudSecret(provider)))
|
|
357
369
|
}
|
|
358
370
|
} else if (channel === 'gist') {
|
|
359
|
-
await credentials.unset(credentialRef(
|
|
371
|
+
await credentials.unset(credentialRef(cloudSecret(GIST_PROVIDER)))
|
|
360
372
|
} else {
|
|
361
|
-
await credentials.unset(credentialRef(channel === 'git' ?
|
|
373
|
+
await credentials.unset(credentialRef(channel === 'git' ? tokenRef : webdavPasswordRef))
|
|
362
374
|
}
|
|
363
|
-
await credentials.unset(credentialRef(
|
|
364
|
-
await credentials.unset(credentialRef(
|
|
375
|
+
await credentials.unset(credentialRef(passwordRef('ENCRYPT', channel)))
|
|
376
|
+
await credentials.unset(credentialRef(passwordRef('DECRYPT', channel)))
|
|
365
377
|
const auto = await readAutosyncConfig(syncDir, channel)
|
|
366
378
|
await writeAutosyncConfig(syncDir, channel, { ...auto, enabled: false, consecutiveFailures: 0 })
|
|
367
379
|
// 立即让调度器丢掉该通道的定时器(否则内存里的旧排期会继续对已删通道发请求)
|
|
@@ -384,13 +396,13 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
384
396
|
// 云端点通道经 CloudSecretWriter 只写端口落库(值绝不进 sync-cloud-config.json / 日志 / 回传)
|
|
385
397
|
await writeSyncConfig(syncDir, syncCfg, cloudSecrets)
|
|
386
398
|
const [cred, webdavCred] = await Promise.all([
|
|
387
|
-
credentials.describe(credentialRef(
|
|
388
|
-
credentials.describe(credentialRef(
|
|
399
|
+
credentials.describe(credentialRef(tokenRef)),
|
|
400
|
+
credentials.describe(credentialRef(webdavPasswordRef)),
|
|
389
401
|
])
|
|
390
402
|
// SEC-03:写完就把落盘结果再读一遍(writeSyncConfig 可能因命名空间合并保留旧值),
|
|
391
403
|
// 成因而非「写成功」才是客户端要显示的真相;字段恒在(默认空数组)。
|
|
392
404
|
const configIssues: SyncConfigIssue[] = []
|
|
393
|
-
const cloud = await cloudChannelViews(await readFullSyncConfig(syncDir, configIssues), credentials)
|
|
405
|
+
const cloud = await cloudChannelViews(await readFullSyncConfig(syncDir, configIssues), credentials, cloudSecret)
|
|
394
406
|
writeJson(res, 200, {
|
|
395
407
|
ok: true,
|
|
396
408
|
configured: true,
|
|
@@ -454,7 +466,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
454
466
|
// 已保存的加密密码兜底(DSH credentials;用户不必每次重输)。请求体里的密码优先,
|
|
455
467
|
// 因为那是用户此刻输入的覆盖值;两者都没有 → 交给 engine 报「加密需要密码」。
|
|
456
468
|
const pushChannel: SyncTransportType = channelOf(syncCfg)
|
|
457
|
-
const effectiveEncryptPassword = encryptPassword ?? await resolveSyncPassword(
|
|
469
|
+
const effectiveEncryptPassword = encryptPassword ?? await resolveSyncPassword(passwordRef('ENCRYPT', pushChannel))
|
|
458
470
|
// sessions 的导出参数(「最新 N 个」/ 逐会话点名);**放行**由引擎的 optInSections 决定
|
|
459
471
|
const sessions = extractSyncSessions(body)
|
|
460
472
|
const sessionsOpt = sections !== undefined && sections.includes('sessions') && sessions !== undefined
|
|
@@ -505,7 +517,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
505
517
|
// 解密密码:请求体 > 已保存(DSH credentials)。明文快照根本不会被解密
|
|
506
518
|
// (engine.prepareSnapshot 只在 manifest.encrypted 时才用密码),因此「未加密备份
|
|
507
519
|
// 不会误用密码」是引擎层保证,而不是靠这里猜。密码仅内存,绝不落盘/落日志。
|
|
508
|
-
const savedDecryptPassword = await resolveSyncPassword(
|
|
520
|
+
const savedDecryptPassword = await resolveSyncPassword(passwordRef('DECRYPT', channelOf(syncCfg)))
|
|
509
521
|
const decryptPassword =
|
|
510
522
|
typeof body['decryptPassword'] === 'string' && body['decryptPassword'] !== ''
|
|
511
523
|
? body['decryptPassword']
|
|
@@ -563,7 +575,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
563
575
|
}),
|
|
564
576
|
// -------------------------------------------------- sync/github/poll
|
|
565
577
|
// m-github-oauth:轮询授权结果。凭 flowId 取回宿主登记的 device_code → GitHub 换 token
|
|
566
|
-
// → 成功则立即写入 DSH credentials
|
|
578
|
+
// → 成功则立即写入 DSH credentials(本档案的 token 槽位,与手动 token 同槽),
|
|
567
579
|
// token 绝不回传浏览器;pending 返回下次轮询延迟;终止态(denied/expired/error)清理登记。
|
|
568
580
|
endpoint({ path: '/api/dsh-config-manager/sync/github/poll', methods: ['POST'] }, async (req, res) => {
|
|
569
581
|
const body = await readJsonBody(req)
|
|
@@ -585,7 +597,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
585
597
|
interval: flow.interval,
|
|
586
598
|
})
|
|
587
599
|
if (result.status === 'success' && result.accessToken !== undefined) {
|
|
588
|
-
await credentials.set(credentialRef(
|
|
600
|
+
await credentials.set(credentialRef(tokenRef), result.accessToken)
|
|
589
601
|
githubFlows.delete(flowId)
|
|
590
602
|
host.log.info('GitHub OAuth 登录成功(token 已写入 DSH credentials)')
|
|
591
603
|
writeJson(res, 200, { status: 'success', credentialConfigured: true })
|
|
@@ -619,7 +631,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
619
631
|
writeJson(res, 200, { ok: true })
|
|
620
632
|
}),
|
|
621
633
|
// -------------------------------------------------- sync/github/validate
|
|
622
|
-
// m-sync-github-valid
|
|
634
|
+
// m-sync-github-valid:校验本档案 token 槽位中已存 token 是否有效(GET /user),
|
|
623
635
|
// 供 UI 判定「是否已登录」→ 已登录隐藏 GitHub 登录区块、token 失效则重新展示。
|
|
624
636
|
// 只回布尔 + 登录名(非敏感),token 值绝不回传;仅 401(无效/过期)→ valid:false,
|
|
625
637
|
// 其余错误(网络/限流)向上抛,由 UI 兜底(不误判登出)。
|
|
@@ -654,7 +666,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
654
666
|
// 仓库选择器(issue:同步通道支持「选择已有仓库 / 新建仓库」):
|
|
655
667
|
// GET → 列出当前用户可见仓库(按最近更新排序),供 UI 下拉选择;
|
|
656
668
|
// POST → 新建**私有**仓库(body: { name, description? }),返回仓库信息供回填 repoUrl。
|
|
657
|
-
// token 来源与 /sync/github/validate 完全一致(DSH credentials
|
|
669
|
+
// token 来源与 /sync/github/validate 完全一致(DSH credentials 的本档案 token 槽位),
|
|
658
670
|
// 401(未登录 / token 失效)单独映射,其余错误走通用 500 —— 与 me 路由同一口径。
|
|
659
671
|
// 不进 mutation gate:两步都不写本地文件(只读列举 + 幂等元操作),
|
|
660
672
|
// 而 gate 在 SAFE MODE 下会直接拒绝,会把「选仓库」变成不可用功能。
|
|
@@ -802,7 +814,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
802
814
|
writeJson(res, 400, { error: 'name must be a .zip file name (no path separators)' })
|
|
803
815
|
return
|
|
804
816
|
}
|
|
805
|
-
const savedDecryptPassword = await resolveSyncPassword(
|
|
817
|
+
const savedDecryptPassword = await resolveSyncPassword(passwordRef('DECRYPT', channelOf(syncCfg)))
|
|
806
818
|
const decryptPassword =
|
|
807
819
|
typeof body['decryptPassword'] === 'string' && body['decryptPassword'] !== ''
|
|
808
820
|
? body['decryptPassword']
|
|
@@ -901,7 +913,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
901
913
|
// 解密密码:请求体 > 已保存(DSH credentials)。明文快照根本不会被解密
|
|
902
914
|
// (engine.prepareSnapshot 只在 manifest.encrypted 时才用密码),因此「未加密备份
|
|
903
915
|
// 不会误用密码」是引擎层保证,而不是靠这里猜。密码仅内存,绝不落盘/落日志。
|
|
904
|
-
const savedDecryptPassword = await resolveSyncPassword(
|
|
916
|
+
const savedDecryptPassword = await resolveSyncPassword(passwordRef('DECRYPT', channelOf(syncCfg)))
|
|
905
917
|
const decryptPassword =
|
|
906
918
|
typeof body['decryptPassword'] === 'string' && body['decryptPassword'] !== ''
|
|
907
919
|
? body['decryptPassword']
|
|
@@ -1019,7 +1031,7 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
1019
1031
|
// 拿不到密码就 `suppressAncestor` —— 宁可不留祖先(下轮两方合并),也绝不落明文副本。
|
|
1020
1032
|
const applyDecryptPassword = typeof body['decryptPassword'] === 'string' && body['decryptPassword'] !== ''
|
|
1021
1033
|
? body['decryptPassword']
|
|
1022
|
-
: await resolveSyncPassword(
|
|
1034
|
+
: await resolveSyncPassword(passwordRef('DECRYPT', channelOf(session.config)))
|
|
1023
1035
|
const ancestorOpts = session.encrypted !== true
|
|
1024
1036
|
? {}
|
|
1025
1037
|
: applyDecryptPassword !== undefined && applyDecryptPassword !== ''
|
|
@@ -1209,8 +1221,8 @@ export function syncRoutes(env: RoutesEnv): WebRoute[] {
|
|
|
1209
1221
|
// 加密/解密密码持久化(用户要求:勾选即记住,取消勾选或主动删除才清)。
|
|
1210
1222
|
// 值只写进 DSH credentials(绝不进 sync-selection.json / 日志 / 响应);
|
|
1211
1223
|
// 清空优先于写入,避免「同一次请求既清又写」产生歧义。
|
|
1212
|
-
const encryptRef =
|
|
1213
|
-
const decryptRef =
|
|
1224
|
+
const encryptRef = passwordRef('ENCRYPT', channel)
|
|
1225
|
+
const decryptRef = passwordRef('DECRYPT', channel)
|
|
1214
1226
|
if (body['clearEncryptPassword'] === true) await credentials.unset(credentialRef(encryptRef))
|
|
1215
1227
|
else if (typeof body['encryptPassword'] === 'string' && body['encryptPassword'] !== '') {
|
|
1216
1228
|
await credentials.set(credentialRef(encryptRef), body['encryptPassword'])
|
package/src/schema/index.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* 据此实现自己的 importer / exporter(ZIP 内路径与文件类分区前缀的唯一权威);
|
|
10
10
|
* - 取到**分区注册表**(`SECTION_REGISTRY` / `SectionMeta` / `sectionMeta` / `jsonPathOf` /
|
|
11
11
|
* `PORTABLE_SECTION_IDS` / `OPT_IN_SYNC_SECTION_IDS` / `DEFAULT_INCLUDED_SECTION_IDS` …)——
|
|
12
|
-
* 「有哪些分区、各自什么形态/可移植性」的机器可读唯一来源,与 `docs/
|
|
12
|
+
* 「有哪些分区、各自什么形态/可移植性」的机器可读唯一来源,与 `docs/contracts/` 的分区清单对应;
|
|
13
13
|
* - 引用 Bundle Format v1 的全部载荷类型。
|
|
14
14
|
*
|
|
15
15
|
* 为什么需要它:此前的 `exports["./schema"]` 指向 `./lib/schema/types.js`,而 `types.ts`
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* `./versions.ts`)。`section-registry.ts` 自身仍然只 import 一个**类型**(`type { SectionId }`;
|
|
23
23
|
* 未注册分区的错误文案 t7 起在 `config.ts`,见那里)。
|
|
24
24
|
* 目标性质是**零 `node:` / 零 npm / 零 @deepseek-ai 依赖**(headless 消费:
|
|
25
|
-
* `docs/
|
|
25
|
+
* `docs/contracts/headless-consumption.md`;client bundle 自包含)。唯一的跨层依赖是本域消息目录
|
|
26
26
|
* (`./messages.ts` → `../core/engine-locale.ts`,纯函数、零 node / 零 npm),不破坏该性质;
|
|
27
27
|
* 除此之外不得 import `../core/*`、`node:*` 或任何 UI / DSH 包。
|
|
28
28
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bundle manifest JSON Schema ↔ 实现绑定测试。
|
|
3
3
|
*
|
|
4
|
-
* 目的:把 `docs/
|
|
4
|
+
* 目的:把 `docs/contracts/bundle-manifest.schema.json`(Bundle Format v1 的机器可校验形态)
|
|
5
5
|
* 焊死在 `src/schema/manifest.ts` 的实现上。规格最大的死法是漂移——文档说一套、代码做一套。
|
|
6
6
|
*
|
|
7
7
|
* 方案选择:(a) 手写仅覆盖本 schema 所用关键字的最小校验器,而不是 (b) 退化为
|
|
@@ -153,7 +153,7 @@ function validateAgainstSchema(schema: SchemaNode, data: unknown): SchemaIssue[]
|
|
|
153
153
|
* 载入 schema 原文(被验证的就是发布出去的那份文件)
|
|
154
154
|
* ==========================================================================*/
|
|
155
155
|
|
|
156
|
-
const SCHEMA_PATH = resolve(import.meta.dirname, '..', '..', 'docs', '
|
|
156
|
+
const SCHEMA_PATH = resolve(import.meta.dirname, '..', '..', 'docs', 'contracts', 'bundle-manifest.schema.json');
|
|
157
157
|
const SCHEMA = JSON.parse(readFileSync(SCHEMA_PATH, 'utf8')) as SchemaNode;
|
|
158
158
|
|
|
159
159
|
/* ============================================================================
|
|
@@ -101,7 +101,7 @@ test('registry: 派生的可移植性 / 可选分区 / 默认勾选与既有声
|
|
|
101
101
|
'settings', 'ui', 'providers', 'plugins', 'prompts', 'skills',
|
|
102
102
|
'agentPresets', 'agentInstructions', 'self',
|
|
103
103
|
]);
|
|
104
|
-
assert.deepEqual([...OPT_IN_SYNC_SECTION_IDS], ['mcp', 'sessions'], '可选分区 = syncOptIn !== off(issue #78
|
|
104
|
+
assert.deepEqual([...OPT_IN_SYNC_SECTION_IDS], ['mcp', 'workspaces', 'sessions'], '可选分区 = syncOptIn !== off(issue #78;#127 起 workspaces 手动可选)');
|
|
105
105
|
assert.deepEqual([...DEFAULT_INCLUDED_SECTION_IDS], [
|
|
106
106
|
'settings', 'ui', 'providers', 'plugins', 'mcp', 'prompts', 'skills',
|
|
107
107
|
'agentPresets', 'agentInstructions', 'workspaces', 'credentialsStatus', 'self',
|
|
@@ -144,7 +144,8 @@ export interface SectionMeta {
|
|
|
144
144
|
* 同步准入档位(非 portable 分区的显式准入;portable 分区恒为 'off',走默认通道)。
|
|
145
145
|
* - 'off' = 永不进入同步通道;
|
|
146
146
|
* - 'manual' = 必须用户在同步分区弹窗里显式勾选,且**只跟随用户驱动的手动 push/pull**;
|
|
147
|
-
* 自动同步永不带(内容隐私 / 设备相关,例如 sessions
|
|
147
|
+
* 自动同步永不带(内容隐私 / 设备相关,例如 sessions;路径与本机绑定的
|
|
148
|
+
* workspaces 同属 manual —— 它要随会话一起走,但绝不悄悄上下行);
|
|
148
149
|
* - 'auto' = 用户显式勾选后,手动与自动同步都带(内容可跨机,只是命令 / 路径可能与
|
|
149
150
|
* 目标机不同,例如 mcp)。
|
|
150
151
|
* **必填**(Record<SectionId, SectionMeta> 强制):新增分区漏填即 tsc 报错。
|
|
@@ -180,7 +181,7 @@ export const SECTION_DATA_VERSION = 1 as const;
|
|
|
180
181
|
* - `portability` / `defaultIncluded` ← 各 adapter 的 `portability` / `defaultIncluded`,
|
|
181
182
|
* 以及 `ui/export-flow.ts` 的内置目录、`market/prepare.ts` 的 SECTION_PORTABILITY
|
|
182
183
|
* (三者此前必须人工保持一致,现以本表为源);
|
|
183
|
-
* - `syncOptIn` ← **本表声明**(mcp='auto' / sessions='manual' / 其余 'off'),
|
|
184
|
+
* - `syncOptIn` ← **本表声明**(mcp='auto' / workspaces='manual' / sessions='manual' / 其余 'off'),
|
|
184
185
|
* `sync/sync-selection.ts` 的 OPT_IN_SYNC_SECTIONS 与 `AUTO_SYNC_OPT_IN_SECTION_IDS` 都是它的派生视图
|
|
185
186
|
* (此前是两份手写字面量、零护栏 —— issue #78 收敛为单一事实源);
|
|
186
187
|
* - `applyOrder` ← 历史 SECTION_IDS 数组顺序(1 起,连续)。
|
|
@@ -318,7 +319,10 @@ export const SECTION_REGISTRY: Record<SectionId, SectionMeta> = {
|
|
|
318
319
|
applyOrder: 10,
|
|
319
320
|
riskTier: 'medium',
|
|
320
321
|
portability: 'platformSpecific',
|
|
321
|
-
|
|
322
|
+
// issue #127:工作区改为**手动可选**同步分区 —— 会话要能在目标机的工作区里显示出来,
|
|
323
|
+
// 包内就必须有指向它 cwd 的工作区记录(DSH 按 realpath(cwd) == workspace.path 归组)。
|
|
324
|
+
// 仍是 platformSpecific(路径与机器绑定,靠 PathMapping 重定基),故只能手动放行、绝不进自动同步。
|
|
325
|
+
syncOptIn: 'manual',
|
|
322
326
|
defaultIncluded: true,
|
|
323
327
|
configSnapshot: true,
|
|
324
328
|
},
|
|
@@ -478,7 +482,8 @@ export const PORTABLE_SECTION_IDS: readonly SectionId[] = SECTION_IDS.filter(
|
|
|
478
482
|
|
|
479
483
|
/**
|
|
480
484
|
* 同步「可选分区」:非 portable、必须推/拉两侧显式放行的分区(syncOptIn !== 'off')。
|
|
481
|
-
* 当前 = ['mcp', 'sessions']。**顺序按 applyOrder
|
|
485
|
+
* 当前 = ['mcp', 'workspaces', 'sessions']。**顺序按 applyOrder**
|
|
486
|
+
* (mcp=5 → workspaces=10 → sessions=14)。
|
|
482
487
|
*/
|
|
483
488
|
export const OPT_IN_SYNC_SECTION_IDS: readonly SectionId[] = SECTION_IDS.filter(
|
|
484
489
|
(id) => SECTION_REGISTRY[id].syncOptIn !== 'off',
|
|
@@ -114,7 +114,7 @@ test('t78-e(正例清单 ≥8 组):散文/字段名/开关/路径必须原
|
|
|
114
114
|
'the bearer scheme is defined by RFC 7235',
|
|
115
115
|
'run with --api-key-required to continue',
|
|
116
116
|
"kind: 'openai-style-key' is an internal enum",
|
|
117
|
-
'path: docs/
|
|
117
|
+
'path: docs/contracts/known-gaps.md',
|
|
118
118
|
'GET /api/health?ready=1',
|
|
119
119
|
'bearer token missing from the header',
|
|
120
120
|
'secrets are never exported by default',
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* 这类**合法**(RFC 7235 / 6750:auth-scheme 名大小写不敏感)的授权头在 env / headers / url 通道上
|
|
6
6
|
* 明文进包且**完全不可见**(refs / skipped 皆空)。
|
|
7
7
|
*
|
|
8
|
-
* 两条口径(改这条判定的任何人先读 `docs/
|
|
8
|
+
* 两条口径(改这条判定的任何人先读 `docs/known-issues/known-gaps.md` **G-36**):
|
|
9
9
|
* ① 规范形态 `Bearer …` 的**行为与历史逐字一致**(命中名仍是 `bearer-token`):本模块只**补**非规范大小写;
|
|
10
10
|
* ② 厂商前缀(`sk-` / `AKIA` / `ghp_` / `github_pat_`)**刻意保持大小写敏感** —— `SK-…` 不是真实厂商形态,
|
|
11
11
|
* 全改 `i` 会连带放宽整个脱敏面(日志 / 导出 / 界面渲染前 redact),代价大于收益 ⇒ 登记为**已知边界**
|
|
@@ -74,7 +74,7 @@ test('t72-d:厂商前缀的大小写边界钉成事实(SK- / GHP_ / akia 是
|
|
|
74
74
|
assert.equal(matchSecretValuePattern('AKIAIOSFODNN7A1B2C3D4'), 'aws-access-key');
|
|
75
75
|
assert.equal(matchSecretValuePattern('ghp_' + 'AbCdEf0123456789aBcDeF0123456789aB'), 'github-token');
|
|
76
76
|
// 不命中侧:**刻意保留**的大小写边界。改这里 = 改整个脱敏面(日志/导出/界面),需单独决策 ——
|
|
77
|
-
// 若确要收,请连同 known-gaps G-36 与 docs/
|
|
77
|
+
// 若确要收,请连同 known-gaps G-36 与 docs/evidence/security-and-credentials.md 一起改,不要只改死这条断言。
|
|
78
78
|
const boundary = [
|
|
79
79
|
'SK-ABCDEFGHIJKLMNOP0123456789XYZ',
|
|
80
80
|
'Sk-abcdefghijklmnop0123456789XYZ',
|
|
@@ -81,7 +81,7 @@ const BEARER_TOKEN_CHARS = '[A-Za-z0-9._~+/=-]';
|
|
|
81
81
|
* 于是 `bearer credentials are required` / `bearer authentication failed` / `BEARER HEADER NOT SET`
|
|
82
82
|
* 这类纯小写或纯大写的英文词**不命中**;而 `bearer abc12345`、`BEARER AbCdEfGh`、`bearer <24+ 字符>` 命中。
|
|
83
83
|
*
|
|
84
|
-
* 已知残余(登记在 `docs/
|
|
84
|
+
* 已知残余(登记在 `docs/known-issues/known-gaps.md` G-36):scheme 用非规范大小写**且** token 是 8–23 个**纯字母、
|
|
85
85
|
* 单一大小写**时本条不命中;规范 `Bearer …` 形态不受此限(上面那条 `bearer-token` 只要求 8+ 字符,行为不变)。
|
|
86
86
|
*/
|
|
87
87
|
const BEARER_TOKEN_ANY_CASE = new RegExp(
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* issue #127:一键同步的临时 ZIP 装配 —— 只装 autoApply 的 merged 载荷,并在「应用了会话」时
|
|
3
|
+
* **伴随**一份 workspaces 载荷。
|
|
4
|
+
*
|
|
5
|
+
* 为什么必须伴随:DSH 把会话显示在工作区里靠「首帧 cwd 的 realpath == workspace.path 且会话 id 在
|
|
6
|
+
* 该记录的 sessionIds 里」,而这条挂接只在导入计划的 workspaces 分区有执行项时才会被
|
|
7
|
+
* `finalizeImport` 触发(analyzer 对零计划项的 adapter 直接跳过)。所以「勾了会话、没勾工作区」
|
|
8
|
+
* 的同步会把会话写进本机,却一条都不显示 —— 用户看到的正是 #127 的现象。
|
|
9
|
+
*
|
|
10
|
+
* 载荷口径:本地现值 ∪ 远端(或本次 merged)记录 —— 走 `mergeWorkspacesSection` 的记录级合并,
|
|
11
|
+
* 于是本机既有工作区不会被覆盖、两侧各自的 sessionIds 都保住(并集)。冲突字段取本地值,
|
|
12
|
+
* 与「不静默覆盖用户本机记录」一致。
|
|
13
|
+
*
|
|
14
|
+
* 边界:本实例没放行 workspaces(构造期 optInSections)或远端压根没有该分区 → 不带伴随载荷,
|
|
15
|
+
* 不越权凭空造工作区。伴随失败**不阻断**主流程(宁可少挂会话,也不让整次同步失败)。
|
|
16
|
+
*/
|
|
17
|
+
import type { ConfigAdapter, HostContext } from '../core/types.ts';
|
|
18
|
+
import type { Platform, SectionData, SectionId } from '../schema/types.ts';
|
|
19
|
+
import { CURRENT_SCHEMA_VERSION } from '../schema/versions.ts';
|
|
20
|
+
import type { MergeSectionResult } from './merge.ts';
|
|
21
|
+
import type { ManifestSummary, SyncSnapshot } from './transport.ts';
|
|
22
|
+
import { mergeWorkspacesSection } from './workspace-merge.ts';
|
|
23
|
+
|
|
24
|
+
/** prepareApplyBundle 的入参:只取装配所需的事实,不把引擎实例漏进来(纯函数好测)。 */
|
|
25
|
+
export interface ApplyBundleInput {
|
|
26
|
+
/** autoApply 的分区(本次真正要写本机的) */
|
|
27
|
+
autoApply: readonly MergeSectionResult[];
|
|
28
|
+
/** 本次 autoApply 的分区 id(返回值会补上伴随分区) */
|
|
29
|
+
baseIds: readonly SectionId[];
|
|
30
|
+
/** 本实例是否放行 workspaces(构造期 optInSections 派生) */
|
|
31
|
+
pullAllowsWorkspaces: boolean;
|
|
32
|
+
/** 计划里待裁决/跳过的项(取其中 merged 作为远端载荷的兜底) */
|
|
33
|
+
planEntries: readonly MergeSectionResult[];
|
|
34
|
+
/** 本次 merge() 记下的远端输入(缺省 = 退回 planEntries 里的 merged) */
|
|
35
|
+
remote: SectionData | undefined;
|
|
36
|
+
ancestor: SectionData | undefined;
|
|
37
|
+
adapter: ConfigAdapter | undefined;
|
|
38
|
+
ctx: HostContext;
|
|
39
|
+
snapshotId: string;
|
|
40
|
+
createdAt: string;
|
|
41
|
+
dshVersion: string;
|
|
42
|
+
platform: Platform;
|
|
43
|
+
/** 远端快照的源机 home('' = 未知,不写进 manifest,跨机重定基自然不发生) */
|
|
44
|
+
sourceHome: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ApplyBundle {
|
|
48
|
+
/** 临时 ZIP 的 sectionIds(可能比 baseIds 多一个 workspaces) */
|
|
49
|
+
sectionIds: SectionId[];
|
|
50
|
+
/** 伴随的 workspaces 载荷(undefined = 本次不需要 / 拿不到) */
|
|
51
|
+
companion: SectionData | undefined;
|
|
52
|
+
tempSnapshot: SyncSnapshot;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function prepareApplyBundle(input: ApplyBundleInput): Promise<ApplyBundle> {
|
|
56
|
+
let companion: SectionData | undefined;
|
|
57
|
+
try {
|
|
58
|
+
companion = await companionWorkspaces(input);
|
|
59
|
+
} catch {
|
|
60
|
+
companion = undefined;
|
|
61
|
+
}
|
|
62
|
+
const sectionIds: SectionId[] = companion === undefined ? [...input.baseIds] : [...input.baseIds, 'workspaces'];
|
|
63
|
+
const sections: Record<string, SectionData> = {};
|
|
64
|
+
for (const r of input.autoApply) {
|
|
65
|
+
if (r.merged !== undefined) sections[r.id] = r.merged as SectionData;
|
|
66
|
+
}
|
|
67
|
+
if (companion !== undefined) sections.workspaces = companion;
|
|
68
|
+
const manifest: ManifestSummary = {
|
|
69
|
+
schemaVersion: CURRENT_SCHEMA_VERSION,
|
|
70
|
+
dshVersion: input.dshVersion,
|
|
71
|
+
platform: input.platform,
|
|
72
|
+
sectionIds: [...sectionIds],
|
|
73
|
+
containsSecrets: false,
|
|
74
|
+
...(input.sourceHome !== '' ? { sourceHome: input.sourceHome } : {}),
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
sectionIds,
|
|
78
|
+
companion,
|
|
79
|
+
tempSnapshot: {
|
|
80
|
+
id: input.snapshotId,
|
|
81
|
+
createdAt: input.createdAt,
|
|
82
|
+
manifest,
|
|
83
|
+
sections: sections as SyncSnapshot['sections'],
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** 会话落地时是否/如何带上工作区(口径见文件头;形状不认识就交回远端原样)。 */
|
|
89
|
+
async function companionWorkspaces(input: ApplyBundleInput): Promise<SectionData | undefined> {
|
|
90
|
+
if (!input.baseIds.includes('sessions') || input.baseIds.includes('workspaces')) return undefined;
|
|
91
|
+
if (!input.pullAllowsWorkspaces || input.adapter === undefined) return undefined;
|
|
92
|
+
const planEntry = input.planEntries.find((r) => r.id === 'workspaces');
|
|
93
|
+
const remote = input.remote ?? planEntry?.merged;
|
|
94
|
+
if (remote === undefined) return undefined;
|
|
95
|
+
let local: SectionData | undefined;
|
|
96
|
+
try {
|
|
97
|
+
local = (await input.adapter.export(input.ctx, { includeSecrets: false })).data as SectionData;
|
|
98
|
+
} catch {
|
|
99
|
+
local = undefined; // 读不到本机现值就只带远端(畸形载荷交给 analyzeImport/validate 如实报错)
|
|
100
|
+
}
|
|
101
|
+
if (local === undefined) return remote;
|
|
102
|
+
const merged = mergeWorkspacesSection(local, remote, input.ancestor);
|
|
103
|
+
return merged === undefined ? remote : merged.merged;
|
|
104
|
+
}
|