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
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
* → engine.applyMergePlan(autoApply) 写入本地
|
|
33
33
|
* - Phase C: 完整双向 → engine.push() 上传。两处策略:
|
|
34
34
|
* ① 无冲突且推送被远端推进挡下 → skipped/partial + skipReason='conflict'(等人工);
|
|
35
|
-
* ② conflictPolicy='local'(**只有用户显式选过才生效**;缺省 ask
|
|
35
|
+
* ② conflictPolicy='local'(**只有用户显式选过才生效**;缺省 ask)且本轮有冲突**或仍有待裁决存量** → **不写本地**,
|
|
36
36
|
* 改 engine.push({force:true}) 把本机版本推成新的远端最新(被覆盖的远端旧版本仍在远端历史快照里
|
|
37
37
|
* 可回滚),状态记 partial + skipReason='conflict-kept-local'(绝不谎报 success);
|
|
38
38
|
* SYN-05:首轮 / 远端有新快照时即使选了 local 也降级 ask 并记 forced=true(见
|
|
@@ -65,6 +65,8 @@ import type { AutosyncConfig, AutosyncInterval } from './autosync-config.ts';
|
|
|
65
65
|
import { readSyncConfigFor, isGitConfig, isWebDavConfig, isS3Config, isGistConfig, SYNC_CHANNELS } from './sync-config.ts';
|
|
66
66
|
import type { SyncConfig, SyncConfigIssue, SyncTransportType } from './sync-config.ts';
|
|
67
67
|
import { readSyncHistory, appendAutosyncEntry, markAutosyncNotified } from './sync-history.ts';
|
|
68
|
+
import { loadSyncState } from './sync-state.ts';
|
|
69
|
+
import { repeatHistorySignature } from './autosync-repeat.ts';
|
|
68
70
|
import { classifyMergePlan } from './risk.ts';
|
|
69
71
|
import type { AutosyncHistoryEntry } from './sync-history.ts';
|
|
70
72
|
import type { AutosyncConflictPolicy } from './autosync-config.ts';
|
|
@@ -125,6 +127,13 @@ export interface AutosyncRunResult {
|
|
|
125
127
|
* 「从来没配」在界面上长得一模一样,用户会反复重填同一个被拒地址。
|
|
126
128
|
*/
|
|
127
129
|
configIssue?: string;
|
|
130
|
+
/**
|
|
131
|
+
* issue #136:本轮下行**实际产生的告警**(例:patch 行里被脱敏剥空的叶子已保留本机值、
|
|
132
|
+
* 叶级未裁决冲突被扣下)。非空 = 有内容没落地,终态不得再报成「成功且零告警」。
|
|
133
|
+
*/
|
|
134
|
+
warnings?: string[];
|
|
135
|
+
/** issue #136:本轮被保留待裁决的叶级冲突所在分区(与 warnings 同源,供界面定位)。 */
|
|
136
|
+
heldSections?: SectionId[];
|
|
128
137
|
}
|
|
129
138
|
|
|
130
139
|
/**
|
|
@@ -135,7 +144,10 @@ export interface AutosyncRunResult {
|
|
|
135
144
|
* - **首轮**(从未跑过)或**远端有新快照**:即使显式选了 'local' 也强制降级 ask(forcedAsk)——
|
|
136
145
|
* 这两个时刻正是「远端最新改动只在历史快照里」的事故现场,静默覆盖等于替用户丢数据;
|
|
137
146
|
* 降级记 forced,界面才能说清「这次没按你的 local 走」;
|
|
138
|
-
* - 只有「显式 local + 非高危时刻 + 真有冲突」才 force
|
|
147
|
+
* - 只有「显式 local + 非高危时刻 + 真有冲突」才 force;
|
|
148
|
+
* - 「真有冲突」= **本轮新判出的冲突** ∪ **磁盘上仍在等裁决的分区**(`held`,issue #146 F9):
|
|
149
|
+
* local 是用户的**长期决定**,不能只对本轮新冲突生效 —— 否则上一轮攒下的待裁决永远等不到结论,
|
|
150
|
+
* 每轮都「不推也不报错」地空转(用户明明选了「本机优先」)。只读条数、不读内容,判定仍是纯函数。
|
|
139
151
|
*
|
|
140
152
|
* 纯函数(无状态、无 I/O):调度层与单测共用同一份判定,避免两处各写一遍阈值。
|
|
141
153
|
*/
|
|
@@ -144,12 +156,15 @@ export function resolveConflictPushPolicy(args: {
|
|
|
144
156
|
firstRun: boolean;
|
|
145
157
|
remoteNew: boolean;
|
|
146
158
|
conflicted: number;
|
|
159
|
+
/** 磁盘上仍在等裁决的分区数(缺省 0 = 只看本轮冲突;读不到状态也按 0 处理,绝不因此 force)。 */
|
|
160
|
+
held?: number;
|
|
147
161
|
}): { policy: AutosyncConflictPolicy; force: boolean; forcedAsk: boolean } {
|
|
148
162
|
const configured = args.configuredPolicy ?? DEFAULT_AUTOSYNC_CONFLICT_POLICY;
|
|
149
163
|
// forcedAsk 只描述「用户选了 local,但本轮被降级」——缺省 ask 不算被强制(那不是用户的决定被推翻)。
|
|
150
164
|
const forcedAsk = configured === 'local' && (args.firstRun || args.remoteNew);
|
|
151
165
|
const policy: AutosyncConflictPolicy = forcedAsk ? 'ask' : configured;
|
|
152
|
-
|
|
166
|
+
const outstanding = args.conflicted + (args.held ?? 0);
|
|
167
|
+
return { policy, force: policy === 'local' && outstanding > 0, forcedAsk };
|
|
153
168
|
}
|
|
154
169
|
|
|
155
170
|
/**
|
|
@@ -242,6 +257,12 @@ export interface AutoSyncSchedulerOptions {
|
|
|
242
257
|
makeWatcher?: (opts: WatcherFactoryOptions) => SyncWatcher;
|
|
243
258
|
/** 触发合并窗口(ms):连续保存/连续远端探测只跑一轮。缺省 3000。 */
|
|
244
259
|
minTriggerGapMs?: number;
|
|
260
|
+
/**
|
|
261
|
+
* 读磁盘上仍在等裁决的分区(issue #146 F9)。缺省读 `<syncDir>/sync-state.json` 的 pendingMerge,
|
|
262
|
+
* 与 SyncEngine 的 stateDir 同源(装配处两处都是 syncDir);测试注入内存实现,免碰真实文件。
|
|
263
|
+
* 读失败 → 空数组(判定退回「只看本轮冲突」的老口径),绝不因为读不到状态就 force。
|
|
264
|
+
*/
|
|
265
|
+
readPendingMerge?: () => Promise<readonly SectionId[]>;
|
|
245
266
|
}
|
|
246
267
|
|
|
247
268
|
export class AutoSyncScheduler {
|
|
@@ -287,10 +308,19 @@ export class AutoSyncScheduler {
|
|
|
287
308
|
private readonly profile: string | undefined;
|
|
288
309
|
private readonly makeWatcher: ((opts: WatcherFactoryOptions) => SyncWatcher) | undefined;
|
|
289
310
|
private readonly minTriggerGapMs: number;
|
|
311
|
+
private readonly readPendingMerge: () => Promise<readonly SectionId[]>;
|
|
290
312
|
/** SEC-03:已 warn 过的「地址被拒」成因(键 = 通道 + 成因文本),进程内去重。 */
|
|
291
313
|
private readonly reportedConfigIssues = new Set<string>();
|
|
292
314
|
private stopped = false;
|
|
293
315
|
private running = false;
|
|
316
|
+
/**
|
|
317
|
+
* P1(2026-11-14 真机事故):上一轮真正落盘的历史签名,见 autosync-repeat.ts。
|
|
318
|
+
* 与本轮签名相同 → 这一轮不追加历史(同一结论连续播报把 200 条历史刷满、首页变成
|
|
319
|
+
* 每 1 分钟一条的噪音);但 lastRunAt / lastRunStatus / 跳过计数仍逐轮刷新。
|
|
320
|
+
*/
|
|
321
|
+
private repeatSignature: string | null = null;
|
|
322
|
+
/** 本轮历史是否被压掉 —— writeFinalConfig 据此保留上一条真记录的 lastRunHistoryId。 */
|
|
323
|
+
private historyDeduped = false;
|
|
294
324
|
|
|
295
325
|
constructor(opts: AutoSyncSchedulerOptions) {
|
|
296
326
|
this.syncDir = opts.syncDir;
|
|
@@ -314,6 +344,13 @@ export class AutoSyncScheduler {
|
|
|
314
344
|
this.profile = opts.profile;
|
|
315
345
|
this.makeWatcher = opts.makeWatcher ?? defaultMakeWatcher;
|
|
316
346
|
this.minTriggerGapMs = opts.minTriggerGapMs ?? 3000;
|
|
347
|
+
this.readPendingMerge = opts.readPendingMerge ?? (async () => {
|
|
348
|
+
try {
|
|
349
|
+
return (await loadSyncState(this.syncDir)).pendingMerge?.sections ?? [];
|
|
350
|
+
} catch {
|
|
351
|
+
return [];
|
|
352
|
+
}
|
|
353
|
+
});
|
|
317
354
|
}
|
|
318
355
|
|
|
319
356
|
/**
|
|
@@ -327,6 +364,16 @@ export class AutoSyncScheduler {
|
|
|
327
364
|
channel: SyncTransportType,
|
|
328
365
|
entry: AutosyncHistoryEntry & { forced?: boolean; configIssue?: string },
|
|
329
366
|
): Promise<void> {
|
|
367
|
+
const signature = repeatHistorySignature(channel, entry);
|
|
368
|
+
if (signature !== null && signature === this.repeatSignature) {
|
|
369
|
+
// 同一状态的第 N 轮(典型:远端快照一直比基线新,60s 轮询每轮都撞同一份冲突)。
|
|
370
|
+
// 不写 sync-history、也不写首页统一历史;但这一轮仍要刷新「上次运行」,
|
|
371
|
+
// 否则界面会停在几十分钟前的 lastRunAt,用户以为自动同步停了。
|
|
372
|
+
this.historyDeduped = true;
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
this.repeatSignature = signature;
|
|
376
|
+
this.historyDeduped = false;
|
|
330
377
|
await this.appendHistoryFn({ ...entry, transport: channel });
|
|
331
378
|
}
|
|
332
379
|
|
|
@@ -404,32 +451,42 @@ export class AutoSyncScheduler {
|
|
|
404
451
|
});
|
|
405
452
|
}
|
|
406
453
|
|
|
407
|
-
/**
|
|
454
|
+
/**
|
|
455
|
+
* 兜底间隔定时器:每个 enabled 通道按各自 interval 排一次性定时器,触发后**只重排自己**。
|
|
456
|
+
*
|
|
457
|
+
* 早期实现是「清掉全部通道再统一重排」:webdav 5m 每跑一轮就把 git 30m 的定时器清掉重排,
|
|
458
|
+
* 30m 永远等不到 → 纯定时器模式下慢通道永久饥饿(审计 P5-1,虚拟时钟 180min 实测 git 只跑 1 次)。
|
|
459
|
+
*/
|
|
408
460
|
private scheduleIntervalTimers(): void {
|
|
409
461
|
for (const timer of this.timers.values()) this.clearTimer(timer);
|
|
410
462
|
this.timers.clear();
|
|
411
463
|
// 通道清单唯一来源 = SYNC_CHANNELS(此前同一数组在本文件写了两遍:漏改一处即某通道永不排期)
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
464
|
+
for (const channel of SYNC_CHANNELS) this.scheduleChannelTimer(channel);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/** 单个通道的一次性 interval 排期(触发后只重排这一个通道)。 */
|
|
468
|
+
private scheduleChannelTimer(channel: SyncTransportType): void {
|
|
469
|
+
const existing = this.timers.get(channel);
|
|
470
|
+
if (existing !== undefined) this.clearTimer(existing);
|
|
471
|
+
this.timers.delete(channel);
|
|
472
|
+
void this.readConfig(channel).then((cfg) => {
|
|
473
|
+
if (this.stopped || !cfg.enabled) return;
|
|
474
|
+
const ms = intervalToMs(cfg.interval);
|
|
475
|
+
const timer = this.setTimer(() => {
|
|
476
|
+
// 一次性定时器:触发后立即从表移除,避免 reload() 清理到已失效的句柄
|
|
477
|
+
this.timers.delete(channel);
|
|
478
|
+
if (this.stopped) return;
|
|
479
|
+
void this.runOnce(channel, { reason: 'interval' })
|
|
480
|
+
.catch((err) => {
|
|
481
|
+
this.host.log.error(`自动同步定时触发失败(${channel})`, { error: err instanceof Error ? err.message : String(err) });
|
|
482
|
+
})
|
|
483
|
+
.then(() => {
|
|
484
|
+
// 只重排自己的 interval 定时器(远端轮询有自己的节奏,别的通道也不得被本通道重置)
|
|
485
|
+
if (!this.stopped) this.scheduleChannelTimer(channel);
|
|
486
|
+
});
|
|
487
|
+
}, ms);
|
|
488
|
+
this.timers.set(channel, timer);
|
|
489
|
+
}).catch(() => { /* 读配置失败静默 */ });
|
|
433
490
|
}
|
|
434
491
|
|
|
435
492
|
/**
|
|
@@ -653,7 +710,12 @@ export class AutoSyncScheduler {
|
|
|
653
710
|
try {
|
|
654
711
|
// 锁内重跑一次检测:预检到写入之间可能被别的进程推进(远端新快照 / 本机配置改动),
|
|
655
712
|
// 拿过期结论去写等于覆盖别人的成果。无锁环境(测试)直接用预检结果 —— 同一份数据,没有竞态。
|
|
656
|
-
|
|
713
|
+
// P0(2026-11-14 真机事故):锁内重跑必须与预检同口径传 localCheck。
|
|
714
|
+
// 此前这里漏传 → 60s 远端轮询在锁内又跑了一遍全量本地导出(plugins 的 npm pack,
|
|
715
|
+
// 实测单插件 44.7s/轮),预检省下的开销全被这一步还回去。
|
|
716
|
+
const phase = releaseLock === null
|
|
717
|
+
? preflight
|
|
718
|
+
: await this.detectPhase(channel, cfg, nowIso, historyId, { localCheck: opts.reason !== 'remote-poll' });
|
|
657
719
|
if (phase.kind === 'skip') return phase.result;
|
|
658
720
|
const { engine, remoteNew, localDirty, firstRun } = phase;
|
|
659
721
|
|
|
@@ -667,6 +729,12 @@ export class AutoSyncScheduler {
|
|
|
667
729
|
* 真机现场「推本机配置当备份」这条链路被远端冲突连续阻塞,用户却只看到 skipped/conflict。
|
|
668
730
|
*/
|
|
669
731
|
let conflictedSections: SectionId[] = [];
|
|
732
|
+
//
|
|
733
|
+
// issue #136:Phase B 的「成功但没全写进去」必须能被看见 —— 旧实现只看 applyReport.ok,
|
|
734
|
+
// ok 时把 warnings / 待裁决项整包丢掉,于是「patch 行被剥空→守卫保留本机」与
|
|
735
|
+
// 「叶级冲突被扣下」都表现为一轮干净的成功。
|
|
736
|
+
let downlinkWarnings: string[] = [];
|
|
737
|
+
let heldLeafSections: SectionId[] = [];
|
|
670
738
|
|
|
671
739
|
// Phase A: pull 合并(下载)—— 仅当远端有新快照才拉取(§3.2)。
|
|
672
740
|
if (remoteNew) {
|
|
@@ -727,6 +795,8 @@ export class AutoSyncScheduler {
|
|
|
727
795
|
})).result as import('./sync-engine.ts').ApplyReport
|
|
728
796
|
: await rawApply();
|
|
729
797
|
appliedSections = applyReport.applied as SectionId[];
|
|
798
|
+
downlinkWarnings = applyReport.warnings;
|
|
799
|
+
heldLeafSections = [...new Set(applyReport.review.map((r) => r.sectionId as SectionId))];
|
|
730
800
|
if (!applyReport.ok) {
|
|
731
801
|
const error = applyReport.warnings.join('; ') || engineMsg('sync.autosyncApplyMergeFailed');
|
|
732
802
|
const result: AutosyncRunResult = {
|
|
@@ -758,16 +828,32 @@ export class AutoSyncScheduler {
|
|
|
758
828
|
* SYN-05:首轮 / 远端有新快照时即使显式选了 local 也强制降级 ask(forced=true 进结果与
|
|
759
829
|
* 历史),绝不在这两个高危时刻替用户覆盖远端最新。
|
|
760
830
|
*/
|
|
831
|
+
// issue #146(F9):local 是用户的长期决定 —— 存量待裁决必须能被它消解,否则上一轮攒下的
|
|
832
|
+
// 分区永远等不到结论(每轮"既不推也不报错"地空转)。只在策略是 local 时读一次磁盘,
|
|
833
|
+
// 读失败按 0 处理(退回老口径:只扣不推 + 由下面的 all-conflicted 如实上报)。
|
|
834
|
+
const heldFromState = cfg.conflictPolicy === 'local' ? await this.readPendingMerge() : [];
|
|
761
835
|
const pushDecision = resolveConflictPushPolicy({
|
|
762
836
|
...(cfg.conflictPolicy !== undefined ? { configuredPolicy: cfg.conflictPolicy } : {}),
|
|
763
837
|
firstRun,
|
|
764
838
|
remoteNew,
|
|
765
839
|
conflicted: conflictedSections.length,
|
|
840
|
+
held: heldFromState.length,
|
|
766
841
|
});
|
|
767
842
|
const forcePush = pushDecision.force;
|
|
768
843
|
const forcedMark = pushDecision.forcedAsk ? { forced: true as const } : {};
|
|
844
|
+
// issue #146:本轮**仍未裁决**的分区(分区级冲突 + 下行被扣下的叶级冲突)绝不上行。
|
|
845
|
+
// 冲突分区在 Phase B 被有意跳过(绝不写本地),但推送侧原本照样导出本机版本 ——
|
|
846
|
+
// 真机事故里 plugins 就这样被 30 → 28 → 26 一路压小。force = 用户明确「用本机覆盖远端」,不扣。
|
|
847
|
+
const heldUp = forcePush ? [] : [...new Set([...conflictedSections, ...heldLeafSections])];
|
|
848
|
+
// 先落盘待裁决:引擎推送成功时只在**已有记录**上保留 since,本轮首次判出的冲突要靠这里写下来。
|
|
849
|
+
const pendingRecorded = heldUp.length > 0;
|
|
850
|
+
if (pendingRecorded) await this.recordPendingMerge(engine, heldUp);
|
|
769
851
|
// Phase C: 完整双向 → engine.push() 上传。P0-A:外部 push 包 intent journal。
|
|
770
|
-
const rawPush = async () => engine.push(
|
|
852
|
+
const rawPush = async () => engine.push({
|
|
853
|
+
...(forcePush ? { force: true } : {}),
|
|
854
|
+
// 空数组也传:本轮没判出新冲突时,磁盘上上一轮留下的待裁决仍要扣下(issue #146)。
|
|
855
|
+
skipSections: heldUp,
|
|
856
|
+
});
|
|
771
857
|
const pushReport = (this.phase3Recovery !== undefined && this.lockCtxForJournal !== null)
|
|
772
858
|
? (await this.phase3Recovery.runExternalIntent({
|
|
773
859
|
operationType: 'autosync-push', lockCtx: this.lockCtxForJournal,
|
|
@@ -779,12 +865,18 @@ export class AutoSyncScheduler {
|
|
|
779
865
|
// 绝不记 failed(那会累加连续失败计数并对用户发通知,把「需要用『检查远程合并』处理」
|
|
780
866
|
// 谎报成「同步坏了」);错误摘要保留引擎给出的说明(用户能看见到底为什么没推上去)。
|
|
781
867
|
const message = pushReport.message ?? engineMsg('sync.autosyncPushFailed');
|
|
868
|
+
// issue #136:下行自身的告警/待裁决与「推送被冲突挡下」合并进同一条记录,
|
|
869
|
+
// 不因上行受阻就把下行的事实抹掉。
|
|
870
|
+
const blockedConflicted = [...new Set([...conflictedSections, ...heldLeafSections])];
|
|
871
|
+
const blockedDegraded = downlinkWarnings.length > 0 || heldLeafSections.length > 0;
|
|
782
872
|
const conflictResult: AutosyncRunResult = {
|
|
783
|
-
status:
|
|
873
|
+
status: blockedConflicted.length > 0 || blockedDegraded ? 'partial' : 'skipped',
|
|
784
874
|
direction: appliedSections.length ? 'both' : 'push',
|
|
785
875
|
skipReason: 'conflict', error: message, historyId,
|
|
786
876
|
appliedSections,
|
|
787
|
-
...(
|
|
877
|
+
...(blockedConflicted.length > 0 ? { conflictedSections: blockedConflicted } : {}),
|
|
878
|
+
...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
|
|
879
|
+
...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
|
|
788
880
|
consecutiveFailures: 0,
|
|
789
881
|
...forcedMark,
|
|
790
882
|
};
|
|
@@ -792,10 +884,15 @@ export class AutoSyncScheduler {
|
|
|
792
884
|
direction: appliedSections.length ? 'both' : 'push', status: conflictResult.status,
|
|
793
885
|
skipReason: 'conflict', error: message,
|
|
794
886
|
appliedSections,
|
|
795
|
-
...(
|
|
887
|
+
...(blockedConflicted.length > 0 ? { conflictedSections: blockedConflicted } : {}),
|
|
888
|
+
...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
|
|
889
|
+
...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
|
|
796
890
|
createdAt: nowIso, failureCountAtRun: 0,
|
|
797
891
|
...forcedMark,
|
|
798
892
|
});
|
|
893
|
+
// 冲突分区落成待裁决(P2):首页与同步页据此给出裁决入口。推送前已写过就不再写一次
|
|
894
|
+
// (重复写会按 lastMergedRemoteSnapshotId 重算 since,抹掉首次判出冲突的时间)。
|
|
895
|
+
if (!pendingRecorded) await this.recordPendingMerge(engine, conflictedSections);
|
|
799
896
|
await this.writeFinalConfig(cfg, conflictResult, nowIso, historyId, channel);
|
|
800
897
|
return conflictResult;
|
|
801
898
|
}
|
|
@@ -819,15 +916,27 @@ export class AutoSyncScheduler {
|
|
|
819
916
|
// 也绝不因为它报成 failed:网络与凭据都是好的,只是远端有内容要用户确认)。
|
|
820
917
|
// conflictPolicy='local' 时冲突已被「本机覆盖远端」消解,但远端那一版确实被盖掉了 →
|
|
821
918
|
// 同样记 partial,skipReason 换成 conflict-kept-local(界面据此说清「本机已覆盖远端」)。
|
|
822
|
-
|
|
823
|
-
|
|
919
|
+
// force 消解的对象 = 本轮冲突 ∪ 磁盘存量(F9):只覆盖本轮会让台账把「覆盖了远端」这件事
|
|
920
|
+
// 说成一次普通成功 —— 用户从来看不出自己那句「本机优先」到底动过哪些分区。
|
|
921
|
+
const keptLocalSections = forcePush
|
|
922
|
+
? [...new Set([...conflictedSections, ...heldFromState])]
|
|
923
|
+
: [];
|
|
924
|
+
const keptLocal = keptLocalSections.length > 0;
|
|
925
|
+
const partial = keptLocal || conflictedSections.length > 0;
|
|
926
|
+
// issue #146(follow-up):引擎把「冲突未裁决 ⇒ 本轮一个分区都没上行」回成 skipped:'all-conflicted'。
|
|
927
|
+
// 以前这里只看 ok/conflict,于是整轮被记成「上传·成功」—— 用户从此看不出有分区被扣下,
|
|
928
|
+
// #146 的「显示成已推送」在自动同步路径原地复发。全扣下与部分扣下都必须落到台账。
|
|
929
|
+
const allConflicted = pushReport.skipped === 'all-conflicted';
|
|
930
|
+
const pushWarnings = pushReport.warnings ?? [];
|
|
824
931
|
const skipReason = keptLocal
|
|
825
932
|
? ('conflict-kept-local' as const)
|
|
826
933
|
: partial
|
|
827
934
|
? ('conflict' as const)
|
|
828
|
-
:
|
|
935
|
+
: allConflicted
|
|
936
|
+
? ('all-conflicted' as const)
|
|
937
|
+
: undefined;
|
|
829
938
|
const reportedConflicted = keptLocal
|
|
830
|
-
?
|
|
939
|
+
? keptLocalSections
|
|
831
940
|
: partial
|
|
832
941
|
? conflictedSections
|
|
833
942
|
: deferredSections;
|
|
@@ -835,21 +944,49 @@ export class AutoSyncScheduler {
|
|
|
835
944
|
// 如实记一条 skipReason,让历史与首页能说清「这次推上去之前先修好了基线」,
|
|
836
945
|
// 而不是让用户以为又发生了一次莫名冲突。冲突原因优先(真有冲突时更该被看见)。
|
|
837
946
|
const adoptedReason = pushReport.adoptedBase !== undefined ? ('baseline-adopted' as const) : undefined;
|
|
947
|
+
// issue #136:下行有告警 / 有待裁决叶级项 → 终态只能是 partial。
|
|
948
|
+
// 「推送成功」不能替下行的未完成背书:用户会从 success 得出「两端一样了」,而实际上
|
|
949
|
+
// 有些叶子被有意扣下(保留本机 / 等待裁决)。
|
|
950
|
+
// 两类降级必须分开说:只有「叶级冲突被扣下」才是冲突待裁决;
|
|
951
|
+
// 纯告警(插件没装上、undo 有残留等)与冲突无关,套上 'conflict' 会让
|
|
952
|
+
// 界面上出现「跳过原因:冲突」「另有 N 个分区待确认」,而 conflictedSections 是空的。
|
|
953
|
+
const heldDegraded = heldLeafSections.length > 0;
|
|
954
|
+
// 引擎告警(分区导出失败 / 非 portable 跳过 / 扣下说明)同样要上屏:静默少推比失败更糟。
|
|
955
|
+
const allWarnings = [...downlinkWarnings, ...pushWarnings];
|
|
956
|
+
// 引擎 push 回传的告警(provider namespace 未配置、目录为空…)是常规事实噪声,只上屏不降级;
|
|
957
|
+
// 状态降级只认「有分区被扣下」与下行冲突 —— 否则每轮都变成 partial,用户就学不会 partial 的含义。
|
|
958
|
+
const degraded = downlinkWarnings.length > 0 || heldDegraded;
|
|
959
|
+
const finalPartial = partial || degraded || allConflicted;
|
|
960
|
+
// 一个分区都没上行 = 「成功但跳过」,不是「成功」也不是「失败」(#146 验收口径②)。
|
|
961
|
+
const finalStatus = allConflicted && appliedSections.length === 0
|
|
962
|
+
? ('skipped' as const)
|
|
963
|
+
: finalPartial ? ('partial' as const) : ('success' as const);
|
|
964
|
+
const finalSkipReason = skipReason
|
|
965
|
+
?? (heldDegraded ? ('conflict' as const) : degraded ? ('warning' as const) : undefined);
|
|
966
|
+
// 扣下的叶级冲突所在分区也要出现在「待处理分区」里(与分区级冲突合并去重)
|
|
967
|
+
const finalConflicted = [...new Set([...reportedConflicted, ...heldLeafSections])];
|
|
838
968
|
const result: AutosyncRunResult = {
|
|
839
|
-
status:
|
|
969
|
+
status: finalStatus,
|
|
840
970
|
direction: appliedSections.length ? 'both' : 'push',
|
|
841
|
-
appliedSections,
|
|
842
|
-
|
|
843
|
-
...(
|
|
971
|
+
appliedSections, historyId,
|
|
972
|
+
// issue #146:全扣下时 snapshotId 为空 —— 绝不写空 id(界面会当成「推了某份快照」)。
|
|
973
|
+
...(pushReport.snapshotId !== '' ? { pushedSnapshotId: pushReport.snapshotId } : {}),
|
|
974
|
+
...(finalSkipReason !== undefined || adoptedReason !== undefined ? { skipReason: finalSkipReason ?? adoptedReason } : {}),
|
|
975
|
+
...(finalConflicted.length > 0 ? { conflictedSections: finalConflicted } : {}),
|
|
976
|
+
...(allWarnings.length > 0 ? { warnings: allWarnings } : {}),
|
|
977
|
+
...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
|
|
844
978
|
consecutiveFailures: 0,
|
|
845
979
|
...forcedMark,
|
|
846
980
|
};
|
|
847
981
|
await this.appendHistory(channel, {
|
|
848
982
|
direction: appliedSections.length ? 'both' : 'push',
|
|
849
|
-
status:
|
|
850
|
-
appliedSections,
|
|
851
|
-
...(
|
|
852
|
-
...(
|
|
983
|
+
status: finalStatus,
|
|
984
|
+
appliedSections,
|
|
985
|
+
...(pushReport.snapshotId !== '' ? { pushedSnapshotId: pushReport.snapshotId } : {}),
|
|
986
|
+
...(finalSkipReason !== undefined || adoptedReason !== undefined ? { skipReason: finalSkipReason ?? adoptedReason } : {}),
|
|
987
|
+
...(finalConflicted.length > 0 ? { conflictedSections: finalConflicted } : {}),
|
|
988
|
+
...(allWarnings.length > 0 ? { warnings: allWarnings } : {}),
|
|
989
|
+
...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
|
|
853
990
|
createdAt: nowIso, failureCountAtRun: 0,
|
|
854
991
|
...forcedMark,
|
|
855
992
|
});
|
|
@@ -875,29 +1012,46 @@ export class AutoSyncScheduler {
|
|
|
875
1012
|
|
|
876
1013
|
// 本轮下行被冲突挡下、且没有可上行内容(startup 变体 / 本地无改动)→ 如实 skipped/conflict。
|
|
877
1014
|
if (conflictedSections.length > 0) {
|
|
1015
|
+
// issue #136:被扣下的叶级冲突也算「待处理分区」(与分区级冲突同列)。
|
|
1016
|
+
const skipConflicted = [...new Set([...conflictedSections, ...heldLeafSections])];
|
|
878
1017
|
const conflictResult: AutosyncRunResult = {
|
|
879
1018
|
status: 'skipped', direction: 'pull', skipReason: 'conflict',
|
|
880
|
-
conflictedSections, historyId, consecutiveFailures: 0,
|
|
1019
|
+
conflictedSections: skipConflicted, historyId, consecutiveFailures: 0,
|
|
1020
|
+
...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
|
|
1021
|
+
...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
|
|
881
1022
|
};
|
|
882
1023
|
await this.appendHistory(channel, {
|
|
883
1024
|
direction: 'pull', status: 'skipped', skipReason: 'conflict',
|
|
884
|
-
conflictedSections, createdAt: nowIso, failureCountAtRun: 0,
|
|
1025
|
+
conflictedSections: skipConflicted, createdAt: nowIso, failureCountAtRun: 0,
|
|
1026
|
+
...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
|
|
1027
|
+
...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
|
|
885
1028
|
});
|
|
1029
|
+
await this.recordPendingMerge(engine, conflictedSections);
|
|
886
1030
|
await this.writeFinalConfig(cfg, conflictResult, nowIso, historyId, channel);
|
|
887
1031
|
return conflictResult;
|
|
888
1032
|
}
|
|
889
1033
|
|
|
890
1034
|
// startup 变体 / 仅远端合并:只做 pull 合并(不上传),或远端无新生且本地无改动(已在上方 upToDate 短路上)。
|
|
1035
|
+
// issue #136:纯下行的告警/待裁决同样算「没全做完」—— 终态不得写成 success。
|
|
1036
|
+
const degraded = downlinkWarnings.length > 0 || heldLeafSections.length > 0;
|
|
1037
|
+
const pulledConflicted = [...new Set([...deferredSections, ...heldLeafSections])];
|
|
1038
|
+
const pullSkipReason = !degraded && appliedSections.length === 0
|
|
1039
|
+
? ('unchanged' as const)
|
|
1040
|
+
: degraded ? ('conflict' as const) : undefined;
|
|
891
1041
|
const result: AutosyncRunResult = {
|
|
892
|
-
status: 'success', direction: 'pull', appliedSections,
|
|
893
|
-
...(
|
|
894
|
-
...(
|
|
1042
|
+
status: degraded ? 'partial' : 'success', direction: 'pull', appliedSections,
|
|
1043
|
+
...(pullSkipReason !== undefined ? { skipReason: pullSkipReason } : {}),
|
|
1044
|
+
...(pulledConflicted.length > 0 ? { conflictedSections: pulledConflicted } : {}),
|
|
1045
|
+
...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
|
|
1046
|
+
...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
|
|
895
1047
|
historyId, consecutiveFailures: 0,
|
|
896
1048
|
};
|
|
897
1049
|
await this.appendHistory(channel, {
|
|
898
|
-
direction: 'pull', status: 'success', appliedSections,
|
|
899
|
-
...(
|
|
900
|
-
...(
|
|
1050
|
+
direction: 'pull', status: degraded ? 'partial' : 'success', appliedSections,
|
|
1051
|
+
...(pullSkipReason !== undefined ? { skipReason: pullSkipReason } : {}),
|
|
1052
|
+
...(pulledConflicted.length > 0 ? { conflictedSections: pulledConflicted } : {}),
|
|
1053
|
+
...(downlinkWarnings.length > 0 ? { warnings: downlinkWarnings } : {}),
|
|
1054
|
+
...(heldLeafSections.length > 0 ? { heldSections: heldLeafSections } : {}),
|
|
901
1055
|
createdAt: nowIso, failureCountAtRun: 0,
|
|
902
1056
|
});
|
|
903
1057
|
await this.writeFinalConfig(cfg, result, nowIso, historyId, channel);
|
|
@@ -1044,6 +1198,25 @@ export class AutoSyncScheduler {
|
|
|
1044
1198
|
return { kind: 'work', engine, remoteNew, localDirty, firstRun };
|
|
1045
1199
|
}
|
|
1046
1200
|
|
|
1201
|
+
/**
|
|
1202
|
+
* P2(2026-11-14 真机事故):把「本轮被冲突挡下的分区」写进 sync-state.pendingMerge。
|
|
1203
|
+
*
|
|
1204
|
+
* 过去自动同步只在历史里留一句「冲突」,sync-state 里没有可挂入口的持久对象 ——
|
|
1205
|
+
* 首页「待裁决」徽章于是只有颜色没有去处,用户点不动、也不知道该去哪裁决。
|
|
1206
|
+
* 这里由引擎按**本轮实际合并过的远端快照 id** 落 pendingMerge(同远端快照连续冲突保留首次 since),
|
|
1207
|
+
* 界面据 /sync/status 的 pendingMerge 显示待裁决分区,首页那一行据此跳到同步页。
|
|
1208
|
+
*
|
|
1209
|
+
* 尽力而为:写待裁决失败绝不能把「远端有冲突」这一事实变成 failed(那会累加连续失败计数)。
|
|
1210
|
+
*/
|
|
1211
|
+
private async recordPendingMerge(engine: SyncEngine, sections: SectionId[]): Promise<void> {
|
|
1212
|
+
if (sections.length === 0) return;
|
|
1213
|
+
try {
|
|
1214
|
+
await engine.recordPendingMerge(sections);
|
|
1215
|
+
} catch (err) {
|
|
1216
|
+
this.host.log.warn(`自动同步待裁决分区未能落盘:${err instanceof Error ? err.message : String(err)}`);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1047
1220
|
private async writeFinalConfig(
|
|
1048
1221
|
base: AutosyncConfig,
|
|
1049
1222
|
result: AutosyncRunResult,
|
|
@@ -1061,7 +1234,8 @@ export class AutoSyncScheduler {
|
|
|
1061
1234
|
lastRunAt: nowIso,
|
|
1062
1235
|
lastRunStatus: result.status,
|
|
1063
1236
|
consecutiveFailures: result.consecutiveFailures,
|
|
1064
|
-
|
|
1237
|
+
// 历史被压掉的轮次没有新记录 id —— 保留上一条真记录的 id,绝不指向不存在的条目。
|
|
1238
|
+
lastRunHistoryId: this.historyDeduped ? (base.lastRunHistoryId ?? historyId) : historyId,
|
|
1065
1239
|
lastRunMessage: result.error ?? '',
|
|
1066
1240
|
lastRunSkipReason: skipReason,
|
|
1067
1241
|
lastRunSkipCount: skipCount,
|
|
@@ -18,6 +18,7 @@ import type { MsgFunc } from '../core/messages.ts';
|
|
|
18
18
|
import { joinFs } from './fs.ts';
|
|
19
19
|
import type { SnapshotFs } from './fs.ts';
|
|
20
20
|
import { loadSyncState, resolveDeviceIdentity, saveSyncState } from './sync-state.ts';
|
|
21
|
+
import type { SectionHashes } from './sync-state.ts';
|
|
21
22
|
import type { SyncSnapshotMeta } from './transport.ts';
|
|
22
23
|
|
|
23
24
|
export interface AdoptOwnRemoteHeadOptions {
|
|
@@ -64,6 +65,11 @@ export async function adoptOwnRemoteHead(opts: AdoptOwnRemoteHeadOptions): Promi
|
|
|
64
65
|
if (typeof hash !== 'string' || hash === '') continue;
|
|
65
66
|
state.sections[sid as SectionId] = { hash, updatedAt: meta.createdAt };
|
|
66
67
|
}
|
|
68
|
+
// issue #140(G-44):被收养的快照自己就是「远端当前观测」——它的 sections 记进独立字段。
|
|
69
|
+
// 空对象(加密快照)⇒ 删除观测:判定层因此回落 id 比较,绝不拿 state.sections 顶上。
|
|
70
|
+
const remoteHashes: SectionHashes = { ...meta.sections };
|
|
71
|
+
if (Object.keys(remoteHashes).length > 0) state.lastRemoteSections = remoteHashes;
|
|
72
|
+
else delete state.lastRemoteSections;
|
|
67
73
|
state.transport = opts.transport;
|
|
68
74
|
await saveSyncState(opts.stateDir, state, opts.fsx);
|
|
69
75
|
opts.warnings.push(opts.msg(ancestorKnown ? 'sync.pushBaselineAdopted' : 'sync.pushBaselineAdoptedNoAncestor', {
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* m-sync-flow:写基线的唯一实现(本地祖先副本 + sync-state)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独成模块:这段逻辑是「祖先副本布局 + 远端指针 + 每分区 hash + 裁剪」的完整落盘决策,
|
|
5
|
+
* 不需要引擎的任何其他状态(只吃快照目录、通道身份与时间);留在 SyncEngine 里会顶穿体量棘轮。
|
|
6
|
+
*
|
|
7
|
+
* **两个 id 语义严格分开(P0-7),不要再混用同一个字段**:
|
|
8
|
+
* - `snapshotId`:本次基线的**本地**快照对象 id,同时是本地祖先副本的目录名(写入 `ancestorId`);
|
|
9
|
+
* - `opts.remoteSnapshotId`:该基线在**远端**对应的快照 id(写入 `lastSnapshotId`)。缺省 = snapshotId
|
|
10
|
+
* (push 路径两者天然相同);合并/应用路径**必须显式传**,否则 lastSnapshotId 会退化成「一个远端
|
|
11
|
+
* 并不存在的本地 id」→ hasNewRemoteSnapshot() 恒判「远端有新生」,每轮白跑 list + download + merge。
|
|
12
|
+
* 传入 `''` 表示「远端 id 未知」——宁可留空,也不要把本地 id 冒充成远端 id。
|
|
13
|
+
*
|
|
14
|
+
* **issue #140 / G-44**:`opts.remoteSections` 是**远端观测**(远端快照自己携带的分区哈希),
|
|
15
|
+
* 与传入的 `sections`(本机观测,用来算 hasLocalChanges 的基线)是两个不同来源。
|
|
16
|
+
* 早先的事故正是「一参两用」:拿本机 hash 当远端现状,判定就永远自洽、永远看不出远端真的变了。
|
|
17
|
+
*/
|
|
18
|
+
import type { Platform, SectionData, SectionId } from '../schema/types.ts';
|
|
19
|
+
import type { MsgFunc } from '../core/messages.ts';
|
|
20
|
+
import { CURRENT_SCHEMA_VERSION } from '../schema/versions.ts';
|
|
21
|
+
import { DEFAULT_ANCESTOR_KEEP, pruneAncestors, writeAncestor, writeEncryptedAncestor } from './ancestor.ts';
|
|
22
|
+
import type { SnapshotFs } from './fs.ts';
|
|
23
|
+
import { encryptSectionsPayload } from './snapshot-crypto.ts';
|
|
24
|
+
import { hashSection, loadSyncState, saveSyncState } from './sync-state.ts';
|
|
25
|
+
import type { PendingMerge, SectionHashes } from './sync-state.ts';
|
|
26
|
+
import type { SyncSnapshot } from './transport.ts';
|
|
27
|
+
|
|
28
|
+
export interface RecordBaselineOptions {
|
|
29
|
+
writeAncestor?: boolean;
|
|
30
|
+
/** 提供即把祖先副本写成**密文**(密码仅本次内存使用;issue #107) */
|
|
31
|
+
ancestorPassword?: string;
|
|
32
|
+
remoteSnapshotId?: string;
|
|
33
|
+
/** 保留当前祖先副本与 ancestorId(缺省 false = 既有行为逐字不变) */
|
|
34
|
+
preserveAncestor?: boolean;
|
|
35
|
+
/** 待裁决冲突记录:null = 清除;缺省 = 不动该字段 */
|
|
36
|
+
pendingMerge?: PendingMerge | null;
|
|
37
|
+
/** P1-5:本轮**实际带走**的会话单元(提供即覆盖;缺省 = 保留原记录) */
|
|
38
|
+
sessionUnits?: string[];
|
|
39
|
+
/** P1-5:本轮累积的删除墓碑(提供即覆盖;缺省 = 保留原记录) */
|
|
40
|
+
deletedSessions?: string[];
|
|
41
|
+
/**
|
|
42
|
+
* issue #140:本次基线对应的**远端观测**(远端快照实际携带的分区哈希,G-44)。
|
|
43
|
+
*
|
|
44
|
+
* - 提供且非空 ⇒ 原样记录(只允许来自「真的看到了远端 sections」的调用点);
|
|
45
|
+
* - 提供但为空(加密快照)或未提供 ⇒ 指针若发生变化则**删除**既有观测(未知 ⇒ 判定回落 id);
|
|
46
|
+
* - 指针未变(preserveAncestor 的待裁决冲突)⇒ 保留既有观测(远端没动,观测仍成立)。
|
|
47
|
+
* 绝不允许由传入的 `sections`(本机观测)推导。
|
|
48
|
+
*/
|
|
49
|
+
remoteSections?: SectionHashes;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** 落盘所需的环境(引擎逐字段透传;此处不持有引擎实例)。 */
|
|
53
|
+
export interface RecordBaselineEnv {
|
|
54
|
+
fsx: SnapshotFs;
|
|
55
|
+
stateDir: string;
|
|
56
|
+
localSnapshotsDir?: string;
|
|
57
|
+
dshVersion: string;
|
|
58
|
+
platform: Platform;
|
|
59
|
+
transport: { type: string; ref: string };
|
|
60
|
+
now: () => Date;
|
|
61
|
+
msg: MsgFunc;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface RecordBaselineInput {
|
|
65
|
+
snapshotId: string;
|
|
66
|
+
/** 基线**恒为明文**(加密快照的基线 hash 也用明文算,供 hasLocalChanges 比较)。 */
|
|
67
|
+
sections: Partial<Record<SectionId, SectionData>>;
|
|
68
|
+
nowIso?: string;
|
|
69
|
+
opts?: RecordBaselineOptions;
|
|
70
|
+
env: RecordBaselineEnv;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function recordBaseline(input: RecordBaselineInput): Promise<void> {
|
|
74
|
+
const { snapshotId, sections, env } = input;
|
|
75
|
+
const opts = input.opts ?? {};
|
|
76
|
+
const ts = input.nowIso ?? env.now().toISOString();
|
|
77
|
+
const preserveAncestor = opts.preserveAncestor === true;
|
|
78
|
+
const ancestorPassword = opts.ancestorPassword;
|
|
79
|
+
const encryptedAncestor = ancestorPassword !== undefined && ancestorPassword !== '';
|
|
80
|
+
const writesAncestorCopy = !preserveAncestor && env.localSnapshotsDir !== undefined && opts.writeAncestor !== false;
|
|
81
|
+
|
|
82
|
+
// 1) 写本地祖先副本(如有 localSnapshotsDir)。
|
|
83
|
+
// ancestorPassword 提供 → 落**密文**祖先副本(issue #107:加密通道也能做三方合并);
|
|
84
|
+
// 否则落明文散文件布局(既有行为逐字不变)。
|
|
85
|
+
if (writesAncestorCopy && env.localSnapshotsDir !== undefined) {
|
|
86
|
+
const manifest: SyncSnapshot['manifest'] = {
|
|
87
|
+
schemaVersion: CURRENT_SCHEMA_VERSION,
|
|
88
|
+
dshVersion: env.dshVersion,
|
|
89
|
+
platform: env.platform,
|
|
90
|
+
sectionIds: Object.keys(sections) as SectionId[],
|
|
91
|
+
containsSecrets: false,
|
|
92
|
+
// 记录触发通道(git/webdav),供同步历史展示「由哪个通道触发」
|
|
93
|
+
transport: env.transport.type,
|
|
94
|
+
...(encryptedAncestor ? { encrypted: true } : {}),
|
|
95
|
+
};
|
|
96
|
+
if (encryptedAncestor) {
|
|
97
|
+
const encryptedSections = await encryptSectionsPayload(sections, ancestorPassword);
|
|
98
|
+
await writeEncryptedAncestor(env.localSnapshotsDir, { id: snapshotId, createdAt: ts, manifest, sections: encryptedSections }, env.fsx);
|
|
99
|
+
} else {
|
|
100
|
+
await writeAncestor(env.localSnapshotsDir, { id: snapshotId, createdAt: ts, manifest, sections }, env.fsx);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 2) 更新 sync-state:远端指针 + 本地祖先目录名 + 每分区 hash/updatedAt + lastSyncAt + transport
|
|
105
|
+
const state = await loadSyncState(env.stateDir, env.fsx, env.msg);
|
|
106
|
+
const previousPointer = state.lastSnapshotId;
|
|
107
|
+
state.lastSnapshotId = opts.remoteSnapshotId ?? snapshotId;
|
|
108
|
+
// issue #140(G-44):远端观测只认调用方显式给出的「远端快照 sections」。
|
|
109
|
+
// 指针变了却拿不到观测 ⇒ 删除(下一轮判定回落 id 比较),绝不沿用上一份观测冒充现状。
|
|
110
|
+
if (opts.remoteSections !== undefined) {
|
|
111
|
+
if (Object.keys(opts.remoteSections).length > 0) state.lastRemoteSections = { ...opts.remoteSections };
|
|
112
|
+
else delete state.lastRemoteSections;
|
|
113
|
+
} else if (state.lastSnapshotId !== previousPointer) {
|
|
114
|
+
delete state.lastRemoteSections;
|
|
115
|
+
}
|
|
116
|
+
// preserveAncestor:祖先目录名一并保持不动(既不是 snapshotId,也不是 '')
|
|
117
|
+
if (!preserveAncestor) state.ancestorId = writesAncestorCopy ? snapshotId : '';
|
|
118
|
+
state.lastSyncAt = ts;
|
|
119
|
+
state.transport = { type: env.transport.type, ref: env.transport.ref };
|
|
120
|
+
// 基线纪律:null = 清除(全部裁决完);undefined = 不动该字段(既有调用方零感知)
|
|
121
|
+
if (opts.pendingMerge === null) delete state.pendingMerge;
|
|
122
|
+
else if (opts.pendingMerge !== undefined) state.pendingMerge = opts.pendingMerge;
|
|
123
|
+
// P1-5:只在调用方明确提供时覆盖(否则保留既有记录,绝不因某条路径不跟踪而清空)
|
|
124
|
+
if (opts.sessionUnits !== undefined) state.sessionUnits = [...opts.sessionUnits];
|
|
125
|
+
if (opts.deletedSessions !== undefined) state.deletedSessions = [...opts.deletedSessions];
|
|
126
|
+
for (const [sid, data] of Object.entries(sections)) {
|
|
127
|
+
state.sections[sid as SectionId] = { hash: hashSection(data as SectionData), updatedAt: ts };
|
|
128
|
+
}
|
|
129
|
+
await saveSyncState(env.stateDir, state, env.fsx);
|
|
130
|
+
|
|
131
|
+
// 3) 裁剪祖先副本(最近 N 个);preserveAncestor 时本轮没有新副本,不参与裁剪
|
|
132
|
+
if (!preserveAncestor && env.localSnapshotsDir !== undefined) {
|
|
133
|
+
await pruneAncestors(env.localSnapshotsDir, DEFAULT_ANCESTOR_KEEP, env.fsx);
|
|
134
|
+
}
|
|
135
|
+
}
|