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
|
@@ -13,8 +13,9 @@ import assert from 'node:assert/strict';
|
|
|
13
13
|
import fs from 'node:fs';
|
|
14
14
|
import { fileURLToPath } from 'node:url';
|
|
15
15
|
import * as yaml from 'js-yaml';
|
|
16
|
+
import * as yaml4 from 'js-yaml4';
|
|
16
17
|
|
|
17
|
-
import { describePatchYamlError, dumpPatchDocument, isPatchJsExpr, loadPatchDocument } from './patch-yaml.ts';
|
|
18
|
+
import { describePatchYamlError, dumpPatchDocument, findPatchKeyHazards, isPatchJsExpr, loadPatchDocument } from './patch-yaml.ts';
|
|
18
19
|
|
|
19
20
|
/** 真机形态(issue #75 报告的那一行):顶层行 + 行内 JS 表达式 + 嵌套 config。 */
|
|
20
21
|
const SAMPLE = [
|
|
@@ -89,6 +90,131 @@ test('describePatchYamlError:只取首行,源码片段(可能含内联密
|
|
|
89
90
|
assert.ok(realSafe.length > 0);
|
|
90
91
|
});
|
|
91
92
|
|
|
93
|
+
/* ------------------------------ 跨大版本读回(issue #135) ------------------------------ */
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* DSH 侧的读端:桌面版随包 js-yaml 4.3.2(`app.asar` 内的 `/dsh/node_modules/js-yaml`)。
|
|
97
|
+
* 它装成 devDependency 别名 `js-yaml4`(运行时依赖仍只有 5.x 的 `js-yaml`)。
|
|
98
|
+
*
|
|
99
|
+
* 为什么必须真读 4.x:既有那条「写回保真」是 `load(dump(x))` 自环 —— 5.x 自己读自己恒等,
|
|
100
|
+
* 于是「空标量 / 裸标量关键字」这类跨版本分歧在自环里根本看不见(#135 就是这么漏掉的)。
|
|
101
|
+
* 而 DSH 才是这份文件的真实读者:它是 4.x,按 YAML 1.1 隐式解析。
|
|
102
|
+
*/
|
|
103
|
+
const JsExpr4 = new yaml4.Type('tag:yaml.org,2002:js', {
|
|
104
|
+
kind: 'scalar',
|
|
105
|
+
construct: (data) => ({ __jsExpr: String(data) }),
|
|
106
|
+
});
|
|
107
|
+
const DSH_READER_SCHEMA = yaml4.JSON_SCHEMA.extend([JsExpr4]);
|
|
108
|
+
|
|
109
|
+
/** 完全按 DSH 的口径读回一份 patch 文本。 */
|
|
110
|
+
function loadAsDsh(text: string): unknown {
|
|
111
|
+
return yaml4.load(text, { schema: DSH_READER_SCHEMA });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 会被 4.x 改判类型的字符串:空串 + YAML 1.1 的 null / 布尔 / 进制 / 浮点特例。
|
|
116
|
+
*
|
|
117
|
+
* 这是**回归样本**,不是完备性证明 —— 完备性来自 `forceQuotes` 对每个字符串值都生效
|
|
118
|
+
* (见下一条「输出必须是带引号标量」的结构性断言)。清单实测来源:24 种串 × map/list
|
|
119
|
+
* 共 48 处发散,判据与明细在 `docs/evidence/profiles-and-instances.md`。
|
|
120
|
+
*/
|
|
121
|
+
const AMBIGUOUS_STRINGS = [
|
|
122
|
+
'',
|
|
123
|
+
'Null',
|
|
124
|
+
'NULL',
|
|
125
|
+
'~',
|
|
126
|
+
'True',
|
|
127
|
+
'TRUE',
|
|
128
|
+
'False',
|
|
129
|
+
'FALSE',
|
|
130
|
+
'007',
|
|
131
|
+
'-007',
|
|
132
|
+
'+7',
|
|
133
|
+
'012',
|
|
134
|
+
'-012',
|
|
135
|
+
'+1',
|
|
136
|
+
'0x10',
|
|
137
|
+
'0x1F',
|
|
138
|
+
'0o17',
|
|
139
|
+
'0b101',
|
|
140
|
+
'0b1010',
|
|
141
|
+
'.5',
|
|
142
|
+
'-.5',
|
|
143
|
+
'.inf',
|
|
144
|
+
'.Inf',
|
|
145
|
+
'-.inf',
|
|
146
|
+
'.nan',
|
|
147
|
+
'.NaN',
|
|
148
|
+
];
|
|
149
|
+
|
|
150
|
+
test('#135 写回空字符串是显式空串,4.x 不会读成 null', () => {
|
|
151
|
+
const text = dumpPatchDocument({ config: { constraints: '' } });
|
|
152
|
+
assert.match(text, /constraints: (''|"")/, '空串必须带引号,实际输出:\n' + text);
|
|
153
|
+
assert.deepEqual(loadAsDsh(text), { config: { constraints: '' } });
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('#135 每种歧义字符串在 map / list 两个位置都能被 4.x 读回(' + AMBIGUOUS_STRINGS.length * 2 + '/' + AMBIGUOUS_STRINGS.length * 2 + ')', () => {
|
|
157
|
+
const inMap: Record<string, string> = {};
|
|
158
|
+
const inList: Record<string, string[]> = {};
|
|
159
|
+
AMBIGUOUS_STRINGS.forEach((value, index) => {
|
|
160
|
+
inMap['k' + index] = value;
|
|
161
|
+
inList['k' + index] = [value];
|
|
162
|
+
});
|
|
163
|
+
const total = AMBIGUOUS_STRINGS.length;
|
|
164
|
+
assert.deepEqual(loadAsDsh(dumpPatchDocument(inMap)), inMap, `map 位置必须 ${total}/${total}`);
|
|
165
|
+
assert.deepEqual(loadAsDsh(dumpPatchDocument(inList)), inList, `list 位置必须 ${total}/${total}`);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 完备性断言(不依赖清单):写出去的**每个字符串值**都必须是带引号标量。
|
|
170
|
+
* 带引号的标量在任何 schema 下都是 string,这正是 forceQuotes 能盖住未知怪串的原因;
|
|
171
|
+
* 一旦有人「优化掉引号」,这条先红 —— 与 4.x 清单无关。
|
|
172
|
+
*/
|
|
173
|
+
test('#135 输出里的字符串值一律是带引号标量(完备性不靠清单)', () => {
|
|
174
|
+
const samples = [...AMBIGUOUS_STRINGS, 'hello', 'a b', 'x:y', '- z', '#tag', '@deepseek-ai/dsh-mcp-client', ' ', '多行\n第二行'];
|
|
175
|
+
for (const value of samples) {
|
|
176
|
+
const text = dumpPatchDocument({ k: value });
|
|
177
|
+
assert.match(text, /^k: ['"]/, '字符串值必须带引号,实际: ' + JSON.stringify(value) + ' -> ' + JSON.stringify(text));
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test('#135 两个读端读到同一份值(行为锁定:dump 里不得留 4.x 歧义标量)', () => {
|
|
182
|
+
const doc = {
|
|
183
|
+
constraints: '',
|
|
184
|
+
reserved: null,
|
|
185
|
+
count: 3,
|
|
186
|
+
enabled: true,
|
|
187
|
+
pkg: '@deepseek-ai/dsh-mcp-client',
|
|
188
|
+
spaced: ' ',
|
|
189
|
+
wordIsNull: 'null',
|
|
190
|
+
expr: { __jsExpr: '(function(){ return true })()' },
|
|
191
|
+
};
|
|
192
|
+
const text = dumpPatchDocument(doc);
|
|
193
|
+
assert.deepEqual(loadAsDsh(text), loadPatchDocument(text), 'DSH 读到的值必须与插件读到的相同:\n' + text);
|
|
194
|
+
assert.deepEqual(loadPatchDocument(text), doc, '5.x 侧仍要保真');
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test('#135 forceQuotes 不改变 !!js:短标签与块标量照旧往返,4.x 侧同样读到 {__jsExpr}', () => {
|
|
198
|
+
const doc = loadPatchDocument(SAMPLE);
|
|
199
|
+
const text = dumpPatchDocument(doc);
|
|
200
|
+
assert.ok(text.includes('!!js '), '短标签保留');
|
|
201
|
+
assert.ok(text.includes('!!js |'), '块标量形态保持(带标签的标量不加引号)');
|
|
202
|
+
assert.deepEqual(loadAsDsh(text), doc, '4.x 必须读到同样的 {__jsExpr}');
|
|
203
|
+
assert.deepEqual(loadPatchDocument(text), doc);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 已知识别缺口(**记录,不是达标**):js-yaml 5 的 `forceQuotes` 只作用于**值**,键名不在范围内。
|
|
208
|
+
* 于是数值样式的键名在 DSH 的 4.x 侧会被解析成数字/布尔/null 再被 JS 强制回字符串,键名变形。
|
|
209
|
+
* 真机 patch 的键名都是插件名/配置字段名(普通标识符),不受影响;哪天 js-yaml 也给键加引号,
|
|
210
|
+
* 这条会变红 —— 届时删掉它并更新 docs/evidence/profiles-and-instances.md 的相邻缺口一节。
|
|
211
|
+
*/
|
|
212
|
+
test('#135 已知缺口:键名不受 forceQuotes 保护(数值样式键名会被 4.x 改名)', () => {
|
|
213
|
+
const text = dumpPatchDocument({ '012': 'v' });
|
|
214
|
+
assert.equal(text, "012: 'v'\n", '当前行为:键名裸写(这是缺口,不是期望)');
|
|
215
|
+
assert.deepEqual(loadAsDsh(text), { '12': 'v' }, '4.x 侧键名变形:012 -> 12');
|
|
216
|
+
});
|
|
217
|
+
|
|
92
218
|
/* ---------------------------------- 接线守卫(源码级) ---------------------------------- */
|
|
93
219
|
|
|
94
220
|
/**
|
|
@@ -99,10 +225,16 @@ test('describePatchYamlError:只取首行,源码片段(可能含内联密
|
|
|
99
225
|
test('接线守卫:patch 门面与 boot-safety 的 YAML 解析都必须走本方言', () => {
|
|
100
226
|
const root = fileURLToPath(new URL('../../', import.meta.url));
|
|
101
227
|
const index = fs.readFileSync(root + 'src/index.ts', 'utf8');
|
|
228
|
+
// #144 起「读既有 patch 文件」与「读整条生效链」下沉到 utils/patch-chain-read.ts(src/index.ts 触体量棘轮),
|
|
229
|
+
// 方言接线随之搬家:两处载入都必须是 loadPatchDocument。
|
|
230
|
+
const chainIo = fs.readFileSync(root + 'src/utils/patch-chain-read.ts', 'utf8');
|
|
102
231
|
|
|
103
232
|
assert.ok(index.includes('doc = loadPatchDocument(text)'), 'readPatchLines 必须用方言载入');
|
|
104
|
-
assert.ok(
|
|
105
|
-
assert.
|
|
233
|
+
assert.ok(chainIo.includes('return loadPatchDocument(text)'), 'applyPatchChanges 的既有文件必须用方言载入');
|
|
234
|
+
assert.ok(chainIo.includes("loadPatchDocument(await fs.readFile(resolve(homeDir, file), 'utf8'))"), '生效链各层必须用方言载入');
|
|
235
|
+
assert.equal(chainIo.includes('yaml.load('), false, '生效链读取不得用裸 yaml.load');
|
|
236
|
+
// 变量名随 #144 的 name 校正改动(out → items),守卫只钉「必须经 dumpPatchDocument 写回」
|
|
237
|
+
assert.match(index, /\+ dumpPatchDocument\(\w+(\.\w+)?\)/, '写回 patch 文件必须用方言(yaml.dump 会把 {__jsExpr} 写成普通 map)');
|
|
106
238
|
assert.match(
|
|
107
239
|
index,
|
|
108
240
|
/parseYaml:\s*\(text\)\s*=>\s*loadPatchDocument\(text\)/,
|
|
@@ -110,3 +242,83 @@ test('接线守卫:patch 门面与 boot-safety 的 YAML 解析都必须走本
|
|
|
110
242
|
);
|
|
111
243
|
assert.equal(index.includes('yaml.dump('), false, 'src/index.ts 不得再用裸 yaml.dump 写 patch 文件');
|
|
112
244
|
});
|
|
245
|
+
|
|
246
|
+
/* ------------------------ 键名跨大版本守卫(issue #137) ------------------------ */
|
|
247
|
+
|
|
248
|
+
test('#137 空键名 → parse-fail(顶层 / 数组元素 / 嵌套 map 都要定位到)', () => {
|
|
249
|
+
assert.deepEqual(findPatchKeyHazards({ '': 'v' }), [{ path: '', key: '', effect: 'parse-fail' }]);
|
|
250
|
+
assert.deepEqual(findPatchKeyHazards({ items: [{ '': 'v' }] }), [{ path: 'items[0]', key: '', effect: 'parse-fail' }]);
|
|
251
|
+
assert.deepEqual(findPatchKeyHazards({ config: { env: { '': 'v' } } }), [{ path: 'config.env', key: '', effect: 'parse-fail' }]);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('#137 4.x 会改判的键名 → rename(全部实测命中)', () => {
|
|
255
|
+
const keys = [
|
|
256
|
+
'~', 'Null', 'NULL', 'True', 'TRUE', 'False', 'FALSE',
|
|
257
|
+
'007', '-007', '+7', '012', '-012', '+1', '00', '000', '0007',
|
|
258
|
+
'0x10', '0x1F', '0o17', '0b101', '0b1010',
|
|
259
|
+
'.5', '.5e2', '00.5', '.inf', '.Inf', '.INF', '-.inf', '.nan', '.NaN', '.NAN',
|
|
260
|
+
];
|
|
261
|
+
for (const key of keys) {
|
|
262
|
+
assert.deepEqual(findPatchKeyHazards({ [key]: 'v' }), [{ path: '', key, effect: 'rename' }], '键 ' + JSON.stringify(key) + ' 必须命中');
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
test('#137 安全键名一个都不许拦(误伤比漏拦更贵:用户改不动自己的配置)', () => {
|
|
267
|
+
const safe = [
|
|
268
|
+
'docs', 'a b', 'k:v', 'k#v', 'k #v', '@scope/pkg', '.cjs', 'yes', 'no', 'on', 'off',
|
|
269
|
+
'1_000', '1:20', '12:34:56', '2020-01-01', '2020-01-01T00:00:00Z', '1.2', '1.2.3', '1.0', '0.',
|
|
270
|
+
'0', '-0', '7', '-7', '80', '1e3', '1E3', '1.0e+3', '1.5E-3', 'e3', '1e',
|
|
271
|
+
'0X10', '0O17', '0B101', '+.5', '-.5', '-0.5', 'Infinity', 'NaN', 'inf', 'nan',
|
|
272
|
+
'null', 'true', 'false', '...', '...x',
|
|
273
|
+
];
|
|
274
|
+
for (const key of safe) {
|
|
275
|
+
assert.deepEqual(findPatchKeyHazards({ [key]: 'v' }), [], '键 ' + JSON.stringify(key) + ' 不该被拦');
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* 语料 = 手写边角 + 生成式数字形态。断言的是「检测器判据 === 真 4.x 判据」:
|
|
281
|
+
* 只有两边完全一致,规则表(AMBIGUOUS_KEYS)才不会悄悄漂移成误伤或漏拦。
|
|
282
|
+
*/
|
|
283
|
+
const KEY_CORPUS: string[] = (() => {
|
|
284
|
+
const keys = new Set<string>([
|
|
285
|
+
'~', 'null', 'Null', 'NULL', 'true', 'True', 'TRUE', 'false', 'False', 'FALSE',
|
|
286
|
+
'...', '---', '--- x', '...x', 'docs', 'a b', 'k:v', 'k#v', 'k #v', '@scope/pkg', '.cjs',
|
|
287
|
+
'yes', 'no', 'on', 'off', '1_000', '1:20', '12:34:56', '2020-01-01', '2020-01-01T00:00:00Z',
|
|
288
|
+
'1.2', '1.2.3', '1.0', '0.', '0', '-0', '7', '-7', '80', '1e3', '1E3', '1.0e+3', '1.5E-3',
|
|
289
|
+
'0X10', '0O17', '0B101', '+.5', '-.5', '-0.5', '+.5e2', 'Infinity', 'NaN', 'inf', 'nan', 'e3', '1e',
|
|
290
|
+
':', 'x:', ':x', 'x :y', '<x>', '[x]', '{x}', '&x', '*', '|', '1 2', 'a:b:c',
|
|
291
|
+
]);
|
|
292
|
+
for (const body of ['7', '007', '012', '0x10', '0o17', '0b101', '.5', '00.5', '.5e2', '1.0', '1e3', '.inf', '.NaN']) {
|
|
293
|
+
for (const sign of ['', '-', '+']) keys.add(sign + body);
|
|
294
|
+
}
|
|
295
|
+
// 空键名单独断言:4.x 的报错文案随位置变化,混进语料只会让失败信息更吵
|
|
296
|
+
keys.delete('');
|
|
297
|
+
return [...keys];
|
|
298
|
+
})();
|
|
299
|
+
|
|
300
|
+
test('#137 检测器判据与真 4.x 完全一致(' + KEY_CORPUS.length + ' 项语料,防规则表漂移)', () => {
|
|
301
|
+
const mismatched: { key: string; realRisk: boolean; guarded: boolean }[] = [];
|
|
302
|
+
for (const key of KEY_CORPUS) {
|
|
303
|
+
const text = dumpPatchDocument({ [key]: 'v' });
|
|
304
|
+
let realRisk: boolean;
|
|
305
|
+
try {
|
|
306
|
+
const read = loadAsDsh(text);
|
|
307
|
+
const keys = read !== null && typeof read === 'object' ? Object.keys(read as Record<string, unknown>) : [];
|
|
308
|
+
realRisk = keys.length !== 1 || keys[0] !== key;
|
|
309
|
+
} catch {
|
|
310
|
+
// 4.x 整份读不了:比改判更糟,同样算风险(空键名 / 文档分隔符形态)
|
|
311
|
+
realRisk = true;
|
|
312
|
+
}
|
|
313
|
+
const guarded = findPatchKeyHazards({ [key]: 'v' }).length > 0;
|
|
314
|
+
if (realRisk !== guarded) mismatched.push({ key, realRisk, guarded });
|
|
315
|
+
}
|
|
316
|
+
assert.deepEqual(mismatched, [], '检测器与 4.x 不一致的键:AMBIGUOUS_KEYS 需要更新');
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
test('#137 跳过 {__jsExpr} 子树,且不怕 YAML 锚点造出的环', () => {
|
|
320
|
+
assert.deepEqual(findPatchKeyHazards({ a: [{ __jsExpr: '007' }] }), [], '{__jsExpr} 是我们的内存形态,不是用户键名');
|
|
321
|
+
const cyclic: Record<string, unknown> = { ok: 'v' };
|
|
322
|
+
cyclic['self'] = cyclic;
|
|
323
|
+
assert.deepEqual(findPatchKeyHazards(cyclic), [], '环必须只走一次(否则守卫自己会爆栈)');
|
|
324
|
+
});
|
package/src/utils/patch-yaml.ts
CHANGED
|
@@ -53,9 +53,105 @@ export function loadPatchDocument(text: string): unknown {
|
|
|
53
53
|
return load(text, { schema: PATCH_YAML_SCHEMA })
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* 写回 patch 文档:`{__jsExpr}` 还原成 `!!js`,字符串一律带引号(issue #135)。
|
|
58
|
+
*
|
|
59
|
+
* `forceQuotes` 不是风格偏好,而是**跨大版本读回的前提**:本插件装在 js-yaml 5.x 上打印,
|
|
60
|
+
* DSH 本体用 4.x 读回(桌面版随包 4.3.2)。5.x 的渲染器只按自己的解析规则决定要不要加引号,
|
|
61
|
+
* 于是 `""` `Null` `~` `True` `007` `0x10` `.inf` 这类**字符串**被写成裸标量,
|
|
62
|
+
* 4.x 按 YAML 1.1 隐式解析成 `null` / `true` / `7` / `16` / `Infinity` —— 两边读到不同的值,
|
|
63
|
+
* 把该字段声明为必填 string 的插件启动时直接 ZodError。
|
|
64
|
+
*
|
|
65
|
+
* 代价(已知且接受):字符串值普遍带引号;普通多行字符串从 `|` 块退化为双引号 + `\n`
|
|
66
|
+
* (`!!js` 的块标量带标签,不受影响)。只影响写出去的字节,读侧语义不变:
|
|
67
|
+
* 已经写成空标量的历史文件仍由 `loadPatchDocument` 读成 `""`,该层下次被写回时自动复原。
|
|
68
|
+
*/
|
|
57
69
|
export function dumpPatchDocument(value: unknown): string {
|
|
58
|
-
return dump(value, { schema: PATCH_YAML_SCHEMA })
|
|
70
|
+
return dump(value, { schema: PATCH_YAML_SCHEMA, forceQuotes: true })
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 键名在 DSH 读端(js-yaml 4.x)的**改判**形态。
|
|
75
|
+
*
|
|
76
|
+
* 为什么需要单独一层检查:`forceQuotes`(issue #135)只保**值**,键名是 js-yaml 自己决定加不加
|
|
77
|
+
* 引号的 —— 5.x 只给「YAML 1.2 会改判」的键加引号,1.1-only 的形态(`007`、`True`、`.5`、`~`)
|
|
78
|
+
* 一律裸写,于是 4.x 把键读成 `7` / `true` / `0.5` / `null`:配置静默改名,插件读不到自己的键。
|
|
79
|
+
* 空键名更糟 —— `: 'v'` 会让 4.x **整份文件解析失败**(该层所有行一起失效)。
|
|
80
|
+
*/
|
|
81
|
+
export type PatchKeyHazardEffect = 'parse-fail' | 'rename'
|
|
82
|
+
|
|
83
|
+
/** 一处键名风险。 */
|
|
84
|
+
export interface PatchKeyHazard {
|
|
85
|
+
/** 键所在容器的路径(`''` = 顶层;数组元素记作 `items[3]`) */
|
|
86
|
+
path: string
|
|
87
|
+
/** 出问题的键名原文(空串 = 空键名) */
|
|
88
|
+
key: string
|
|
89
|
+
/** `parse-fail` = 4.x 整份文件解析失败;`rename` = 键被改判成数字 / 布尔 / null */
|
|
90
|
+
effect: PatchKeyHazardEffect
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 4.x(YAML 1.1 隐式解析)会改判的裸键形态 —— **只列实测会改判的**。
|
|
95
|
+
*
|
|
96
|
+
* 实测口径(`.tmp` 之外不留脚本,结论进 docs/evidence):`0X10` / `0B101` / `+.5` / `-.5` /
|
|
97
|
+
* `1_000` / `2020-01-01` / `yes` / `1.2`(5.x 自己会加引号或两端都是字符串)一律**不算**风险。
|
|
98
|
+
*/
|
|
99
|
+
const AMBIGUOUS_KEYS: readonly RegExp[] = [
|
|
100
|
+
/^~$/,
|
|
101
|
+
/^(?:null|Null|NULL|true|True|TRUE|false|False|FALSE)$/,
|
|
102
|
+
/^[-+]?0x[0-9a-fA-F]+$/,
|
|
103
|
+
/^[-+]?0b[01]+$/,
|
|
104
|
+
/^[-+]?0o[0-7]+$/,
|
|
105
|
+
/^[-+]?\d+$/,
|
|
106
|
+
/^(?:[-+]?\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/,
|
|
107
|
+
/^[-+]?\.(?:inf|Inf|INF)$/,
|
|
108
|
+
/^\.(?:nan|NaN|NAN)$/,
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
/** 5.x 会把键裸写吗(不加引号)—— 用真 dumper 判,不靠推断引号规则。 */
|
|
112
|
+
function isKeyWrittenBare(key: string): boolean {
|
|
113
|
+
try {
|
|
114
|
+
return dumpPatchDocument({ [key]: 'x' }).startsWith(`${key}:`)
|
|
115
|
+
} catch {
|
|
116
|
+
return false
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function keyHazardEffect(key: string): PatchKeyHazardEffect | null {
|
|
121
|
+
if (key === '') return 'parse-fail'
|
|
122
|
+
if (!isKeyWrittenBare(key)) return null
|
|
123
|
+
// 文档分隔符写进键位会把整份文件切成两段(`--- x: v` 连 5.x 自己都读不回来)
|
|
124
|
+
if (key === '---' || key.startsWith('--- ')) return 'parse-fail'
|
|
125
|
+
return AMBIGUOUS_KEYS.some((pattern) => pattern.test(key)) ? 'rename' : null
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 找出一个 patch 行里**会跨大版本读坏**的键名(issue #137)。
|
|
130
|
+
*
|
|
131
|
+
* 只扫键、不扫值(值由 `dumpPatchDocument` 的 `forceQuotes` 兜住);`{__jsExpr}` 是本模块的
|
|
132
|
+
* 内存形态不是用户键名,整棵子树跳过;YAML 锚点可以造环,同一对象只走一次。
|
|
133
|
+
* 返回空数组 = 这一行写出去 4.x / 5.x 读到的键名一致。
|
|
134
|
+
*/
|
|
135
|
+
export function findPatchKeyHazards(value: unknown): PatchKeyHazard[] {
|
|
136
|
+
const hazards: PatchKeyHazard[] = []
|
|
137
|
+
const seen = new Set<object>()
|
|
138
|
+
const walk = (node: unknown, path: string): void => {
|
|
139
|
+
if (node === null || typeof node !== 'object') return
|
|
140
|
+
if (isPatchJsExpr(node)) return
|
|
141
|
+
if (seen.has(node)) return
|
|
142
|
+
seen.add(node)
|
|
143
|
+
if (Array.isArray(node)) {
|
|
144
|
+
node.forEach((item, index) => walk(item, `${path}[${index}]`))
|
|
145
|
+
return
|
|
146
|
+
}
|
|
147
|
+
for (const [key, child] of Object.entries(node as Record<string, unknown>)) {
|
|
148
|
+
const effect = keyHazardEffect(key)
|
|
149
|
+
if (effect !== null) hazards.push({ path, key, effect })
|
|
150
|
+
walk(child, path === '' ? key : `${path}.${key}`)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
walk(value, '')
|
|
154
|
+
return hazards
|
|
59
155
|
}
|
|
60
156
|
|
|
61
157
|
/**
|
package/src/utils/paths.test.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import test from 'node:test';
|
|
9
9
|
import assert from 'node:assert/strict';
|
|
10
10
|
import path from 'node:path';
|
|
11
|
-
import { applyPrefixMappings, isPathInside, isSameOrChild } from './paths.ts';
|
|
11
|
+
import { applyPrefixMappings, isPathInside, isSameOrChild, isSensitiveHomeRel } from './paths.ts';
|
|
12
12
|
import type { PathMapping } from '../core/types.ts';
|
|
13
13
|
|
|
14
14
|
/** 测试用映射(appliesTo 与语义无关,任选一个合法分区) */
|
|
@@ -96,3 +96,16 @@ test('core-E1:越界判定只有一份实现,且 `..foo` 这种合法兄弟
|
|
|
96
96
|
// foldCase:false 只在 POSIX 生效:win32 的 path.relative 自己就折大小写(故此处结果仍 true)
|
|
97
97
|
assert.equal(isPathInside('/a/B', '/a/b', { foldCase: false }), process.platform === 'win32');
|
|
98
98
|
});
|
|
99
|
+
|
|
100
|
+
test('审计 P2-1:isSensitiveHomeRel 认得出凭据形状(分区出包的单一判据)', () => {
|
|
101
|
+
// 命中:vault 段 / 常见凭据文件名(大小写与分隔符不敏感)
|
|
102
|
+
for (const rel of ['.mnemon/vault/key', '.mnemon/VAULT/key', '.mnemon/credentials.yaml', '.mnemon/CREDENTIALS.json',
|
|
103
|
+
'.mnemon/credentials', '.dsh-x/secrets.yaml', '.dsh-x/auth.json', '.dsh-x/.env', '.dsh-x/.env.local', '.dsh-x/.credentials.yml']) {
|
|
104
|
+
assert.equal(isSensitiveHomeRel(rel), true, `必须判敏感:${rel}`);
|
|
105
|
+
}
|
|
106
|
+
// 不命中:普通配置/资产/包含关键词但不是凭据名的文件
|
|
107
|
+
for (const rel of ['.mnemon/runtime/MEMORY.md', '.dsh-x/config.json', '.dsh-x/uploads/wall.mp4',
|
|
108
|
+
'.dsh-x/credentials-backup.txt', '.dsh-x/my-credentials-notes.md', '.dsh-x/vaulted/config.json']) {
|
|
109
|
+
assert.equal(isSensitiveHomeRel(rel), false, `不得误判:${rel}`);
|
|
110
|
+
}
|
|
111
|
+
});
|
package/src/utils/paths.ts
CHANGED
|
@@ -89,6 +89,10 @@ const RESERVED_INTERNAL_PREFIXES: readonly string[] = [
|
|
|
89
89
|
'dsh-config-manager/environment-fingerprint.token',
|
|
90
90
|
// Phase 6:迁移历史审计目录(统一历史引擎;防 F23 投毒链——不可信导入不得映射到该目录)。
|
|
91
91
|
'dsh-config-manager/migration-history/',
|
|
92
|
+
// Phase 6+(审计 P12-5):敏感文件镜像目录(<dataDir>/vault)存的是 .credentials.yaml 等明文镜像,
|
|
93
|
+
// 与上面几项同属「不可信归档不得映射进来」的 control-plane 区;isSensitiveHomeRel 已在**收集/打包**
|
|
94
|
+
// 侧按 vault 段拦这种文件,这里补上**导入目标**侧的同一判据,免得 crafted 归档把条目写进镜像目录。
|
|
95
|
+
'dsh-config-manager/vault/',
|
|
92
96
|
// 注意:不得整段保留 dsh-config-manager/sync/ —— self 分区合法持有 sync/*.json 白名单配置
|
|
93
97
|
//(sync-config / sync-selection / ui-prefs / backup-schedule),会误伤。
|
|
94
98
|
'dsh-config-manager/sync/snapshots/',
|
|
@@ -129,6 +133,37 @@ export function isReservedInternalRel(relPath: string): boolean {
|
|
|
129
133
|
return false;
|
|
130
134
|
}
|
|
131
135
|
|
|
136
|
+
/**
|
|
137
|
+
* 凭据文件(home 相对路径)判定 —— **全仓唯一出口**(审计 P2-1 P0 修复,2026-11-13)。
|
|
138
|
+
*
|
|
139
|
+
* 为什么必须有:pluginData / pluginAssets 的分区根是**系统主目录**,来源既可能是内置表,
|
|
140
|
+
* 也可能是插件自己在 package.json 里声明的 `dsh.dataDirs`。声明方只要写 `.dsh`,就会把
|
|
141
|
+
* `~/.dsh/.credentials.yaml` 当普通配置收进**明文 ZIP** —— 而 manifest 仍报「不含密钥」
|
|
142
|
+
* (真机实测:包内出现 plugin-data/.dsh/.credentials.yaml,containsSecrets=false)。
|
|
143
|
+
* 字段级脱敏只处理结构化值,管不到「整文件即秘密」的形态,所以按**文件名形态**判一次,
|
|
144
|
+
* 收集侧(adapter)与打包侧(exporter)共用同一判据 —— 两处都在,缺一即回归。
|
|
145
|
+
*
|
|
146
|
+
* 只认名字、不做内容嗅探:收集期读全部字节既慢又读不完大资产。
|
|
147
|
+
*/
|
|
148
|
+
export function isSensitiveHomeRel(relPath: string): boolean {
|
|
149
|
+
const norm = normalizePathCollapsed(relPath).toLowerCase();
|
|
150
|
+
if (norm === '') return false;
|
|
151
|
+
const segments = norm.split('/');
|
|
152
|
+
// vault 目录本身即凭据明文镜像(<dataDir>/vault),任何形态都不得进归档
|
|
153
|
+
if (segments.includes('vault')) return true;
|
|
154
|
+
const base = segments[segments.length - 1] ?? '';
|
|
155
|
+
return SENSITIVE_HOME_BASENAMES.some((re) => re.test(base));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** 凭据文件名形态(小写比较;与 DEFAULT_SENSITIVE_RELS 的「整文件即秘密」同口径) */
|
|
159
|
+
const SENSITIVE_HOME_BASENAMES: readonly RegExp[] = [
|
|
160
|
+
/^\.?credentials(\..*)?$/, // .credentials.yaml / credentials.json / .credentials
|
|
161
|
+
/^credentials\.(ya?ml|json)$/,
|
|
162
|
+
/^secrets\.(ya?ml|json)$/,
|
|
163
|
+
/^auth\.json$/,
|
|
164
|
+
/^\.env(\..*)?$/,
|
|
165
|
+
];
|
|
166
|
+
|
|
132
167
|
/**
|
|
133
168
|
* Windows 语义路径(盘符 "C:/"、"C:\\";UNC 以两个斜杠或两个反斜杠开头)。
|
|
134
169
|
*
|
|
@@ -135,6 +135,75 @@ test('链上排队也计入超时:排在长任务后面的调用按时失败
|
|
|
135
135
|
assert.equal(await slow, 'slow');
|
|
136
136
|
});
|
|
137
137
|
|
|
138
|
+
test('fn 自身耗时不算等锁超时:拿到锁后跑多久都由调用方决定(审计 P12-1 回归)', async (t) => {
|
|
139
|
+
// 旧实现把 timeoutMs race 在整条链上:inspectWorkDir(lockTimeoutMs=1500 的只读自检)里的真实
|
|
140
|
+
// git 调用一超过 1.5 s 就被判「正被另一个同步任务占用」,文案撒谎、且隔离复跑必红。
|
|
141
|
+
// 新语义:timeoutMs 只约束「拿到锁」,拿到之后 fn 的耗时与锁无关。
|
|
142
|
+
const dir = await makeDir(t);
|
|
143
|
+
const t0 = Date.now();
|
|
144
|
+
const result = await withWorkdirLock(dir, async () => {
|
|
145
|
+
await new Promise((r) => setTimeout(r, 220));
|
|
146
|
+
return 'slow-ok';
|
|
147
|
+
}, { timeoutMs: 40 });
|
|
148
|
+
const elapsed = Date.now() - t0;
|
|
149
|
+
assert.equal(result, 'slow-ok', 'fn 超过 timeoutMs 仍必须返回结果,而不是伪造等锁冲突');
|
|
150
|
+
assert.ok(elapsed >= 200, '确实跑满了 fn 的耗时(实测 ' + String(elapsed) + 'ms)');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('审计 P12-6(死线只约束等锁):无竞争 + fn 睡 200ms + timeoutMs 40ms ⇒ 成功返回', async (t) => {
|
|
154
|
+
// 审计条目:旧实现把 timeoutMs race 在**整条链**上(含 fn),于是一把没人竞争的锁 + 一个
|
|
155
|
+
// 合法慢任务(超过 timeoutMs)也会被判成「正被另一个任务占用」。这里钉住新语义:
|
|
156
|
+
// timeoutMs 只是「等锁预算」,拿到锁之后 fn 跑多久由调用方决定。
|
|
157
|
+
const dir = await makeDir(t);
|
|
158
|
+
const lockPath = workdirLockPath(dir);
|
|
159
|
+
// 预热(只为消除环境噪声,不放宽任何断言):withWorkdirLock 的**第一次**取锁会顺带触发
|
|
160
|
+
// 「一次性 tmpdir 清扫」——它读整个 %TEMP% 并逐条 stat,跟本次取锁抢 libuv 线程池;本机实测能把
|
|
161
|
+
// 无竞争的首次取锁拖到 125ms。40ms 的死线太窄,先把这两件一次性的事做掉,量的才是被测语义。
|
|
162
|
+
await pruneDeadWorkdirLocksOnce();
|
|
163
|
+
assert.equal(await withWorkdirLock(dir, async () => 'warm', { timeoutMs: 5_000 }), 'warm');
|
|
164
|
+
// 前提:确实没有竞争(无锁文件),否则本用例证明不了「无竞争 + 慢 fn」这一格
|
|
165
|
+
await assert.rejects(fs.access(lockPath), '前提:开始时不存在锁文件');
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* 旧语义的最小复刻(P12-1 修复前的形状):把死线与「等锁 + 执行」整体 race。
|
|
169
|
+
* 它只用同一对参数在内存里跑一遍,用来证明下面这条断言对旧实现**会红**,而不是空断言。
|
|
170
|
+
*/
|
|
171
|
+
const legacyRaceWholeChain = async <T>(run: () => Promise<T>, timeoutMs: number): Promise<T> => {
|
|
172
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
173
|
+
const deadline = new Promise<never>((_, reject) => {
|
|
174
|
+
timer = setTimeout(() => reject(new WorkdirLockError(dir, timeoutMs)), timeoutMs);
|
|
175
|
+
});
|
|
176
|
+
try {
|
|
177
|
+
return await Promise.race([run(), deadline]);
|
|
178
|
+
} finally {
|
|
179
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
await assert.rejects(
|
|
183
|
+
legacyRaceWholeChain(async () => {
|
|
184
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
185
|
+
return 'slow-ok';
|
|
186
|
+
}, 40),
|
|
187
|
+
(err: unknown) => err instanceof WorkdirLockError,
|
|
188
|
+
'旧语义(fn 计入预算)在同一对参数下必须失败 —— 否则本用例对它没有约束力',
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
// 现实现:同一对参数(200ms fn / 40ms timeoutMs),无竞争 ⇒ 必须成功返回 fn 的结果
|
|
192
|
+
const t0 = Date.now();
|
|
193
|
+
const result = await withWorkdirLock(dir, async () => {
|
|
194
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
195
|
+
return 'slow-ok';
|
|
196
|
+
}, { timeoutMs: 40 });
|
|
197
|
+
const elapsed = Date.now() - t0;
|
|
198
|
+
|
|
199
|
+
assert.equal(result, 'slow-ok', 'fn 慢于 timeoutMs 也必须拿到结果,不得伪造等锁冲突');
|
|
200
|
+
assert.ok(elapsed >= 200, '确实跑满了 fn 的耗时(实测 ' + String(elapsed) + 'ms)');
|
|
201
|
+
assert.ok(elapsed < 3_000, '不得额外空等到别的上限(实测 ' + String(elapsed) + 'ms)');
|
|
202
|
+
// 收尾照旧:成功返回后锁必须释放,后续调用能立刻拿到
|
|
203
|
+
await assert.rejects(fs.access(lockPath), '成功路径同样要释放锁');
|
|
204
|
+
assert.equal(await withWorkdirLock(dir, async () => 'next', { timeoutMs: 40 }), 'next');
|
|
205
|
+
});
|
|
206
|
+
|
|
138
207
|
test('异常也释放锁:fn 抛错后下一次仍能拿到锁(不会把后续同步永久卡死)', async (t) => {
|
|
139
208
|
const dir = await makeDir(t);
|
|
140
209
|
await assert.rejects(withWorkdirLock(dir, async () => { throw new Error('boom'); }), /boom/);
|
|
@@ -232,6 +232,15 @@ export async function withWorkdirLock<T>(
|
|
|
232
232
|
// 上一个 300 s 的同步后面时,计时从轮到它那一刻才清零,超时上限形同失效(2026-10-27 现场)。
|
|
233
233
|
const started = now();
|
|
234
234
|
|
|
235
|
+
/**
|
|
236
|
+
* 是否已经**拿到锁**(timeoutMs 只约束「等锁」,拿到之后 fn 自己的耗时不受它管)。
|
|
237
|
+
*
|
|
238
|
+
* 为什么必须分开(审计 P12-1 P1,真机 #104 复现):旧实现对整条链 race 一个 timeoutMs,
|
|
239
|
+
* 于是 `inspectWorkDir`(lockTimeoutMs=1500 的只读自检)里的真实 git 调用只要跑过 1.5 s,
|
|
240
|
+
* 就被判成「等锁超时」—— 错误文案说「正被另一个同步任务占用」,实际根本没有竞争;
|
|
241
|
+
* 单文件隔离复跑同样必红(30 s 处抛锁冲突)。等锁与干活是两件事,不能共用一个死线。
|
|
242
|
+
*/
|
|
243
|
+
let acquired = false;
|
|
235
244
|
const run = async (): Promise<T> => {
|
|
236
245
|
// 排队期间调用方已超时放弃:轮到它时直接失败,**不执行 fn**,免得被遗弃的请求稍后仍去驱动工作副本
|
|
237
246
|
if (now() - started >= timeoutMs) throw new WorkdirLockError(workDir, now() - started);
|
|
@@ -243,6 +252,7 @@ export async function withWorkdirLock<T>(
|
|
|
243
252
|
await sleep(POLL_INTERVAL_MS);
|
|
244
253
|
release = await tryAcquire(lockPath, workDir, staleMs, now);
|
|
245
254
|
}
|
|
255
|
+
acquired = true;
|
|
246
256
|
try {
|
|
247
257
|
return await fn();
|
|
248
258
|
} finally {
|
|
@@ -257,11 +267,15 @@ export async function withWorkdirLock<T>(
|
|
|
257
267
|
chains.set(key, tail);
|
|
258
268
|
|
|
259
269
|
// 硬上界:timeoutMs 是「拿到锁」的上限,不是「开始计时后」的上限。只用 run 内的计时不够 ——
|
|
260
|
-
//
|
|
261
|
-
//
|
|
270
|
+
// 排在长任务后面的调用永远轮不到自己计时,界面就被历史任务拖着走。这里对链头 race,超时 reject;
|
|
271
|
+
// 被放弃的 run 之后还会被链唤醒,但入口的过期检查让它立刻抛(不碰工作副本)。
|
|
272
|
+
// 关键:**拿到锁之后不再受这条死线约束**(见上面 acquired 的说明)。
|
|
262
273
|
let rejectDeadline: ((reason: Error) => void) | undefined;
|
|
263
274
|
const deadline = new Promise<never>((_, reject) => { rejectDeadline = reject; });
|
|
264
|
-
const timer = setTimeout(() => {
|
|
275
|
+
const timer = setTimeout(() => {
|
|
276
|
+
if (acquired) return;
|
|
277
|
+
rejectDeadline?.(new WorkdirLockError(workDir, timeoutMs));
|
|
278
|
+
}, timeoutMs);
|
|
265
279
|
// unref:这个计时器不该拖住进程退出(缺省 300 s)
|
|
266
280
|
if (typeof timer.unref === 'function') timer.unref();
|
|
267
281
|
try {
|
package/lib/ui/path-mapping.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 路径映射编辑器(规范 §12,m6-ui)。
|
|
3
|
-
*
|
|
4
|
-
* 两种形态(§12 批量映射优先):
|
|
5
|
-
* - 单项映射:某条具体 PathIssue(如 workspace 绝对路径)→ 新路径;
|
|
6
|
-
* - 批量前缀映射:oldPrefix → newPrefix,一次替换全部相关路径。
|
|
7
|
-
*
|
|
8
|
-
* 输出 core PathMapping[]:newPrefix 非空的映射才进入执行计划
|
|
9
|
-
* (core mergePathMappings 只保留已解析映射;未解析项保留在 plan.items 供 UI 提示)。
|
|
10
|
-
* 应用范围 appliesTo 缺省 [](全部相关分区),与 core applyMappingsToSections 语义一致。
|
|
11
|
-
*/
|
|
12
|
-
import type { PathIssue, PathMapping } from '../core/types.ts';
|
|
13
|
-
import type { PathMappingAppliesTo, PathMappingDraft } from './types.ts';
|
|
14
|
-
export interface PathMappingEditorOptions {
|
|
15
|
-
/** 从分析结果得到的路径问题 */
|
|
16
|
-
issues?: PathIssue[];
|
|
17
|
-
/** 预置映射(如上次导入可复用的映射) */
|
|
18
|
-
existing?: PathMapping[];
|
|
19
|
-
}
|
|
20
|
-
export declare class PathMappingEditor {
|
|
21
|
-
private readonly issues;
|
|
22
|
-
private drafts;
|
|
23
|
-
constructor(opts?: PathMappingEditorOptions);
|
|
24
|
-
/** 全部草稿(含未解析) */
|
|
25
|
-
get all(): PathMappingDraft[];
|
|
26
|
-
/** 已解析(newPrefix 非空)的草稿 */
|
|
27
|
-
get resolved(): PathMappingDraft[];
|
|
28
|
-
/** 未解析的问题(UI 需提示用户选择文件夹;按「是否被已解析映射覆盖」判断,批量前缀映射一次覆盖多条) */
|
|
29
|
-
get unresolved(): PathIssue[];
|
|
30
|
-
/** 单项/批量设置映射(oldPrefix 已存在则更新;否则新建批量映射) */
|
|
31
|
-
setMapping(oldPrefix: string, newPrefix: string, appliesTo?: PathMappingAppliesTo[]): void;
|
|
32
|
-
/** 对某个具体值应用当前映射,返回替换结果(预览用;无映射则原样返回) */
|
|
33
|
-
preview(value: string): string;
|
|
34
|
-
/** 未解析项是否可进入执行(false = 有路径问题未解决) */
|
|
35
|
-
get isComplete(): boolean;
|
|
36
|
-
/** 输出 core PathMapping[](仅已解析项) */
|
|
37
|
-
toPathMappings(): PathMapping[];
|
|
38
|
-
}
|