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
|
@@ -20,6 +20,14 @@ export interface PatchLineChange {
|
|
|
20
20
|
lineId: string;
|
|
21
21
|
raw: unknown;
|
|
22
22
|
action: 'insert' | 'update' | 'remove';
|
|
23
|
+
/**
|
|
24
|
+
* 强制这一行落在**顶层**(覆盖行),即使本层还留着同名 insert 成员(issue #144 的存量修复)。
|
|
25
|
+
*
|
|
26
|
+
* 不变①的例外,只在调用方**知道该 id 已被别的层提供**时置位:此时本层的旧 insert 成员与
|
|
27
|
+
* 别处的 insert 是两条新增抢同一个 id(宿主 compose 后取到没有 config 的那份,插件保存配置
|
|
28
|
+
* 必然报 overridden)。光把 action 改成 update 不够 —— 归属按原文档决定,insert 成员会原地留下。
|
|
29
|
+
*/
|
|
30
|
+
forceTopLevel?: boolean;
|
|
23
31
|
}
|
|
24
32
|
export interface PatchDocumentPlan {
|
|
25
33
|
/** 重建后的文档条目(顺序尽量贴原文档:顶层行原位、insert 块原位、新增项追加在尾部) */
|
|
@@ -34,6 +42,21 @@ export declare class PatchPromoteRefusedError extends Error {
|
|
|
34
42
|
readonly ids: string[];
|
|
35
43
|
constructor(ids: string[]);
|
|
36
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* 文档里的一条条目:id、它声明的 name、以及出现在 insert 块里还是顶层。
|
|
47
|
+
*
|
|
48
|
+
* 为什么把 name 一起读出来:写**顶层覆盖行**时宿主会校验 `name === target.name`,不一致就
|
|
49
|
+
* `patch: name mismatch … skipping` 整行跳过(issue #144 的条目都来自 bundle 层,name 在那边)。
|
|
50
|
+
*/
|
|
51
|
+
export interface PatchDocumentEntry {
|
|
52
|
+
id: string;
|
|
53
|
+
/** 条目里声明的 name(没写就没有;覆盖行不写 name 也合法) */
|
|
54
|
+
name?: string;
|
|
55
|
+
/** true = `- insert:` 块成员(新增);false = 顶层行(覆盖) */
|
|
56
|
+
inInsert: boolean;
|
|
57
|
+
}
|
|
58
|
+
/** 读出文档里的全部条目(不判重、保持文档顺序)。 */
|
|
59
|
+
export declare function patchDocumentEntries(doc: unknown): PatchDocumentEntry[];
|
|
37
60
|
/** 读出文档里的 insert 成员 id 与顶层行 id(自检与测试共用;不判重、保持文档顺序)。 */
|
|
38
61
|
export declare function describePatchDocument(doc: unknown): {
|
|
39
62
|
insertIds: string[];
|
|
@@ -57,9 +80,14 @@ export declare function describePatchLayoutDrift(planned: {
|
|
|
57
80
|
topLevelIds: readonly string[];
|
|
58
81
|
}): string | null;
|
|
59
82
|
/**
|
|
60
|
-
*
|
|
83
|
+
* 覆盖行孤儿检查(issue #133 起、issue #144 改判到「整条生效链」口径)。
|
|
84
|
+
*
|
|
85
|
+
* 宿主对顶层行只做**覆盖**:`entryMap` 查不到该 id ⇒ `patch: entry %C not found` 整行丢弃。
|
|
86
|
+
* 所以真正值得拒绝的只有一种:**任何一层都没有提供这个 id**。旧判据反过来拒绝「别的层用
|
|
87
|
+
* `- insert:` 提供过它」—— 那恰恰是条目已经存在、覆盖**合法**的情形,#144 里 bundle 层提供的
|
|
88
|
+
* 6 个 id 正是被这条旧判据误拒的(写进去就是重复条目)。
|
|
61
89
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
90
|
+
* `docs` = 判定依据的层文档(生效链 + 本文件写入前的文档;读不出来的层由调用方自行丢弃 ——
|
|
91
|
+
* 守卫只做加强,绝不因为兄弟层损坏而永久阻塞写入)。
|
|
64
92
|
*/
|
|
65
|
-
export declare function
|
|
93
|
+
export declare function unprovidedTopLevelIds(docs: readonly unknown[], topLevelIds: readonly string[]): string[];
|
|
@@ -21,25 +21,44 @@ function blockMembers(value) {
|
|
|
21
21
|
return null;
|
|
22
22
|
return insert.filter((entry) => entry !== null && typeof entry === 'object');
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
25
|
-
export function
|
|
26
|
-
const
|
|
27
|
-
const topLevelIds = [];
|
|
24
|
+
/** 读出文档里的全部条目(不判重、保持文档顺序)。 */
|
|
25
|
+
export function patchDocumentEntries(doc) {
|
|
26
|
+
const entries = [];
|
|
28
27
|
if (!Array.isArray(doc))
|
|
29
|
-
return
|
|
28
|
+
return entries;
|
|
30
29
|
for (const item of doc) {
|
|
31
30
|
const members = blockMembers(item);
|
|
32
31
|
if (members !== null) {
|
|
33
32
|
for (const member of members) {
|
|
34
33
|
const id = entryId(member);
|
|
35
|
-
if (id
|
|
36
|
-
|
|
34
|
+
if (id === null)
|
|
35
|
+
continue;
|
|
36
|
+
const name = member['name'];
|
|
37
|
+
entries.push(typeof name === 'string'
|
|
38
|
+
? { id, name, inInsert: true }
|
|
39
|
+
: { id, inInsert: true });
|
|
37
40
|
}
|
|
38
41
|
continue;
|
|
39
42
|
}
|
|
40
43
|
const id = entryId(item);
|
|
41
|
-
if (id
|
|
42
|
-
|
|
44
|
+
if (id === null)
|
|
45
|
+
continue;
|
|
46
|
+
const name = item['name'];
|
|
47
|
+
entries.push(typeof name === 'string'
|
|
48
|
+
? { id, name, inInsert: false }
|
|
49
|
+
: { id, inInsert: false });
|
|
50
|
+
}
|
|
51
|
+
return entries;
|
|
52
|
+
}
|
|
53
|
+
/** 读出文档里的 insert 成员 id 与顶层行 id(自检与测试共用;不判重、保持文档顺序)。 */
|
|
54
|
+
export function describePatchDocument(doc) {
|
|
55
|
+
const insertIds = [];
|
|
56
|
+
const topLevelIds = [];
|
|
57
|
+
for (const entry of patchDocumentEntries(doc)) {
|
|
58
|
+
if (entry.inInsert)
|
|
59
|
+
insertIds.push(entry.id);
|
|
60
|
+
else
|
|
61
|
+
topLevelIds.push(entry.id);
|
|
43
62
|
}
|
|
44
63
|
return { insertIds, topLevelIds };
|
|
45
64
|
}
|
|
@@ -82,8 +101,11 @@ export function planPatchDocument(doc, changes) {
|
|
|
82
101
|
continue;
|
|
83
102
|
}
|
|
84
103
|
const previous = state.get(change.lineId);
|
|
85
|
-
//
|
|
86
|
-
|
|
104
|
+
// 归属默认由**原文档**决定:更新一条既有 insert 成员不会把它搬到顶层;新增才按动作分流。
|
|
105
|
+
// forceTopLevel 是唯一例外(#144 存量:本层旧 insert 成员 + 别层也 insert 同一 id)。
|
|
106
|
+
const inInsert = change.forceTopLevel === true
|
|
107
|
+
? false
|
|
108
|
+
: previous !== undefined ? previous.inInsert : change.action === 'insert';
|
|
87
109
|
state.set(change.lineId, { raw: change.raw, inInsert });
|
|
88
110
|
}
|
|
89
111
|
const items = [];
|
|
@@ -147,15 +169,24 @@ export function describePatchLayoutDrift(planned, observed) {
|
|
|
147
169
|
+ '; got ' + fmt('insert', observed.insertIds) + ' ' + fmt('top-level', observed.topLevelIds);
|
|
148
170
|
}
|
|
149
171
|
/**
|
|
150
|
-
*
|
|
172
|
+
* 覆盖行孤儿检查(issue #133 起、issue #144 改判到「整条生效链」口径)。
|
|
173
|
+
*
|
|
174
|
+
* 宿主对顶层行只做**覆盖**:`entryMap` 查不到该 id ⇒ `patch: entry %C not found` 整行丢弃。
|
|
175
|
+
* 所以真正值得拒绝的只有一种:**任何一层都没有提供这个 id**。旧判据反过来拒绝「别的层用
|
|
176
|
+
* `- insert:` 提供过它」—— 那恰恰是条目已经存在、覆盖**合法**的情形,#144 里 bundle 层提供的
|
|
177
|
+
* 6 个 id 正是被这条旧判据误拒的(写进去就是重复条目)。
|
|
151
178
|
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
179
|
+
* `docs` = 判定依据的层文档(生效链 + 本文件写入前的文档;读不出来的层由调用方自行丢弃 ——
|
|
180
|
+
* 守卫只做加强,绝不因为兄弟层损坏而永久阻塞写入)。
|
|
154
181
|
*/
|
|
155
|
-
export function
|
|
182
|
+
export function unprovidedTopLevelIds(docs, topLevelIds) {
|
|
156
183
|
if (topLevelIds.length === 0)
|
|
157
184
|
return [];
|
|
158
|
-
const
|
|
159
|
-
|
|
185
|
+
const provided = new Set();
|
|
186
|
+
for (const doc of docs) {
|
|
187
|
+
for (const entry of patchDocumentEntries(doc))
|
|
188
|
+
provided.add(entry.id);
|
|
189
|
+
}
|
|
190
|
+
return topLevelIds.filter((id) => !provided.has(id));
|
|
160
191
|
}
|
|
161
192
|
//# sourceMappingURL=patch-document.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* patch 行写回守卫(issue #136 A + C)。
|
|
3
|
+
*
|
|
4
|
+
* 背景:导出侧 SecretScanner 会把命中字段名/值形状的字符串叶子替换成空串(占位符),语义是
|
|
5
|
+
* 「需补录」。同步/导入落盘时,若照抄这个空串,就会**静默**抹掉本机同一行里用户手写的明文
|
|
6
|
+
* —— 行是整行写回的,行内没有粒度。
|
|
7
|
+
*
|
|
8
|
+
* 本模块是那条「最后一个能拒绝写入」的纯逻辑:比对导入值与本机当前行,把「被脱敏剥空」的
|
|
9
|
+
* 叶子换回本机值;只有调用方显式声明逐行确认(`confirmed`)才允许真的写空。
|
|
10
|
+
*
|
|
11
|
+
* 两条分支(issue #136 C 的载荷字段决定):
|
|
12
|
+
* - `redactedPaths` 存在(新载荷):只保护**声明过的**路径,精确、可解释;
|
|
13
|
+
* - 缺省(旧载荷 / 未知):保守口径 —— 导入值为空串且本机同叶子非空即保留本机值。
|
|
14
|
+
* 绝不反过来假定「空值一定来自用户主动清空」(旧载荷没有能力区分剥空与真空)。
|
|
15
|
+
*
|
|
16
|
+
* 纯函数:不读盘、不打日志、不抛错;返回值不含任何值本身(只有路径),可直接进报告。
|
|
17
|
+
*/
|
|
18
|
+
/** 路径段(对象键或数组下标)。 */
|
|
19
|
+
type Segment = string | number;
|
|
20
|
+
export interface PatchSecretGuardInput {
|
|
21
|
+
/** 备份/远端载荷里的整行值(可能含被剥空的叶子)。 */
|
|
22
|
+
importedRaw: unknown;
|
|
23
|
+
/** 本机当前同一行的值;`undefined` = 本机没有这一行(Create 语义,无可保护对象)。 */
|
|
24
|
+
localRaw: unknown;
|
|
25
|
+
/** 载荷声明的剥空路径(行内相对,如 `raw.mcp.args.token`);缺省 = 未知(旧载荷)。 */
|
|
26
|
+
redactedPaths?: readonly string[] | undefined;
|
|
27
|
+
/** 调用方已拿到对该行的**逐行显式确认** → 允许写空。 */
|
|
28
|
+
confirmed: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface PatchSecretGuardResult {
|
|
31
|
+
/** 实际应写入的行值(受保护叶子已换回本机值)。 */
|
|
32
|
+
raw: unknown;
|
|
33
|
+
/** 被保留的本机值路径(行内相对,展示用)。 */
|
|
34
|
+
kept: string[];
|
|
35
|
+
/** 逐行确认后真的写空的路径(同一份事实进报告)。 */
|
|
36
|
+
cleared: string[];
|
|
37
|
+
/** true = 载荷没带剥空路径,走的是保守推断分支。 */
|
|
38
|
+
conservative: boolean;
|
|
39
|
+
}
|
|
40
|
+
/** 解析扫描器路径语法(`a.b[0].c`)→ 路径段;语法不认识返回 null(宁可放过,不误判)。 */
|
|
41
|
+
export declare function parsePath(path: string): Segment[] | null;
|
|
42
|
+
/** 路径段 → 展示用相对路径(与扫描器语法同形,如 `raw.mcp.args.token`)。 */
|
|
43
|
+
declare function formatPath(segs: readonly Segment[]): string;
|
|
44
|
+
export declare function applyPatchSecretGuard(input: PatchSecretGuardInput): PatchSecretGuardResult;
|
|
45
|
+
export declare const __test: {
|
|
46
|
+
parsePath: typeof parsePath;
|
|
47
|
+
formatPath: typeof formatPath;
|
|
48
|
+
};
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* patch 行写回守卫(issue #136 A + C)。
|
|
3
|
+
*
|
|
4
|
+
* 背景:导出侧 SecretScanner 会把命中字段名/值形状的字符串叶子替换成空串(占位符),语义是
|
|
5
|
+
* 「需补录」。同步/导入落盘时,若照抄这个空串,就会**静默**抹掉本机同一行里用户手写的明文
|
|
6
|
+
* —— 行是整行写回的,行内没有粒度。
|
|
7
|
+
*
|
|
8
|
+
* 本模块是那条「最后一个能拒绝写入」的纯逻辑:比对导入值与本机当前行,把「被脱敏剥空」的
|
|
9
|
+
* 叶子换回本机值;只有调用方显式声明逐行确认(`confirmed`)才允许真的写空。
|
|
10
|
+
*
|
|
11
|
+
* 两条分支(issue #136 C 的载荷字段决定):
|
|
12
|
+
* - `redactedPaths` 存在(新载荷):只保护**声明过的**路径,精确、可解释;
|
|
13
|
+
* - 缺省(旧载荷 / 未知):保守口径 —— 导入值为空串且本机同叶子非空即保留本机值。
|
|
14
|
+
* 绝不反过来假定「空值一定来自用户主动清空」(旧载荷没有能力区分剥空与真空)。
|
|
15
|
+
*
|
|
16
|
+
* 纯函数:不读盘、不打日志、不抛错;返回值不含任何值本身(只有路径),可直接进报告。
|
|
17
|
+
*/
|
|
18
|
+
/** 解析扫描器路径语法(`a.b[0].c`)→ 路径段;语法不认识返回 null(宁可放过,不误判)。 */
|
|
19
|
+
export function parsePath(path) {
|
|
20
|
+
const segs = [];
|
|
21
|
+
let rest = path;
|
|
22
|
+
while (rest !== '') {
|
|
23
|
+
const m = /^([^.[\]]+)((?:\[\d+\])*)/.exec(rest);
|
|
24
|
+
if (m === null)
|
|
25
|
+
return null;
|
|
26
|
+
const head = m[1];
|
|
27
|
+
const tail = m[2] ?? '';
|
|
28
|
+
if (head === undefined)
|
|
29
|
+
return null;
|
|
30
|
+
segs.push(head);
|
|
31
|
+
for (const hit of tail.matchAll(/\[(\d+)\]/g)) {
|
|
32
|
+
const idx = hit[1];
|
|
33
|
+
if (idx !== undefined)
|
|
34
|
+
segs.push(Number(idx));
|
|
35
|
+
}
|
|
36
|
+
rest = rest.slice(m[0].length);
|
|
37
|
+
if (rest === '')
|
|
38
|
+
break;
|
|
39
|
+
if (!rest.startsWith('.'))
|
|
40
|
+
return null;
|
|
41
|
+
rest = rest.slice(1);
|
|
42
|
+
}
|
|
43
|
+
return segs.length > 0 ? segs : null;
|
|
44
|
+
}
|
|
45
|
+
/** 路径段 → 展示用相对路径(与扫描器语法同形,如 `raw.mcp.args.token`)。 */
|
|
46
|
+
function formatPath(segs) {
|
|
47
|
+
let out = '';
|
|
48
|
+
for (const seg of segs) {
|
|
49
|
+
if (typeof seg === 'number')
|
|
50
|
+
out += `[${seg}]`;
|
|
51
|
+
else
|
|
52
|
+
out += out === '' ? seg : `.${seg}`;
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
function getAt(root, segs) {
|
|
57
|
+
let cur = root;
|
|
58
|
+
for (const seg of segs) {
|
|
59
|
+
if (typeof seg === 'number') {
|
|
60
|
+
if (!Array.isArray(cur))
|
|
61
|
+
return undefined;
|
|
62
|
+
cur = cur[seg];
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
if (cur === null || typeof cur !== 'object' || Array.isArray(cur))
|
|
66
|
+
return undefined;
|
|
67
|
+
cur = cur[seg];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return cur;
|
|
71
|
+
}
|
|
72
|
+
/** 深拷贝后按路径写回(只在确有保护项时调用,避免无谓的整行拷贝)。 */
|
|
73
|
+
function setAt(root, segs, value) {
|
|
74
|
+
if (segs.length === 0)
|
|
75
|
+
return value;
|
|
76
|
+
const clone = structuredClone(root);
|
|
77
|
+
let cur = clone;
|
|
78
|
+
for (let i = 0; i < segs.length - 1; i++) {
|
|
79
|
+
const next = Array.isArray(cur)
|
|
80
|
+
? cur[segs[i]]
|
|
81
|
+
: cur[segs[i]];
|
|
82
|
+
if (next === null || typeof next !== 'object')
|
|
83
|
+
return clone; // 形状不符 → 不猜,原样返回
|
|
84
|
+
cur = next;
|
|
85
|
+
}
|
|
86
|
+
const last = segs[segs.length - 1];
|
|
87
|
+
if (Array.isArray(cur))
|
|
88
|
+
cur[last] = value;
|
|
89
|
+
else
|
|
90
|
+
cur[last] = value;
|
|
91
|
+
return clone;
|
|
92
|
+
}
|
|
93
|
+
/** 本机值是否「非空」:只有非空字符串算(脱敏占位符恒为空串,故此判据与载荷同口径)。 */
|
|
94
|
+
function isNonEmptyLocal(value) {
|
|
95
|
+
return typeof value === 'string' && value !== '';
|
|
96
|
+
}
|
|
97
|
+
/** 保守分支:逐叶子找出「导入空串 + 本机非空」的路径(旧载荷没有剥空信息时的唯一线索)。 */
|
|
98
|
+
function collectSuspects(imported, local, segs, out) {
|
|
99
|
+
if (imported === null || typeof imported !== 'object') {
|
|
100
|
+
if (imported === '' && isNonEmptyLocal(local))
|
|
101
|
+
out.push([...segs]);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (Array.isArray(imported)) {
|
|
105
|
+
for (let i = 0; i < imported.length; i++) {
|
|
106
|
+
collectSuspects(imported[i], Array.isArray(local) ? local[i] : undefined, [...segs, i], out);
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const obj = imported;
|
|
111
|
+
const localObj = local !== null && typeof local === 'object' && !Array.isArray(local)
|
|
112
|
+
? local
|
|
113
|
+
: undefined;
|
|
114
|
+
for (const [k, v] of Object.entries(obj))
|
|
115
|
+
collectSuspects(v, localObj?.[k], [...segs, k], out);
|
|
116
|
+
}
|
|
117
|
+
export function applyPatchSecretGuard(input) {
|
|
118
|
+
const { importedRaw, localRaw, redactedPaths, confirmed } = input;
|
|
119
|
+
// 本机没有这一行 → 没有可覆盖的东西(Create 语义),原样返回。
|
|
120
|
+
if (localRaw === undefined)
|
|
121
|
+
return { raw: importedRaw, kept: [], cleared: [], conservative: false };
|
|
122
|
+
const conservative = redactedPaths === undefined || redactedPaths.length === 0;
|
|
123
|
+
/** 候选:相对路径段(不含 `raw` 前缀;空数组 = 整行值本身)。 */
|
|
124
|
+
const candidates = [];
|
|
125
|
+
if (conservative) {
|
|
126
|
+
const found = [];
|
|
127
|
+
collectSuspects(importedRaw, localRaw, [], found);
|
|
128
|
+
for (const segs of found)
|
|
129
|
+
candidates.push({ segs, declared: false });
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
for (const path of redactedPaths) {
|
|
133
|
+
const segs = parsePath(path);
|
|
134
|
+
if (segs === null)
|
|
135
|
+
continue;
|
|
136
|
+
// 载荷里的路径是相对**行对象**(`{ file, lineId, raw }`)的;行内相对只剩 `raw` 之后的部分。
|
|
137
|
+
const rel = segs[0] === 'raw' ? segs.slice(1) : segs;
|
|
138
|
+
candidates.push({ segs: rel, declared: true });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const kept = [];
|
|
142
|
+
const cleared = [];
|
|
143
|
+
let raw = importedRaw;
|
|
144
|
+
for (const cand of candidates) {
|
|
145
|
+
const localVal = getAt(localRaw, cand.segs);
|
|
146
|
+
if (!isNonEmptyLocal(localVal))
|
|
147
|
+
continue;
|
|
148
|
+
const importedVal = getAt(importedRaw, cand.segs);
|
|
149
|
+
// 声明路径上出现了非空导入值 = 载荷自相矛盾(或值形状命中后被上游改回):以导入值为准,
|
|
150
|
+
// 绝不因为声明了路径就把远端真实新值挡掉(issue #136 验收 3)。
|
|
151
|
+
if (importedVal === '' || importedVal === undefined) {
|
|
152
|
+
const rel = formatPath(['raw', ...cand.segs]);
|
|
153
|
+
if (confirmed)
|
|
154
|
+
cleared.push(rel);
|
|
155
|
+
else {
|
|
156
|
+
kept.push(rel);
|
|
157
|
+
raw = setAt(raw, cand.segs, localVal);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return { raw, kept, cleared, conservative };
|
|
162
|
+
}
|
|
163
|
+
export const __test = { parsePath, formatPath };
|
|
164
|
+
//# sourceMappingURL=patch-secret-guard.js.map
|
package/lib/core/reconcile.d.ts
CHANGED
|
@@ -48,6 +48,12 @@ export interface ReconcileOutcome {
|
|
|
48
48
|
safeModeRequired: boolean;
|
|
49
49
|
/** unresolved(未到 terminal)的 incomplete op id(RECOVERY_REQUIRED 候选)。 */
|
|
50
50
|
unresolved: string[];
|
|
51
|
+
/**
|
|
52
|
+
* 「owner 仍活着(live)但 journal 本身还没到 terminal」的 op id(审计 P3-8)。
|
|
53
|
+
* 与 unresolved 的区别:它们不该进 recovery(执行方还在跑),但也**不是已收敛**。
|
|
54
|
+
* 锁被另一实例持有时启动分类据此产出 LOCKED_LIVE,而不是把「确实在跑」误报成 NORMAL。
|
|
55
|
+
*/
|
|
56
|
+
liveIncomplete: string[];
|
|
51
57
|
}
|
|
52
58
|
/** 可自证「不可能掩盖半成品配置改动」的残留类型(issue #87)。 */
|
|
53
59
|
export type SelfProvableResidualClass = 'artifact-only' | 'no-steps';
|
|
@@ -99,6 +105,8 @@ export interface StartupInspection {
|
|
|
99
105
|
recoveryRequired: boolean;
|
|
100
106
|
decisions: ReconcileDecision[];
|
|
101
107
|
unresolved: string[];
|
|
108
|
+
/** live owner 持有但 journal 未到 terminal 的 op id(P3-8:LOCKED_LIVE 的判据) */
|
|
109
|
+
liveIncomplete: string[];
|
|
102
110
|
/**
|
|
103
111
|
* durable SAFE MODE 标记的三态判定(t37):'blocked' / 'clear' / **'unknown'**。
|
|
104
112
|
* 单独暴露的原因:`safeModeRequired` 是聚合结论(还可能因 corrupt journal / needs-attention 为 true),
|
package/lib/core/reconcile.js
CHANGED
|
@@ -74,6 +74,7 @@ function selfProvableResidual(j) {
|
|
|
74
74
|
export async function reconcileActive(store, hooks, env, opts = {}) {
|
|
75
75
|
const decisions = [];
|
|
76
76
|
const unresolved = [];
|
|
77
|
+
const liveIncomplete = [];
|
|
77
78
|
let safeModeRequired = false;
|
|
78
79
|
const activeIds = await store.scanActive();
|
|
79
80
|
for (const operationId of activeIds) {
|
|
@@ -83,8 +84,10 @@ export async function reconcileActive(store, hooks, env, opts = {}) {
|
|
|
83
84
|
safeModeRequired = true;
|
|
84
85
|
if (outcome.unresolved)
|
|
85
86
|
unresolved.push(operationId);
|
|
87
|
+
if (outcome.liveIncomplete === true)
|
|
88
|
+
liveIncomplete.push(operationId);
|
|
86
89
|
}
|
|
87
|
-
return { decisions, safeModeRequired, unresolved };
|
|
90
|
+
return { decisions, safeModeRequired, unresolved, liveIncomplete };
|
|
88
91
|
}
|
|
89
92
|
async function reconcileOne(store, hooks, env, opts, operationId) {
|
|
90
93
|
const j = await store.loadActive(operationId);
|
|
@@ -102,7 +105,14 @@ async function reconcileOne(store, hooks, env, opts, operationId) {
|
|
|
102
105
|
}
|
|
103
106
|
// live owner 检查
|
|
104
107
|
if (await env.isLiveOwner(j)) {
|
|
105
|
-
|
|
108
|
+
// P3-8:live 只说明「有人还在跑」,不等于这条 journal 已收敛。未到 terminal 的 live journal
|
|
109
|
+
// 必须如实上报(liveIncomplete),否则 LOCKED 下的启动分类会把「确实在跑」误判成 NORMAL。
|
|
110
|
+
return {
|
|
111
|
+
decision: { operationId, kind: 'live', reason: engineMsg('core.reconcile.ownerLive'), snapshotId: j.snapshotId },
|
|
112
|
+
safeMode: false,
|
|
113
|
+
unresolved: false,
|
|
114
|
+
liveIncomplete: !isTerminalState(j.state),
|
|
115
|
+
};
|
|
106
116
|
}
|
|
107
117
|
// P1-A:ownership binding 强制校验(显式 recovery 捕获的 crashed ownership 证据)。
|
|
108
118
|
// journal.ownerInstanceId/lockId 必须匹配期望的 crashed ownership instanceId,否则不作 trusted 恢复。
|
|
@@ -461,7 +471,12 @@ export async function inspectStartup(store, hooks, env, opts, lockState) {
|
|
|
461
471
|
const durableSafe = durableSafeState !== 'clear';
|
|
462
472
|
const safeModeRequired = outcome.safeModeRequired || recoveryRequired || durableSafe;
|
|
463
473
|
return {
|
|
464
|
-
safeModeRequired,
|
|
474
|
+
safeModeRequired,
|
|
475
|
+
recoveryRequired,
|
|
476
|
+
decisions: outcome.decisions,
|
|
477
|
+
unresolved: outcome.unresolved,
|
|
478
|
+
liveIncomplete: outcome.liveIncomplete,
|
|
479
|
+
durableSafeState,
|
|
465
480
|
};
|
|
466
481
|
}
|
|
467
482
|
//# sourceMappingURL=reconcile.js.map
|
package/lib/core/reinstall.d.ts
CHANGED
package/lib/core/reinstall.js
CHANGED
|
@@ -133,9 +133,11 @@ export function copyDirCommand(src, dest, platform = process.platform) {
|
|
|
133
133
|
const s = isWindows(platform) ? psQuote(src) : shellQuote(src);
|
|
134
134
|
const d = isWindows(platform) ? psQuote(dest) : shellQuote(dest);
|
|
135
135
|
if (isWindows(platform)) {
|
|
136
|
-
|
|
136
|
+
// 删旧目标可失败(本来不存在);复制失败必须让命令退出码非零 —— 备份是删除前唯一兜底。
|
|
137
|
+
return `Remove-Item -Recurse -Force ${d} -ErrorAction SilentlyContinue; Copy-Item -Recurse ${s} ${d} -ErrorAction Stop`;
|
|
137
138
|
}
|
|
138
|
-
|
|
139
|
+
// 同上:不吞 stderr、不用 `; true` 抹平退出码(审计 P11-7)。
|
|
140
|
+
return `rm -rf ${d} && cp -r ${s} ${d}`;
|
|
139
141
|
}
|
|
140
142
|
/**
|
|
141
143
|
* 生成重装计划。exec 用于实时解析 npm root 等路径;plan 生成完成后,
|
|
@@ -198,6 +200,8 @@ export async function buildReinstallPlan(selection, version, exec, env = process
|
|
|
198
200
|
label: engineMsg('core.reinstall.stepBackupHome'),
|
|
199
201
|
command: copyDirCommand(dshHome, `${dshHome}.reinstall-backup`, platform),
|
|
200
202
|
dangerous: true,
|
|
203
|
+
// 备份失败 → 后面的 settings/profiles/sessions/credentials 清空没有抢救副本,必须中止。
|
|
204
|
+
critical: true,
|
|
201
205
|
});
|
|
202
206
|
}
|
|
203
207
|
if (selection.has('settings')) {
|
package/lib/core/restore.js
CHANGED
|
@@ -42,6 +42,18 @@ async function loadSnapshot(snapshotDir, msg) {
|
|
|
42
42
|
}
|
|
43
43
|
return parsed;
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* `snapshot.entries` 兜底(审计 P3-3):旧 / 截断 / 手改的 snapshot.json 可能整段缺 entries
|
|
47
|
+
* (或写成非数组),直接 `for…of` 会抛裸 TypeError(`snapshot.entries is not iterable`)。
|
|
48
|
+
*
|
|
49
|
+
* 为什么按空集合而不是拒绝:快照可信度已在计划期按 verdict 过门(CORRUPT/INVALID 拒绝、
|
|
50
|
+
* LEGACY 放行),字段缺失属旧快照常态;同文件 `hostFileBackups ?? []` / `pluginRemovals ?? []`
|
|
51
|
+
* / `expectedSessionRefs(entries ?? [])` 都是这个口径 —— 旧快照诚实跳过,绝不把「字段缺失」
|
|
52
|
+
* 升级成类型错误。
|
|
53
|
+
*/
|
|
54
|
+
function snapshotEntries(snapshot) {
|
|
55
|
+
return Array.isArray(snapshot.entries) ? snapshot.entries : [];
|
|
56
|
+
}
|
|
45
57
|
async function fileExists(p) {
|
|
46
58
|
try {
|
|
47
59
|
await fs.access(p);
|
|
@@ -166,7 +178,12 @@ function createTargetSafetyChecker(homeDir) {
|
|
|
166
178
|
return 'target-symlink';
|
|
167
179
|
}
|
|
168
180
|
catch (err) {
|
|
169
|
-
|
|
181
|
+
// ENOTDIR 与 ENOENT 同义:路径上某一段是普通文件(POSIX 的 lstat 抛 ENOTDIR,
|
|
182
|
+
// Windows 抛 ERROR_PATH_NOT_FOUND ⇒ ENOENT)。目标本身既不存在,也就不可能是链接
|
|
183
|
+
// ⇒ 交给下面的父级投影判定;真越界仍会被 isPathInside 拒。
|
|
184
|
+
// 判据 → docs/evidence/recovery-console.md;CI 三平台复现见 tests/core/restore.test.ts R-ghost-unreadable。
|
|
185
|
+
const code = err.code;
|
|
186
|
+
if (code !== 'ENOENT' && code !== 'ENOTDIR')
|
|
170
187
|
return 'target-unreadable';
|
|
171
188
|
}
|
|
172
189
|
const parentReal = projectedParentReal(path.dirname(absTarget));
|
|
@@ -542,7 +559,7 @@ export async function planRestore(opts) {
|
|
|
542
559
|
let patchLineCount = 0;
|
|
543
560
|
let workspaceCount = 0;
|
|
544
561
|
let credentialAbsentCount = 0;
|
|
545
|
-
for (const entry of snapshot
|
|
562
|
+
for (const entry of snapshotEntries(snapshot)) {
|
|
546
563
|
switch (entry.kind) {
|
|
547
564
|
case 'file': {
|
|
548
565
|
const rel = toRelPath(homeDir, resolveFileAbs(homeDir, entry.adapter, entry.ref));
|
|
@@ -917,16 +934,24 @@ export async function restore(opts) {
|
|
|
917
934
|
}
|
|
918
935
|
/* ------------------------------------------------------------ 幽灵会话(F5) */
|
|
919
936
|
/**
|
|
920
|
-
* 磁盘 sessions 目录实际相对路径清单(相对 <homeDir>/sessions
|
|
937
|
+
* 磁盘 sessions 目录实际相对路径清单(相对 <homeDir>/sessions;**只有 ENOENT** 视为空)。
|
|
921
938
|
* 用 node fs 递归列举(离线引擎不依赖 HostContext),分隔符由 sessionKeyOf 归一。
|
|
939
|
+
*
|
|
940
|
+
* 「读不到」≠「没有」(AGENTS.md 文件类分区条;同 listSnapshots 的 EACCES/ENOTDIR 处理):
|
|
941
|
+
* EACCES / EPERM / ENOTDIR(sessions 被普通文件占住)若也降级成空集合,幽灵判定会把快照里
|
|
942
|
+
* **每一个**期望会话都报成「备份有记录、磁盘无文件,需人工清理」(审计 P3-4)。
|
|
943
|
+
* 故只在 ENOENT(确实没有会话分区)时返回空;其余错误原样上抛,由调用方记入 failed
|
|
944
|
+
* —— 报告成「未知」,绝不断言磁盘上没有这些会话。
|
|
922
945
|
*/
|
|
923
946
|
async function listSessionEntries(homeDir) {
|
|
924
947
|
const base = path.join(homeDir, 'sessions');
|
|
925
948
|
try {
|
|
926
949
|
return await fs.readdir(base, { recursive: true });
|
|
927
950
|
}
|
|
928
|
-
catch {
|
|
929
|
-
|
|
951
|
+
catch (err) {
|
|
952
|
+
if (err.code === 'ENOENT')
|
|
953
|
+
return [];
|
|
954
|
+
throw err;
|
|
930
955
|
}
|
|
931
956
|
}
|
|
932
957
|
/**
|
|
@@ -938,7 +963,7 @@ async function listSessionEntries(homeDir) {
|
|
|
938
963
|
*/
|
|
939
964
|
async function sweepRestoredSessions(snapshotDir, homeDir, msg) {
|
|
940
965
|
const snapshot = await loadSnapshot(snapshotDir, msg);
|
|
941
|
-
const expected = expectedSessionRefs(snapshot
|
|
966
|
+
const expected = expectedSessionRefs(snapshotEntries(snapshot));
|
|
942
967
|
if (expected.length === 0)
|
|
943
968
|
return [];
|
|
944
969
|
return sweepGhostSessions(expected, await listSessionEntries(homeDir));
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 分区载荷脱敏的**唯一入口**(issue #136 C)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么必须只有一处:同一分区数据有五个出口 —— 导出、push 载荷、push 预览、
|
|
5
|
+
* `hasLocalChanges` 的基线比对、合并落地的本地侧与「落地后重新导出记基线」。
|
|
6
|
+
* 这些字节必须**逐字相同**(参见 AGENTS.md「本地有改动与导出载荷必须同一份字节」):
|
|
7
|
+
* 任何一处只做 `scanAndRedact` 而不做归属标注,就会让「被剥空路径」在那一侧消失,
|
|
8
|
+
* 与另一侧算出的 hash 分叉,表现为每轮同步都真推一次 / 合并判冲突。
|
|
9
|
+
*
|
|
10
|
+
* 归属标注钩子见 `ConfigAdapter.annotateRedactions`(只有 plugins 分区实现:把 hit 的
|
|
11
|
+
* `patch[i].raw.x` 归属回第 i 行的 `redactedPaths`)。
|
|
12
|
+
*/
|
|
13
|
+
import type { ConfigAdapter, SensitiveHit } from './types.ts';
|
|
14
|
+
/** 扫描器最小契约(`SecretScanner` 结构性满足;此处只依赖用到的那一个方法)。 */
|
|
15
|
+
export interface SectionScanner {
|
|
16
|
+
scanAndRedact(data: unknown): {
|
|
17
|
+
sanitized: unknown;
|
|
18
|
+
hits: SensitiveHit[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** 可参与脱敏归属标注的适配器(只要求用到的那部分形状)。 */
|
|
22
|
+
type AnnotatingAdapter = Pick<ConfigAdapter, 'annotateRedactions'>;
|
|
23
|
+
/**
|
|
24
|
+
* 扫描 + 剥离 + (如实现)归属标注。
|
|
25
|
+
*
|
|
26
|
+
* @param adapter 分区适配器;未实现 `annotateRedactions` 时行为与直接 `scanAndRedact` 逐字相同。
|
|
27
|
+
*/
|
|
28
|
+
export declare function sanitizeSectionData(adapter: AnnotatingAdapter | undefined, scanner: SectionScanner, data: unknown): {
|
|
29
|
+
sanitized: unknown;
|
|
30
|
+
hits: SensitiveHit[];
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 扫描 + 剥离 + (如实现)归属标注。
|
|
3
|
+
*
|
|
4
|
+
* @param adapter 分区适配器;未实现 `annotateRedactions` 时行为与直接 `scanAndRedact` 逐字相同。
|
|
5
|
+
*/
|
|
6
|
+
export function sanitizeSectionData(adapter, scanner, data) {
|
|
7
|
+
const scanned = scanner.scanAndRedact(data);
|
|
8
|
+
const annotate = adapter?.annotateRedactions;
|
|
9
|
+
if (annotate === undefined)
|
|
10
|
+
return { sanitized: scanned.sanitized, hits: scanned.hits };
|
|
11
|
+
return { sanitized: annotate.call(adapter, scanned.sanitized, scanned.hits), hits: scanned.hits };
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=section-sanitize.js.map
|
|
@@ -55,6 +55,35 @@ export interface RestoreChangeSummary {
|
|
|
55
55
|
/** 统计口径上限(UI 提示用) */
|
|
56
56
|
limits: typeof SNAPSHOT_DIFF_LIMITS;
|
|
57
57
|
}
|
|
58
|
+
/** 单侧读取结果(缺文件 = exists:false 且 text 为空串)。 */
|
|
59
|
+
interface SideRead {
|
|
60
|
+
exists: boolean;
|
|
61
|
+
bytes: number;
|
|
62
|
+
/** 文本内容;null = 未读取(二进制 / 超限 / 不可读) */
|
|
63
|
+
text: string | null;
|
|
64
|
+
binary: boolean;
|
|
65
|
+
oversized: boolean;
|
|
66
|
+
unreadable: boolean;
|
|
67
|
+
}
|
|
68
|
+
/** readSide 依赖的最小 fs 能力(默认 = 真 fs)。 */
|
|
69
|
+
export interface SideReadIo {
|
|
70
|
+
stat(abs: string): Promise<{
|
|
71
|
+
isFile(): boolean;
|
|
72
|
+
size: number;
|
|
73
|
+
}>;
|
|
74
|
+
readFile(abs: string): Promise<Buffer>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 读单侧内容。
|
|
78
|
+
*
|
|
79
|
+
* 三种结果必须分开:真的没有(ABSENT)/ 存在但读不出(unreadable)/ 正常读到。
|
|
80
|
+
* 原先整段包一个 try + 末尾 `catch { return ABSENT }`,把「stat 成功、readFile 抛 EACCES」
|
|
81
|
+
* 判成了不存在 —— 预览因此把只读文件显示成「新增」(审计 P2-6)。
|
|
82
|
+
*
|
|
83
|
+
* `io` 参数只为单测注入:Windows 上造不出 EACCES 夹具,而这条分支必须被真正覆盖;
|
|
84
|
+
* 生产调用方一律不传(走 REAL_SIDE_IO)。
|
|
85
|
+
*/
|
|
86
|
+
export declare function readSide(abs: string, maxBytes: number, io?: SideReadIo): Promise<SideRead>;
|
|
58
87
|
/**
|
|
59
88
|
* 列表阶段:逐动作产出变更状态 + 行数统计(零写入;不抛错)。
|
|
60
89
|
* plan 为空或 action 不可分析时返回对应 entry(status='skip'),绝不抛错给路由。
|
|
@@ -104,3 +133,4 @@ export declare function snapshotFileDiff(opts: {
|
|
|
104
133
|
blobPath?: string;
|
|
105
134
|
msg?: MsgFunc;
|
|
106
135
|
}): Promise<SnapshotFileDiff>;
|
|
136
|
+
export {};
|