dsh-config-manager 0.8.1 → 0.9.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 +42 -13
- 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 +147 -4
- 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/index.js +14 -0
- package/lib/cli/write-gates.d.ts +61 -0
- package/lib/cli/write-gates.js +110 -0
- package/lib/client.d.ts +122 -50
- package/lib/client.js +12676 -12091
- 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 +7 -0
- package/lib/core/messages.js +14 -0
- package/lib/core/migration-history.js +16 -9
- package/lib/core/model-tools.d.ts +2 -2
- package/lib/core/model-tools.js +14 -2
- 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 +22 -0
- 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/read-trae.d.ts +11 -0
- package/lib/foreign/read-trae.js +124 -4
- 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/foreign/session-source.d.ts +12 -4
- package/lib/foreign/session-source.js +5 -3
- package/lib/foreign/trae-sqlcipher.d.ts +127 -0
- package/lib/foreign/trae-sqlcipher.js +519 -0
- package/lib/foreign/trae.js +3 -1
- package/lib/foreign/truth-table.js +3 -2
- package/lib/foreign/types.d.ts +9 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- 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 +13 -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 +34 -1
- package/lib/sync/autosync-scheduler.js +151 -43
- 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/merge-apply-plan.d.ts +38 -0
- package/lib/sync/merge-apply-plan.js +76 -0
- package/lib/sync/messages.d.ts +1 -0
- package/lib/sync/messages.js +2 -0
- package/lib/sync/pending-merge.d.ts +34 -0
- package/lib/sync/pending-merge.js +53 -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 +23 -40
- package/lib/sync/sync-engine.js +115 -132
- 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/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 +19 -0
- package/lib/ui/foreign-view.js +24 -0
- package/lib/ui/i18n.d.ts +7 -1
- package/lib/ui/i18n.js +17 -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 +8 -0
- package/lib/ui/selection-model.js +16 -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 +2 -1
- package/src/adapters/mcp.test.ts +29 -0
- package/src/adapters/mcp.ts +43 -12
- 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 +288 -0
- package/src/adapters/plugins.ts +141 -4
- 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/index.ts +18 -0
- package/src/cli/web/web.test.ts +27 -0
- package/src/cli/write-gates.ts +149 -0
- package/src/client/about/AboutPanel.tsx +7 -6
- package/src/client/about/release-notes-view.test.ts +17 -0
- package/src/client/about/release-notes-view.ts +49 -24
- 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 +13 -12
- 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 +188 -3
- 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 +1507 -272
- package/src/client/consult/ConsultCard.tsx +7 -6
- package/src/client/environment/EnvironmentPanel.tsx +20 -21
- package/src/client/environment/maintenance/DiskUsageCard.tsx +65 -91
- 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 +35 -30
- package/src/client/home/HomePanel.tsx +45 -10
- package/src/client/import/ConflictList.tsx +13 -13
- package/src/client/import/ForeignImportView.tsx +32 -13
- package/src/client/import/ImportWizardView.tsx +2 -3
- package/src/client/import/PathMappingForm.tsx +4 -4
- package/src/client/import/PathPickerDialog.tsx +2 -1
- package/src/client/import/foreign-import-view-guard.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 +19 -15
- package/src/client/library/LibraryActions.tsx +56 -16
- package/src/client/library/LibraryPanel.tsx +7 -7
- package/src/client/library/RestorePlanView.tsx +13 -8
- package/src/client/locales/about.ts +0 -2
- package/src/client/locales/backup.ts +10 -12
- package/src/client/locales/common.ts +2 -0
- package/src/client/locales/export.ts +5 -12
- package/src/client/locales/foreign.ts +11 -2
- package/src/client/locales/import.ts +3 -2
- package/src/client/locales/overview.ts +4 -0
- package/src/client/locales/profiles.ts +32 -4
- package/src/client/locales/restore.ts +0 -2
- package/src/client/locales/sessions.ts +0 -2
- package/src/client/locales/shell.ts +2 -2
- package/src/client/market/MarketPanel.tsx +38 -20
- package/src/client/market/MyConfigsList.tsx +34 -32
- package/src/client/market/MyConfigsLoginCard.tsx +12 -15
- package/src/client/market/MyConfigsView.tsx +5 -5
- 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 +31 -16
- package/src/client/recovery/RollbackCard.tsx +58 -16
- 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/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 +182 -108
- package/src/client/sync/ChannelClearConfirmDialog.tsx +5 -1
- package/src/client/sync/ChannelConfigDialog.tsx +27 -48
- package/src/client/sync/MergePreviewView.tsx +3 -5
- package/src/client/sync/PushReportSections.tsx +35 -0
- package/src/client/sync/SyncChannelEntryCard.tsx +33 -24
- package/src/client/sync/SyncConfirmView.tsx +3 -3
- package/src/client/sync/SyncLogList.tsx +16 -5
- package/src/client/sync/SyncPanel.tsx +153 -159
- 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 +304 -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 +3 -0
- package/src/client/sync/merge-request.ts +20 -0
- package/src/client/sync/sync-api.ts +12 -0
- package/src/client/sync/sync-locales.ts +87 -47
- package/src/client/sync/sync-panel-clear.test.ts +44 -0
- package/src/client/sync/sync-view.test.ts +20 -0
- package/src/client/sync/sync-view.ts +42 -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 +14 -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 +16 -4
- 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/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 +27 -1
- 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/file-budget.test.ts +7 -1
- 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/read-trae.ts +117 -5
- 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/foreign/session-source.ts +15 -5
- package/src/foreign/trae-sqlcipher.test.ts +360 -0
- package/src/foreign/trae-sqlcipher.ts +564 -0
- package/src/foreign/trae.test.ts +188 -0
- package/src/foreign/trae.ts +3 -1
- package/src/foreign/truth-table.ts +4 -2
- package/src/foreign/types.ts +10 -1
- package/src/index.ts +1 -1
- 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 +13 -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/sync/autosync-repeat.test.ts +58 -0
- package/src/sync/autosync-repeat.ts +55 -0
- package/src/sync/autosync-scheduler.test.ts +417 -0
- package/src/sync/autosync-scheduler.ts +154 -41
- 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/merge-apply-plan.ts +117 -0
- package/src/sync/messages.ts +2 -0
- package/src/sync/pending-merge.ts +77 -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 +130 -135
- 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/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 +36 -0
- package/src/ui/foreign-view.ts +46 -0
- package/src/ui/i18n.ts +17 -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 +15 -1
- package/src/ui/selection-model.ts +18 -0
- package/src/utils/js-yaml4.d.ts +35 -0
- package/src/utils/patch-yaml.test.ts +207 -1
- package/src/utils/patch-yaml.ts +98 -2
- package/src/utils/paths.test.ts +14 -1
- package/src/utils/paths.ts +35 -0
- package/src/utils/workdir-lock.test.ts +69 -0
- package/src/utils/workdir-lock.ts +17 -3
- package/lib/ui/path-mapping.d.ts +0 -38
- package/lib/ui/path-mapping.js +0 -75
- package/src/client/common/InfoHint.tsx +0 -289
- package/src/client/common/info-hint-guard.test.ts +0 -1119
- package/src/client/sync/DecryptPasswordCard.tsx +0 -48
- package/src/client/sync/SecurityOptionsCard.tsx +0 -97
- package/src/client/sync/SyncSectionPickerDialog.tsx +0 -213
- package/src/ui/path-mapping.test.ts +0 -67
- package/src/ui/path-mapping.ts +0 -103
package/src/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
|
-
}
|
package/lib/ui/path-mapping.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { applyPrefixMappings } from '../utils/paths.js';
|
|
2
|
-
export class PathMappingEditor {
|
|
3
|
-
issues;
|
|
4
|
-
drafts = new Map();
|
|
5
|
-
constructor(opts = {}) {
|
|
6
|
-
this.issues = opts.issues ?? [];
|
|
7
|
-
for (const issue of this.issues) {
|
|
8
|
-
this.drafts.set(issue.value, {
|
|
9
|
-
oldPrefix: issue.value,
|
|
10
|
-
newPrefix: issue.mappedTo ?? '',
|
|
11
|
-
issue,
|
|
12
|
-
appliesTo: [],
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
// 批量映射按 oldPrefix 聚合(一个 oldPrefix 一条 draft)
|
|
16
|
-
for (const m of opts.existing ?? []) {
|
|
17
|
-
const prev = this.drafts.get(m.oldPrefix);
|
|
18
|
-
this.drafts.set(m.oldPrefix, {
|
|
19
|
-
oldPrefix: m.oldPrefix,
|
|
20
|
-
newPrefix: m.newPrefix,
|
|
21
|
-
appliesTo: [...m.appliesTo],
|
|
22
|
-
});
|
|
23
|
-
void prev;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/** 全部草稿(含未解析) */
|
|
27
|
-
get all() {
|
|
28
|
-
return [...this.drafts.values()];
|
|
29
|
-
}
|
|
30
|
-
/** 已解析(newPrefix 非空)的草稿 */
|
|
31
|
-
get resolved() {
|
|
32
|
-
return this.all.filter((d) => d.newPrefix !== '');
|
|
33
|
-
}
|
|
34
|
-
/** 未解析的问题(UI 需提示用户选择文件夹;按「是否被已解析映射覆盖」判断,批量前缀映射一次覆盖多条) */
|
|
35
|
-
get unresolved() {
|
|
36
|
-
const mappings = this.toPathMappings();
|
|
37
|
-
return (this.issues ?? []).filter((issue) => {
|
|
38
|
-
const mapped = applyPrefixMappings(issue.value, mappings);
|
|
39
|
-
return mapped === issue.value;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
/** 单项/批量设置映射(oldPrefix 已存在则更新;否则新建批量映射) */
|
|
43
|
-
setMapping(oldPrefix, newPrefix, appliesTo = []) {
|
|
44
|
-
const existing = this.drafts.get(oldPrefix);
|
|
45
|
-
this.drafts.set(oldPrefix, {
|
|
46
|
-
oldPrefix,
|
|
47
|
-
newPrefix,
|
|
48
|
-
appliesTo,
|
|
49
|
-
issue: existing?.issue,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
/** 对某个具体值应用当前映射,返回替换结果(预览用;无映射则原样返回) */
|
|
53
|
-
preview(value) {
|
|
54
|
-
const resolved = this.resolved.map((d) => ({
|
|
55
|
-
oldPrefix: d.oldPrefix,
|
|
56
|
-
newPrefix: d.newPrefix,
|
|
57
|
-
appliesTo: d.appliesTo,
|
|
58
|
-
}));
|
|
59
|
-
const mapped = applyPrefixMappings(value, resolved);
|
|
60
|
-
return typeof mapped === 'string' ? mapped : value;
|
|
61
|
-
}
|
|
62
|
-
/** 未解析项是否可进入执行(false = 有路径问题未解决) */
|
|
63
|
-
get isComplete() {
|
|
64
|
-
return this.unresolved.length === 0;
|
|
65
|
-
}
|
|
66
|
-
/** 输出 core PathMapping[](仅已解析项) */
|
|
67
|
-
toPathMappings() {
|
|
68
|
-
return this.resolved.map((d) => ({
|
|
69
|
-
oldPrefix: d.oldPrefix,
|
|
70
|
-
newPrefix: d.newPrefix,
|
|
71
|
-
appliesTo: d.appliesTo,
|
|
72
|
-
}));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=path-mapping.js.map
|