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
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { isBundlesOnlyEntry } from '../core/plugin-cli.js';
|
|
2
|
+
import { mergeKeyedList } from './merge-keyed.js';
|
|
3
|
+
import { patchIdentityContext, patchLineIdentity } from './patch-line-identity.js';
|
|
4
|
+
import { mergeJsonValues } from './text-merge.js';
|
|
2
5
|
function byName(list) {
|
|
3
6
|
const map = new Map();
|
|
4
7
|
for (const p of list ?? []) {
|
|
@@ -61,35 +64,30 @@ function asPlugins(data) {
|
|
|
61
64
|
function entryKey(e) {
|
|
62
65
|
return [e.version ?? '', e.spec ?? '', e.bundlesOnly === true ? '1' : '0'].join('\u0000');
|
|
63
66
|
}
|
|
64
|
-
/**
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return
|
|
67
|
+
/** patch 行的键分隔符:file 与 lineId 各自可能含任意字符,用 NUL 才不会撞键。 */
|
|
68
|
+
const PATCH_KEY_SEP = '\u0000';
|
|
69
|
+
/** patch 行的身份键 = file + lineId(同一文件里 lineId 才是行身份;issue #145)。 */
|
|
70
|
+
function patchLineKey(line) {
|
|
71
|
+
return [line.file ?? '', line.lineId ?? ''].join(PATCH_KEY_SEP);
|
|
72
|
+
}
|
|
73
|
+
/** 本地 tarball 的身份(同包名 = 同一条目;内容变了才算改过)。 */
|
|
74
|
+
function tarballIdentity(t) {
|
|
75
|
+
return JSON.stringify({ version: t.version ?? '', relativePath: t.relativePath ?? '', base64: t.base64 ?? '' });
|
|
76
|
+
}
|
|
77
|
+
/** patch 文件的身份(同相对路径 = 同一条目)。 */
|
|
78
|
+
function patchFileIdentity(f) {
|
|
79
|
+
return JSON.stringify({ relativePath: f.relativePath ?? '', base64: f.base64 ?? '' });
|
|
73
80
|
}
|
|
74
81
|
/**
|
|
75
|
-
* plugins
|
|
82
|
+
* plugins 分区的按键三方合并(`merge.ts` 的 `GRANULAR_MERGES.plugins`)。
|
|
76
83
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* - 只有本机:有祖先且与祖先相同 → 跟随远端删除(真删除);无祖先 → 本机独有,保留;有祖先且不同 →
|
|
80
|
-
* modify-delete 冲突(用户在 A 机卸载、B 机却升级过它,不能替用户选);
|
|
81
|
-
* - 只有远端:有祖先且与祖先相同 → 本机删除,跟随(不复活);无祖先 → 远端独有,采纳;有祖先且不同 →
|
|
82
|
-
* delete-modify 冲突;
|
|
83
|
-
* - 两侧都没有:消失。
|
|
84
|
+
* 逐条规则见 `merge-keyed.ts`;本函数只负责「四条有序集合各用什么键与身份」以及
|
|
85
|
+
* `pnpmWorkspace` 原文的三方(两侧都改且不同 → overlap 交人工,与通用 JSON 合并同口径)。
|
|
84
86
|
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
+
* 形状不认识(`version !== 1` 或缺 plugins 数组)时返回 `undefined`:畸形数据交回通用路径的
|
|
88
|
+
* 形状闸门,这里不另造第二套拒绝逻辑。
|
|
87
89
|
*/
|
|
88
90
|
export function mergePluginsSection(local, remote, ancestor, hooks = {}) {
|
|
89
|
-
// 开关关着 → 钩子不参与(交回通用合并 = 与 #132 之前逐字一致)。若照常「跟随远端删除」,
|
|
90
|
-
// 合并结果会丢掉本机条目:插件包还在盘上,下一轮导出会把它当「本机独有」推回远端 = 复活。
|
|
91
|
-
if (hooks.deletePlugins !== true)
|
|
92
|
-
return undefined;
|
|
93
91
|
const l = asPlugins(local);
|
|
94
92
|
const r = asPlugins(remote);
|
|
95
93
|
if (l === undefined || r === undefined)
|
|
@@ -97,71 +95,124 @@ export function mergePluginsSection(local, remote, ancestor, hooks = {}) {
|
|
|
97
95
|
const a = ancestor === undefined ? undefined : asPlugins(ancestor);
|
|
98
96
|
if (ancestor !== undefined && a === undefined)
|
|
99
97
|
return undefined;
|
|
100
|
-
|
|
98
|
+
// 开关只决定「远端删了要不要真删」,不再决定钩子是否介入(issue #145 解耦)。
|
|
99
|
+
const followDelete = hooks.deletePlugins === true;
|
|
100
|
+
const selfName = hooks.selfPluginName ?? '';
|
|
101
|
+
const plugins = mergeKeyedList({
|
|
102
|
+
local: l.plugins,
|
|
103
|
+
remote: r.plugins,
|
|
104
|
+
ancestor: a?.plugins,
|
|
105
|
+
spec: {
|
|
106
|
+
keyOf: (p) => (typeof p.name === 'string' ? p.name : ''),
|
|
107
|
+
identityOf: (p) => entryKey(p),
|
|
108
|
+
pathOf: (name) => `plugins.${name}`,
|
|
109
|
+
followDelete,
|
|
110
|
+
// 自身条目永不删、永不报冲突:删了等于把正在跑的宿主插件卸掉。
|
|
111
|
+
keepLocal: (p) => selfName !== '' && p.name === selfName,
|
|
112
|
+
// 版本/来源听远端(本机没改过它才走这条分支),启停是本机 UI 态 —— 恒留本机,
|
|
113
|
+
// 否则远端升一次版本就把用户在本机关掉的插件改回启用(复审 P0-2)。
|
|
114
|
+
compose: (local, remote) => ({ ...remote, enabled: local.enabled }),
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
const patch = mergeKeyedList({
|
|
118
|
+
local: l.patch ?? [],
|
|
119
|
+
remote: r.patch ?? [],
|
|
120
|
+
ancestor: a?.patch,
|
|
121
|
+
spec: {
|
|
122
|
+
keyOf: patchLineKey,
|
|
123
|
+
// 身份按三侧 redactedPaths 并集归一化:本机被剥空、远端明文的同一行算「没改过」(门②)。
|
|
124
|
+
// 并集路径每键只解析一次(上下文),三侧各自比较时复用 —— 行多时不再逐次重解析。
|
|
125
|
+
identityContextOf: (peers) => patchIdentityContext(peers),
|
|
126
|
+
identityOf: (line, peers, context) => patchLineIdentity(line, peers, context),
|
|
127
|
+
// 冲突路径带 lineId:同一文件里两行各自冲突时必须能分辨(复审 P2)。
|
|
128
|
+
pathOf: (key) => {
|
|
129
|
+
const [file = '', lineId = ''] = key.split(PATCH_KEY_SEP);
|
|
130
|
+
return `patch.${file}#${lineId}`;
|
|
131
|
+
},
|
|
132
|
+
// 外壳列表**不跟随删除**:deletePlugins 的语义是「远端删了插件」,不是「远端删了 MCP 配置」
|
|
133
|
+
// —— 跟着删会把本机还在用的 patch 行 / tarball 一起丢掉(复审 P1-1)。
|
|
134
|
+
followDelete: false,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
const tarballs = mergeKeyedList({
|
|
138
|
+
local: l.localTarballs ?? [],
|
|
139
|
+
remote: r.localTarballs ?? [],
|
|
140
|
+
ancestor: a?.localTarballs,
|
|
141
|
+
spec: {
|
|
142
|
+
keyOf: (t) => (typeof t.packageName === 'string' ? t.packageName : ''),
|
|
143
|
+
identityOf: (t) => tarballIdentity(t),
|
|
144
|
+
pathOf: (key) => `localTarballs.${key}`,
|
|
145
|
+
followDelete: false, // 同上:开关只管插件清单(复审 P1-1)
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
const files = mergeKeyedList({
|
|
149
|
+
local: l.patchFiles ?? [],
|
|
150
|
+
remote: r.patchFiles ?? [],
|
|
151
|
+
ancestor: a?.patchFiles,
|
|
152
|
+
spec: {
|
|
153
|
+
keyOf: (f) => (typeof f.relativePath === 'string' ? f.relativePath : ''),
|
|
154
|
+
identityOf: (f) => patchFileIdentity(f),
|
|
155
|
+
pathOf: (key) => `patchFiles.${key}`,
|
|
156
|
+
followDelete: false, // 同上:开关只管插件清单(复审 P1-1)
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
// 形状不支持按键合并(同键重复 / 非对象条目 / 无身份键):交回通用路径,
|
|
160
|
+
// 绝不在这里「留一条丢一条」(复审 P1-2)。
|
|
161
|
+
if (plugins.malformed || patch.malformed || tarballs.malformed || files.malformed)
|
|
101
162
|
return undefined;
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
merged.push(rp);
|
|
131
|
-
mergePoints += 1;
|
|
132
|
-
continue;
|
|
163
|
+
const conflicts = [
|
|
164
|
+
...plugins.conflicts,
|
|
165
|
+
...patch.conflicts,
|
|
166
|
+
...tarballs.conflicts,
|
|
167
|
+
...files.conflicts,
|
|
168
|
+
];
|
|
169
|
+
let mergePoints = plugins.mergePoints + patch.mergePoints + tarballs.mergePoints + files.mergePoints;
|
|
170
|
+
// pnpm-workspace 原文:标量/对象三方。两侧都改且不同 → overlap(不猜用哪一份)。
|
|
171
|
+
// null 与「没有这个键」在语义上是同一件事(adapter 没有 patch 组时导出 null),
|
|
172
|
+
// 但三方合并之后必须按**原始形态**写回:本机原本带这个键就继续写 null,不能抹成缺键(复审 P0-1)。
|
|
173
|
+
const wsCarried = 'pnpmWorkspace' in l || 'pnpmWorkspace' in r;
|
|
174
|
+
const wsLocal = l.pnpmWorkspace ?? null;
|
|
175
|
+
const wsRemote = r.pnpmWorkspace ?? null;
|
|
176
|
+
const wsAncestor = a?.pnpmWorkspace ?? null;
|
|
177
|
+
const ws = mergeJsonValues(wsAncestor, wsLocal, wsRemote, 'pnpmWorkspace');
|
|
178
|
+
const wsMerged = ws.ok ? ws.merged : undefined;
|
|
179
|
+
if (!ws.ok) {
|
|
180
|
+
for (const _ of ws.conflicts) {
|
|
181
|
+
conflicts.push({
|
|
182
|
+
path: 'pnpmWorkspace',
|
|
183
|
+
kind: 'key',
|
|
184
|
+
reason: 'overlap',
|
|
185
|
+
autoMergeAttempted: true,
|
|
186
|
+
local: wsLocal ?? null,
|
|
187
|
+
remote: wsRemote ?? null,
|
|
188
|
+
ancestor: wsAncestor ?? null,
|
|
189
|
+
});
|
|
133
190
|
}
|
|
134
|
-
// 只有本机有
|
|
135
|
-
if (ap === undefined) {
|
|
136
|
-
merged.push(lp);
|
|
137
|
-
mergePoints += 1;
|
|
138
|
-
continue;
|
|
139
|
-
} // 本机独有
|
|
140
|
-
if (entryKey(lp) === entryKey(ap)) {
|
|
141
|
-
mergePoints += 1;
|
|
142
|
-
continue;
|
|
143
|
-
} // 本机未改、远端删 → 跟随删除
|
|
144
|
-
conflict(`plugins.${name}`, 'modify-delete', lp, undefined, ap);
|
|
145
191
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const name = rp.name;
|
|
149
|
-
if (l.plugins.some((p) => p.name === name))
|
|
150
|
-
continue;
|
|
151
|
-
const ap = aMap.get(name);
|
|
152
|
-
if (ap === undefined) {
|
|
153
|
-
merged.push(rp);
|
|
154
|
-
mergePoints += 1;
|
|
155
|
-
continue;
|
|
156
|
-
} // 远端独有
|
|
157
|
-
if (entryKey(rp) === entryKey(ap)) {
|
|
158
|
-
mergePoints += 1;
|
|
159
|
-
continue;
|
|
160
|
-
} // 远端未改、本机删 → 跟随删除
|
|
161
|
-
conflict(`plugins.${name}`, 'delete-modify', undefined, rp, ap);
|
|
192
|
+
else if (wsMerged !== wsLocal) {
|
|
193
|
+
mergePoints += 1;
|
|
162
194
|
}
|
|
163
195
|
if (conflicts.length > 0)
|
|
164
196
|
return { merged: l, conflicts, mergePoints };
|
|
165
|
-
|
|
197
|
+
// 以远端为底再盖本机:远端独有的未知/将来字段被采纳,而不是被本机形状悄悄吞掉(复审 P2)。
|
|
198
|
+
const next = { ...r, ...l };
|
|
199
|
+
next.plugins = plugins.merged;
|
|
200
|
+
next.patch = patch.merged;
|
|
201
|
+
// 可选字段只在「本机或合并结果里确实有」时写回:不擅自在载荷里新增空字段。
|
|
202
|
+
if (l.localTarballs !== undefined || tarballs.merged.length > 0)
|
|
203
|
+
next.localTarballs = tarballs.merged;
|
|
204
|
+
else
|
|
205
|
+
delete next.localTarballs;
|
|
206
|
+
if (l.patchFiles !== undefined || files.merged.length > 0)
|
|
207
|
+
next.patchFiles = files.merged;
|
|
208
|
+
else
|
|
209
|
+
delete next.patchFiles;
|
|
210
|
+
// 只有「两侧都没带这个键、合并也没产出值」才删键;否则原样写回(含 null)。
|
|
211
|
+
// 把 null 抹成缺键会让合并结果与两侧都不等 ⇒ 每轮都判「已合并」,永不收敛(复审 P0-1)。
|
|
212
|
+
if (wsMerged === undefined || (wsMerged === null && !wsCarried))
|
|
213
|
+
delete next.pnpmWorkspace;
|
|
214
|
+
else
|
|
215
|
+
next.pnpmWorkspace = wsMerged;
|
|
216
|
+
return { merged: next, conflicts: [], mergePoints };
|
|
166
217
|
}
|
|
167
218
|
//# sourceMappingURL=plugin-removals.js.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 推送目标选择与「冲突扣下」语义(issue #146)的单一实现。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独成模块:SyncEngine 已到体量棘轮上限,而这套语义是**纯决策** ——
|
|
5
|
+
* 「这轮推哪些分区 / 哪些被扣下 / 待裁决留哪些」与 IO 无关,放这里能被单测直接钉住。
|
|
6
|
+
*
|
|
7
|
+
* 事故背景(真机):冲突分区在合并阶段被有意跳过(绝不把冲突内容写进本地),
|
|
8
|
+
* 但推送侧原本没有任何过滤,于是「本机版本」照样被导出并覆盖远端 —— plugins 被 30 → 28 → 26 一路压小。
|
|
9
|
+
*
|
|
10
|
+
* 三条不变量:
|
|
11
|
+
* 1. 过滤只在一处发生(`resolvePushTargets`),push 与 previewPush 共用同一出口 ⇒ **同一份 opts 下**
|
|
12
|
+
* 预览必等于实际。跨入口的口径差只可能来自「调用方传没传 skipSections」(`undefined` = 手动不扣磁盘,
|
|
13
|
+
* 空数组 = 连磁盘待裁决一起扣),契约 §7.3 有调用方对照表 —— 别再把它读成无条件不变量;
|
|
14
|
+
* 2. `force: true` 不扣任何分区(强推 = 用户明确要「用本机覆盖远端」);
|
|
15
|
+
* 3. 全被扣下 ⇒ 一个分区都不上行,基线与待裁决都不动(引擎返回 `skipped:'all-conflicted'`)。
|
|
16
|
+
*/
|
|
17
|
+
import type { ConfigAdapter } from '../core/types.ts';
|
|
18
|
+
import type { SectionId } from '../schema/types.ts';
|
|
19
|
+
import type { PendingMerge } from './sync-state.ts';
|
|
20
|
+
/**
|
|
21
|
+
* 本轮推送目标:真正上行的分区 + 被扣下(held)的分区 —— 两者互斥、合起来 = 全部候选。
|
|
22
|
+
* 词汇统一:`held` = 仍在等裁决、本轮必须扣下的分区(对应引擎选项 `skipSections` 的入参语义)。
|
|
23
|
+
*/
|
|
24
|
+
export interface PushTargets {
|
|
25
|
+
targets: ConfigAdapter[];
|
|
26
|
+
held: SectionId[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 本轮要扣下(held)的分区集合 = 调用方点名的分区 ∪ 磁盘上**仍在等裁决**的分区(`force` 时不扣:强推就是明确覆盖远端)。
|
|
30
|
+
* 触发条件是「调用方传了 `skipSections`」而不是「传了非空数组」:自动同步本轮没判出新冲突时也必须
|
|
31
|
+
* 传空数组 —— 磁盘上上一轮留下的待裁决照样要扣下(否则任何一轮别的分区有改动就把它推上去,#146 复发)。
|
|
32
|
+
* 不传(`undefined`)= 手动推送:照旧不受历史待裁决影响。
|
|
33
|
+
* 读不到状态 ⇒ 只扣点名的分区(不猜),但绝不因此放行点名要扣的那些。
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveHeldSections(opts: {
|
|
36
|
+
force?: boolean;
|
|
37
|
+
skipSections?: readonly SectionId[];
|
|
38
|
+
}, load?: () => Promise<{
|
|
39
|
+
pendingMerge?: PendingMerge;
|
|
40
|
+
}>): Promise<ReadonlySet<SectionId>>;
|
|
41
|
+
/**
|
|
42
|
+
* 计算本轮推送目标并扣掉 `held` 里的分区(**唯一过滤点**)。
|
|
43
|
+
* 未指定 sections = portable 全量 + 本次放行的可选分区;未知 id 交给 `onSkipNonPortable` 告警。
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolvePushTargets(portable: readonly ConfigAdapter[], optIn: readonly ConfigAdapter[], sections: readonly SectionId[] | undefined, held: ReadonlySet<SectionId> | undefined, onSkipNonPortable: (id: SectionId) => void): PushTargets;
|
|
46
|
+
/**
|
|
47
|
+
* 推送成功后的待裁决:只剔除**真正推上去**的分区(其余 sections 与 since 原样保留)。
|
|
48
|
+
* 按 `pushed` 剔除而不是按「被扣下的分区」剔除:本轮不在候选里的分区(如未放行的可选分区)
|
|
49
|
+
* 根本没推上去,它的待裁决必须留下,否则等于静默丢记录。
|
|
50
|
+
* 一条都不剩 → `null`(这次推送已把本机版本推成远端最新,待裁决随之消解);
|
|
51
|
+
* 读不到状态 → `undefined`(recordBaseline 只在 `null` 时删字段 ⇒ 读失败保留原记录)。
|
|
52
|
+
*/
|
|
53
|
+
export declare function pendingMergeAfterPush(load: () => Promise<{
|
|
54
|
+
pendingMerge?: PendingMerge;
|
|
55
|
+
}>, pushed: readonly SectionId[]): Promise<PendingMerge | null | undefined>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 本轮要扣下(held)的分区集合 = 调用方点名的分区 ∪ 磁盘上**仍在等裁决**的分区(`force` 时不扣:强推就是明确覆盖远端)。
|
|
3
|
+
* 触发条件是「调用方传了 `skipSections`」而不是「传了非空数组」:自动同步本轮没判出新冲突时也必须
|
|
4
|
+
* 传空数组 —— 磁盘上上一轮留下的待裁决照样要扣下(否则任何一轮别的分区有改动就把它推上去,#146 复发)。
|
|
5
|
+
* 不传(`undefined`)= 手动推送:照旧不受历史待裁决影响。
|
|
6
|
+
* 读不到状态 ⇒ 只扣点名的分区(不猜),但绝不因此放行点名要扣的那些。
|
|
7
|
+
*/
|
|
8
|
+
export async function resolveHeldSections(opts, load) {
|
|
9
|
+
if (opts.force === true || opts.skipSections === undefined)
|
|
10
|
+
return new Set();
|
|
11
|
+
const held = new Set(opts.skipSections);
|
|
12
|
+
if (load !== undefined) {
|
|
13
|
+
try {
|
|
14
|
+
for (const id of (await load()).pendingMerge?.sections ?? [])
|
|
15
|
+
held.add(id);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// 读不到就只扣点名分区
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return held;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 计算本轮推送目标并扣掉 `held` 里的分区(**唯一过滤点**)。
|
|
25
|
+
* 未指定 sections = portable 全量 + 本次放行的可选分区;未知 id 交给 `onSkipNonPortable` 告警。
|
|
26
|
+
*/
|
|
27
|
+
export function resolvePushTargets(portable, optIn, sections, held, onSkipNonPortable) {
|
|
28
|
+
const all = [];
|
|
29
|
+
if (sections === undefined || sections.length === 0) {
|
|
30
|
+
all.push(...portable, ...optIn);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const byId = new Map(portable.map((a) => [a.id, a]));
|
|
34
|
+
for (const a of optIn)
|
|
35
|
+
byId.set(a.id, a);
|
|
36
|
+
for (const id of sections) {
|
|
37
|
+
const adapter = byId.get(id);
|
|
38
|
+
if (adapter === undefined)
|
|
39
|
+
onSkipNonPortable(id);
|
|
40
|
+
else
|
|
41
|
+
all.push(adapter);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (held === undefined || held.size === 0)
|
|
45
|
+
return { targets: all, held: [] };
|
|
46
|
+
return {
|
|
47
|
+
targets: all.filter((a) => !held.has(a.id)),
|
|
48
|
+
held: all.filter((a) => held.has(a.id)).map((a) => a.id),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 推送成功后的待裁决:只剔除**真正推上去**的分区(其余 sections 与 since 原样保留)。
|
|
53
|
+
* 按 `pushed` 剔除而不是按「被扣下的分区」剔除:本轮不在候选里的分区(如未放行的可选分区)
|
|
54
|
+
* 根本没推上去,它的待裁决必须留下,否则等于静默丢记录。
|
|
55
|
+
* 一条都不剩 → `null`(这次推送已把本机版本推成远端最新,待裁决随之消解);
|
|
56
|
+
* 读不到状态 → `undefined`(recordBaseline 只在 `null` 时删字段 ⇒ 读失败保留原记录)。
|
|
57
|
+
*/
|
|
58
|
+
export async function pendingMergeAfterPush(load, pushed) {
|
|
59
|
+
try {
|
|
60
|
+
const prev = (await load()).pendingMerge;
|
|
61
|
+
if (prev === undefined)
|
|
62
|
+
return null;
|
|
63
|
+
const kept = prev.sections.filter((s) => !pushed.includes(s));
|
|
64
|
+
return kept.length === 0 ? null : { ...prev, sections: kept };
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=push-skip.js.map
|
|
@@ -96,7 +96,7 @@ export declare class S3Transport implements SyncTransport {
|
|
|
96
96
|
*/
|
|
97
97
|
private reassertIndexEtag;
|
|
98
98
|
/**
|
|
99
|
-
* 条件写失败分类(issue #109 第二层复核):`
|
|
99
|
+
* 条件写失败分类(issue #109 第二层复核):`isPreconditionFailedStatus` 只看「状态码像不像」,
|
|
100
100
|
* 这里再问报文一句确认「对象确实已存在」。OSS 的 **409 不止 FileAlreadyExists** ——
|
|
101
101
|
* FileImmutable(Bucket 数据处于保护状态,删改都会被拒)同为 409,一律按并发写报
|
|
102
102
|
* 「别的设备改过索引」就是假话。报文读不出时仍按并发写处理(宁可让用户重跑一次,
|
|
@@ -136,7 +136,6 @@ export declare class S3Transport implements SyncTransport {
|
|
|
136
136
|
private readIndexDetailed;
|
|
137
137
|
private parseIndex;
|
|
138
138
|
private parseSnapshot;
|
|
139
|
-
/** 读取 blob 索引(哈希 → 写入时间 ms);缺失/损坏 → 空(GC 只会「少删」,不会误删) */
|
|
140
139
|
/**
|
|
141
140
|
* 远端是否已存在历史内容(t66)。判据 = **blob 仓索引对象存在**:它是本通道唯一的、
|
|
142
141
|
* 无需列举整个桶就能读到的「这里以前写过」证据(本实现未用 ListObjects)。
|
|
@@ -146,7 +145,20 @@ export declare class S3Transport implements SyncTransport {
|
|
|
146
145
|
* 已知残余(如实登记):远端只有**未外置**的历史快照、索引又缺失时本判据看不出内容(无列举能力)。
|
|
147
146
|
*/
|
|
148
147
|
private remoteHasPriorContent;
|
|
148
|
+
/** 读取 blob 索引(哈希 → 写入时间 ms);只读失败即抛,绝不回落成空索引,见 readBlobIndexDetailed。 */
|
|
149
149
|
private readBlobIndex;
|
|
150
|
+
/**
|
|
151
|
+
* audit-sync sync-P6-4(P3):与 WebDAV 同型 —— 「读失败」与「确实没有索引」必须分开。
|
|
152
|
+
*
|
|
153
|
+
* 旧实现把非 404 与坏 JSON 一律当成空索引,紧接着 appendBlobIndex 读→合并→整体 PUT 覆盖,
|
|
154
|
+
* 一次 5xx 抖动就把远端已登记条目全丢掉(GC 从此看不见这些 blob,等于远端漏账)。三态语义:
|
|
155
|
+
* - 404 → missing = true:桶里确实没有 blob 索引,按空处理是安全的(不会被覆盖成假集合);
|
|
156
|
+
* - 其它非 2xx(5xx / 403 / …)→ 抛错(可重试):读不出来就**不许**整体覆盖;
|
|
157
|
+
* - 200 但坏 JSON / 非对象 → 抛 protocol(不可重试):索引损坏是远端状态问题,覆盖写会抹掉残存记录。
|
|
158
|
+
*
|
|
159
|
+
* 最坏情况(可重试失败):本可跳过的 blob 被重传一遍,或本次 blob 漏登记(只占空间,不误删)。
|
|
160
|
+
*/
|
|
161
|
+
private readBlobIndexDetailed;
|
|
150
162
|
private writeBlobIndex;
|
|
151
163
|
private appendBlobIndex;
|
|
152
164
|
/** blob 仓端口:命中索引 = 零传输;失败安全取舍与 WebDAV 通道一致 */
|
|
@@ -27,7 +27,7 @@ import { parseJsonSafe } from '../../utils/json.js';
|
|
|
27
27
|
import { GC_SKIP_REFERENCE_MISSING, GC_SKIP_REFERENCE_UNREADABLE, GC_SKIP_SNAPSHOT_UNPARSABLE } from '../gc-skip.js';
|
|
28
28
|
import { deserializeSnapshot, serializeSnapshot } from '../snapshot-json.js';
|
|
29
29
|
import { BLOB_SECTIONS, gcBlobs, isBlobRefsSection, isFilesSectionLike, referencedBlobHashes, refsToSection, sectionToBlobRefs, } from '../blob-store.js';
|
|
30
|
-
import { classifyHttpStatus, classifyNetworkErrorText, computeSnapshotMeta, DEFAULT_SYNC_TIMEOUT_MS, isEncryptedSections, sectionsEqual, SyncTransportError, withSyncRetry, } from '../transport.js';
|
|
30
|
+
import { classifyHttpStatus, classifyNetworkErrorText, computeSnapshotMeta, DEFAULT_SYNC_TIMEOUT_MS, isEncryptedSections, isPreconditionFailedStatus, sectionsEqual, SyncTransportError, withSyncRetry, } from '../transport.js';
|
|
31
31
|
import { signRequest } from './sigv4.js';
|
|
32
32
|
import { composeMsg, s3Msg } from './messages.js';
|
|
33
33
|
import { blobIndexKey, blobKey, canonicalObjectPath, indexKey, objectUrl, resolveS3Target, snapshotKey, } from './s3-providers.js';
|
|
@@ -61,15 +61,6 @@ function conditionalHeaders(etag, indexMissing, mode) {
|
|
|
61
61
|
return {};
|
|
62
62
|
return guarded ? { 'x-oss-forbid-overwrite': 'true' } : { 'if-none-match': '*' };
|
|
63
63
|
}
|
|
64
|
-
/**
|
|
65
|
-
* 条件写失败判定:412 恒是;409 仅在**确实带了条件写头**时才算
|
|
66
|
-
* (无条件的 409 另有含义,不吞;条件写头的存在由调用方显式告知)。
|
|
67
|
-
*/
|
|
68
|
-
function isConcurrentWrite(status, guarded) {
|
|
69
|
-
if (status === 412)
|
|
70
|
-
return true;
|
|
71
|
-
return status === 409 && guarded;
|
|
72
|
-
}
|
|
73
64
|
/** S3 通道错误:继承统一错误基类(kind / retryable / status 对上层可见)。 */
|
|
74
65
|
export class S3TransportError extends SyncTransportError {
|
|
75
66
|
constructor(message, opts = {}) {
|
|
@@ -268,30 +259,45 @@ export class S3Transport {
|
|
|
268
259
|
// audit-sync sync-N1(P0):与 WebDAV 同型 —— 写路径**不接受 404 = 空集合**。索引真缺失时
|
|
269
260
|
// 「远端一条快照都没有」是缺信息而非事实,沿用空索引会覆盖 index.json 并用空引用集回收 blob。
|
|
270
261
|
const { entries: idx, missing: indexMissing, etag: idxEtag } = await this.readIndexDetailed(secret);
|
|
271
|
-
const
|
|
272
|
-
if (
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
262
|
+
const key = snapshotKey(this.target.prefix, id);
|
|
263
|
+
if (indexMissing) {
|
|
264
|
+
// audit-sync sync-N1(P0):索引真缺失(404)= 缺信息而非「集合为空」→ **不写回索引、不触发 GC**,
|
|
265
|
+
// 其余快照与其引用的 blob 原样保留(与 WebDAV 同型)。目标快照文件按用户意图删除(404 视为成功)。
|
|
266
|
+
const del = await this.send('DELETE', key, { secret });
|
|
267
|
+
if (!del.res.ok && del.res.status !== 404) {
|
|
268
|
+
throw new S3TransportError(await this.failText('DELETE', del.url, del.res, secret), classifyHttpStatus(del.res.status));
|
|
269
|
+
}
|
|
278
270
|
return;
|
|
271
|
+
}
|
|
279
272
|
const remaining = idx.filter((m) => m.id !== id);
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
273
|
+
const entryPresent = remaining.length !== idx.length;
|
|
274
|
+
// audit-sync sync-P6-1(P3):与 WebDAV 同型 —— **先写索引、后删对象**。
|
|
275
|
+
// 反序(旧实现先 DELETE 对象)的伤害:索引 PUT 408/412/409 冲突时本次删除已抛错中止,但对象没了
|
|
276
|
+
// ⇒ 索引留下指向不存在对象的条目;list() 不校验存在性,别的设备 pull 到该 id 即 notfound 硬失败。
|
|
277
|
+
// 调整顺序后的**最坏情况**:索引摘除成功而对象 DELETE 失败 ⇒ 远端留一个索引里不存在、list() 看不到、
|
|
278
|
+
// pull 不会命中的孤儿对象(只占空间);重跑 delete 会把对象补删(404 视为成功)。
|
|
279
|
+
if (entryPresent) {
|
|
280
|
+
const condHeaders = conditionalHeaders(idxEtag, false, this.target.conditionalWrite);
|
|
281
|
+
await this.reassertIndexEtag(idxEtag, secret);
|
|
282
|
+
const putIdx = await this.send('PUT', indexKey(this.target.prefix), {
|
|
283
|
+
body: JSON.stringify(remaining),
|
|
284
|
+
secret,
|
|
285
|
+
headers: condHeaders,
|
|
286
|
+
});
|
|
287
|
+
const idxFailure = await this.conditionalFailure('PUT', putIdx.url, putIdx.res, Object.keys(condHeaders).length > 0, secret);
|
|
288
|
+
if (idxFailure !== undefined)
|
|
289
|
+
throw idxFailure;
|
|
290
|
+
if (!putIdx.res.ok) {
|
|
291
|
+
throw new S3TransportError(await this.failText('PUT', putIdx.url, putIdx.res, secret), classifyHttpStatus(putIdx.res.status));
|
|
292
|
+
}
|
|
294
293
|
}
|
|
294
|
+
// 索引已摘除(或本来就无该 id)后才动对象:404 = 不存在,视为成功
|
|
295
|
+
const del = await this.send('DELETE', key, { secret });
|
|
296
|
+
if (!del.res.ok && del.res.status !== 404) {
|
|
297
|
+
throw new S3TransportError(await this.failText('DELETE', del.url, del.res, secret), classifyHttpStatus(del.res.status));
|
|
298
|
+
}
|
|
299
|
+
if (!entryPresent && !del.res.ok)
|
|
300
|
+
return; // 索引无该 id 且对象本就不存在 → 静默成功,无 GC 可做
|
|
295
301
|
await this.gcBlobStore(secret, remaining).catch(() => undefined);
|
|
296
302
|
}
|
|
297
303
|
/* ---------------- 内部实现 ---------------- */
|
|
@@ -326,14 +332,15 @@ export class S3Transport {
|
|
|
326
332
|
}
|
|
327
333
|
}
|
|
328
334
|
/**
|
|
329
|
-
* 条件写失败分类(issue #109 第二层复核):`
|
|
335
|
+
* 条件写失败分类(issue #109 第二层复核):`isPreconditionFailedStatus` 只看「状态码像不像」,
|
|
330
336
|
* 这里再问报文一句确认「对象确实已存在」。OSS 的 **409 不止 FileAlreadyExists** ——
|
|
331
337
|
* FileImmutable(Bucket 数据处于保护状态,删改都会被拒)同为 409,一律按并发写报
|
|
332
338
|
* 「别的设备改过索引」就是假话。报文读不出时仍按并发写处理(宁可让用户重跑一次,
|
|
333
339
|
* 不吞掉真冲突)。412 是 If-Match 语义,恒为并发写。
|
|
334
340
|
*/
|
|
335
341
|
async conditionalFailure(method, url, res, guarded, secret) {
|
|
336
|
-
|
|
342
|
+
// 判定与 WebDAV 通道共用 transport.ts 的唯一实现(412 恒算;409 仅在真的带了条件头时算)
|
|
343
|
+
if (!isPreconditionFailedStatus(res.status, { guarded }))
|
|
337
344
|
return undefined;
|
|
338
345
|
if (res.status !== 409)
|
|
339
346
|
return this.concurrentWrite(url, res.status);
|
|
@@ -531,7 +538,6 @@ export class S3Transport {
|
|
|
531
538
|
}
|
|
532
539
|
}
|
|
533
540
|
/* ---------------- P1-4:内容寻址 blob 仓 ---------------- */
|
|
534
|
-
/** 读取 blob 索引(哈希 → 写入时间 ms);缺失/损坏 → 空(GC 只会「少删」,不会误删) */
|
|
535
541
|
/**
|
|
536
542
|
* 远端是否已存在历史内容(t66)。判据 = **blob 仓索引对象存在**:它是本通道唯一的、
|
|
537
543
|
* 无需列举整个桶就能读到的「这里以前写过」证据(本实现未用 ListObjects)。
|
|
@@ -564,26 +570,44 @@ export class S3Transport {
|
|
|
564
570
|
return true;
|
|
565
571
|
}
|
|
566
572
|
}
|
|
573
|
+
/** 读取 blob 索引(哈希 → 写入时间 ms);只读失败即抛,绝不回落成空索引,见 readBlobIndexDetailed。 */
|
|
567
574
|
async readBlobIndex(secret) {
|
|
575
|
+
return (await this.readBlobIndexDetailed(secret)).index;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* audit-sync sync-P6-4(P3):与 WebDAV 同型 —— 「读失败」与「确实没有索引」必须分开。
|
|
579
|
+
*
|
|
580
|
+
* 旧实现把非 404 与坏 JSON 一律当成空索引,紧接着 appendBlobIndex 读→合并→整体 PUT 覆盖,
|
|
581
|
+
* 一次 5xx 抖动就把远端已登记条目全丢掉(GC 从此看不见这些 blob,等于远端漏账)。三态语义:
|
|
582
|
+
* - 404 → missing = true:桶里确实没有 blob 索引,按空处理是安全的(不会被覆盖成假集合);
|
|
583
|
+
* - 其它非 2xx(5xx / 403 / …)→ 抛错(可重试):读不出来就**不许**整体覆盖;
|
|
584
|
+
* - 200 但坏 JSON / 非对象 → 抛 protocol(不可重试):索引损坏是远端状态问题,覆盖写会抹掉残存记录。
|
|
585
|
+
*
|
|
586
|
+
* 最坏情况(可重试失败):本可跳过的 blob 被重传一遍,或本次 blob 漏登记(只占空间,不误删)。
|
|
587
|
+
*/
|
|
588
|
+
async readBlobIndexDetailed(secret) {
|
|
568
589
|
const sent = await this.send('GET', blobIndexKey(this.target.prefix), { secret });
|
|
569
590
|
if (sent.res.status === 404)
|
|
570
|
-
return {};
|
|
571
|
-
if (!sent.res.ok)
|
|
572
|
-
|
|
591
|
+
return { index: {}, missing: true };
|
|
592
|
+
if (!sent.res.ok) {
|
|
593
|
+
throw new S3TransportError(await this.failText('GET', sent.url, sent.res, secret), classifyHttpStatus(sent.res.status));
|
|
594
|
+
}
|
|
595
|
+
let parsed;
|
|
573
596
|
try {
|
|
574
|
-
|
|
575
|
-
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
576
|
-
return {};
|
|
577
|
-
const out = {};
|
|
578
|
-
for (const [hash, at] of Object.entries(parsed)) {
|
|
579
|
-
if (BLOB_HASH_RE.test(hash) && typeof at === 'number' && Number.isFinite(at))
|
|
580
|
-
out[hash] = at;
|
|
581
|
-
}
|
|
582
|
-
return out;
|
|
597
|
+
parsed = parseJsonSafe(await sent.res.text());
|
|
583
598
|
}
|
|
584
|
-
catch {
|
|
585
|
-
|
|
599
|
+
catch (err) {
|
|
600
|
+
throw new S3TransportError(this.o.msg('sync.s3.indexInvalid', { url: sent.url, err: this.mask(String(err?.message ?? ''), secret) }), { kind: 'protocol', retryable: false });
|
|
601
|
+
}
|
|
602
|
+
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
603
|
+
throw new S3TransportError(this.o.msg('sync.s3.indexInvalid', { url: sent.url, err: 'not an object' }), { kind: 'protocol', retryable: false });
|
|
604
|
+
}
|
|
605
|
+
const out = {};
|
|
606
|
+
for (const [hash, at] of Object.entries(parsed)) {
|
|
607
|
+
if (BLOB_HASH_RE.test(hash) && typeof at === 'number' && Number.isFinite(at))
|
|
608
|
+
out[hash] = at;
|
|
586
609
|
}
|
|
610
|
+
return { index: out, missing: false };
|
|
587
611
|
}
|
|
588
612
|
async writeBlobIndex(secret, index) {
|
|
589
613
|
const sent = await this.send('PUT', blobIndexKey(this.target.prefix), { body: JSON.stringify(index), secret });
|