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/adapters/mcp.js
CHANGED
|
@@ -16,6 +16,8 @@ import { msgOf, zhMsg } from '../core/messages.js';
|
|
|
16
16
|
import { sectionMeta } from '../schema/section-registry.js';
|
|
17
17
|
import { validateJsonSection } from './json-section.js';
|
|
18
18
|
import { locatePatchLineLayer, readEffectivePatchLines, resolveWriteLayer } from '../core/patch-layers.js';
|
|
19
|
+
import { findPatchKeyHazards } from '../utils/patch-yaml.js';
|
|
20
|
+
import { patchKeyHazardMessage } from './patch-key-guard.js';
|
|
19
21
|
import { MCP_CONNECTOR_STORE_REL, buildConnectorRecord, comparableConnector, exportConnectorBlock, findConnectorRecord, mergeConnectorIntoStoreText, pickConnectorKey, readConnectorStore, refillFieldsOf, } from '../core/mcp-connector-store.js';
|
|
20
22
|
/**
|
|
21
23
|
* 从 patch 行数组中提取 MCP server 条目(以 config.serverName 存在为判定)。
|
|
@@ -122,6 +124,16 @@ const MCP_BUNDLE_NAME = '@deepseek-ai/dsh-mcp-client';
|
|
|
122
124
|
* 上才回落 url 猜测(issue #133:此前写回丢了这个字段,stdio/http 只能靠 url 有没有值猜)。
|
|
123
125
|
*/
|
|
124
126
|
export function buildMcpPatchLine(lineId, server) {
|
|
127
|
+
return { id: lineId, name: MCP_BUNDLE_NAME, config: mcpPatchConfig(server) };
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 写进 patch 行的 `config`。
|
|
131
|
+
*
|
|
132
|
+
* 单独抽出来是因为**键名守卫**(issue #137)要检查同一份对象:`env` / `headers` 的键名完全由
|
|
133
|
+
* 用户的 MCP 配置决定,`007` / `~` 这类名字会被 DSH 的 4.x 读端改判、空键会让整份文件解析失败。
|
|
134
|
+
* 守卫必须与真正写盘的形状同源,否则查的和写的不是同一份东西。
|
|
135
|
+
*/
|
|
136
|
+
function mcpPatchConfig(server) {
|
|
125
137
|
const config = { serverName: server.serverName, transport: server.type };
|
|
126
138
|
if (server.type === 'streamable-http') {
|
|
127
139
|
config['url'] = server.url;
|
|
@@ -137,7 +149,7 @@ export function buildMcpPatchLine(lineId, server) {
|
|
|
137
149
|
if (server.cwd !== undefined)
|
|
138
150
|
config['cwd'] = server.cwd;
|
|
139
151
|
}
|
|
140
|
-
return
|
|
152
|
+
return config;
|
|
141
153
|
}
|
|
142
154
|
/** 连接器计划项的 id 前缀(导入时按前缀分派到 applyConnectorItem) */
|
|
143
155
|
const MCP_CONNECTOR_ITEM_PREFIX = 'mcp-connector:';
|
|
@@ -302,6 +314,27 @@ export class McpAdapter {
|
|
|
302
314
|
const comparable = { ...server };
|
|
303
315
|
delete comparable.sourceLineId;
|
|
304
316
|
delete comparable.sourceFile;
|
|
317
|
+
// 与目标一致 ⇒ 不会写盘,键名风险不归我们管(先判 Skip 以免误报)。
|
|
318
|
+
if (existing) {
|
|
319
|
+
const existingComparable = { ...existing };
|
|
320
|
+
delete existingComparable.sourceLineId;
|
|
321
|
+
delete existingComparable.sourceFile;
|
|
322
|
+
if (isDeepStrictEqual(existingComparable, comparable)) {
|
|
323
|
+
items.push({ id, kind: 'Skip', adapter: 'mcp', description: msg('adapter.mcpSame', { serverName: server.serverName }), severity: 'info' });
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
// issue #137:env / headers 的键名完全由用户配置决定,写出去的键名会被 DSH 的 4.x 读端改判
|
|
328
|
+
// (空键更会让整份文件解析失败)。命中即降级成本项「预判阻断」:本项不写、不整笔回滚。
|
|
329
|
+
const hazard = findPatchKeyHazards(mcpPatchConfig(server))[0];
|
|
330
|
+
if (hazard) {
|
|
331
|
+
const refForMessage = existing?.sourceLineId ?? server.sourceLineId ?? newLineId(server.serverName);
|
|
332
|
+
items.push({
|
|
333
|
+
id, kind: 'Error', adapter: 'mcp',
|
|
334
|
+
description: patchKeyHazardMessage(msg, refForMessage, hazard), severity: 'error',
|
|
335
|
+
});
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
305
338
|
if (!existing) {
|
|
306
339
|
const lineId = server.sourceLineId && targetLines.some((l) => l.lineId === server.sourceLineId)
|
|
307
340
|
? `${server.sourceLineId}-imported`
|
|
@@ -316,21 +349,17 @@ export class McpAdapter {
|
|
|
316
349
|
});
|
|
317
350
|
}
|
|
318
351
|
else {
|
|
352
|
+
// 已在上方判过「一致 ⇒ Skip」,到这里只可能是真差异;existingComparable 仍要给 detail 用
|
|
319
353
|
const existingComparable = { ...existing };
|
|
320
354
|
delete existingComparable.sourceLineId;
|
|
321
355
|
delete existingComparable.sourceFile;
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
detail: `current=${JSON.stringify(existingComparable)} imported=${JSON.stringify(comparable)}`.slice(0, 200),
|
|
330
|
-
severity: 'warning',
|
|
331
|
-
target: { adapter: 'mcp', ref: existing.sourceLineId, file: existing.sourceFile },
|
|
332
|
-
});
|
|
333
|
-
}
|
|
356
|
+
items.push({
|
|
357
|
+
id, kind: 'Conflict', adapter: 'mcp',
|
|
358
|
+
description: msg('adapter.mcpDiff', { serverName: server.serverName }),
|
|
359
|
+
detail: `current=${JSON.stringify(existingComparable)} imported=${JSON.stringify(comparable)}`.slice(0, 200),
|
|
360
|
+
severity: 'warning',
|
|
361
|
+
target: { adapter: 'mcp', ref: existing.sourceLineId, file: existing.sourceFile },
|
|
362
|
+
});
|
|
334
363
|
}
|
|
335
364
|
}
|
|
336
365
|
items.push(...await this.analyzeConnectors(data, ctx));
|
|
@@ -14,6 +14,7 @@ export declare const zh: {
|
|
|
14
14
|
readonly 'adapter.uiLocalStorageGeneric': '浏览器端 UI 状态无法经 Host API 迁移';
|
|
15
15
|
readonly 'adapter.pluginDataEnvOverridden': '{path} 的位置被环境变量 {env} 覆盖,本次已跳过(不猜它指向哪里)';
|
|
16
16
|
readonly 'adapter.pluginDataPathNotAllowed': '路径不在第三方插件数据的允许范围内,已拒绝写入: {path}';
|
|
17
|
+
readonly 'adapter.pluginDataSensitiveSkipped': '已剔除 {count} 个凭据文件(首个:{sample})——第三方插件数据分区永不搬运凭据明文';
|
|
17
18
|
readonly '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';
|
|
18
19
|
readonly 'adapter.pwMachinePathStripped': '已剥离 {count} 条与本机路径绑定的 pnpm 设置(换机后会指向不存在的目录):{keys}';
|
|
19
20
|
readonly 'adapter.pwMachinePathKept': '保留本机原有的 {count} 条 pnpm 路径设置(不搬运来源机的路径):{keys}';
|
package/lib/adapters/messages.js
CHANGED
|
@@ -32,6 +32,7 @@ export const zh = {
|
|
|
32
32
|
// ---------- pluginData / pluginAssets(第三方插件数据迁移) ----------
|
|
33
33
|
'adapter.pluginDataEnvOverridden': '{path} 的位置被环境变量 {env} 覆盖,本次已跳过(不猜它指向哪里)',
|
|
34
34
|
'adapter.pluginDataPathNotAllowed': '路径不在第三方插件数据的允许范围内,已拒绝写入: {path}',
|
|
35
|
+
'adapter.pluginDataSensitiveSkipped': '已剔除 {count} 个凭据文件(首个:{sample})——第三方插件数据分区永不搬运凭据明文',
|
|
35
36
|
'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',
|
|
36
37
|
// ---------- pnpm 配置可移植净化(机器相关路径键) ----------
|
|
37
38
|
'adapter.pwMachinePathStripped': '已剥离 {count} 条与本机路径绑定的 pnpm 设置(换机后会指向不存在的目录):{keys}',
|
|
@@ -53,6 +54,7 @@ export const en = {
|
|
|
53
54
|
'adapter.uiLocalStorageGeneric': 'Browser-side UI state cannot be migrated through the host API',
|
|
54
55
|
'adapter.pluginDataEnvOverridden': "the location of {path} is overridden by the {env} environment variable; skipped this time (the new location is never guessed)",
|
|
55
56
|
'adapter.pluginDataPathNotAllowed': 'the path is outside the range allowed for third-party plugin data and was refused: {path}',
|
|
57
|
+
'adapter.pluginDataSensitiveSkipped': 'dropped {count} credential file(s) (first: {sample}) — third-party plugin data never carries credential plaintext',
|
|
56
58
|
'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',
|
|
57
59
|
'adapter.pwMachinePathStripped': 'Stripped {count} pnpm setting(s) bound to machine-specific paths (they would point to non-existent directories on another machine): {keys}',
|
|
58
60
|
'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,23 @@
|
|
|
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
|
+
* @param ref 计划项对应的 patch 行 id(`lineId`),用于让用户定位到具体是哪一行
|
|
21
|
+
* @param hazard `findPatchKeyHazards` 的命中项
|
|
22
|
+
*/
|
|
23
|
+
export declare function patchKeyHazardMessage(msg: MsgFunc, ref: string, hazard: PatchKeyHazard): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 把一处键名风险转成用户可见文案。
|
|
3
|
+
*
|
|
4
|
+
* @param ref 计划项对应的 patch 行 id(`lineId`),用于让用户定位到具体是哪一行
|
|
5
|
+
* @param hazard `findPatchKeyHazards` 的命中项
|
|
6
|
+
*/
|
|
7
|
+
export function patchKeyHazardMessage(msg, ref, hazard) {
|
|
8
|
+
const path = hazard.path === '' ? '-' : hazard.path;
|
|
9
|
+
return hazard.effect === 'parse-fail'
|
|
10
|
+
? msg('adapter.patchKeyParseFail', { ref, path })
|
|
11
|
+
: msg('adapter.patchKeyAmbiguous', { ref, key: hazard.key, path });
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=patch-key-guard.js.map
|
|
@@ -2,7 +2,7 @@ import type { RecursiveListing } from '../utils/recursive-walk.ts';
|
|
|
2
2
|
import type { PluginDataArea, PluginDataSource, PluginDataSection } from '../core/plugin-data-registry.ts';
|
|
3
3
|
import { FileCollectionAdapter } from './file-collection.ts';
|
|
4
4
|
import type { FilesSection } from '../schema/types.ts';
|
|
5
|
-
import type { ApplyResult, ExportOptions, ExportSection, HostContext, ImportContext, PlanItem, SectionPreview } from '../core/types.ts';
|
|
5
|
+
import type { ApplyResult, ExportOptions, ExportSection, ExportUnit, HostContext, ImportContext, PlanItem, SectionPreview } from '../core/types.ts';
|
|
6
6
|
/** 区域条目(来源 + 区域),编译期与运行期唯一的区域表示 */
|
|
7
7
|
export type PluginDataEntry = {
|
|
8
8
|
source: PluginDataSource;
|
|
@@ -38,10 +38,16 @@ export declare class PluginDataAdapter extends FileCollectionAdapter {
|
|
|
38
38
|
* 白名单就变成了「谁先导入谁说了算」。
|
|
39
39
|
*/
|
|
40
40
|
private declaredMemo;
|
|
41
|
-
/**
|
|
42
|
-
private
|
|
43
|
-
/**
|
|
44
|
-
|
|
41
|
+
/** 每次收集调用一份作用域(listRelPaths 写、unitIdOf 读):绝不放实例字段,否则并发两路互相覆盖 */
|
|
42
|
+
private readonly scope;
|
|
43
|
+
/**
|
|
44
|
+
* 产物 section → 本轮区域表。
|
|
45
|
+
*
|
|
46
|
+
* `listUnits()` 在收集**结束之后**才被调用(作用域已退出),但它必须用「当初归组这批文件的那张区域表」
|
|
47
|
+
* —— 重新解析会与清单不一致(声明来源在这期间装了/卸了插件就会出现「单元 id 不在清单里」)。
|
|
48
|
+
* 键是产物对象本身,因此两路并发各挂各的,不存在覆盖。
|
|
49
|
+
*/
|
|
50
|
+
private readonly unitsOf;
|
|
45
51
|
constructor(section: PluginDataSection, options?: PluginDataAdapterOptions);
|
|
46
52
|
/** 本分区可收集区域(内置 + 自述声明) */
|
|
47
53
|
private allowedEntries;
|
|
@@ -100,6 +106,14 @@ export declare class PluginDataAdapter extends FileCollectionAdapter {
|
|
|
100
106
|
}>;
|
|
101
107
|
export(ctx: HostContext, options: ExportOptions): Promise<ExportSection<FilesSection>>;
|
|
102
108
|
preview(ctx: HostContext, options: ExportOptions): Promise<SectionPreview<FilesSection>>;
|
|
109
|
+
/**
|
|
110
|
+
* 收集结束后按**那一次收集**的区域表归组(审计 P2-7)。
|
|
111
|
+
*
|
|
112
|
+
* listUnits 通常在 export/preview 返回之后才被调用(作用域已退出),因此 export/preview 把区域表
|
|
113
|
+
* 挂在产物对象上;这里重新铺作用域再交给基类,unitIdOf 规则只有一处实现。
|
|
114
|
+
* 拿不到登记(例如消费者自己构造的 section、来自快照反序列化)→ 交给基类,走内置来源的兜底口径。
|
|
115
|
+
*/
|
|
116
|
+
listUnits(section: ExportSection<FilesSection>): ExportUnit[];
|
|
103
117
|
/**
|
|
104
118
|
* 导入分析 + **写入路径白名单**(本分区唯一的越界防线)。
|
|
105
119
|
*
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
* - **环境变量覆盖即跳过**:区域声明的 env 存在且解析结果与默认位置不同 → 报码跳过,绝不猜新位置。
|
|
27
27
|
* - **不产生用户可见散文**:告警与计划项文案一律走消息目录(i18n 铁律)。
|
|
28
28
|
*/
|
|
29
|
-
import {
|
|
29
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
30
|
+
import { isSensitiveHomeRel, normalizePath } from '../utils/paths.js';
|
|
30
31
|
import { engineMsg } from './messages.js';
|
|
31
32
|
import { listFilesDetailed } from './link-report.js';
|
|
32
33
|
import { sectionMeta } from '../schema/section-registry.js';
|
|
@@ -52,10 +53,16 @@ export class PluginDataAdapter extends FileCollectionAdapter {
|
|
|
52
53
|
* 白名单就变成了「谁先导入谁说了算」。
|
|
53
54
|
*/
|
|
54
55
|
declaredMemo;
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
|
|
56
|
+
/** 每次收集调用一份作用域(listRelPaths 写、unitIdOf 读):绝不放实例字段,否则并发两路互相覆盖 */
|
|
57
|
+
scope = new AsyncLocalStorage();
|
|
58
|
+
/**
|
|
59
|
+
* 产物 section → 本轮区域表。
|
|
60
|
+
*
|
|
61
|
+
* `listUnits()` 在收集**结束之后**才被调用(作用域已退出),但它必须用「当初归组这批文件的那张区域表」
|
|
62
|
+
* —— 重新解析会与清单不一致(声明来源在这期间装了/卸了插件就会出现「单元 id 不在清单里」)。
|
|
63
|
+
* 键是产物对象本身,因此两路并发各挂各的,不存在覆盖。
|
|
64
|
+
*/
|
|
65
|
+
unitsOf = new WeakMap();
|
|
59
66
|
constructor(section, options = {}) {
|
|
60
67
|
super();
|
|
61
68
|
this.id = section;
|
|
@@ -152,13 +159,16 @@ export class PluginDataAdapter extends FileCollectionAdapter {
|
|
|
152
159
|
// 本分区的根是**系统 home**(~/.dsh-wallpaper-engine、~/.mnemon …),不是 $DSH_HOME ——
|
|
153
160
|
// 内容 I/O 一律走 homeFs;宿主没提供就什么都不收集,并如实报码(绝不退回 $DSH_HOME 去读错位置)。
|
|
154
161
|
const homeFs = ctx.homeFs;
|
|
162
|
+
// 作用域按调用持有(审计 P2-7):没人包住本次调用时(直接调 listRelPaths 的测试)退化成丢弃用的空壳,
|
|
163
|
+
// 绝不写回实例字段 —— 那正是并发串台的根因。
|
|
164
|
+
const scope = this.scope.getStore() ?? { warnings: [] };
|
|
155
165
|
if (homeFs === undefined) {
|
|
156
|
-
|
|
157
|
-
|
|
166
|
+
scope.entries = [];
|
|
167
|
+
scope.warnings = [engineMsg('adapter.pluginDataNoOsHome')];
|
|
158
168
|
return PluginDataAdapter.emptyListing();
|
|
159
169
|
}
|
|
160
170
|
const entries = await this.allowedEntries(ctx);
|
|
161
|
-
|
|
171
|
+
scope.entries = entries;
|
|
162
172
|
const warnings = [];
|
|
163
173
|
const paths = [];
|
|
164
174
|
const listing = PluginDataAdapter.emptyListing();
|
|
@@ -191,8 +201,27 @@ export class PluginDataAdapter extends FileCollectionAdapter {
|
|
|
191
201
|
paths.push(p);
|
|
192
202
|
}
|
|
193
203
|
}
|
|
194
|
-
|
|
195
|
-
|
|
204
|
+
// 凭据文件永不进第三方数据分区(审计 P2-1 P0):分区根是系统主目录,来源含插件自述声明,
|
|
205
|
+
// 声明 `.dsh` 就会把 ~/.dsh/.credentials.yaml 当配置带走 —— 收集侧先剔一次(打包侧还有同判据的兜底)。
|
|
206
|
+
const kept = [];
|
|
207
|
+
let sensitiveSkipped = 0;
|
|
208
|
+
let sensitiveSample = '';
|
|
209
|
+
for (const p of paths) {
|
|
210
|
+
if (!isSensitiveHomeRel(p)) {
|
|
211
|
+
kept.push(p);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
sensitiveSkipped += 1;
|
|
215
|
+
if (sensitiveSample === '')
|
|
216
|
+
sensitiveSample = p;
|
|
217
|
+
}
|
|
218
|
+
if (sensitiveSkipped > 0) {
|
|
219
|
+
warnings.push(engineMsg('adapter.pluginDataSensitiveSkipped', {
|
|
220
|
+
count: String(sensitiveSkipped), sample: sensitiveSample,
|
|
221
|
+
}));
|
|
222
|
+
}
|
|
223
|
+
listing.paths = kept;
|
|
224
|
+
scope.warnings = warnings;
|
|
196
225
|
return listing;
|
|
197
226
|
}
|
|
198
227
|
/**
|
|
@@ -203,7 +232,9 @@ export class PluginDataAdapter extends FileCollectionAdapter {
|
|
|
203
232
|
* \`active\` 可能是 undefined(例如直接调 listUnits),此时退回**内置来源**的最长前缀 —— 与清单口径同源。
|
|
204
233
|
*/
|
|
205
234
|
unitIdOf(relativePath) {
|
|
206
|
-
|
|
235
|
+
// 区域表取自**本次调用**的作用域(AsyncLocalStorage)⇒ 并发两路各读各的(审计 P2-7);
|
|
236
|
+
// 收集结束后才调用的 listUnits 由覆写先铺好作用域,仍走这一处判定。
|
|
237
|
+
const entries = this.scope.getStore()?.entries ?? areasForSection(this.builtin, this.id);
|
|
207
238
|
const hit = areaOfPath(entries, normalizePath(relativePath));
|
|
208
239
|
return hit === null ? normalizePath(relativePath) : hit.area.relPath;
|
|
209
240
|
}
|
|
@@ -220,17 +251,37 @@ export class PluginDataAdapter extends FileCollectionAdapter {
|
|
|
220
251
|
return super.readMember({ ...ctx, fs: homeFs }, rel, mode, statTimes);
|
|
221
252
|
}
|
|
222
253
|
async export(ctx, options) {
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
|
|
254
|
+
// 每次导出各持一份作用域(审计 P2-7):告警与区域表都属于**这一次**调用,收尾时从它合并/登记
|
|
255
|
+
const scope = { warnings: [] };
|
|
256
|
+
const out = await this.scope.run(scope, () => super.export(ctx, options));
|
|
257
|
+
const merged = { ...out, warnings: [...out.warnings, ...scope.warnings] };
|
|
258
|
+
if (scope.entries !== undefined)
|
|
259
|
+
this.unitsOf.set(merged, scope.entries);
|
|
260
|
+
return merged;
|
|
226
261
|
}
|
|
227
262
|
async preview(ctx, options) {
|
|
228
|
-
|
|
229
|
-
const out = await super.preview(ctx, options);
|
|
230
|
-
|
|
231
|
-
...out,
|
|
232
|
-
|
|
263
|
+
const scope = { warnings: [] };
|
|
264
|
+
const out = await this.scope.run(scope, () => super.preview(ctx, options));
|
|
265
|
+
const section = {
|
|
266
|
+
...out.section,
|
|
267
|
+
warnings: [...out.section.warnings, ...scope.warnings],
|
|
233
268
|
};
|
|
269
|
+
if (scope.entries !== undefined)
|
|
270
|
+
this.unitsOf.set(section, scope.entries);
|
|
271
|
+
return { ...out, section };
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* 收集结束后按**那一次收集**的区域表归组(审计 P2-7)。
|
|
275
|
+
*
|
|
276
|
+
* listUnits 通常在 export/preview 返回之后才被调用(作用域已退出),因此 export/preview 把区域表
|
|
277
|
+
* 挂在产物对象上;这里重新铺作用域再交给基类,unitIdOf 规则只有一处实现。
|
|
278
|
+
* 拿不到登记(例如消费者自己构造的 section、来自快照反序列化)→ 交给基类,走内置来源的兜底口径。
|
|
279
|
+
*/
|
|
280
|
+
listUnits(section) {
|
|
281
|
+
const entries = this.unitsOf.get(section);
|
|
282
|
+
if (entries === undefined)
|
|
283
|
+
return super.listUnits(section);
|
|
284
|
+
return this.scope.run({ entries, warnings: [] }, () => super.listUnits(section));
|
|
234
285
|
}
|
|
235
286
|
/**
|
|
236
287
|
* 导入分析 + **写入路径白名单**(本分区唯一的越界防线)。
|
|
@@ -243,13 +294,16 @@ export class PluginDataAdapter extends FileCollectionAdapter {
|
|
|
243
294
|
// 绝不退回 $DSH_HOME 的 ctx.fs 去比对/写入(那会落到错误位置)。
|
|
244
295
|
const homeFs = ctx.target.homeFs;
|
|
245
296
|
const entries = homeFs === undefined ? [] : await this.allowedEntries(ctx.target);
|
|
246
|
-
|
|
297
|
+
// 用**本机**白名单表铺作用域:基类逐文件调 unitIdOf 时就有确定口径。
|
|
298
|
+
// 旧代码读的是实例上「上次导出的残留区域表」,并发或首次导入时直接错位(审计 P2-7);
|
|
299
|
+
// 而且被放行的路径必然落在某个本机区域内,区域 id 与导入后 listUnits 的口径一致。
|
|
300
|
+
const items = await this.scope.run({ entries, warnings: [] }, () => super.analyzeImport(data, homeFs === undefined ? ctx : { ...ctx, target: { ...ctx.target, fs: homeFs } }));
|
|
247
301
|
return items.map((item) => {
|
|
248
302
|
const ref = item.target?.ref;
|
|
249
303
|
if (ref === undefined)
|
|
250
304
|
return item;
|
|
251
305
|
const rel = normalizeHomeRel(ref);
|
|
252
|
-
if (rel !== null && areaOfPath(entries, rel) !== null)
|
|
306
|
+
if (rel !== null && areaOfPath(entries, rel) !== null && !isSensitiveHomeRel(rel))
|
|
253
307
|
return item;
|
|
254
308
|
return {
|
|
255
309
|
id: item.id,
|
|
@@ -271,7 +325,7 @@ export class PluginDataAdapter extends FileCollectionAdapter {
|
|
|
271
325
|
if (ref !== undefined) {
|
|
272
326
|
const rel = normalizeHomeRel(ref);
|
|
273
327
|
const entries = await this.allowedEntries(ctx.target);
|
|
274
|
-
if (rel === null || areaOfPath(entries, rel) === null) {
|
|
328
|
+
if (rel === null || areaOfPath(entries, rel) === null || isSensitiveHomeRel(rel)) {
|
|
275
329
|
return { ok: false, message: engineMsg('adapter.pluginDataPathNotAllowed', { path: ref }) };
|
|
276
330
|
}
|
|
277
331
|
}
|
|
@@ -2,7 +2,7 @@ import type { PackLocalPluginsResult } from '../core/local-plugin-pack.ts';
|
|
|
2
2
|
import type { MsgFunc } from '../core/messages.ts';
|
|
3
3
|
import { USER_PATCH_FILE } from '../core/patch-layers.ts';
|
|
4
4
|
import type { PluginEntry, PluginsSection } from '../schema/types.ts';
|
|
5
|
-
import type { ApplyResult, ConfigAdapter, ExportOptions, ExportSection, ExportUnit, HostContext, ImportContext, PlanItem, SectionPreview, ValidationResult } from '../core/types.ts';
|
|
5
|
+
import type { ApplyResult, ConfigAdapter, ExportOptions, ExportSection, ExportUnit, HostContext, ImportContext, PlanItem, SectionPreview, SensitiveHit, ValidationResult } from '../core/types.ts';
|
|
6
6
|
/**
|
|
7
7
|
* 用户(home)patch 层路径 —— 定义已移到 `core/patch-layers.ts`(issue #71:patch 有 home /
|
|
8
8
|
* profile 两层,层身份属于引擎知识,不属于某个 adapter)。此处 re-export 保持既有 import 面。
|
|
@@ -36,6 +36,19 @@ export declare class PluginsAdapter implements ConfigAdapter<PluginsSection> {
|
|
|
36
36
|
private readonly localPack;
|
|
37
37
|
constructor(selfName?: string, localPack?: LocalPluginPackHook);
|
|
38
38
|
export(ctx: HostContext, options: ExportOptions): Promise<ExportSection<PluginsSection>>;
|
|
39
|
+
/**
|
|
40
|
+
* issue #136 C:脱敏**归属标注** —— 把 SecretScanner 的命中路径归属回具体 patch 行。
|
|
41
|
+
*
|
|
42
|
+
* 为什么必须做:导出侧把命中字段名/值形状的字符串叶子替换成空串(占位符),语义是「需补录」。
|
|
43
|
+
* 目标机只看到空串,无法区分「被剥空」与「用户主动写空」——于是合并/导入落地时照抄空串,
|
|
44
|
+
* 静默抹掉本机同一行里用户手写的明文(行是整行写回的,行内没有粒度)。
|
|
45
|
+
*
|
|
46
|
+
* 归属规则:命中路径 `patch[i].<内部路径>` → 第 i 行的 `redactedPaths`(行内相对,原样保留
|
|
47
|
+
* 扫描器语法,如 `raw.mcp.args.token`);未命中的行不写该字段(缺省 = 未知,写回侧走保守分支)。
|
|
48
|
+
*
|
|
49
|
+
* 纯函数:不改入参;命中不落在 patch 行上(plugins / pnpmWorkspace / localTarballs 等)→ 原样返回。
|
|
50
|
+
*/
|
|
51
|
+
annotateRedactions(sanitized: unknown, hits: SensitiveHit[]): unknown;
|
|
39
52
|
/**
|
|
40
53
|
* 只读预览(`/export-preview` 用):与 `export()` **同口径**,但不做任何本地源打包。
|
|
41
54
|
*
|
package/lib/adapters/plugins.js
CHANGED
|
@@ -20,8 +20,11 @@ import { engineMsg } from './messages.js';
|
|
|
20
20
|
import { stringifyJsonSafe } from '../utils/json.js';
|
|
21
21
|
import { isPathSafe, normalizePath } from '../utils/paths.js';
|
|
22
22
|
import { isENOENT } from '../utils/guards.js';
|
|
23
|
+
import { findPatchKeyHazards } from '../utils/patch-yaml.js';
|
|
24
|
+
import { patchKeyHazardMessage } from './patch-key-guard.js';
|
|
23
25
|
import { PLUGIN_PATCH_REF_PREFIX, PLUGIN_PROFILE_MANIFEST_REF } from '../core/backup.js';
|
|
24
26
|
import { readEffectivePatchLines, resolveWriteLayer, USER_PATCH_FILE } from '../core/patch-layers.js';
|
|
27
|
+
import { applyPatchSecretGuard } from '../core/patch-secret-guard.js';
|
|
25
28
|
import { stripMcpEntries } from './mcp.js';
|
|
26
29
|
import { parsePnpmPatchedDependencies, restorePnpmMachinePaths, sanitizePnpmWorkspacePatches, stripPnpmMachinePaths, } from './pnpm-workspace.js';
|
|
27
30
|
import { BUILTIN_PLUGIN_DATA_SOURCES, areasForSection } from '../core/plugin-data-registry.js';
|
|
@@ -245,6 +248,31 @@ async function measureLocalSources(plugins, ctx) {
|
|
|
245
248
|
}
|
|
246
249
|
return sizes;
|
|
247
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* issue #136 A:读目标机**当前生效**的 patch 行原文(写回守卫的「本机现值」)。
|
|
253
|
+
*
|
|
254
|
+
* 口径与 analyzeImport 判定 Skip/Conflict 时逐字相同(readEffectivePatchLines + lineId 匹配),
|
|
255
|
+
* 这样「计划阶段看到的现值」与「写回阶段比对的现值」不会分叉。
|
|
256
|
+
*
|
|
257
|
+
* 读失败**不得**降级成「没有本机行」:那等于跳过守卫、静默覆盖本机明文(#136 的复现条件),
|
|
258
|
+
* 而且连一条告警都不会有。失败必须显式上抛给 applyItem,由它对这一行返回非致命失败。
|
|
259
|
+
*/
|
|
260
|
+
async function readLocalPatchRaw(ctx, lineId) {
|
|
261
|
+
try {
|
|
262
|
+
const { lines, failures } = await readEffectivePatchLines(ctx.target.patchFile, ctx.target.profile);
|
|
263
|
+
// 有层读不出来 → 无法证明「本机这一行现在是什么 / 到底有没有」。
|
|
264
|
+
// readEffectivePatchLines 把层读失败收进 failures(不抛错),此前的实现只 catch 抛错、
|
|
265
|
+
// 于是「有层读不出来」被当成「本机没有这一行」放行 —— 守卫被绕过且零告警(#136 的复现条件)。
|
|
266
|
+
// 这里宁可跳过这一行并说明原因,也不按「无本机值」写入。
|
|
267
|
+
if (failures.length > 0) {
|
|
268
|
+
return { ok: false, reason: failures.map((f) => `${f.file}: ${f.reason}`).join('; ') };
|
|
269
|
+
}
|
|
270
|
+
return { ok: true, raw: lines.find((l) => l.lineId === lineId)?.raw };
|
|
271
|
+
}
|
|
272
|
+
catch (err) {
|
|
273
|
+
return { ok: false, reason: err instanceof Error ? err.message : String(err) };
|
|
274
|
+
}
|
|
275
|
+
}
|
|
248
276
|
/**
|
|
249
277
|
* 由分区载荷派生单元清单(纯函数、零 I/O)。
|
|
250
278
|
*
|
|
@@ -319,6 +347,54 @@ export class PluginsAdapter {
|
|
|
319
347
|
async export(ctx, options) {
|
|
320
348
|
return this.collect(ctx, options, true);
|
|
321
349
|
}
|
|
350
|
+
/**
|
|
351
|
+
* issue #136 C:脱敏**归属标注** —— 把 SecretScanner 的命中路径归属回具体 patch 行。
|
|
352
|
+
*
|
|
353
|
+
* 为什么必须做:导出侧把命中字段名/值形状的字符串叶子替换成空串(占位符),语义是「需补录」。
|
|
354
|
+
* 目标机只看到空串,无法区分「被剥空」与「用户主动写空」——于是合并/导入落地时照抄空串,
|
|
355
|
+
* 静默抹掉本机同一行里用户手写的明文(行是整行写回的,行内没有粒度)。
|
|
356
|
+
*
|
|
357
|
+
* 归属规则:命中路径 `patch[i].<内部路径>` → 第 i 行的 `redactedPaths`(行内相对,原样保留
|
|
358
|
+
* 扫描器语法,如 `raw.mcp.args.token`);未命中的行不写该字段(缺省 = 未知,写回侧走保守分支)。
|
|
359
|
+
*
|
|
360
|
+
* 纯函数:不改入参;命中不落在 patch 行上(plugins / pnpmWorkspace / localTarballs 等)→ 原样返回。
|
|
361
|
+
*/
|
|
362
|
+
annotateRedactions(sanitized, hits) {
|
|
363
|
+
if (hits.length === 0)
|
|
364
|
+
return sanitized;
|
|
365
|
+
if (sanitized === null || typeof sanitized !== 'object')
|
|
366
|
+
return sanitized;
|
|
367
|
+
const section = sanitized;
|
|
368
|
+
if (!Array.isArray(section.patch) || section.patch.length === 0)
|
|
369
|
+
return sanitized;
|
|
370
|
+
const byLine = new Map();
|
|
371
|
+
for (const hit of hits) {
|
|
372
|
+
const m = /^patch\[(\d+)\]\.(.+)$/.exec(hit.path);
|
|
373
|
+
if (m === null)
|
|
374
|
+
continue;
|
|
375
|
+
const index = Number(m[1]);
|
|
376
|
+
if (!Number.isInteger(index) || index < 0 || index >= section.patch.length)
|
|
377
|
+
continue;
|
|
378
|
+
let paths = byLine.get(index);
|
|
379
|
+
if (paths === undefined) {
|
|
380
|
+
paths = new Set();
|
|
381
|
+
byLine.set(index, paths);
|
|
382
|
+
}
|
|
383
|
+
const rel = m[2];
|
|
384
|
+
if (rel === undefined || rel === '')
|
|
385
|
+
continue;
|
|
386
|
+
paths.add(rel);
|
|
387
|
+
}
|
|
388
|
+
if (byLine.size === 0)
|
|
389
|
+
return sanitized;
|
|
390
|
+
const patch = section.patch.map((line, i) => {
|
|
391
|
+
const paths = byLine.get(i);
|
|
392
|
+
if (paths === undefined)
|
|
393
|
+
return line;
|
|
394
|
+
return { ...line, redactedPaths: [...paths].sort() };
|
|
395
|
+
});
|
|
396
|
+
return { ...section, patch };
|
|
397
|
+
}
|
|
322
398
|
/**
|
|
323
399
|
* 只读预览(`/export-preview` 用):与 `export()` **同口径**,但不做任何本地源打包。
|
|
324
400
|
*
|
|
@@ -836,6 +912,21 @@ export class PluginsAdapter {
|
|
|
836
912
|
// 层身份随计划项走:applyItem 按 pl.file 写回,导入前快照按 target.file 记原行,
|
|
837
913
|
// 两者必须是同一层,否则回滚会把另一层改坏(issue #71)。
|
|
838
914
|
const layer = resolveWriteLayer(pl.file, ctx.target.profile);
|
|
915
|
+
// 与目标一致 ⇒ 一个字节都不会写,键名风险不归我们管(见下方守卫);先判 Skip 以免误报。
|
|
916
|
+
if (tl && isDeepStrictEqual(tl.raw, pl.raw)) {
|
|
917
|
+
items.push({ id, kind: 'Skip', adapter: 'plugins', description: msg('adapter.patchLineSame', { lineId: pl.lineId }), severity: 'info' });
|
|
918
|
+
continue;
|
|
919
|
+
}
|
|
920
|
+
// issue #137:写侧的 forceQuotes 只保**值**,键名仍会被 4.x 改判(空键更会让整份文件解析失败)。
|
|
921
|
+
// 命中即降级成本项「预判阻断」—— 本项不写、不触发整笔回滚,其余行照常导入。
|
|
922
|
+
const hazard = findPatchKeyHazards(pl.raw)[0];
|
|
923
|
+
if (hazard) {
|
|
924
|
+
items.push({
|
|
925
|
+
id, kind: 'Error', adapter: 'plugins',
|
|
926
|
+
description: patchKeyHazardMessage(msg, pl.lineId, hazard), severity: 'error',
|
|
927
|
+
});
|
|
928
|
+
continue;
|
|
929
|
+
}
|
|
839
930
|
if (!tl) {
|
|
840
931
|
items.push({
|
|
841
932
|
id, kind: 'Create', adapter: 'plugins',
|
|
@@ -843,9 +934,6 @@ export class PluginsAdapter {
|
|
|
843
934
|
target: { adapter: 'plugins', ref: pl.lineId, file: layer },
|
|
844
935
|
});
|
|
845
936
|
}
|
|
846
|
-
else if (isDeepStrictEqual(tl.raw, pl.raw)) {
|
|
847
|
-
items.push({ id, kind: 'Skip', adapter: 'plugins', description: msg('adapter.patchLineSame', { lineId: pl.lineId }), severity: 'info' });
|
|
848
|
-
}
|
|
849
937
|
else {
|
|
850
938
|
items.push({
|
|
851
939
|
id, kind: 'Conflict', adapter: 'plugins',
|
|
@@ -1050,11 +1138,48 @@ export class PluginsAdapter {
|
|
|
1050
1138
|
const pl = data?.patch.find((p) => p.lineId === ref);
|
|
1051
1139
|
if (!pl)
|
|
1052
1140
|
return { ok: false, message: msg('adapter.patchMissing', { ref }) };
|
|
1141
|
+
// issue #136 A:写回层守卫 —— 「被脱敏剥空」的叶子不得覆盖本机非空明文。
|
|
1142
|
+
//
|
|
1143
|
+
// 为什么在写回层做(而不是只靠导出侧标注):协同场景里对方的载荷来自更早版本、第三方工具或
|
|
1144
|
+
// 手工改过,`redactedPaths` 可能缺失;写回是最后一道能同时看见「本机现值」与「将被写下的值」
|
|
1145
|
+
// 的地方,也唯一能区分「被剥空」与「用户主动写空」(显式逐行 useImported 才放行清空)。
|
|
1146
|
+
// 守卫只在 Update/Conflict 上生效;Create 没有本机行可保(新行原样写入)。
|
|
1147
|
+
// 本机现值读不出来 → 无法证明这次写入不会覆盖明文,这一行**拒绝写**。
|
|
1148
|
+
// 非致命(warning):一行读不出来不该拖垮其余分区,也不该把整笔导入回滚。
|
|
1149
|
+
const localRead = item.kind === 'Create'
|
|
1150
|
+
? ({ ok: true, raw: undefined })
|
|
1151
|
+
: await readLocalPatchRaw(ctx, ref);
|
|
1152
|
+
if (!localRead.ok) {
|
|
1153
|
+
return {
|
|
1154
|
+
ok: false,
|
|
1155
|
+
warning: true,
|
|
1156
|
+
message: msg('adapter.patchLocalReadFailed', { ref: item.id, reason: localRead.reason }),
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
const guard = applyPatchSecretGuard({
|
|
1160
|
+
importedRaw: pl.raw,
|
|
1161
|
+
localRaw: localRead.raw,
|
|
1162
|
+
redactedPaths: pl.redactedPaths,
|
|
1163
|
+
// 显式逐行确认 = 用户对本行选了 useImported(全局 replace 策略不算确认)
|
|
1164
|
+
// #136 A:只有**逐项**确认才算「我要这一行按导入值写」。判定必须是**白名单**:
|
|
1165
|
+
// 分区级裁决(decidedBy: 'section',由合并落地 planMergeApply 注入)只决定分区是否应用,
|
|
1166
|
+
// 不构成对本行的确认;来源缺省(未来新增的注入路径忘了标注)一律按「未确认」处理 ——
|
|
1167
|
+
// 默认放行等于给同类漏洞留后门;翻转成默认拒绝后,忘标注只会少清空、不会误清空。
|
|
1168
|
+
confirmed: item.conflict?.resolution === 'useImported' && item.conflict?.decidedBy === 'item',
|
|
1169
|
+
});
|
|
1053
1170
|
// 层身份按**语义**映射到目标机:来源是别的 profile 层时不能照抄名字(目标机未必有那个
|
|
1054
1171
|
// profile,宿主门面会拒绝),一律落到目标机当前 profile 层(与计划项 target.file 同口径)。
|
|
1055
1172
|
await ctx.target.patchFile.applyPatchChanges(resolveWriteLayer(pl.file, ctx.target.profile), [
|
|
1056
|
-
{ lineId: ref, raw:
|
|
1173
|
+
{ lineId: ref, raw: guard.raw, action: item.kind === 'Create' ? 'insert' : 'update' },
|
|
1057
1174
|
]);
|
|
1175
|
+
if (guard.kept.length > 0) {
|
|
1176
|
+
// 告警只报行 id 与字段路径,绝不带值(值本身就是密钥)
|
|
1177
|
+
// 报告面用**计划项 id**(`patch:<lineId>`)而不是裸 lineId:报告与计划项要能逐条对上
|
|
1178
|
+
return { ok: true, warning: true, needsRestart: true, message: msg('adapter.patchSecretsKept', { ref: item.id, paths: guard.kept.join(', ') }) };
|
|
1179
|
+
}
|
|
1180
|
+
if (guard.cleared.length > 0) {
|
|
1181
|
+
return { ok: true, warning: true, needsRestart: true, message: msg('adapter.patchSecretsCleared', { ref: item.id, paths: guard.cleared.join(', ') }) };
|
|
1182
|
+
}
|
|
1058
1183
|
return { ok: true, needsRestart: true, message: msg('adapter.patchWritten', { ref }) };
|
|
1059
1184
|
}
|
|
1060
1185
|
async validate(data, msg = zhMsg) {
|
|
@@ -1091,6 +1216,24 @@ export class PluginsAdapter {
|
|
|
1091
1216
|
const pl = raw;
|
|
1092
1217
|
if (pl === null || typeof pl !== 'object') {
|
|
1093
1218
|
issues.push({ path: `patch[${i}]`, message: msg('adapter.validate.recordObject', { subject: 'patch line' }), severity: 'error' });
|
|
1219
|
+
continue;
|
|
1220
|
+
}
|
|
1221
|
+
// issue #136 C:脱敏归属路径(可选;存在时必须是字符串数组、元素非空,写回守卫按它精确比对)。
|
|
1222
|
+
// **空数组合法**:语义就是「本行没有剥空位置」,守卫按缺省(保守分支)处理。
|
|
1223
|
+
// 不把空数组当形状错误 —— 第三方 exporter 写出 `[]` 时拦下整包导入,代价远大于收益,
|
|
1224
|
+
// 而且凝死一个「字段在但内容空」与「字段缺省」不等价的契约,纯属自找兼容债。
|
|
1225
|
+
const redactedPaths = pl.redactedPaths;
|
|
1226
|
+
if (redactedPaths !== undefined) {
|
|
1227
|
+
if (!Array.isArray(redactedPaths)) {
|
|
1228
|
+
issues.push({ path: `patch[${i}].redactedPaths`, message: msg('adapter.validate.array', { subject: 'patch[].redactedPaths' }), severity: 'error' });
|
|
1229
|
+
}
|
|
1230
|
+
else {
|
|
1231
|
+
for (const [j, p] of redactedPaths.entries()) {
|
|
1232
|
+
if (typeof p !== 'string' || p === '') {
|
|
1233
|
+
issues.push({ path: `patch[${i}].redactedPaths[${j}]`, message: msg('adapter.validate.string', { subject: 'patch[].redactedPaths[]' }), severity: 'error' });
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1094
1237
|
}
|
|
1095
1238
|
}
|
|
1096
1239
|
}
|