dsh-config-manager 0.8.2 → 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 +104 -49
- package/lib/client.js +12536 -12006
- 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/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 +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/i18n.d.ts +2 -1
- package/lib/ui/i18n.js +4 -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 +7 -6
- 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/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 +2 -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/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.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/i18n.ts +4 -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/lib/utils/patch-yaml.js
CHANGED
|
@@ -43,9 +43,89 @@ export const PATCH_YAML_SCHEMA = JSON_SCHEMA.withTags(jsExprTag);
|
|
|
43
43
|
export function loadPatchDocument(text) {
|
|
44
44
|
return load(text, { schema: PATCH_YAML_SCHEMA });
|
|
45
45
|
}
|
|
46
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* 写回 patch 文档:`{__jsExpr}` 还原成 `!!js`,字符串一律带引号(issue #135)。
|
|
48
|
+
*
|
|
49
|
+
* `forceQuotes` 不是风格偏好,而是**跨大版本读回的前提**:本插件装在 js-yaml 5.x 上打印,
|
|
50
|
+
* DSH 本体用 4.x 读回(桌面版随包 4.3.2)。5.x 的渲染器只按自己的解析规则决定要不要加引号,
|
|
51
|
+
* 于是 `""` `Null` `~` `True` `007` `0x10` `.inf` 这类**字符串**被写成裸标量,
|
|
52
|
+
* 4.x 按 YAML 1.1 隐式解析成 `null` / `true` / `7` / `16` / `Infinity` —— 两边读到不同的值,
|
|
53
|
+
* 把该字段声明为必填 string 的插件启动时直接 ZodError。
|
|
54
|
+
*
|
|
55
|
+
* 代价(已知且接受):字符串值普遍带引号;普通多行字符串从 `|` 块退化为双引号 + `\n`
|
|
56
|
+
* (`!!js` 的块标量带标签,不受影响)。只影响写出去的字节,读侧语义不变:
|
|
57
|
+
* 已经写成空标量的历史文件仍由 `loadPatchDocument` 读成 `""`,该层下次被写回时自动复原。
|
|
58
|
+
*/
|
|
47
59
|
export function dumpPatchDocument(value) {
|
|
48
|
-
return dump(value, { schema: PATCH_YAML_SCHEMA });
|
|
60
|
+
return dump(value, { schema: PATCH_YAML_SCHEMA, forceQuotes: true });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 4.x(YAML 1.1 隐式解析)会改判的裸键形态 —— **只列实测会改判的**。
|
|
64
|
+
*
|
|
65
|
+
* 实测口径(`.tmp` 之外不留脚本,结论进 docs/evidence):`0X10` / `0B101` / `+.5` / `-.5` /
|
|
66
|
+
* `1_000` / `2020-01-01` / `yes` / `1.2`(5.x 自己会加引号或两端都是字符串)一律**不算**风险。
|
|
67
|
+
*/
|
|
68
|
+
const AMBIGUOUS_KEYS = [
|
|
69
|
+
/^~$/,
|
|
70
|
+
/^(?:null|Null|NULL|true|True|TRUE|false|False|FALSE)$/,
|
|
71
|
+
/^[-+]?0x[0-9a-fA-F]+$/,
|
|
72
|
+
/^[-+]?0b[01]+$/,
|
|
73
|
+
/^[-+]?0o[0-7]+$/,
|
|
74
|
+
/^[-+]?\d+$/,
|
|
75
|
+
/^(?:[-+]?\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/,
|
|
76
|
+
/^[-+]?\.(?:inf|Inf|INF)$/,
|
|
77
|
+
/^\.(?:nan|NaN|NAN)$/,
|
|
78
|
+
];
|
|
79
|
+
/** 5.x 会把键裸写吗(不加引号)—— 用真 dumper 判,不靠推断引号规则。 */
|
|
80
|
+
function isKeyWrittenBare(key) {
|
|
81
|
+
try {
|
|
82
|
+
return dumpPatchDocument({ [key]: 'x' }).startsWith(`${key}:`);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function keyHazardEffect(key) {
|
|
89
|
+
if (key === '')
|
|
90
|
+
return 'parse-fail';
|
|
91
|
+
if (!isKeyWrittenBare(key))
|
|
92
|
+
return null;
|
|
93
|
+
// 文档分隔符写进键位会把整份文件切成两段(`--- x: v` 连 5.x 自己都读不回来)
|
|
94
|
+
if (key === '---' || key.startsWith('--- '))
|
|
95
|
+
return 'parse-fail';
|
|
96
|
+
return AMBIGUOUS_KEYS.some((pattern) => pattern.test(key)) ? 'rename' : null;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 找出一个 patch 行里**会跨大版本读坏**的键名(issue #137)。
|
|
100
|
+
*
|
|
101
|
+
* 只扫键、不扫值(值由 `dumpPatchDocument` 的 `forceQuotes` 兜住);`{__jsExpr}` 是本模块的
|
|
102
|
+
* 内存形态不是用户键名,整棵子树跳过;YAML 锚点可以造环,同一对象只走一次。
|
|
103
|
+
* 返回空数组 = 这一行写出去 4.x / 5.x 读到的键名一致。
|
|
104
|
+
*/
|
|
105
|
+
export function findPatchKeyHazards(value) {
|
|
106
|
+
const hazards = [];
|
|
107
|
+
const seen = new Set();
|
|
108
|
+
const walk = (node, path) => {
|
|
109
|
+
if (node === null || typeof node !== 'object')
|
|
110
|
+
return;
|
|
111
|
+
if (isPatchJsExpr(node))
|
|
112
|
+
return;
|
|
113
|
+
if (seen.has(node))
|
|
114
|
+
return;
|
|
115
|
+
seen.add(node);
|
|
116
|
+
if (Array.isArray(node)) {
|
|
117
|
+
node.forEach((item, index) => walk(item, `${path}[${index}]`));
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
for (const [key, child] of Object.entries(node)) {
|
|
121
|
+
const effect = keyHazardEffect(key);
|
|
122
|
+
if (effect !== null)
|
|
123
|
+
hazards.push({ path, key, effect });
|
|
124
|
+
walk(child, path === '' ? key : `${path}.${key}`);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
walk(value, '');
|
|
128
|
+
return hazards;
|
|
49
129
|
}
|
|
50
130
|
/**
|
|
51
131
|
* 解析报错的**安全摘要**:只取首行。
|
package/lib/utils/paths.d.ts
CHANGED
|
@@ -41,6 +41,19 @@ export declare function normalizePathCollapsed(p: string): string;
|
|
|
41
41
|
* 大小写不敏感(Windows 文件系统大小写不敏感,防 `DSh-Config-Manager/...` 绕过);
|
|
42
42
|
* 先折叠 `..`/`.` 段(宿主 fs 会折叠,此处必须同样折叠以免被路径穿越绕过)。 */
|
|
43
43
|
export declare function isReservedInternalRel(relPath: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* 凭据文件(home 相对路径)判定 —— **全仓唯一出口**(审计 P2-1 P0 修复,2026-11-13)。
|
|
46
|
+
*
|
|
47
|
+
* 为什么必须有:pluginData / pluginAssets 的分区根是**系统主目录**,来源既可能是内置表,
|
|
48
|
+
* 也可能是插件自己在 package.json 里声明的 `dsh.dataDirs`。声明方只要写 `.dsh`,就会把
|
|
49
|
+
* `~/.dsh/.credentials.yaml` 当普通配置收进**明文 ZIP** —— 而 manifest 仍报「不含密钥」
|
|
50
|
+
* (真机实测:包内出现 plugin-data/.dsh/.credentials.yaml,containsSecrets=false)。
|
|
51
|
+
* 字段级脱敏只处理结构化值,管不到「整文件即秘密」的形态,所以按**文件名形态**判一次,
|
|
52
|
+
* 收集侧(adapter)与打包侧(exporter)共用同一判据 —— 两处都在,缺一即回归。
|
|
53
|
+
*
|
|
54
|
+
* 只认名字、不做内容嗅探:收集期读全部字节既慢又读不完大资产。
|
|
55
|
+
*/
|
|
56
|
+
export declare function isSensitiveHomeRel(relPath: string): boolean;
|
|
44
57
|
/**
|
|
45
58
|
* 前缀批量映射(规范 §12):把对象内所有字符串值中匹配 oldPrefix 的路径
|
|
46
59
|
* 替换为 newPrefix(路径感知:必须落在段边界)。返回新对象(不改原对象)。
|
package/lib/utils/paths.js
CHANGED
|
@@ -86,6 +86,10 @@ const RESERVED_INTERNAL_PREFIXES = [
|
|
|
86
86
|
'dsh-config-manager/environment-fingerprint.token',
|
|
87
87
|
// Phase 6:迁移历史审计目录(统一历史引擎;防 F23 投毒链——不可信导入不得映射到该目录)。
|
|
88
88
|
'dsh-config-manager/migration-history/',
|
|
89
|
+
// Phase 6+(审计 P12-5):敏感文件镜像目录(<dataDir>/vault)存的是 .credentials.yaml 等明文镜像,
|
|
90
|
+
// 与上面几项同属「不可信归档不得映射进来」的 control-plane 区;isSensitiveHomeRel 已在**收集/打包**
|
|
91
|
+
// 侧按 vault 段拦这种文件,这里补上**导入目标**侧的同一判据,免得 crafted 归档把条目写进镜像目录。
|
|
92
|
+
'dsh-config-manager/vault/',
|
|
89
93
|
// 注意:不得整段保留 dsh-config-manager/sync/ —— self 分区合法持有 sync/*.json 白名单配置
|
|
90
94
|
//(sync-config / sync-selection / ui-prefs / backup-schedule),会误伤。
|
|
91
95
|
'dsh-config-manager/sync/snapshots/',
|
|
@@ -129,6 +133,37 @@ export function isReservedInternalRel(relPath) {
|
|
|
129
133
|
}
|
|
130
134
|
return false;
|
|
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) {
|
|
149
|
+
const norm = normalizePathCollapsed(relPath).toLowerCase();
|
|
150
|
+
if (norm === '')
|
|
151
|
+
return false;
|
|
152
|
+
const segments = norm.split('/');
|
|
153
|
+
// vault 目录本身即凭据明文镜像(<dataDir>/vault),任何形态都不得进归档
|
|
154
|
+
if (segments.includes('vault'))
|
|
155
|
+
return true;
|
|
156
|
+
const base = segments[segments.length - 1] ?? '';
|
|
157
|
+
return SENSITIVE_HOME_BASENAMES.some((re) => re.test(base));
|
|
158
|
+
}
|
|
159
|
+
/** 凭据文件名形态(小写比较;与 DEFAULT_SENSITIVE_RELS 的「整文件即秘密」同口径) */
|
|
160
|
+
const SENSITIVE_HOME_BASENAMES = [
|
|
161
|
+
/^\.?credentials(\..*)?$/, // .credentials.yaml / credentials.json / .credentials
|
|
162
|
+
/^credentials\.(ya?ml|json)$/,
|
|
163
|
+
/^secrets\.(ya?ml|json)$/,
|
|
164
|
+
/^auth\.json$/,
|
|
165
|
+
/^\.env(\..*)?$/,
|
|
166
|
+
];
|
|
132
167
|
/**
|
|
133
168
|
* Windows 语义路径(盘符 "C:/"、"C:\\";UNC 以两个斜杠或两个反斜杠开头)。
|
|
134
169
|
*
|
|
@@ -224,6 +224,15 @@ export async function withWorkdirLock(workDir, fn, options = {}) {
|
|
|
224
224
|
// 计时必须在进入串行链**之前**取:链上排队同样属于「在等这把锁」。否则一个只读调用排在
|
|
225
225
|
// 上一个 300 s 的同步后面时,计时从轮到它那一刻才清零,超时上限形同失效(2026-10-27 现场)。
|
|
226
226
|
const started = now();
|
|
227
|
+
/**
|
|
228
|
+
* 是否已经**拿到锁**(timeoutMs 只约束「等锁」,拿到之后 fn 自己的耗时不受它管)。
|
|
229
|
+
*
|
|
230
|
+
* 为什么必须分开(审计 P12-1 P1,真机 #104 复现):旧实现对整条链 race 一个 timeoutMs,
|
|
231
|
+
* 于是 `inspectWorkDir`(lockTimeoutMs=1500 的只读自检)里的真实 git 调用只要跑过 1.5 s,
|
|
232
|
+
* 就被判成「等锁超时」—— 错误文案说「正被另一个同步任务占用」,实际根本没有竞争;
|
|
233
|
+
* 单文件隔离复跑同样必红(30 s 处抛锁冲突)。等锁与干活是两件事,不能共用一个死线。
|
|
234
|
+
*/
|
|
235
|
+
let acquired = false;
|
|
227
236
|
const run = async () => {
|
|
228
237
|
// 排队期间调用方已超时放弃:轮到它时直接失败,**不执行 fn**,免得被遗弃的请求稍后仍去驱动工作副本
|
|
229
238
|
if (now() - started >= timeoutMs)
|
|
@@ -237,6 +246,7 @@ export async function withWorkdirLock(workDir, fn, options = {}) {
|
|
|
237
246
|
await sleep(POLL_INTERVAL_MS);
|
|
238
247
|
release = await tryAcquire(lockPath, workDir, staleMs, now);
|
|
239
248
|
}
|
|
249
|
+
acquired = true;
|
|
240
250
|
try {
|
|
241
251
|
return await fn();
|
|
242
252
|
}
|
|
@@ -250,11 +260,16 @@ export async function withWorkdirLock(workDir, fn, options = {}) {
|
|
|
250
260
|
const tail = current.then(() => undefined, () => undefined);
|
|
251
261
|
chains.set(key, tail);
|
|
252
262
|
// 硬上界:timeoutMs 是「拿到锁」的上限,不是「开始计时后」的上限。只用 run 内的计时不够 ——
|
|
253
|
-
//
|
|
254
|
-
//
|
|
263
|
+
// 排在长任务后面的调用永远轮不到自己计时,界面就被历史任务拖着走。这里对链头 race,超时 reject;
|
|
264
|
+
// 被放弃的 run 之后还会被链唤醒,但入口的过期检查让它立刻抛(不碰工作副本)。
|
|
265
|
+
// 关键:**拿到锁之后不再受这条死线约束**(见上面 acquired 的说明)。
|
|
255
266
|
let rejectDeadline;
|
|
256
267
|
const deadline = new Promise((_, reject) => { rejectDeadline = reject; });
|
|
257
|
-
const timer = setTimeout(() => {
|
|
268
|
+
const timer = setTimeout(() => {
|
|
269
|
+
if (acquired)
|
|
270
|
+
return;
|
|
271
|
+
rejectDeadline?.(new WorkdirLockError(workDir, timeoutMs));
|
|
272
|
+
}, timeoutMs);
|
|
258
273
|
// unref:这个计时器不该拖住进程退出(缺省 300 s)
|
|
259
274
|
if (typeof timer.unref === 'function')
|
|
260
275
|
timer.unref();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-config-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Backup, restore, export, import, migrate and sync your DeepSeek Harness (DSH) configuration: settings, plugins, MCP servers, skills, agent presets and workspaces. One-click migration to another machine. DSH 配置一键备份、恢复、导出、导入、迁移与同步插件。",
|
|
6
6
|
"icon": "./icon.svg",
|
|
@@ -197,6 +197,7 @@
|
|
|
197
197
|
"@types/node": "^26.6.5",
|
|
198
198
|
"@types/react": "~18.3.1",
|
|
199
199
|
"@types/react-dom": "^18.3.5",
|
|
200
|
+
"js-yaml4": "npm:js-yaml@^4.3.2",
|
|
200
201
|
"lightningcss": "1.33.0",
|
|
201
202
|
"lucide": "^1.61.0",
|
|
202
203
|
"lucide-react": "^1.61.0",
|
package/src/adapters/mcp.test.ts
CHANGED
|
@@ -7,6 +7,7 @@ import assert from 'node:assert/strict';
|
|
|
7
7
|
import { McpAdapter, extractMcpServers, buildMcpPatchLine, mcpServerUnitId, mcpConnectorUnitId } from './mcp.ts';
|
|
8
8
|
import { makeContext, makeImportContext } from './test-helpers.ts';
|
|
9
9
|
import type { PlanItem } from '../core/types.ts';
|
|
10
|
+
import type { McpExportSection } from './mcp.ts';
|
|
10
11
|
|
|
11
12
|
test('mcp: extractMcpServers 兼容单行与 insert 块', () => {
|
|
12
13
|
const lines = [
|
|
@@ -419,3 +420,31 @@ test('mcp 条目级:单元 id 与 export 自洽(勾哪个就带出哪个)'
|
|
|
419
420
|
}
|
|
420
421
|
});
|
|
421
422
|
|
|
423
|
+
test('#137 mcp: env / headers 的键名会被 DSH 读端改判 → 计划项降级为 Error(本项不写、不整笔回滚)', async () => {
|
|
424
|
+
const adapter = new McpAdapter();
|
|
425
|
+
const data = {
|
|
426
|
+
version: 1,
|
|
427
|
+
servers: [
|
|
428
|
+
{ serverName: 'with-env', type: 'stdio', command: 'node', env: { '007': 'v' }, sourceLineId: 'mcp-num' },
|
|
429
|
+
{ serverName: 'with-empty', type: 'stdio', command: 'node', env: { '': 'v' }, sourceLineId: 'mcp-empty' },
|
|
430
|
+
{ serverName: 'clean', type: 'stdio', command: 'node', env: { NORMAL: 'v' }, sourceLineId: 'mcp-clean' },
|
|
431
|
+
],
|
|
432
|
+
} as unknown as McpExportSection;
|
|
433
|
+
const dst = makeContext('linux', '/home/bob', 'web');
|
|
434
|
+
const items = await adapter.analyzeImport(data, makeImportContext(dst, new Map([['mcp', data]])));
|
|
435
|
+
const byId = new Map(items.map((i) => [i.id, i]));
|
|
436
|
+
|
|
437
|
+
const numeric = byId.get('mcp:with-env');
|
|
438
|
+
assert.equal(numeric?.kind, 'Error', '键 007 会被 4.x 读成 7 → 必须拦');
|
|
439
|
+
assert.equal(numeric?.severity, 'error');
|
|
440
|
+
assert.match(numeric!.description, /007/, '文案要点名是哪个键,否则用户无从下手');
|
|
441
|
+
assert.match(numeric!.description, /mcp-num/, '文案要点名是哪一行');
|
|
442
|
+
assert.equal(numeric?.target, undefined, '被拦的项没有写入面,不该认领 target');
|
|
443
|
+
|
|
444
|
+
const empty = byId.get('mcp:with-empty');
|
|
445
|
+
assert.equal(empty?.kind, 'Error', '空键名会让 4.x 整份文件解析失败 → 必须拦');
|
|
446
|
+
assert.match(empty!.description, /解析失败/);
|
|
447
|
+
|
|
448
|
+
assert.equal(byId.get('mcp:clean')?.kind, 'Create', '正常键名照旧 Create');
|
|
449
|
+
});
|
|
450
|
+
|
package/src/adapters/mcp.ts
CHANGED
|
@@ -22,6 +22,8 @@ import type {
|
|
|
22
22
|
ImportContext, PlanItem, ValidationResult,
|
|
23
23
|
} from '../core/types.ts';
|
|
24
24
|
import { locatePatchLineLayer, readEffectivePatchLines, resolveWriteLayer } from '../core/patch-layers.ts';
|
|
25
|
+
import { findPatchKeyHazards } from '../utils/patch-yaml.ts';
|
|
26
|
+
import { patchKeyHazardMessage } from './patch-key-guard.ts';
|
|
25
27
|
import {
|
|
26
28
|
MCP_CONNECTOR_STORE_REL, buildConnectorRecord, comparableConnector, exportConnectorBlock,
|
|
27
29
|
findConnectorRecord, mergeConnectorIntoStoreText, pickConnectorKey, readConnectorStore,
|
|
@@ -153,6 +155,17 @@ const MCP_BUNDLE_NAME = '@deepseek-ai/dsh-mcp-client';
|
|
|
153
155
|
* 上才回落 url 猜测(issue #133:此前写回丢了这个字段,stdio/http 只能靠 url 有没有值猜)。
|
|
154
156
|
*/
|
|
155
157
|
export function buildMcpPatchLine(lineId: string, server: McpServerEntry): Record<string, unknown> {
|
|
158
|
+
return { id: lineId, name: MCP_BUNDLE_NAME, config: mcpPatchConfig(server) };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 写进 patch 行的 `config`。
|
|
163
|
+
*
|
|
164
|
+
* 单独抽出来是因为**键名守卫**(issue #137)要检查同一份对象:`env` / `headers` 的键名完全由
|
|
165
|
+
* 用户的 MCP 配置决定,`007` / `~` 这类名字会被 DSH 的 4.x 读端改判、空键会让整份文件解析失败。
|
|
166
|
+
* 守卫必须与真正写盘的形状同源,否则查的和写的不是同一份东西。
|
|
167
|
+
*/
|
|
168
|
+
function mcpPatchConfig(server: McpServerEntry): Record<string, unknown> {
|
|
156
169
|
const config: Record<string, unknown> = { serverName: server.serverName, transport: server.type };
|
|
157
170
|
if (server.type === 'streamable-http') {
|
|
158
171
|
config['url'] = server.url;
|
|
@@ -163,7 +176,7 @@ export function buildMcpPatchLine(lineId: string, server: McpServerEntry): Recor
|
|
|
163
176
|
if (server.env !== undefined) config['env'] = server.env;
|
|
164
177
|
if (server.cwd !== undefined) config['cwd'] = server.cwd;
|
|
165
178
|
}
|
|
166
|
-
return
|
|
179
|
+
return config;
|
|
167
180
|
}
|
|
168
181
|
|
|
169
182
|
/** 连接器计划项的 id 前缀(导入时按前缀分派到 applyConnectorItem) */
|
|
@@ -331,6 +344,27 @@ export class McpAdapter implements ConfigAdapter<McpExportSection> {
|
|
|
331
344
|
const comparable = { ...server } as Record<string, unknown>;
|
|
332
345
|
delete comparable.sourceLineId;
|
|
333
346
|
delete comparable.sourceFile;
|
|
347
|
+
// 与目标一致 ⇒ 不会写盘,键名风险不归我们管(先判 Skip 以免误报)。
|
|
348
|
+
if (existing) {
|
|
349
|
+
const existingComparable = { ...existing } as Record<string, unknown>;
|
|
350
|
+
delete existingComparable.sourceLineId;
|
|
351
|
+
delete existingComparable.sourceFile;
|
|
352
|
+
if (isDeepStrictEqual(existingComparable, comparable)) {
|
|
353
|
+
items.push({ id, kind: 'Skip', adapter: 'mcp', description: msg('adapter.mcpSame', { serverName: server.serverName }), severity: 'info' });
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
// issue #137:env / headers 的键名完全由用户配置决定,写出去的键名会被 DSH 的 4.x 读端改判
|
|
358
|
+
// (空键更会让整份文件解析失败)。命中即降级成本项「预判阻断」:本项不写、不整笔回滚。
|
|
359
|
+
const hazard = findPatchKeyHazards(mcpPatchConfig(server))[0];
|
|
360
|
+
if (hazard) {
|
|
361
|
+
const refForMessage = existing?.sourceLineId ?? server.sourceLineId ?? newLineId(server.serverName);
|
|
362
|
+
items.push({
|
|
363
|
+
id, kind: 'Error', adapter: 'mcp',
|
|
364
|
+
description: patchKeyHazardMessage(msg, refForMessage, hazard), severity: 'error',
|
|
365
|
+
});
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
334
368
|
if (!existing) {
|
|
335
369
|
const lineId = server.sourceLineId && targetLines.some((l) => l.lineId === server.sourceLineId)
|
|
336
370
|
? `${server.sourceLineId}-imported`
|
|
@@ -344,20 +378,17 @@ export class McpAdapter implements ConfigAdapter<McpExportSection> {
|
|
|
344
378
|
target: { adapter: 'mcp', ref: lineId, file: resolveWriteLayer(server.sourceFile, ctx.target.profile) },
|
|
345
379
|
});
|
|
346
380
|
} else {
|
|
381
|
+
// 已在上方判过「一致 ⇒ Skip」,到这里只可能是真差异;existingComparable 仍要给 detail 用
|
|
347
382
|
const existingComparable = { ...existing } as Record<string, unknown>;
|
|
348
383
|
delete existingComparable.sourceLineId;
|
|
349
384
|
delete existingComparable.sourceFile;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
severity: 'warning',
|
|
358
|
-
target: { adapter: 'mcp', ref: existing.sourceLineId, file: existing.sourceFile },
|
|
359
|
-
});
|
|
360
|
-
}
|
|
385
|
+
items.push({
|
|
386
|
+
id, kind: 'Conflict', adapter: 'mcp',
|
|
387
|
+
description: msg('adapter.mcpDiff', { serverName: server.serverName }),
|
|
388
|
+
detail: `current=${JSON.stringify(existingComparable)} imported=${JSON.stringify(comparable)}`.slice(0, 200),
|
|
389
|
+
severity: 'warning',
|
|
390
|
+
target: { adapter: 'mcp', ref: existing.sourceLineId, file: existing.sourceFile },
|
|
391
|
+
});
|
|
361
392
|
}
|
|
362
393
|
}
|
|
363
394
|
items.push(...await this.analyzeConnectors(data, ctx));
|
package/src/adapters/messages.ts
CHANGED
|
@@ -34,6 +34,7 @@ export const zh = {
|
|
|
34
34
|
// ---------- pluginData / pluginAssets(第三方插件数据迁移) ----------
|
|
35
35
|
'adapter.pluginDataEnvOverridden': '{path} 的位置被环境变量 {env} 覆盖,本次已跳过(不猜它指向哪里)',
|
|
36
36
|
'adapter.pluginDataPathNotAllowed': '路径不在第三方插件数据的允许范围内,已拒绝写入: {path}',
|
|
37
|
+
'adapter.pluginDataSensitiveSkipped': '已剔除 {count} 个凭据文件(首个:{sample})——第三方插件数据分区永不搬运凭据明文',
|
|
37
38
|
'adapter.pluginDataNoOsHome': '第三方插件的数据在系统主目录下,但当前宿主没有提供该目录的文件通道(旧版本宿主):本次不读取也不导入 / third-party plugin data lives under the system home directory, but this host offers no file channel for it (older host): nothing is read or imported this time',
|
|
38
39
|
// ---------- pnpm 配置可移植净化(机器相关路径键) ----------
|
|
39
40
|
'adapter.pwMachinePathStripped': '已剥离 {count} 条与本机路径绑定的 pnpm 设置(换机后会指向不存在的目录):{keys}',
|
|
@@ -56,6 +57,7 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
56
57
|
'adapter.uiLocalStorageGeneric': 'Browser-side UI state cannot be migrated through the host API',
|
|
57
58
|
'adapter.pluginDataEnvOverridden': "the location of {path} is overridden by the {env} environment variable; skipped this time (the new location is never guessed)",
|
|
58
59
|
'adapter.pluginDataPathNotAllowed': 'the path is outside the range allowed for third-party plugin data and was refused: {path}',
|
|
60
|
+
'adapter.pluginDataSensitiveSkipped': 'dropped {count} credential file(s) (first: {sample}) — third-party plugin data never carries credential plaintext',
|
|
59
61
|
'adapter.pluginDataNoOsHome': 'third-party plugin data lives under the system home directory, but this host offers no file channel for it (older host): nothing is read or imported this time',
|
|
60
62
|
'adapter.pwMachinePathStripped': 'Stripped {count} pnpm setting(s) bound to machine-specific paths (they would point to non-existent directories on another machine): {keys}',
|
|
61
63
|
'adapter.pwMachinePathKept': "Kept this machine's own {count} pnpm path setting(s) (the source machine's paths are never carried over): {keys}",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* patch 行**键名**的跨大版本守卫(issue #137)。
|
|
3
|
+
*
|
|
4
|
+
* 写侧 `forceQuotes`(issue #135)只保**值**;键名仍由 js-yaml 决定加不加引号,于是
|
|
5
|
+
* `007` / `True` / `.5` / `~` 这类键被 4.x 读成 `7` / `true` / `0.5` / `null`,
|
|
6
|
+
* 空键名更会让整份 `cordis.patch.yml` 解析失败。检测器在 `utils/patch-yaml.ts`
|
|
7
|
+
* (`findPatchKeyHazards`),这里只负责把命中翻成计划项文案 —— 各适配器共用一份措辞,
|
|
8
|
+
* 免得同一个风险在插件 / MCP 两处说法不一致。
|
|
9
|
+
*
|
|
10
|
+
* 为什么是「计划项降级」而不是「写盘时抛错」:抛错走 analyzer 的 hardFailed ⇒
|
|
11
|
+
* `rollbackOnError` 会把**整笔导入**回滚(别的分区也跟着白做);`kind: 'Error'` 的计划项
|
|
12
|
+
* 在 `src/core/analyzer.ts` 里只记账、不回滚、不中断后续条目(与 plugin-files 的
|
|
13
|
+
* SEC-05 同一条通道)。
|
|
14
|
+
*/
|
|
15
|
+
import type { MsgFunc } from '../core/messages.ts'
|
|
16
|
+
import type { PatchKeyHazard } from '../utils/patch-yaml.ts'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 把一处键名风险转成用户可见文案。
|
|
20
|
+
*
|
|
21
|
+
* @param ref 计划项对应的 patch 行 id(`lineId`),用于让用户定位到具体是哪一行
|
|
22
|
+
* @param hazard `findPatchKeyHazards` 的命中项
|
|
23
|
+
*/
|
|
24
|
+
export function patchKeyHazardMessage(msg: MsgFunc, ref: string, hazard: PatchKeyHazard): string {
|
|
25
|
+
const path = hazard.path === '' ? '-' : hazard.path
|
|
26
|
+
return hazard.effect === 'parse-fail'
|
|
27
|
+
? msg('adapter.patchKeyParseFail', { ref, path })
|
|
28
|
+
: msg('adapter.patchKeyAmbiguous', { ref, key: hazard.key, path })
|
|
29
|
+
}
|
|
@@ -13,6 +13,7 @@ import assert from 'node:assert/strict';
|
|
|
13
13
|
|
|
14
14
|
import { PluginDataAdapter } from './plugin-data.ts';
|
|
15
15
|
import { makeContext, makeImportContext, sha256Hex } from './test-helpers.ts';
|
|
16
|
+
import type { FileSystemFacade } from '../core/types.ts';
|
|
16
17
|
import type { PluginDataSource } from '../core/plugin-data-registry.ts';
|
|
17
18
|
import type { FilesSection } from '../schema/types.ts';
|
|
18
19
|
|
|
@@ -41,6 +42,38 @@ async function seedHome(ctx: ReturnType<typeof makeContext>): Promise<void> {
|
|
|
41
42
|
await ctx.fs.writeFile('.mnemon/data/body.db', bytes('db'));
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
/** 把 homeFs 的第一次 readFile 挂上闸门(造「清单已解析、内容还没读」的交错点) */
|
|
46
|
+
function gatedReadFile(inner: FileSystemFacade): {
|
|
47
|
+
facade: FileSystemFacade;
|
|
48
|
+
atGate: Promise<void>;
|
|
49
|
+
release: () => void;
|
|
50
|
+
} {
|
|
51
|
+
let release!: () => void;
|
|
52
|
+
const gate = new Promise<void>((resolve) => { release = resolve; });
|
|
53
|
+
let reachedGate!: () => void;
|
|
54
|
+
const atGate = new Promise<void>((resolve) => { reachedGate = resolve; });
|
|
55
|
+
let armed = true;
|
|
56
|
+
const facade = new Proxy(inner, {
|
|
57
|
+
get(target, prop) {
|
|
58
|
+
const value = Reflect.get(target, prop) as unknown;
|
|
59
|
+
if (typeof value !== 'function') return value;
|
|
60
|
+
if (prop === 'readFile') {
|
|
61
|
+
return async (rel: string): Promise<Uint8Array> => {
|
|
62
|
+
if (armed) {
|
|
63
|
+
armed = false;
|
|
64
|
+
reachedGate();
|
|
65
|
+
await gate;
|
|
66
|
+
}
|
|
67
|
+
return (value as (p: string) => Promise<Uint8Array>).call(target, rel);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// Proxy 转发会丢 this:其余方法一律显式 bind 回原门面
|
|
71
|
+
return (value as (...args: unknown[]) => unknown).bind(target);
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
return { facade, atGate, release };
|
|
75
|
+
}
|
|
76
|
+
|
|
44
77
|
test('收录口径:配置分区只带配置,资产分区只带大资产,缓存永不出现', async () => {
|
|
45
78
|
const ctx = ctxFor(HOME);
|
|
46
79
|
await seedHome(ctx);
|
|
@@ -150,6 +183,46 @@ test('导入白名单:包外路径一律 Error,applyItem 也拒绝;包内
|
|
|
150
183
|
assert.equal(await dst.fs.exists('AGENTS.md'), false);
|
|
151
184
|
});
|
|
152
185
|
|
|
186
|
+
test('审计 P2-1(P0 回归):凭据形状文件永不进入 pluginData/pluginAssets 出包,导入侧同样拒绝', async () => {
|
|
187
|
+
const src = ctxFor(HOME);
|
|
188
|
+
await seedHome(src);
|
|
189
|
+
// 真机形态:插件把 token / 凭据放在自己的区域里(region 在来源表内,路径不越界)
|
|
190
|
+
await src.fs.writeFile('.mnemon/credentials.yaml', bytes('token: SECRET-VALUE'));
|
|
191
|
+
await src.fs.writeFile('.mnemon/vault/oauth.json', bytes('{"access_token":"SECRET-VALUE"}'));
|
|
192
|
+
await src.fs.writeFile('.dsh-wallpaper-engine/secrets.json', bytes('{"key":"SECRET-VALUE"}'));
|
|
193
|
+
await src.fs.writeFile('.dsh-wallpaper-engine/.env.local', bytes('API_KEY=SECRET-VALUE'));
|
|
194
|
+
|
|
195
|
+
const config = new PluginDataAdapter('pluginData', { env: {} });
|
|
196
|
+
const out = await config.export(src, { includeSecrets: false });
|
|
197
|
+
const shipped = out.data.files.map((f) => f.relativePath)
|
|
198
|
+
for (const rel of ['.mnemon/credentials.yaml', '.mnemon/vault/oauth.json', '.dsh-wallpaper-engine/secrets.json', '.dsh-wallpaper-engine/.env.local']) {
|
|
199
|
+
assert.ok(!shipped.includes(rel), `凭据形状文件不得出包:${rel}`)
|
|
200
|
+
}
|
|
201
|
+
assert.deepEqual(shipped.sort(), ['.dsh-wallpaper-engine/config.json', '.mnemon/runtime/MEMORY.md'], '正常配置文件照常出包')
|
|
202
|
+
// 剔除必须可见(不是静默少带)
|
|
203
|
+
assert.ok(
|
|
204
|
+
out.warnings.some((w) => w.includes('凭据文件')),
|
|
205
|
+
`剔除凭据文件必须进 warnings,实际:${JSON.stringify(out.warnings)}`,
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
// 导入侧:即使包里被塞进凭据形状路径(伪造的包),也必须判 Error 且 applyItem 拒绝
|
|
209
|
+
const forged: FilesSection = {
|
|
210
|
+
version: 1,
|
|
211
|
+
files: [
|
|
212
|
+
{ relativePath: '.mnemon/credentials.yaml', data: bytes('token: x'), contentHash: sha256Hex(bytes('token: x')) },
|
|
213
|
+
{ relativePath: '.mnemon/vault/oauth.json', data: bytes('{}'), contentHash: sha256Hex(bytes('{}')) },
|
|
214
|
+
],
|
|
215
|
+
}
|
|
216
|
+
const dst = ctxFor('/home/bob')
|
|
217
|
+
const sections = new Map<string, unknown>([['pluginData', forged]])
|
|
218
|
+
const items = await config.analyzeImport(forged, makeImportContext(dst, sections))
|
|
219
|
+
assert.equal(items.filter((i) => i.kind === 'Error').length, 2, '凭据形状路径必须在计划期判 Error')
|
|
220
|
+
const first = items[0]!
|
|
221
|
+
const r = await config.applyItem(first, makeImportContext(dst, sections))
|
|
222
|
+
assert.equal(r.ok, false, 'applyItem 必须拒绝(纵深防御)')
|
|
223
|
+
assert.equal(await dst.fs.exists('.mnemon/credentials.yaml'), false)
|
|
224
|
+
});
|
|
225
|
+
|
|
153
226
|
test('自述声明(dsh.dataDirs):已安装插件的区域可导出、可导入;未声明的插件目录仍被拒', async () => {
|
|
154
227
|
const ctx = ctxFor(HOME);
|
|
155
228
|
await ctx.fs.writeFile('profiles/web/package.json', bytes(JSON.stringify({ dependencies: { 'dsh-fake': '^1.0.0' } })));
|
|
@@ -223,3 +296,56 @@ test('注入假来源:来源表可替换(测试与未来扩展都走同一
|
|
|
223
296
|
const out = await adapter.export(ctx, { includeSecrets: false });
|
|
224
297
|
assert.deepEqual(out.data.files.map((f) => f.relativePath), ['.my-plugin/a.json']);
|
|
225
298
|
});
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* 审计 P2-7(并发回归):同一 adapter 上并发两路导出,区域归属与告警必须各归各。
|
|
302
|
+
*
|
|
303
|
+
* 触发点:把 A 的 homeFs.readFile 挂上闸门 —— A 的清单先解析完(区域表与告警已就位),
|
|
304
|
+
* 卡在「读内容」处;这期间 B 完整跑完一路导出。旧实现把区域表/告警放在实例字段上,
|
|
305
|
+
* B 会覆盖 A 的那份 ⇒ A 的单元 id 退化成「区域内的裸路径」、A 的告警被 B 的空数组冲掉。
|
|
306
|
+
*/
|
|
307
|
+
test('审计 P2-7(并发回归):同一 adapter 并发两路导出,区域归属与告警互不串台', async () => {
|
|
308
|
+
const declare = async (ctx: ReturnType<typeof ctxFor>, pkg: string, area: string): Promise<void> => {
|
|
309
|
+
await ctx.fs.writeFile('profiles/web/package.json', bytes(JSON.stringify({ dependencies: { [pkg]: '^1.0.0' } })));
|
|
310
|
+
await ctx.fs.writeFile(
|
|
311
|
+
`profiles/web/node_modules/${pkg}/package.json`,
|
|
312
|
+
bytes(JSON.stringify({ name: pkg, dsh: { dataDirs: [{ path: area, role: 'config' }] } })),
|
|
313
|
+
);
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const ctxA = ctxFor(HOME);
|
|
317
|
+
await declare(ctxA, 'dsh-a', '.alpha-plugin');
|
|
318
|
+
await ctxA.fs.writeFile('.alpha-plugin/state.json', bytes('{"a":1}'));
|
|
319
|
+
// 凭据形状文件:A 这一路必须带「剔除凭据文件」告警(用来分辨告警有没有被 B 冲掉)
|
|
320
|
+
await ctxA.fs.writeFile('.alpha-plugin/credentials.yaml', bytes('token: SECRET-VALUE'));
|
|
321
|
+
|
|
322
|
+
const ctxB = ctxFor('/home/bob');
|
|
323
|
+
await declare(ctxB, 'dsh-b', '.beta-plugin');
|
|
324
|
+
await ctxB.fs.writeFile('.beta-plugin/state.json', bytes('{"b":2}'));
|
|
325
|
+
|
|
326
|
+
const adapter = new PluginDataAdapter('pluginData', { env: {} });
|
|
327
|
+
const gated = gatedReadFile(ctxA.homeFs!);
|
|
328
|
+
ctxA.homeFs = gated.facade;
|
|
329
|
+
|
|
330
|
+
const pendingA = adapter.export(ctxA, { includeSecrets: false });
|
|
331
|
+
await gated.atGate; // A 的清单已解析,正卡在「读内容」
|
|
332
|
+
const outB = await adapter.export(ctxB, { includeSecrets: false });
|
|
333
|
+
gated.release();
|
|
334
|
+
const outA = await pendingA;
|
|
335
|
+
|
|
336
|
+
assert.deepEqual(outA.data.files.map((f) => f.relativePath), ['.alpha-plugin/state.json']);
|
|
337
|
+
assert.deepEqual(
|
|
338
|
+
adapter.listUnits(outA).map((u) => u.id),
|
|
339
|
+
['pluginData:.alpha-plugin'],
|
|
340
|
+
'A 的单元必须按 A 自己的区域表归组(旧实现会被 B 的区域表覆盖成裸路径)',
|
|
341
|
+
);
|
|
342
|
+
assert.ok(
|
|
343
|
+
outA.warnings.some((w) => w.includes('凭据文件')),
|
|
344
|
+
`A 的告警不得被并发的 B 冲掉,实际:${JSON.stringify(outA.warnings)}`,
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
assert.deepEqual(outB.data.files.map((f) => f.relativePath), ['.beta-plugin/state.json']);
|
|
348
|
+
assert.deepEqual(adapter.listUnits(outB).map((u) => u.id), ['pluginData:.beta-plugin']);
|
|
349
|
+
assert.ok(!outB.warnings.some((w) => w.includes('凭据文件')), 'B 不得继承 A 的告警');
|
|
350
|
+
});
|
|
351
|
+
|