dsh-config-manager 0.8.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/adapters/mcp.js +51 -15
- package/lib/adapters/messages.d.ts +1 -0
- package/lib/adapters/messages.js +2 -0
- package/lib/adapters/patch-key-guard.d.ts +23 -0
- package/lib/adapters/patch-key-guard.js +13 -0
- package/lib/adapters/plugin-data.d.ts +19 -5
- package/lib/adapters/plugin-data.js +76 -22
- package/lib/adapters/plugins.d.ts +14 -1
- package/lib/adapters/plugins.js +204 -6
- package/lib/adapters/prompts.js +15 -4
- package/lib/adapters/test-helpers.d.ts +15 -1
- package/lib/adapters/test-helpers.js +11 -0
- package/lib/cli/actions.d.ts +7 -105
- package/lib/cli/actions.js +16 -172
- package/lib/cli/control-state.d.ts +54 -0
- package/lib/cli/control-state.js +107 -0
- package/lib/cli/help.d.ts +1 -1
- package/lib/cli/help.js +21 -14
- package/lib/cli/index.js +132 -104
- package/lib/cli/sessions-repair.js +58 -22
- package/lib/cli/web/client-script.d.ts +1 -1
- package/lib/cli/web/client-script.js +71 -5
- package/lib/cli/web/page.d.ts +9 -19
- package/lib/cli/web/page.js +277 -173
- package/lib/cli/web/routes.js +85 -25
- package/lib/cli/write-gates.d.ts +61 -0
- package/lib/cli/write-gates.js +110 -0
- package/lib/client.d.ts +196 -75
- package/lib/client.js +8139 -7487
- package/lib/core/backup.d.ts +0 -4
- package/lib/core/backup.js +21 -4
- package/lib/core/boot-rescue.d.ts +1 -1
- package/lib/core/boot-rescue.js +12 -1
- package/lib/core/boot-safety.js +37 -2
- package/lib/core/conflict-decisions.js +2 -1
- package/lib/core/exporter.js +22 -1
- package/lib/core/journal.d.ts +54 -4
- package/lib/core/journal.js +158 -35
- package/lib/core/local-plugin-host.d.ts +29 -0
- package/lib/core/local-plugin-host.js +55 -48
- package/lib/core/messages.d.ts +17 -0
- package/lib/core/messages.js +34 -0
- package/lib/core/migration-history.js +16 -9
- package/lib/core/model-tools.d.ts +2 -2
- package/lib/core/model-tools.js +20 -2
- package/lib/core/patch-chain.d.ts +65 -0
- package/lib/core/patch-chain.js +100 -0
- package/lib/core/patch-document.d.ts +32 -4
- package/lib/core/patch-document.js +48 -17
- package/lib/core/patch-secret-guard.d.ts +49 -0
- package/lib/core/patch-secret-guard.js +164 -0
- package/lib/core/reconcile.d.ts +8 -0
- package/lib/core/reconcile.js +18 -3
- package/lib/core/reinstall.d.ts +2 -0
- package/lib/core/reinstall.js +6 -2
- package/lib/core/restore.js +31 -6
- package/lib/core/section-sanitize.d.ts +32 -0
- package/lib/core/section-sanitize.js +13 -0
- package/lib/core/snapshot-diff.d.ts +30 -0
- package/lib/core/snapshot-diff.js +56 -20
- package/lib/core/startup-barrier.js +8 -2
- package/lib/core/types.d.ts +38 -1
- package/lib/core/update-check.js +51 -2
- package/lib/foreign/kernel.js +9 -2
- package/lib/foreign/read-claude-plugins.js +29 -11
- package/lib/foreign/read-dsh.js +31 -2
- package/lib/foreign/session-ir.js +50 -9
- package/lib/foreign/session-read.d.ts +8 -0
- package/lib/foreign/session-read.js +26 -0
- package/lib/index.d.ts +9 -4
- package/lib/index.js +42 -47
- package/lib/profiles/dsh-profile-io.d.ts +20 -0
- package/lib/profiles/dsh-profile-io.js +27 -0
- package/lib/profiles/dsh-profile-manager.d.ts +27 -0
- package/lib/profiles/dsh-profile-manager.js +45 -4
- package/lib/profiles/dsh-profile-runtime.d.ts +5 -1
- package/lib/profiles/dsh-profile-runtime.js +16 -3
- package/lib/profiles/process-control.d.ts +18 -1
- package/lib/profiles/process-control.js +25 -1
- package/lib/routes/profiles.js +2 -1
- package/lib/routes/sync.js +19 -1
- package/lib/schema/types.d.ts +11 -0
- package/lib/security/redaction.js +22 -6
- package/lib/sync/autosync-repeat.d.ts +27 -0
- package/lib/sync/autosync-repeat.js +23 -0
- package/lib/sync/autosync-scheduler.d.ts +47 -2
- package/lib/sync/autosync-scheduler.js +217 -53
- package/lib/sync/baseline-heal.js +7 -0
- package/lib/sync/baseline-record.d.ts +67 -0
- package/lib/sync/baseline-record.js +74 -0
- package/lib/sync/blob-store.js +13 -0
- package/lib/sync/content-diff.d.ts +39 -0
- package/lib/sync/content-diff.js +46 -0
- package/lib/sync/git/git-transport.d.ts +32 -1
- package/lib/sync/git/git-transport.js +146 -26
- package/lib/sync/github-auth.d.ts +17 -1
- package/lib/sync/github-auth.js +37 -1
- package/lib/sync/local-changes.d.ts +15 -0
- package/lib/sync/local-changes.js +39 -0
- package/lib/sync/merge-apply-plan.d.ts +38 -0
- package/lib/sync/merge-apply-plan.js +76 -0
- package/lib/sync/merge-keyed.d.ts +68 -0
- package/lib/sync/merge-keyed.js +124 -0
- package/lib/sync/messages.d.ts +1 -0
- package/lib/sync/messages.js +2 -0
- package/lib/sync/patch-line-identity.d.ts +19 -0
- package/lib/sync/patch-line-identity.js +99 -0
- package/lib/sync/pending-merge.d.ts +41 -0
- package/lib/sync/pending-merge.js +61 -0
- package/lib/sync/plugin-removals.d.ts +15 -15
- package/lib/sync/plugin-removals.js +134 -83
- package/lib/sync/push-skip.d.ts +55 -0
- package/lib/sync/push-skip.js +70 -0
- package/lib/sync/s3/s3-transport.d.ts +14 -2
- package/lib/sync/s3/s3-transport.js +72 -48
- package/lib/sync/sync-engine.d.ts +44 -51
- package/lib/sync/sync-engine.js +160 -194
- package/lib/sync/sync-history.d.ts +7 -0
- package/lib/sync/sync-state.d.ts +28 -0
- package/lib/sync/sync-state.js +20 -0
- package/lib/sync/transport.d.ts +12 -3
- package/lib/sync/transport.js +13 -4
- package/lib/sync/webdav/webdav-transport.d.ts +19 -2
- package/lib/sync/webdav/webdav-transport.js +81 -40
- package/lib/sync/workspace-merge.d.ts +8 -2
- package/lib/ui/artifact-view.d.ts +1 -1
- package/lib/ui/commands.js +5 -11
- package/lib/ui/dsh-profiles-view.d.ts +8 -3
- package/lib/ui/dsh-profiles-view.js +9 -5
- package/lib/ui/foreign-view.d.ts +14 -0
- package/lib/ui/foreign-view.js +34 -0
- package/lib/ui/i18n.d.ts +7 -1
- package/lib/ui/i18n.js +15 -2
- package/lib/ui/menu-placement.js +1 -1
- package/lib/ui/migration-consult-view.d.ts +11 -0
- package/lib/ui/migration-consult-view.js +15 -0
- package/lib/ui/overview-view.d.ts +7 -0
- package/lib/ui/overview-view.js +3 -0
- package/lib/ui/report.d.ts +9 -0
- package/lib/ui/report.js +17 -4
- package/lib/ui/selection-model.d.ts +10 -2
- package/lib/ui/selection-model.js +23 -3
- package/lib/utils/async-once.d.ts +11 -0
- package/lib/utils/async-once.js +15 -0
- package/lib/utils/patch-chain-read.d.ts +51 -0
- package/lib/utils/patch-chain-read.js +240 -0
- package/lib/utils/patch-yaml.d.ts +39 -1
- package/lib/utils/patch-yaml.js +82 -2
- package/lib/utils/paths.d.ts +13 -0
- package/lib/utils/paths.js +35 -0
- package/lib/utils/workdir-lock.js +18 -3
- package/package.json +3 -2
- package/src/adapters/mcp.test.ts +29 -0
- package/src/adapters/mcp.ts +52 -14
- package/src/adapters/messages.ts +2 -0
- package/src/adapters/patch-key-guard.ts +29 -0
- package/src/adapters/plugin-data.test.ts +126 -0
- package/src/adapters/plugin-data.ts +97 -26
- package/src/adapters/plugins.test.ts +403 -0
- package/src/adapters/plugins.ts +198 -8
- package/src/adapters/prompts.ts +15 -4
- package/src/adapters/test-helpers.ts +15 -1
- package/src/cli/actions.test.ts +74 -1
- package/src/cli/actions.ts +27 -246
- package/src/cli/control-state.ts +143 -0
- package/src/cli/help.ts +21 -14
- package/src/cli/index.ts +123 -107
- package/src/cli/sessions-repair.ts +55 -22
- package/src/cli/web/client-script.ts +71 -5
- package/src/cli/web/page.ts +327 -208
- package/src/cli/web/routes.ts +85 -25
- package/src/cli/web/web.test.ts +65 -0
- package/src/cli/write-gates.ts +149 -0
- package/src/client/ConfigManagerSection.tsx +8 -4
- package/src/client/about/AboutPanel.tsx +9 -12
- package/src/client/about/release-notes-view.test.ts +17 -0
- package/src/client/about/release-notes-view.ts +49 -24
- package/src/client/api.ts +2 -1
- package/src/client/chat/ChatEntryView.tsx +2 -2
- package/src/client/chat/rollback-entry-view.ts +6 -1
- package/src/client/common/CommandPalette.tsx +6 -3
- package/src/client/common/ConfirmDialog.tsx +29 -12
- package/src/client/common/ContentPicker.tsx +24 -24
- package/src/client/common/Modal.tsx +12 -5
- package/src/client/common/MoreMenu.tsx +4 -1
- package/src/client/common/RunsCenter.tsx +103 -32
- package/src/client/common/Select.tsx +2 -2
- package/src/client/common/floating-bounds.ts +1 -1
- package/src/client/common/floating-units.test.ts +1 -2
- package/src/client/common/plan-text-redaction.test.ts +190 -5
- package/src/client/common/runs-center-guard.test.ts +60 -0
- package/src/client/common/runs-center-view.test.ts +128 -0
- package/src/client/common/runs-center-view.ts +96 -0
- package/src/client/common/section-title-action.test.ts +66 -0
- package/src/client/common/ui.tsx +93 -30
- package/src/client/config-manager.module.css +1515 -270
- package/src/client/consult/ConsultCard.tsx +7 -6
- package/src/client/environment/EnvironmentPanel.tsx +22 -25
- package/src/client/environment/maintenance/DiskUsageCard.tsx +69 -96
- package/src/client/environment/profiles-incomplete-ui.test.ts +8 -8
- package/src/client/export/ExportView.tsx +7 -16
- package/src/client/history/HistoryPanel.tsx +88 -28
- package/src/client/history/history-locales.ts +3 -3
- package/src/client/home/BackupScheduleCard.tsx +77 -69
- package/src/client/home/HomePanel.tsx +47 -12
- package/src/client/import/ConflictList.tsx +13 -13
- package/src/client/import/ForeignImportView.tsx +67 -9
- package/src/client/import/ImportWizardView.tsx +4 -4
- package/src/client/import/PathMappingForm.tsx +36 -9
- package/src/client/import/PathPickerDialog.tsx +2 -1
- package/src/client/import/import-wizard-split.test.ts +1 -1
- package/src/client/import/import-wizard-steps.tsx +51 -39
- package/src/client/import/use-import-wizard-controller.test.ts +129 -0
- package/src/client/import/use-import-wizard-controller.ts +116 -22
- package/src/client/library/ArtifactRow.tsx +2 -2
- package/src/client/library/BackupInspectView.tsx +21 -15
- package/src/client/library/LibraryActions.tsx +116 -28
- package/src/client/library/LibraryPanel.tsx +14 -15
- package/src/client/library/RestorePlanView.tsx +13 -8
- package/src/client/locales/about.ts +0 -2
- package/src/client/locales/backup.ts +15 -12
- package/src/client/locales/common.ts +2 -0
- package/src/client/locales/export.ts +5 -12
- package/src/client/locales/foreign.ts +4 -2
- package/src/client/locales/import.ts +5 -2
- package/src/client/locales/overview.ts +4 -0
- package/src/client/locales/profiles.ts +32 -4
- package/src/client/locales/restore.ts +2 -2
- package/src/client/locales/sessions.ts +0 -2
- package/src/client/locales/shell.ts +2 -2
- package/src/client/market/MarketImportReview.tsx +4 -4
- package/src/client/market/MarketPanel.tsx +58 -56
- package/src/client/market/MyConfigsList.tsx +34 -32
- package/src/client/market/MyConfigsLoginCard.tsx +12 -15
- package/src/client/market/MyConfigsView.tsx +8 -15
- package/src/client/market/MyConfigsWizard.tsx +7 -12
- package/src/client/market/market-locales.ts +0 -6
- package/src/client/market/my-configs-split.test.ts +2 -1
- package/src/client/nav-menu-clip-guard.test.ts +52 -0
- package/src/client/recovery/IncompleteCopiesSection.tsx +1 -3
- package/src/client/recovery/RecoveryPanel.tsx +35 -22
- package/src/client/recovery/RollbackCard.tsx +132 -75
- package/src/client/recovery/RollbackFileChanges.tsx +40 -27
- package/src/client/recovery/SessionHealthCard.tsx +2 -2
- package/src/client/recovery/SessionHealthDialog.tsx +5 -7
- package/src/client/recovery/SessionLayoutSection.tsx +3 -5
- package/src/client/recovery/recovery-locales.ts +12 -8
- package/src/client/recovery/rollback-enabled.ts +29 -0
- package/src/client/recovery/use-recovery-write.ts +5 -0
- package/src/client/run-store.test.ts +30 -0
- package/src/client/run-store.ts +21 -1
- package/src/client/sync/AddChannelCard.tsx +65 -0
- package/src/client/sync/AutosyncCard.tsx +184 -108
- package/src/client/sync/ChannelClearConfirmDialog.tsx +5 -1
- package/src/client/sync/ChannelConfigDialog.tsx +27 -48
- package/src/client/sync/MergePreviewView.tsx +5 -7
- package/src/client/sync/PushPreviewCard.tsx +2 -1
- package/src/client/sync/PushReportSections.tsx +35 -0
- package/src/client/sync/SyncChannelEntryCard.tsx +33 -24
- package/src/client/sync/SyncConfirmView.tsx +130 -133
- package/src/client/sync/SyncLogList.tsx +29 -14
- package/src/client/sync/SyncPanel.tsx +188 -185
- package/src/client/sync/SyncProbeRow.tsx +5 -7
- package/src/client/sync/SyncRepositoryPicker.tsx +17 -4
- package/src/client/sync/SyncSecuritySection.tsx +157 -0
- package/src/client/sync/SyncSettingsDialog.tsx +293 -0
- package/src/client/sync/SyncSettingsView.test.ts +26 -8
- package/src/client/sync/WorkDirCard.tsx +2 -4
- package/src/client/sync/config-clear-guard.test.ts +94 -0
- package/src/client/sync/config-clear-guard.ts +98 -0
- package/src/client/sync/config-dirty.test.ts +91 -0
- package/src/client/sync/config-dirty.ts +88 -0
- package/src/client/sync/history-model.test.ts +2 -0
- package/src/client/sync/history-model.ts +5 -0
- package/src/client/sync/merge-request.ts +20 -0
- package/src/client/sync/sync-api.ts +13 -1
- package/src/client/sync/sync-locales.ts +95 -47
- package/src/client/sync/sync-panel-clear.test.ts +44 -0
- package/src/client/sync/sync-push-preview.test.ts +9 -0
- package/src/client/sync/sync-view.test.ts +20 -0
- package/src/client/sync/sync-view.ts +76 -4
- package/src/core/backup.test.ts +61 -1
- package/src/core/backup.ts +21 -4
- package/src/core/boot-rescue.test.ts +35 -0
- package/src/core/boot-rescue.ts +13 -2
- package/src/core/boot-safety.test.ts +25 -0
- package/src/core/boot-safety.ts +37 -2
- package/src/core/conflict-decisions.ts +2 -1
- package/src/core/exporter.ts +21 -1
- package/src/core/journal.test.ts +183 -0
- package/src/core/journal.ts +163 -25
- package/src/core/local-plugin-host.test.ts +68 -2
- package/src/core/local-plugin-host.ts +31 -4
- package/src/core/messages.ts +34 -0
- package/src/core/migration-history.test.ts +27 -0
- package/src/core/migration-history.ts +12 -4
- package/src/core/model-tools.test.ts +67 -0
- package/src/core/model-tools.ts +22 -4
- package/src/core/patch-chain.test.ts +83 -0
- package/src/core/patch-chain.ts +150 -0
- package/src/core/patch-document.test.ts +48 -1
- package/src/core/patch-document.ts +66 -15
- package/src/core/patch-layers.test.ts +1 -1
- package/src/core/patch-secret-guard.test.ts +110 -0
- package/src/core/patch-secret-guard.ts +176 -0
- package/src/core/reconcile.ts +32 -4
- package/src/core/reinstall.ts +8 -2
- package/src/core/restore.ts +32 -7
- package/src/core/section-sanitize.ts +37 -0
- package/src/core/smoke.test.ts +2 -1
- package/src/core/snapshot-diff.test.ts +73 -1
- package/src/core/snapshot-diff.ts +66 -21
- package/src/core/startup-barrier.test.ts +64 -0
- package/src/core/startup-barrier.ts +8 -2
- package/src/core/types.ts +43 -2
- package/src/core/update-check.test.ts +40 -0
- package/src/core/update-check.ts +53 -2
- package/src/foreign/claude-code.test.ts +5 -0
- package/src/foreign/claude-plugins.test.ts +57 -0
- package/src/foreign/claude-sessions-bytes.test.ts +7 -1
- package/src/foreign/dsh.test.ts +23 -0
- package/src/foreign/kernel.ts +9 -2
- package/src/foreign/read-claude-plugins.ts +32 -11
- package/src/foreign/read-dsh.ts +33 -2
- package/src/foreign/session-ir.test.ts +67 -0
- package/src/foreign/session-ir.ts +54 -14
- package/src/foreign/session-read.ts +23 -0
- package/src/index.facade.test.ts +186 -6
- package/src/index.ts +53 -47
- package/src/profiles/dsh-profile-copy-rollback.test.ts +58 -4
- package/src/profiles/dsh-profile-io.ts +29 -0
- package/src/profiles/dsh-profile-manager.test.ts +30 -0
- package/src/profiles/dsh-profile-manager.ts +53 -5
- package/src/profiles/dsh-profile-runtime.test.ts +29 -7
- package/src/profiles/dsh-profile-runtime.ts +17 -3
- package/src/profiles/process-control.test.ts +97 -0
- package/src/profiles/process-control.ts +28 -1
- package/src/routes/profiles.ts +2 -1
- package/src/routes/sync.ts +19 -1
- package/src/schema/types.ts +16 -1
- package/src/security/redaction.test.ts +31 -0
- package/src/security/redaction.ts +23 -6
- package/src/security/security.test.ts +1 -1
- package/src/sync/autosync-repeat.test.ts +58 -0
- package/src/sync/autosync-repeat.ts +55 -0
- package/src/sync/autosync-scheduler.test.ts +515 -0
- package/src/sync/autosync-scheduler.ts +225 -51
- package/src/sync/baseline-heal.ts +6 -0
- package/src/sync/baseline-record.ts +135 -0
- package/src/sync/blob-store.test.ts +16 -0
- package/src/sync/blob-store.ts +13 -0
- package/src/sync/content-diff.test.ts +95 -0
- package/src/sync/content-diff.ts +79 -0
- package/src/sync/git/git-transport.test.ts +151 -4
- package/src/sync/git/git-transport.ts +143 -27
- package/src/sync/github-auth.test.ts +26 -1
- package/src/sync/github-auth.ts +37 -1
- package/src/sync/local-changes.ts +40 -0
- package/src/sync/merge-apply-plan.ts +117 -0
- package/src/sync/merge-keyed.test.ts +167 -0
- package/src/sync/merge-keyed.ts +160 -0
- package/src/sync/messages.ts +3 -0
- package/src/sync/patch-line-identity.test.ts +73 -0
- package/src/sync/patch-line-identity.ts +105 -0
- package/src/sync/pending-merge.test.ts +41 -0
- package/src/sync/pending-merge.ts +85 -0
- package/src/sync/plugin-removals.test.ts +199 -39
- package/src/sync/plugin-removals.ts +150 -64
- package/src/sync/push-skip.test.ts +326 -0
- package/src/sync/push-skip.ts +102 -0
- package/src/sync/s3/s3-delete-and-blob-index.test.ts +249 -0
- package/src/sync/s3/s3-transport.ts +76 -42
- package/src/sync/sync-config.test.ts +39 -12
- package/src/sync/sync-device-identity.test.ts +3 -0
- package/src/sync/sync-engine.test.ts +465 -12
- package/src/sync/sync-engine.ts +189 -193
- package/src/sync/sync-history.ts +7 -0
- package/src/sync/sync-state.ts +48 -0
- package/src/sync/transport.test.ts +13 -1
- package/src/sync/transport.ts +12 -4
- package/src/sync/webdav/webdav-delete-and-blob-index.test.ts +249 -0
- package/src/sync/webdav/webdav-transport.ts +86 -34
- package/src/sync/workspace-merge.ts +9 -2
- package/src/ui/artifact-view.ts +1 -1
- package/src/ui/commands.test.ts +11 -0
- package/src/ui/commands.ts +5 -14
- package/src/ui/dsh-profiles-view.test.ts +16 -0
- package/src/ui/dsh-profiles-view.ts +11 -5
- package/src/ui/foreign-view.test.ts +49 -0
- package/src/ui/foreign-view.ts +47 -0
- package/src/ui/i18n.ts +15 -2
- package/src/ui/menu-placement.ts +1 -1
- package/src/ui/migration-consult-view.test.ts +20 -1
- package/src/ui/migration-consult-view.ts +17 -0
- package/src/ui/overview-view.ts +10 -0
- package/src/ui/report.test.ts +25 -1
- package/src/ui/report.ts +15 -4
- package/src/ui/selection-model.test.ts +29 -1
- package/src/ui/selection-model.ts +25 -4
- package/src/utils/async-once.ts +14 -0
- package/src/utils/js-yaml4.d.ts +35 -0
- package/src/utils/patch-chain-read.test.ts +171 -0
- package/src/utils/patch-chain-read.ts +259 -0
- package/src/utils/patch-yaml.test.ts +215 -3
- package/src/utils/patch-yaml.ts +98 -2
- package/src/utils/paths.test.ts +14 -1
- package/src/utils/paths.ts +35 -0
- package/src/utils/workdir-lock.test.ts +69 -0
- package/src/utils/workdir-lock.ts +17 -3
- package/lib/ui/path-mapping.d.ts +0 -38
- package/lib/ui/path-mapping.js +0 -75
- package/src/client/common/InfoHint.tsx +0 -289
- package/src/client/common/info-hint-guard.test.ts +0 -1119
- package/src/client/sync/DecryptPasswordCard.tsx +0 -48
- package/src/client/sync/SecurityOptionsCard.tsx +0 -97
- package/src/client/sync/SyncSectionPickerDialog.tsx +0 -213
- package/src/ui/path-mapping.test.ts +0 -67
- package/src/ui/path-mapping.ts +0 -103
package/src/sync/sync-engine.ts
CHANGED
|
@@ -22,6 +22,7 @@ import path from 'node:path';
|
|
|
22
22
|
|
|
23
23
|
import { createAdapters } from '../adapters/index.ts';
|
|
24
24
|
import { defaultSecretScanner } from '../core/exporter.ts';
|
|
25
|
+
import { sanitizeSectionData } from '../core/section-sanitize.ts';
|
|
25
26
|
import { Importer } from '../core/importer.ts';
|
|
26
27
|
import { DEFAULT_ROLLBACK_ON_ERROR } from '../core/import-defaults.ts';
|
|
27
28
|
// issue #91:只读预览与基线 hash 的口径判定(本地源插件在预览里不会被 npm pack)
|
|
@@ -60,14 +61,27 @@ import {
|
|
|
60
61
|
import type { SessionBookkeepingResult } from './session-tombstones.ts';
|
|
61
62
|
import { DEFAULT_RETENTION_POLICY, selectPruneCandidatesByPolicy } from './retention-policy.ts';
|
|
62
63
|
import type { RetentionPolicy } from './retention-policy.ts';
|
|
63
|
-
import { hashSection, loadSyncState, resolveDeviceIdentity
|
|
64
|
+
import { hashSection, loadSyncState, resolveDeviceIdentity } from './sync-state.ts';
|
|
65
|
+
import {
|
|
66
|
+
pendingMergeFor as buildPendingMerge,
|
|
67
|
+
recordPendingMerge as persistPendingMerge,
|
|
68
|
+
writeMergeBaseline as persistMergeBaseline,
|
|
69
|
+
} from './pending-merge.ts';
|
|
64
70
|
import type { PendingMerge, SyncState } from './sync-state.ts';
|
|
71
|
+
import { pendingMergeAfterPush, resolveHeldSections, resolvePushTargets, type PushTargets } from './push-skip.ts';
|
|
72
|
+
import { memoAsync } from '../utils/async-once.ts';
|
|
73
|
+
import { hasLocalSectionChanges } from './local-changes.ts';
|
|
74
|
+
// 写基线(祖先副本 + sync-state)的实现整体下沉,引擎只做环境透传(体量棘轮 + G-44 口径集中)
|
|
75
|
+
import { recordBaseline as recordBaselineAt } from './baseline-record.ts';
|
|
76
|
+
import type { RecordBaselineOptions } from './baseline-record.ts';
|
|
77
|
+
// issue #140:内容判定(拉取/推送共用同一处实现,绝不各自比 id)
|
|
78
|
+
import { diffSnapshotContent, hashSections } from './content-diff.ts';
|
|
65
79
|
import type { EncryptedCredentials, SyncProbeResult, SyncSnapshot, SyncSnapshotMeta, SyncTransport } from './transport.ts';
|
|
66
80
|
import { isEncryptedSections, PROBE_UNSUPPORTED_CODE, SyncTransportError } from './transport.ts';
|
|
67
81
|
import { msgOf, zhMsg } from '../core/messages.ts';
|
|
68
82
|
import { engineMsg } from './messages.ts';
|
|
69
83
|
import type { MsgFunc } from '../core/messages.ts';
|
|
70
|
-
import {
|
|
84
|
+
import { tryLoadAncestor } from './ancestor.ts';
|
|
71
85
|
import type { MergePlan, MergeSectionResult } from './merge.ts';
|
|
72
86
|
import { merge as mergeSections } from './merge.ts';
|
|
73
87
|
import { prepareApplyBundle } from './apply-bundle.ts';
|
|
@@ -77,6 +91,7 @@ export type { MergePreview, MergePreviewConflictView, MergePreviewSectionView }
|
|
|
77
91
|
import { gcSkipWarning, readGcSkipCode, reportGcSkipOnce } from './gc-skip.ts';
|
|
78
92
|
import { classifyMergePlan } from './risk.ts';
|
|
79
93
|
import type { SyncApplyPlan } from './risk.ts';
|
|
94
|
+
import { createMergeApplySnapshot, planMergeApply } from './merge-apply-plan.ts';
|
|
80
95
|
import { registerMessageCatalog } from '../core/engine-locale.ts';
|
|
81
96
|
import { createSnapshot, selectPruneCandidates } from '../core/backup.ts';
|
|
82
97
|
import { rollback } from '../core/rollback.ts';
|
|
@@ -98,6 +113,7 @@ const zh = {
|
|
|
98
113
|
'sync.sessionTombstonesInherited': '已从远端快照继承 {count} 条会话删除墓碑:删除继续跨设备传播(本机数据不动)',
|
|
99
114
|
'sync.applyMergeResolutionsNoImporter': 'applyMergeResolutions: SyncEngine 缺少 importer(需在 options 中注入)',
|
|
100
115
|
'sync.mergePendingConflicts': '仍有 {count} 个分区未裁决({sections}):已裁决的部分已写入本机,但基线不推进,冲突下一轮会重新出现',
|
|
116
|
+
'sync.mergeHeldConflicts': '有 {count} 个叶级冲突未裁决(分区:{sections}):这些项保持本机原值、未写入,其余内容已应用;确认后下一轮再合并',
|
|
101
117
|
'sync.baselineRexportFailed': '写回成功但重新导出本机分区失败({sections}):无法证明基线与本机一致,本次**不记基线**(远端指针保持原值,下一轮重新合并收敛)',
|
|
102
118
|
'sync.pushBaselineAdopted': '远端最新快照 {remote} 是本机上次推送的(本机基线停在 {base},上次推送在记录基线前被打断):已把它收养为基线并继续本次推送',
|
|
103
119
|
'sync.pushBaselineAdoptedNoAncestor': '远端最新快照 {remote} 是本机上次推送的,但本机没有它的本地祖先副本:已收养基线(下次合并退化为两方合并,结果仍安全)',
|
|
@@ -109,6 +125,7 @@ const en: Record<keyof typeof zh, string> = {
|
|
|
109
125
|
'sync.sessionTombstonesInherited': 'Inherited {count} session deletion tombstone(s) from the remote snapshot: deletions keep propagating across devices (local data untouched)',
|
|
110
126
|
'sync.applyMergeResolutionsNoImporter': 'applyMergeResolutions: SyncEngine is missing the importer (must be injected via options)',
|
|
111
127
|
'sync.mergePendingConflicts': '{count} section(s) still have no decision ({sections}): the decided parts were written locally, but the baseline is not advanced, so the conflicts will reappear next round',
|
|
128
|
+
'sync.mergeHeldConflicts': '{count} leaf-level conflict(s) remain undecided (sections: {sections}): those items keep the local value and were not written, while the rest was applied; they merge again next round once decided',
|
|
112
129
|
'sync.baselineRexportFailed': 'The write succeeded but re-exporting the local section(s) failed ({sections}): the baseline cannot be proven to match this machine, so no baseline was recorded (the remote pointer keeps its old value and the next merge converges again)',
|
|
113
130
|
'sync.pushBaselineAdopted': 'The newest remote snapshot {remote} was pushed by this device (its baseline stopped at {base}: that push was interrupted before recording the baseline): the baseline has been adopted and this push continues',
|
|
114
131
|
'sync.pushBaselineAdoptedNoAncestor': 'The newest remote snapshot {remote} was pushed by this device, but no local ancestor copy exists for it: the baseline has been adopted (the next merge degrades to a two-way merge, which is still safe)',
|
|
@@ -208,6 +225,14 @@ export interface SyncPushOptions {
|
|
|
208
225
|
* 「最新 N 个里被我勾中的那几个」。宿主侧由 sync-selection.json 的 sessionsInclude 持久化。
|
|
209
226
|
*/
|
|
210
227
|
sessions?: { limit?: number; include?: string[] };
|
|
228
|
+
/**
|
|
229
|
+
* 本轮**必须扣下**的分区(issue #146):未裁决冲突的分区绝不上行。语义看「传没传」,不是「空不空」:
|
|
230
|
+
* - 不传(`undefined`)= 手动推送:只按本参数扣,**不读磁盘**上的历史待裁决;
|
|
231
|
+
* - 传了(含空数组)= 本参数 ∥ 磁盘 pendingMerge 一起扣(自动同步必须传,否则上一轮留下的待裁决
|
|
232
|
+
* 会被任何一轮别的分区的改动顺手推上去 —— #146 的复发路径);
|
|
233
|
+
* - `force: true` 时整个扣下语义不生效(强推 = 明确要用本机覆盖远端)。实现见 `push-skip.ts`。
|
|
234
|
+
*/
|
|
235
|
+
skipSections?: SectionId[];
|
|
211
236
|
/** 加密快照:sections 载荷整体加密(AES-256-GCM),manifest.encrypted=true。
|
|
212
237
|
* 开启时必须提供 password(仅本次调用内存使用,绝不落盘/落日志)。 */
|
|
213
238
|
encrypt?: boolean;
|
|
@@ -266,6 +291,17 @@ export interface SyncPushReport {
|
|
|
266
291
|
* deviceId」,别的设备推进过就仍然按冲突返回,绝不越过。
|
|
267
292
|
*/
|
|
268
293
|
adoptedBase?: string;
|
|
294
|
+
/**
|
|
295
|
+
* issue #140:本次推送**没有产生新快照**(远端最新快照的分区内容与本次导出逐字相同)。
|
|
296
|
+
*
|
|
297
|
+
* 语义:`ok:true` + 本字段 = 「什么都没做,也不算失败」——未 upload、未建目录、未裁剪;
|
|
298
|
+
* 只是把基线指针**收养**到远端最新快照(`adoptedSnapshotId`),让下一轮判定有正确起点。
|
|
299
|
+
* GUI / 报告必须显式区分它(「内容未变化,已跳过」),不能显示成「已推送 xx」。
|
|
300
|
+
* issue #146:`all-conflicted` = 一个分区都没推(`ok:true` + `snapshotId:''`,远端与基线都没动),不是失败,但绝不能显示成「已推送」。
|
|
301
|
+
*/
|
|
302
|
+
skipped?: 'unchanged' | 'all-conflicted';
|
|
303
|
+
/** issue #140:`skipped='unchanged'` 时被收养的远端快照 id(= 本次报告里的 snapshotId) */
|
|
304
|
+
adoptedSnapshotId?: string;
|
|
269
305
|
}
|
|
270
306
|
|
|
271
307
|
/** 差异报告中的单个变更项(PlanItem 摘要,不含敏感细节) */
|
|
@@ -308,6 +344,8 @@ export interface SyncPushPreview {
|
|
|
308
344
|
encrypted: boolean;
|
|
309
345
|
/** 本次推送是否真的会带上凭据载荷(.credentials.yaml 可读且非空;issue #38) */
|
|
310
346
|
credentialsIncluded: boolean;
|
|
347
|
+
/** issue #146:与 push 同口径的终态(全被冲突扣下 ⇒ 预览也是「什么都没得推」,不是错误) */
|
|
348
|
+
skipped?: 'all-conflicted';
|
|
311
349
|
message?: string;
|
|
312
350
|
}
|
|
313
351
|
|
|
@@ -603,9 +641,16 @@ export class SyncEngine {
|
|
|
603
641
|
* 「推上去了、拉下来静默没有」)。
|
|
604
642
|
*/
|
|
605
643
|
private pullSectionIds(): Set<SectionId> {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
644
|
+
return new Set(this.candidateAdapters().map((a) => a.id));
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* 会进载荷的分区 adapter = portable(受注入范围约束)+ 本次放行的可选分区。
|
|
649
|
+
* 「哪些分区算数」只留这一处:hasLocalChanges / pullSectionIds / pushTargets 三处各写一份候选集合时,
|
|
650
|
+
* 漏掉一处就出现「推上去了、拉下来静默没有」或「有改动却判成无变化」(#146 的候选面纪律)。
|
|
651
|
+
*/
|
|
652
|
+
private candidateAdapters(): ConfigAdapter[] {
|
|
653
|
+
return [...this.portableAdapters(), ...this.optInAdapters()];
|
|
609
654
|
}
|
|
610
655
|
|
|
611
656
|
/** 本次显式放行的「可选分区」adapter(空集 = 一个都不放行;顺序跟随 adapters) */
|
|
@@ -615,35 +660,17 @@ export class SyncEngine {
|
|
|
615
660
|
}
|
|
616
661
|
|
|
617
662
|
/**
|
|
618
|
-
* push 候选 adapter
|
|
619
|
-
* -
|
|
620
|
-
* - sections 显式给出 → 只取 portable 且命中的(「高级/自定义导出」模式);
|
|
621
|
-
* 非 portable / 未知分区 → 警告跳过(安全约束 + 不静默,用户能看见自己勾了哪个无效项);
|
|
622
|
-
* - 例外:本次构造显式放行的可选分区(optInSections,见 SyncEngineOptions)作为候选取出。
|
|
623
|
-
* 缺省空集 → 与改造前逐字等价(可选分区一律不进同步通道)。
|
|
663
|
+
* push 候选 adapter:缺省 = portable 全量 + 放行的可选分区;显式 sections 只取命中项,非 portable 警告跳过。
|
|
664
|
+
* issue #146 的「扣下」判定一并解完(`push-skip.ts`)⇒ 过滤只有一处,push 与 previewPush 必然同口径。
|
|
624
665
|
*/
|
|
625
|
-
private pushTargets(
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
// (scheduler 只传 'auto' 档 → sessions 永不悄悄上行)。
|
|
634
|
-
if (sections === undefined || sections.length === 0) return [...portable, ...optIn];
|
|
635
|
-
const byId = new Map(portable.map((a) => [a.id, a]));
|
|
636
|
-
for (const a of optIn) byId.set(a.id, a);
|
|
637
|
-
const out: ConfigAdapter[] = [];
|
|
638
|
-
for (const id of sections) {
|
|
639
|
-
const adapter = byId.get(id);
|
|
640
|
-
if (adapter === undefined) {
|
|
641
|
-
warnings.push(this.msg('sync.skipNonPortable', { section: id }));
|
|
642
|
-
continue;
|
|
643
|
-
}
|
|
644
|
-
out.push(adapter);
|
|
645
|
-
}
|
|
646
|
-
return out;
|
|
666
|
+
private async pushTargets(
|
|
667
|
+
opts: SyncPushOptions, warnings: string[], load: () => Promise<{ pendingMerge?: PendingMerge }>,
|
|
668
|
+
): Promise<PushTargets> {
|
|
669
|
+
const held = await resolveHeldSections(opts, load);
|
|
670
|
+
// 两列表分开传是为了 sections 的「非 portable 警告跳过」,候选面仍是 candidateAdapters 的同一批。
|
|
671
|
+
return resolvePushTargets(this.portableAdapters(), this.optInAdapters(), opts.sections, held, (id) => {
|
|
672
|
+
warnings.push(this.msg('sync.skipNonPortable', { section: id }));
|
|
673
|
+
});
|
|
647
674
|
}
|
|
648
675
|
|
|
649
676
|
/** 结构性断言:凭据/秘密分区绝不进入同步载荷(双保险,portable 过滤之上) */
|
|
@@ -851,6 +878,8 @@ export class SyncEngine {
|
|
|
851
878
|
if (encrypt && (opts.password === undefined || opts.password === '')) {
|
|
852
879
|
throw new Error(this.msg('sync.encryptRequiresPassword'));
|
|
853
880
|
}
|
|
881
|
+
const loadState = memoAsync(() => loadSyncState(this.stateDir, this.fsx, this.msg));
|
|
882
|
+
const { targets, held } = await this.pushTargets(opts, warnings, loadState);
|
|
854
883
|
// SYN-02:本轮只列一次远端 index(推进检测 + 继承会话删除墓碑共用;墓碑累积在最新快照里)
|
|
855
884
|
const remoteIndex = await listRemoteSnapshotIndex(this.transport);
|
|
856
885
|
const remoteTombstones = remoteIndex.reason === undefined ? remoteTombstonesOf(remoteIndex.metas) : [];
|
|
@@ -865,8 +894,12 @@ export class SyncEngine {
|
|
|
865
894
|
if (!pre.ok) return { ok: false, snapshotId: '', sections: [], warnings, conflict: true, message: pre.message };
|
|
866
895
|
adopted = pre.adopted;
|
|
867
896
|
}
|
|
897
|
+
// issue #146:全被冲突扣下 ⇒ 一个分区都不上行。放在前置检测之后:远端已推进时「先同步远端」更该被报出来。
|
|
898
|
+
if (targets.length === 0 && held.length > 0) {
|
|
899
|
+
const message = this.msg('sync.pushSkipConflicted', { sections: held.join(', ') });
|
|
900
|
+
return { ok: true, snapshotId: '', sections: [], warnings: [...warnings, message], message, skipped: 'all-conflicted' };
|
|
901
|
+
}
|
|
868
902
|
const plainSections: Partial<Record<SectionId, SectionData>> = {};
|
|
869
|
-
const targets = this.pushTargets(opts.sections, warnings);
|
|
870
903
|
for (const adapter of targets) {
|
|
871
904
|
let section: ExportSection;
|
|
872
905
|
try {
|
|
@@ -881,9 +914,11 @@ export class SyncEngine {
|
|
|
881
914
|
}
|
|
882
915
|
warnings.push(...section.warnings);
|
|
883
916
|
// includeSecrets=true:凭据值保留(随后整体加密);否则过 SecretScanner 剥离(默认安全)
|
|
917
|
+
// issue #136 C:与 exporter 同走 `sanitizeSectionData`(脱敏 + 归属标注一次完成),
|
|
918
|
+
// 否则推送载荷里没有 `redactedPaths`,目标机无从判断哪一行被剥空。
|
|
884
919
|
const data = isFileSection(adapter.id) || includeSecrets
|
|
885
920
|
? section.data
|
|
886
|
-
: this.scanner
|
|
921
|
+
: sanitizeSectionData(adapter, this.scanner, section.data).sanitized;
|
|
887
922
|
plainSections[adapter.id] = data as SectionData;
|
|
888
923
|
}
|
|
889
924
|
|
|
@@ -907,6 +942,7 @@ export class SyncEngine {
|
|
|
907
942
|
// P1-5 + SYN-02:本机墓碑(上次推过、本机已删)叠加上远端继承的墓碑 ——
|
|
908
943
|
// 不继承的话「A 删 → B 推」会漏掉墓碑,C 带旧快照就能把已删会话复活(删除只在本机传播)。
|
|
909
944
|
const bookkeeping = await this.computeSessionBookkeeping(targets, plainSections, remoteTombstones);
|
|
945
|
+
const sessionBookkeeping = bookkeeping.tracked ? { sessionUnits: bookkeeping.sessionUnits, deletedSessions: bookkeeping.tombstones } : {};
|
|
910
946
|
if (bookkeeping.deletedNow.length > 0) {
|
|
911
947
|
warnings.push(this.msg('sync.sessionDeletionsRecorded', { count: String(bookkeeping.deletedNow.length) }));
|
|
912
948
|
}
|
|
@@ -914,6 +950,40 @@ export class SyncEngine {
|
|
|
914
950
|
warnings.push(this.msg('sync.sessionTombstonesInherited', { count: String(bookkeeping.inherited) }));
|
|
915
951
|
}
|
|
916
952
|
|
|
953
|
+
// issue #146:待裁决只剔除**真正推上去**的分区(导出失败/不在候选里的分区一律保留)。
|
|
954
|
+
const pushedSections = Object.keys(plainSections) as SectionId[];
|
|
955
|
+
const pendingAfterPush = await pendingMergeAfterPush(loadState, pushedSections);
|
|
956
|
+
// issue #140:内容没变就**不新建快照**(不 upload、不建目录、不裁剪),只收养远端最新指针。
|
|
957
|
+
// 判据只有一处实现(content-diff.ts):远端最新快照实际携带的分区哈希 vs 本次导出。
|
|
958
|
+
// - force:true = 用户明确要求「就算一样也新建」(覆盖语义),跳过本判定;
|
|
959
|
+
// - 加密快照的 sections 恒空(transport.ts)⇒ 判定 unknown ⇒ 维持既有行为,不新增下载/解密;
|
|
960
|
+
// - 本轮新发现会话删除墓碑时不跳过:墓碑只随新快照的 manifest 传播,跳过等于丢掉删除。
|
|
961
|
+
if (!encrypted && opts.force !== true && bookkeeping.deletedNow.length === 0) {
|
|
962
|
+
const latest = remoteIndex.metas[remoteIndex.metas.length - 1];
|
|
963
|
+
const diff = diffSnapshotContent(latest, undefined, hashSections(plainSections));
|
|
964
|
+
if (diff.reason === 'same-content' && latest !== undefined) {
|
|
965
|
+
await this.recordBaseline(latest.id, plainSections, this.now().toISOString(), {
|
|
966
|
+
remoteSnapshotId: latest.id,
|
|
967
|
+
// P2:本轮内容已被远端收下 ⇒ 待裁决已有结论;但 issue #146 被扣下的分区仍待裁决,绝不一起清掉。
|
|
968
|
+
pendingMerge: pendingAfterPush,
|
|
969
|
+
// G-44:远端观测必须是**远端快照自己**的 sections,绝不由 state.sections 反推
|
|
970
|
+
remoteSections: latest.sections,
|
|
971
|
+
...sessionBookkeeping,
|
|
972
|
+
});
|
|
973
|
+
return {
|
|
974
|
+
ok: true,
|
|
975
|
+
snapshotId: latest.id,
|
|
976
|
+
sections: pushedSections,
|
|
977
|
+
warnings,
|
|
978
|
+
skipped: 'unchanged',
|
|
979
|
+
adoptedSnapshotId: latest.id,
|
|
980
|
+
// 0.4.1 的基线收养是独立事实:本轮可能刚收养了「本机上次被打断的推送」,
|
|
981
|
+
// 紧接着又判定内容一致 —— 两件事都要如实回报(否则面板看不到基线自己动过)。
|
|
982
|
+
...(adopted !== undefined ? { adoptedBase: adopted } : {}),
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
|
|
917
987
|
// ⑥ 设备身份(cloud-sync 借鉴项 ⑥):首次生成后持久化在 sync-state.json(已有则纯读),
|
|
918
988
|
// 随 manifest 上行 → 别的设备在历史列表里能看到「这份快照是哪台机器推的」。
|
|
919
989
|
const device = await resolveDeviceIdentity(this.stateDir, os.hostname(), this.fsx, this.msg);
|
|
@@ -927,7 +997,7 @@ export class SyncEngine {
|
|
|
927
997
|
schemaVersion: CURRENT_SCHEMA_VERSION,
|
|
928
998
|
dshVersion: this.ctx.dshVersion,
|
|
929
999
|
platform: this.ctx.platform as Platform,
|
|
930
|
-
sectionIds:
|
|
1000
|
+
sectionIds: pushedSections,
|
|
931
1001
|
containsSecrets: includeSecrets,
|
|
932
1002
|
// 记录触发通道(git/webdav),供同步历史展示「由哪个通道触发」
|
|
933
1003
|
transport: this.transport.type,
|
|
@@ -952,6 +1022,8 @@ export class SyncEngine {
|
|
|
952
1022
|
}
|
|
953
1023
|
// ② 上传远端(传输通道负责散文件落盘 + 提交推送)
|
|
954
1024
|
await this.transport.upload(snapshot);
|
|
1025
|
+
// issue #141:git 的 latest/ 视图只由明文快照生成(密文无明文镜像);显式告警,否则用户看到「push 成功但 latest/ 是旧内容」无从解释。
|
|
1026
|
+
if (encrypted && this.transport.type === 'git') warnings.push(this.msg('sync.latestSkippedEncrypted'));
|
|
955
1027
|
// ②·1 裁剪远端快照:保留最新 MAX_REMOTE_SNAPSHOTS 个(含刚 push 的)。
|
|
956
1028
|
// 删除失败只告警(进 warnings),不上抛 —— 不阻断 push 主流程。
|
|
957
1029
|
// 放在 upload 之后(保证新快照已推送成功)与 recordBaseline 之前(先管好远端再记基线)。
|
|
@@ -963,16 +1035,19 @@ export class SyncEngine {
|
|
|
963
1035
|
// 不落任何副本的旧行为会让每轮合并都缺共同祖先 → 三方退化成两方、整分区冲突,
|
|
964
1036
|
// 用户被迫反复人工裁决。明文通道不受影响(缺省走 writeAncestor 的明文散文件布局)。
|
|
965
1037
|
...(encrypted ? { ancestorPassword: opts.password! } : {}),
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1038
|
+
...sessionBookkeeping,
|
|
1039
|
+
// issue #140:远端刚收下的就是这份明文 hash ⇒ 记录远端观测(下一次推送/拉取的内容判定起点)。
|
|
1040
|
+
// 加密快照的 sections 恒空 ⇒ 不写(指针一变就清空该字段,判定因此回落 id 比较)。
|
|
1041
|
+
...(encrypted ? {} : { remoteSections: hashSections(plainSections) }),
|
|
1042
|
+
// P2:本机配置已经推成远端最新 ⇒ 之前的待裁决已被这次推送消解,不再挂着误导用户。
|
|
1043
|
+
// issue #146:被扣下的分区没推上去,它们的待裁决必须留下(只剔除已推分区)。
|
|
1044
|
+
pendingMerge: pendingAfterPush,
|
|
970
1045
|
});
|
|
971
1046
|
|
|
972
1047
|
return {
|
|
973
1048
|
ok: true,
|
|
974
1049
|
snapshotId: id,
|
|
975
|
-
sections:
|
|
1050
|
+
sections: pushedSections,
|
|
976
1051
|
warnings,
|
|
977
1052
|
...(adopted !== undefined ? { adoptedBase: adopted } : {}),
|
|
978
1053
|
};
|
|
@@ -1005,7 +1080,15 @@ export class SyncEngine {
|
|
|
1005
1080
|
credentialsIncluded = false; // 读不到 = 不会带凭据;预览如实显示 false
|
|
1006
1081
|
}
|
|
1007
1082
|
}
|
|
1008
|
-
|
|
1083
|
+
// 预览最多读一次状态(扣下集合),不需要记忆化 —— 套 memoAsync 只会多一层空壳。
|
|
1084
|
+
const { targets, held } = await this.pushTargets(opts, warnings, () => loadSyncState(this.stateDir, this.fsx, this.msg));
|
|
1085
|
+
if (targets.length === 0) {
|
|
1086
|
+
// issue #146:两种「空目标」必须分开说 —— 全被冲突扣下(不是错误:push 也回 ok:true + skipped)≠ 没有可同步分区。
|
|
1087
|
+
if (held.length > 0) {
|
|
1088
|
+
return { ok: true, sections: [], remoteSnapshotCount: 0, encrypted, credentialsIncluded, skipped: 'all-conflicted', message: this.msg('sync.pushAllConflicted', { sections: held.join(', ') }) };
|
|
1089
|
+
}
|
|
1090
|
+
return { ok: false, sections: [], remoteSnapshotCount: 0, encrypted, credentialsIncluded, message: this.msg('sync.noPortableSections') };
|
|
1091
|
+
}
|
|
1009
1092
|
const plainSections: Partial<Record<SectionId, SectionData>> = {};
|
|
1010
1093
|
const counts: Partial<Record<SectionId, number>> = {};
|
|
1011
1094
|
/** issue #91:本趟只读预览省掉了本地源打包 ⇒ 与基线不可比的分区(不可断言「无变化」) */
|
|
@@ -1037,7 +1120,7 @@ export class SyncEngine {
|
|
|
1037
1120
|
}
|
|
1038
1121
|
const data = isFileSection(adapter.id) || includeSecrets
|
|
1039
1122
|
? section.data
|
|
1040
|
-
: this.scanner
|
|
1123
|
+
: sanitizeSectionData(adapter, this.scanner, section.data).sanitized;
|
|
1041
1124
|
plainSections[adapter.id] = data as SectionData;
|
|
1042
1125
|
counts[adapter.id] = section.counts ? Object.values(section.counts).reduce((a, b) => a + b, 0) : 0;
|
|
1043
1126
|
}
|
|
@@ -1336,7 +1419,10 @@ export class SyncEngine {
|
|
|
1336
1419
|
* 远端是否出现比本地共同祖先更新的快照(§3.2「检测到远端新快照」)。
|
|
1337
1420
|
* - 远端为空 → false(无物可拉);
|
|
1338
1421
|
* - 远端指针未知(lastSnapshotId='':从未同步 / 远端 id 未知)且远端非空 → true(首次可拉);
|
|
1339
|
-
* -
|
|
1422
|
+
* - 否则比较**内容**(issue #140):远端最新快照实际携带的分区哈希 vs 上次记录的远端观测。
|
|
1423
|
+
* 只比 id 时,任何一次新推送(哪怕分区逐字相同)都会判成「有新生」,白跑 download + 合并。
|
|
1424
|
+
* - 两边任一观测缺失(加密快照 sections 恒空 / 旧 state 没记过观测)⇒ 回落 id 比较,
|
|
1425
|
+
* 绝不把「读不到」猜成「没变」(判据与回落规则只在 content-diff.ts)。
|
|
1340
1426
|
* 只读远端列表(transport.list),不做下载/合并。
|
|
1341
1427
|
*
|
|
1342
1428
|
* 前提:lastSnapshotId 必须是**远端**快照 id(P0-7)。旧实现把本地生成的快照 id 也写进去,
|
|
@@ -1349,10 +1435,13 @@ export class SyncEngine {
|
|
|
1349
1435
|
async hasNewRemoteSnapshot(listed?: readonly SyncSnapshotMeta[]): Promise<boolean> {
|
|
1350
1436
|
const metas = listed ?? await this.transport.list();
|
|
1351
1437
|
if (metas.length === 0) return false;
|
|
1352
|
-
const
|
|
1438
|
+
const latest = metas[metas.length - 1]!; // list 按 createdAt 升序 → 最新在末
|
|
1353
1439
|
const state = await loadSyncState(this.stateDir, this.fsx, this.msg);
|
|
1354
1440
|
if (state.lastSnapshotId === '') return true;
|
|
1355
|
-
|
|
1441
|
+
const diff = diffSnapshotContent(latest, state.lastRemoteSections);
|
|
1442
|
+
// unknown(加密快照 / 旧 state 没有远端观测)⇒ 只能比 id:这是「读不到」的唯一退路。
|
|
1443
|
+
if (diff.reason === 'unknown') return latest.id !== state.lastSnapshotId;
|
|
1444
|
+
return diff.changed;
|
|
1356
1445
|
}
|
|
1357
1446
|
|
|
1358
1447
|
/**
|
|
@@ -1371,28 +1460,12 @@ export class SyncEngine {
|
|
|
1371
1460
|
}
|
|
1372
1461
|
|
|
1373
1462
|
/**
|
|
1374
|
-
*
|
|
1375
|
-
*
|
|
1376
|
-
* - 任一 pushTargets 分区(portable + 本次放行的可选分区)导出 hash ≠ 基线 → true;
|
|
1377
|
-
* - 全部一致 → false(无本地改动,不上传)。只读本地导出 + sync-state,不碰远端。
|
|
1378
|
-
* 判定集合必须 == 推送载荷集合,且被比较字节必须可复现(细节与实测 → docs/evidence/sync-channel.md)。
|
|
1463
|
+
* 本地**会进载荷**的配置与上次基线相比是否有变化(§3.1,「看变化」)。
|
|
1464
|
+
* 判定集合 == 推送载荷集合(candidateAdapters),字节口径与载荷同源 —— 实现与理由见 local-changes.ts。
|
|
1379
1465
|
*/
|
|
1380
1466
|
async hasLocalChanges(): Promise<boolean> {
|
|
1381
1467
|
const state = await loadSyncState(this.stateDir, this.fsx, this.msg);
|
|
1382
|
-
|
|
1383
|
-
for (const adapter of this.pushTargets(undefined, [])) {
|
|
1384
|
-
let section: ExportSection;
|
|
1385
|
-
try {
|
|
1386
|
-
section = await adapter.export(this.ctx, { includeSecrets: false });
|
|
1387
|
-
} catch {
|
|
1388
|
-
continue; // 单项导出失败不影响判定(与 push 单项跳过语义一致)
|
|
1389
|
-
}
|
|
1390
|
-
const data = isFileSection(adapter.id) ? section.data : this.scanner.scanAndRedact(section.data).sanitized;
|
|
1391
|
-
const recorded = state.sections[adapter.id];
|
|
1392
|
-
if (recorded === undefined) return true; // 基线缺该分区 → 视为有变化
|
|
1393
|
-
if (recorded.hash !== hashSection(data as SectionData)) return true;
|
|
1394
|
-
}
|
|
1395
|
-
return false;
|
|
1468
|
+
return hasLocalSectionChanges({ state, adapters: this.candidateAdapters(), ctx: this.ctx, scanner: this.scanner });
|
|
1396
1469
|
}
|
|
1397
1470
|
|
|
1398
1471
|
/**
|
|
@@ -1504,7 +1577,7 @@ export class SyncEngine {
|
|
|
1504
1577
|
} catch {
|
|
1505
1578
|
continue;
|
|
1506
1579
|
}
|
|
1507
|
-
const data = isFileSection(adapter.id) ? section.data : this.scanner
|
|
1580
|
+
const data = isFileSection(adapter.id) ? section.data : sanitizeSectionData(adapter, this.scanner, section.data).sanitized;
|
|
1508
1581
|
localSections[adapter.id] = data as SectionData;
|
|
1509
1582
|
}
|
|
1510
1583
|
const portableIds = this.pullSectionIds();
|
|
@@ -1518,7 +1591,7 @@ export class SyncEngine {
|
|
|
1518
1591
|
if (portableIds.has(id as SectionId)) ancestorPortable[id as SectionId] = data as SectionData;
|
|
1519
1592
|
}
|
|
1520
1593
|
}
|
|
1521
|
-
const plan = mergeSections(localSections, remotePortable, ancestorPortable, { deletePlugins: this.deletePlugins });
|
|
1594
|
+
const plan = mergeSections(localSections, remotePortable, ancestorPortable, { deletePlugins: this.deletePlugins, selfPluginName: this.selfPluginName });
|
|
1522
1595
|
// 结果**经返回值**交给调用方(previewMerge / applyMergeResolutions 都用这一份,不会二次下载);
|
|
1523
1596
|
// 这里只留两个进程内备忘:祖先可用性(预览要如实说明「为什么全是冲突」)与三方输入
|
|
1524
1597
|
// (applyMergeResolutions 要把分区级裁决落回**整分区**数据)。
|
|
@@ -1694,32 +1767,20 @@ export class SyncEngine {
|
|
|
1694
1767
|
};
|
|
1695
1768
|
}
|
|
1696
1769
|
|
|
1697
|
-
/**
|
|
1770
|
+
/** P2(2026-11-14 真机事故):自动同步撞冲突时把分区落成待裁决;实现与为什么见 pending-merge.ts。 */
|
|
1771
|
+
async recordPendingMerge(sections: readonly SectionId[]): Promise<PendingMerge | null> {
|
|
1772
|
+
const deps = { stateDir: this.stateDir, fsx: this.fsx, msg: this.msg };
|
|
1773
|
+
return persistPendingMerge(deps, this.lastMergedRemoteSnapshotId, sections, this.now().toISOString());
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
/** 组装 pendingMerge 记录(同一远端快照上连续冲突保留首次时间);见 pending-merge.ts。 */
|
|
1698
1777
|
private pendingMergeFor(state: SyncState, remoteSnapshotId: string, sections: SectionId[]): PendingMerge {
|
|
1699
|
-
|
|
1700
|
-
? state.pendingMerge.since
|
|
1701
|
-
: this.now().toISOString();
|
|
1702
|
-
return { remoteSnapshotId, sections, since };
|
|
1778
|
+
return buildPendingMerge(state, remoteSnapshotId, sections, this.now().toISOString());
|
|
1703
1779
|
}
|
|
1704
1780
|
|
|
1705
|
-
/**
|
|
1706
|
-
* 基线纪律的**纯状态**写入(不写祖先副本、不碰远端):仅在本机没有任何配置写入时使用。
|
|
1707
|
-
*
|
|
1708
|
-
* - pending 提供 → 写 pendingMerge;undefined → 清除该字段(「全部裁决完」);
|
|
1709
|
-
* - advanceRemoteId 提供 → 把远端指针推进到该快照 id(缺省 = 保持不变)。
|
|
1710
|
-
*
|
|
1711
|
-
* 为什么不走 recordBaseline:那条路径会重建祖先副本并只带本次应用的分区 —— 在「没有应用任何分区」
|
|
1712
|
-
* 或「仍有未裁决冲突」时都会把共同基线改坏(下一轮所有分区都退化成「无祖先 → 冲突」)。
|
|
1713
|
-
*/
|
|
1781
|
+
/** 基线纪律的纯状态写入(不碰祖先副本、不推远端);为什么不用 recordBaseline 见 pending-merge.ts。 */
|
|
1714
1782
|
private async writeMergeBaseline(opts: { pending?: PendingMerge; advanceRemoteId?: string }): Promise<void> {
|
|
1715
|
-
|
|
1716
|
-
if (opts.pending === undefined) delete state.pendingMerge;
|
|
1717
|
-
else state.pendingMerge = opts.pending;
|
|
1718
|
-
if (opts.advanceRemoteId !== undefined) {
|
|
1719
|
-
state.lastSnapshotId = opts.advanceRemoteId;
|
|
1720
|
-
state.lastSyncAt = this.now().toISOString();
|
|
1721
|
-
}
|
|
1722
|
-
await saveSyncState(this.stateDir, state, this.fsx);
|
|
1783
|
+
await persistMergeBaseline({ stateDir: this.stateDir, fsx: this.fsx, msg: this.msg }, opts, this.now().toISOString());
|
|
1723
1784
|
}
|
|
1724
1785
|
|
|
1725
1786
|
/**
|
|
@@ -1741,7 +1802,7 @@ export class SyncEngine {
|
|
|
1741
1802
|
const section = await adapter.export(this.ctx, { includeSecrets: false });
|
|
1742
1803
|
out[adapter.id] = (isFileSection(adapter.id)
|
|
1743
1804
|
? section.data
|
|
1744
|
-
: this.scanner
|
|
1805
|
+
: sanitizeSectionData(adapter, this.scanner, section.data).sanitized) as SectionData;
|
|
1745
1806
|
} catch {
|
|
1746
1807
|
return null;
|
|
1747
1808
|
}
|
|
@@ -1753,89 +1814,31 @@ export class SyncEngine {
|
|
|
1753
1814
|
* 记录祖先基线:写本地祖先副本 + 更新 sync-state(每分区 hash/updatedAt、lastSyncAt、transport、
|
|
1754
1815
|
* 远端指针 lastSnapshotId、本地祖先目录名 ancestorId)+ 裁剪到 keep。
|
|
1755
1816
|
*
|
|
1756
|
-
*
|
|
1757
|
-
*
|
|
1758
|
-
* - `opts.remoteSnapshotId`:该基线在**远端**对应的快照 id(写入 `lastSnapshotId`)。缺省 = snapshotId
|
|
1759
|
-
* (push 路径两者天然相同);合并/应用路径**必须显式传**,否则 lastSnapshotId 会退化成「一个远端
|
|
1760
|
-
* 并不存在的本地 id」→ hasNewRemoteSnapshot() 恒判「远端有新生」,每轮白跑 list + download + merge。
|
|
1761
|
-
* 传入 `''` 表示「远端 id 未知」——宁可留空,也不要把本地 id 冒充成远端 id。
|
|
1762
|
-
* - `opts.writeAncestor === false`:不落本地祖先副本,`ancestorId` 一并置 '' ——
|
|
1763
|
-
* 绝不把一个本地并不存在的目录名写进状态(旧实现正是这样让下一轮 merge 直接抛错)。
|
|
1764
|
-
* - `opts.ancestorPassword`(issue #107):祖先副本落**密文**(manifest.encrypted + 单密文载荷);
|
|
1765
|
-
* 加密快照 push 必须传,否则下轮三方合并缺共同祖先、整分区冲突。
|
|
1766
|
-
* - `opts.preserveAncestor === true`(合并仍有未裁决冲突):祖先副本与 ancestorId **保持不动** ——
|
|
1767
|
-
* 共同基线必须仍是「本机与远端都认可的上一版」;拿只带本次应用分区的副本去覆盖它,会让
|
|
1768
|
-
* 下一轮所有分区都退化成「无祖先 → 冲突」。
|
|
1769
|
-
* - `opts.pendingMerge`(基线纪律):提供即写入;`null` = 清除该字段;缺省 = 不动(既有行为不变)。
|
|
1817
|
+
* 实现整体在 `baseline-record.ts`:P0-7 的两个 id 语义、G-44 的「远端观测 vs 本机观测」口径
|
|
1818
|
+
* 都写在那份文件头里,改这里之前先读它。引擎只把本机环境(快照目录、通道身份、时钟、文案)交出去。
|
|
1770
1819
|
*/
|
|
1771
1820
|
async recordBaseline(
|
|
1772
1821
|
snapshotId: string,
|
|
1773
|
-
// 基线**恒为明文**(加密快照的基线 hash 也用明文算,供 hasLocalChanges 比较);
|
|
1774
|
-
// 需要落盘副本时由 opts.ancestorPassword 决定写明文还是密文目录。
|
|
1775
1822
|
sections: Partial<Record<SectionId, SectionData>>,
|
|
1776
1823
|
nowIso?: string,
|
|
1777
|
-
opts: {
|
|
1778
|
-
writeAncestor?: boolean;
|
|
1779
|
-
/** 提供即把祖先副本写成**密文**(密码仅本次内存使用;issue #107) */
|
|
1780
|
-
ancestorPassword?: string;
|
|
1781
|
-
remoteSnapshotId?: string;
|
|
1782
|
-
/** 保留当前祖先副本与 ancestorId(缺省 false = 既有行为逐字不变) */
|
|
1783
|
-
preserveAncestor?: boolean;
|
|
1784
|
-
/** 待裁决冲突记录:null = 清除;缺省 = 不动该字段 */
|
|
1785
|
-
pendingMerge?: PendingMerge | null;
|
|
1786
|
-
/** P1-5:本轮**实际带走**的会话单元(提供即覆盖;缺省 = 保留原记录) */
|
|
1787
|
-
sessionUnits?: string[];
|
|
1788
|
-
/** P1-5:本轮累积的删除墓碑(提供即覆盖;缺省 = 保留原记录) */
|
|
1789
|
-
deletedSessions?: string[];
|
|
1790
|
-
} = {},
|
|
1824
|
+
opts: RecordBaselineOptions = {},
|
|
1791
1825
|
): Promise<void> {
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
const manifest: SyncSnapshot['manifest'] = {
|
|
1802
|
-
schemaVersion: CURRENT_SCHEMA_VERSION,
|
|
1826
|
+
await recordBaselineAt({
|
|
1827
|
+
snapshotId,
|
|
1828
|
+
sections,
|
|
1829
|
+
...(nowIso === undefined ? {} : { nowIso }),
|
|
1830
|
+
opts,
|
|
1831
|
+
env: {
|
|
1832
|
+
fsx: this.fsx,
|
|
1833
|
+
stateDir: this.stateDir,
|
|
1834
|
+
...(this.localSnapshotsDir === undefined ? {} : { localSnapshotsDir: this.localSnapshotsDir }),
|
|
1803
1835
|
dshVersion: this.ctx.dshVersion,
|
|
1804
1836
|
platform: this.ctx.platform as Platform,
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
};
|
|
1811
|
-
if (encryptedAncestor) {
|
|
1812
|
-
const encryptedSections = await encryptSectionsPayload(sections, ancestorPassword);
|
|
1813
|
-
await writeEncryptedAncestor(this.localSnapshotsDir, { id: snapshotId, createdAt: ts, manifest, sections: encryptedSections }, this.fsx);
|
|
1814
|
-
} else {
|
|
1815
|
-
await writeAncestor(this.localSnapshotsDir, { id: snapshotId, createdAt: ts, manifest, sections }, this.fsx);
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
// 2) 更新 sync-state:远端指针 + 本地祖先目录名 + 每分区 hash/updatedAt + lastSyncAt + transport
|
|
1819
|
-
const state = await loadSyncState(this.stateDir, this.fsx, this.msg);
|
|
1820
|
-
state.lastSnapshotId = opts.remoteSnapshotId ?? snapshotId;
|
|
1821
|
-
// preserveAncestor:祖先目录名一并保持不动(既不是 snapshotId,也不是 '')
|
|
1822
|
-
if (!preserveAncestor) state.ancestorId = writesAncestorCopy ? snapshotId : '';
|
|
1823
|
-
state.lastSyncAt = ts;
|
|
1824
|
-
state.transport = { type: this.transport.type, ref: this.transportRef };
|
|
1825
|
-
// 基线纪律:null = 清除(全部裁决完);undefined = 不动该字段(既有调用方零感知)
|
|
1826
|
-
if (opts.pendingMerge === null) delete state.pendingMerge;
|
|
1827
|
-
else if (opts.pendingMerge !== undefined) state.pendingMerge = opts.pendingMerge;
|
|
1828
|
-
// P1-5:只在调用方明确提供时覆盖(否则保留既有记录,绝不因某条路径不跟踪而清空)
|
|
1829
|
-
if (opts.sessionUnits !== undefined) state.sessionUnits = [...opts.sessionUnits];
|
|
1830
|
-
if (opts.deletedSessions !== undefined) state.deletedSessions = [...opts.deletedSessions];
|
|
1831
|
-
for (const [sid, data] of Object.entries(sections)) {
|
|
1832
|
-
state.sections[sid as SectionId] = { hash: hashSection(data as SectionData), updatedAt: ts };
|
|
1833
|
-
}
|
|
1834
|
-
await saveSyncState(this.stateDir, state, this.fsx);
|
|
1835
|
-
// 3) 裁剪祖先副本(最近 N 个);preserveAncestor 时本轮没有新副本,不参与裁剪
|
|
1836
|
-
if (!preserveAncestor && this.localSnapshotsDir !== undefined) {
|
|
1837
|
-
await pruneAncestors(this.localSnapshotsDir, DEFAULT_ANCESTOR_KEEP, this.fsx);
|
|
1838
|
-
}
|
|
1837
|
+
transport: { type: this.transport.type, ref: this.transportRef },
|
|
1838
|
+
now: () => this.now(),
|
|
1839
|
+
msg: this.msg,
|
|
1840
|
+
},
|
|
1841
|
+
});
|
|
1839
1842
|
}
|
|
1840
1843
|
|
|
1841
1844
|
/**
|
|
@@ -1881,6 +1884,7 @@ export class SyncEngine {
|
|
|
1881
1884
|
if (!this.importer) {
|
|
1882
1885
|
throw new Error(this.msg('sync.applyMergePlanNoImporter'));
|
|
1883
1886
|
}
|
|
1887
|
+
const importer = this.importer;
|
|
1884
1888
|
const appliedIds: SectionId[] = apply.autoApply.map((r) => r.id);
|
|
1885
1889
|
// 0) 空 autoApply:无物可应用,直接短路(不构造 ZIP、不调 Importer)
|
|
1886
1890
|
if (appliedIds.length === 0) {
|
|
@@ -1906,28 +1910,22 @@ export class SyncEngine {
|
|
|
1906
1910
|
const tempSnapshot = bundle.tempSnapshot;
|
|
1907
1911
|
const zipPath = await this.snapshotToZip(tempSnapshot, this.pullSectionIds());
|
|
1908
1912
|
try {
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
// issue #45:合并路径的映射来自 merge() 记下的远端 sourceHome + 用户映射
|
|
1913
|
+
// issue #136 B:两趟计划 + 待裁决面(判定与理由见 `planMergeApply` 的文档注释;不再兜底 replace)。
|
|
1914
|
+
const { plan, heldReview, heldWarnings } = await planMergeApply({
|
|
1915
|
+
zipPath,
|
|
1913
1916
|
pathMappings: opts.pathMappings ?? this.lastMergedPathMappings,
|
|
1917
|
+
appliedIds,
|
|
1918
|
+
createImportPlan: (zip, decisions) => importer.createImportPlan(zip, decisions),
|
|
1919
|
+
heldConflictMessage: (count, sections) => this.msg('sync.mergeHeldConflicts', { count: String(count), sections: sections.join(', ') }),
|
|
1914
1920
|
});
|
|
1915
1921
|
if (!plan.items.length) {
|
|
1916
1922
|
// 没有可执行项 → 视为 ok 但空 applied
|
|
1917
1923
|
return { ok: true, applied: [], restoreId: '', rolledBack: false, review: [], warnings: [] };
|
|
1918
1924
|
}
|
|
1919
1925
|
// 2) 兜底:先建快照(拿到 restoreId 给 UI 一键回滚用)
|
|
1920
|
-
const
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
snapshot = await createSnapshot({
|
|
1924
|
-
ctx: this.ctx,
|
|
1925
|
-
plan,
|
|
1926
|
-
sourceZip: zipPath,
|
|
1927
|
-
store,
|
|
1928
|
-
adapters: this.adapters,
|
|
1929
|
-
});
|
|
1930
|
-
} catch (backupErr) {
|
|
1926
|
+
const snap = await createMergeApplySnapshot({ ctx: this.ctx, plan, zipPath, storeDir: this.rollbackSnapshotsDir, adapters: this.adapters });
|
|
1927
|
+
if (!snap.ok) {
|
|
1928
|
+
const backupErr = snap.error;
|
|
1931
1929
|
return {
|
|
1932
1930
|
ok: false,
|
|
1933
1931
|
applied: [],
|
|
@@ -1937,9 +1935,9 @@ export class SyncEngine {
|
|
|
1937
1935
|
warnings: [this.msg('sync.preApplySnapshotFailed', { err: backupErr instanceof Error ? backupErr.message : String(backupErr) })],
|
|
1938
1936
|
};
|
|
1939
1937
|
}
|
|
1940
|
-
|
|
1941
|
-
//
|
|
1942
|
-
//
|
|
1938
|
+
const { store, snapshot } = snap;
|
|
1939
|
+
// 3) 真正执行:rollbackOnError 取单一缺省 → 任一失败整体回滚;自动同步没有密码,
|
|
1940
|
+
// 恒不注入 decryptedCredentials(加密快照本就不进自动同步)。
|
|
1943
1941
|
const result = await this.importer.executeImportPlan(zipPath, plan, {
|
|
1944
1942
|
confirm: true,
|
|
1945
1943
|
rollbackOnError: DEFAULT_ROLLBACK_ON_ERROR,
|
|
@@ -1963,13 +1961,11 @@ export class SyncEngine {
|
|
|
1963
1961
|
rollbackFull: rb.full,
|
|
1964
1962
|
};
|
|
1965
1963
|
}
|
|
1966
|
-
// 4') issue #132
|
|
1967
|
-
//
|
|
1964
|
+
// 4') issue #132:跟随远端删除插件(手动与自动共享此路径),必须先于基线重导出 ——
|
|
1965
|
+
// 基线要记录「删完之后」的真实清单,否则祖先仍带着刚删的包、每轮重复提删除。
|
|
1968
1966
|
// 4'') undo 线索:删掉的插件写进本次回滚快照,恢复计划据此反向重装;记不上只告警。
|
|
1969
|
-
const pluginStep = await applyPluginRemovalStep({
|
|
1970
|
-
|
|
1971
|
-
uninstall: (name) => this.ctx.plugins.uninstall(name), msg: this.msg,
|
|
1972
|
-
});
|
|
1967
|
+
const pluginStep = await applyPluginRemovalStep({ appliedIds, plan: await this.pluginRemovalPlan(),
|
|
1968
|
+
enabled: this.deletePlugins, uninstall: (name) => this.ctx.plugins.uninstall(name), msg: this.msg });
|
|
1973
1969
|
const undoWarnings = await recordPluginRemovalUndo({
|
|
1974
1970
|
removals: pluginStep.removals, snapshotId: snapshot.id,
|
|
1975
1971
|
record: store.recordPluginRemovals?.bind(store), msg: this.msg,
|
|
@@ -1987,8 +1983,8 @@ export class SyncEngine {
|
|
|
1987
1983
|
applied: appliedIds,
|
|
1988
1984
|
restoreId: snapshot.id,
|
|
1989
1985
|
rolledBack: false,
|
|
1990
|
-
review:
|
|
1991
|
-
warnings: [...(result.warnings ?? []), ...pluginStep.warnings, ...undoWarnings, this.msg('sync.baselineRexportFailed', { sections: appliedIds.join(', ') })],
|
|
1986
|
+
review: heldReview,
|
|
1987
|
+
warnings: [...(result.warnings ?? []), ...pluginStep.warnings, ...undoWarnings, ...heldWarnings, this.msg('sync.baselineRexportFailed', { sections: appliedIds.join(', ') })],
|
|
1992
1988
|
...(pluginStep.removals.length === 0 ? {} : { pluginRemovals: pluginStep.removals, needsRestart: true }),
|
|
1993
1989
|
};
|
|
1994
1990
|
}
|
|
@@ -2003,8 +1999,8 @@ export class SyncEngine {
|
|
|
2003
1999
|
applied: appliedIds,
|
|
2004
2000
|
restoreId: snapshot.id,
|
|
2005
2001
|
rolledBack: false,
|
|
2006
|
-
review:
|
|
2007
|
-
warnings: [...(result.warnings ?? []), ...pluginStep.warnings, ...undoWarnings],
|
|
2002
|
+
review: heldReview,
|
|
2003
|
+
warnings: [...(result.warnings ?? []), ...pluginStep.warnings, ...undoWarnings, ...heldWarnings],
|
|
2008
2004
|
// 删过插件必须重启(与安装同语义):报告不能只说「已应用」
|
|
2009
2005
|
...(pluginStep.removals.length === 0 ? {} : { pluginRemovals: pluginStep.removals, needsRestart: true }),
|
|
2010
2006
|
};
|