dsh-config-manager 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/adapters/mcp.js +42 -13
- package/lib/adapters/messages.d.ts +1 -0
- package/lib/adapters/messages.js +2 -0
- package/lib/adapters/patch-key-guard.d.ts +23 -0
- package/lib/adapters/patch-key-guard.js +13 -0
- package/lib/adapters/plugin-data.d.ts +19 -5
- package/lib/adapters/plugin-data.js +76 -22
- package/lib/adapters/plugins.d.ts +14 -1
- package/lib/adapters/plugins.js +147 -4
- package/lib/cli/actions.d.ts +7 -105
- package/lib/cli/actions.js +16 -172
- package/lib/cli/control-state.d.ts +54 -0
- package/lib/cli/control-state.js +107 -0
- package/lib/cli/index.js +14 -0
- package/lib/cli/write-gates.d.ts +61 -0
- package/lib/cli/write-gates.js +110 -0
- package/lib/client.d.ts +122 -50
- package/lib/client.js +12676 -12091
- package/lib/core/backup.d.ts +0 -4
- package/lib/core/backup.js +21 -4
- package/lib/core/boot-rescue.d.ts +1 -1
- package/lib/core/boot-rescue.js +12 -1
- package/lib/core/boot-safety.js +37 -2
- package/lib/core/conflict-decisions.js +2 -1
- package/lib/core/exporter.js +22 -1
- package/lib/core/journal.d.ts +54 -4
- package/lib/core/journal.js +158 -35
- package/lib/core/local-plugin-host.d.ts +29 -0
- package/lib/core/local-plugin-host.js +55 -48
- package/lib/core/messages.d.ts +7 -0
- package/lib/core/messages.js +14 -0
- package/lib/core/migration-history.js +16 -9
- package/lib/core/model-tools.d.ts +2 -2
- package/lib/core/model-tools.js +14 -2
- package/lib/core/patch-secret-guard.d.ts +49 -0
- package/lib/core/patch-secret-guard.js +164 -0
- package/lib/core/reconcile.d.ts +8 -0
- package/lib/core/reconcile.js +18 -3
- package/lib/core/reinstall.d.ts +2 -0
- package/lib/core/reinstall.js +6 -2
- package/lib/core/restore.js +31 -6
- package/lib/core/section-sanitize.d.ts +32 -0
- package/lib/core/section-sanitize.js +13 -0
- package/lib/core/snapshot-diff.d.ts +30 -0
- package/lib/core/snapshot-diff.js +56 -20
- package/lib/core/startup-barrier.js +8 -2
- package/lib/core/types.d.ts +22 -0
- package/lib/core/update-check.js +51 -2
- package/lib/foreign/kernel.js +9 -2
- package/lib/foreign/read-claude-plugins.js +29 -11
- package/lib/foreign/read-dsh.js +31 -2
- package/lib/foreign/read-trae.d.ts +11 -0
- package/lib/foreign/read-trae.js +124 -4
- package/lib/foreign/session-ir.js +50 -9
- package/lib/foreign/session-read.d.ts +8 -0
- package/lib/foreign/session-read.js +26 -0
- package/lib/foreign/session-source.d.ts +12 -4
- package/lib/foreign/session-source.js +5 -3
- package/lib/foreign/trae-sqlcipher.d.ts +127 -0
- package/lib/foreign/trae-sqlcipher.js +519 -0
- package/lib/foreign/trae.js +3 -1
- package/lib/foreign/truth-table.js +3 -2
- package/lib/foreign/types.d.ts +9 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/profiles/dsh-profile-io.d.ts +20 -0
- package/lib/profiles/dsh-profile-io.js +27 -0
- package/lib/profiles/dsh-profile-manager.d.ts +27 -0
- package/lib/profiles/dsh-profile-manager.js +45 -4
- package/lib/profiles/dsh-profile-runtime.d.ts +5 -1
- package/lib/profiles/dsh-profile-runtime.js +16 -3
- package/lib/profiles/process-control.d.ts +18 -1
- package/lib/profiles/process-control.js +25 -1
- package/lib/routes/profiles.js +2 -1
- package/lib/routes/sync.js +13 -1
- package/lib/schema/types.d.ts +11 -0
- package/lib/security/redaction.js +22 -6
- package/lib/sync/autosync-repeat.d.ts +27 -0
- package/lib/sync/autosync-repeat.js +23 -0
- package/lib/sync/autosync-scheduler.d.ts +34 -1
- package/lib/sync/autosync-scheduler.js +151 -43
- package/lib/sync/baseline-heal.js +7 -0
- package/lib/sync/baseline-record.d.ts +67 -0
- package/lib/sync/baseline-record.js +74 -0
- package/lib/sync/blob-store.js +13 -0
- package/lib/sync/content-diff.d.ts +39 -0
- package/lib/sync/content-diff.js +46 -0
- package/lib/sync/git/git-transport.d.ts +32 -1
- package/lib/sync/git/git-transport.js +146 -26
- package/lib/sync/github-auth.d.ts +17 -1
- package/lib/sync/github-auth.js +37 -1
- package/lib/sync/merge-apply-plan.d.ts +38 -0
- package/lib/sync/merge-apply-plan.js +76 -0
- package/lib/sync/messages.d.ts +1 -0
- package/lib/sync/messages.js +2 -0
- package/lib/sync/pending-merge.d.ts +34 -0
- package/lib/sync/pending-merge.js +53 -0
- package/lib/sync/s3/s3-transport.d.ts +14 -2
- package/lib/sync/s3/s3-transport.js +72 -48
- package/lib/sync/sync-engine.d.ts +23 -40
- package/lib/sync/sync-engine.js +115 -132
- package/lib/sync/sync-history.d.ts +7 -0
- package/lib/sync/sync-state.d.ts +28 -0
- package/lib/sync/sync-state.js +20 -0
- package/lib/sync/transport.d.ts +12 -3
- package/lib/sync/transport.js +13 -4
- package/lib/sync/webdav/webdav-transport.d.ts +19 -2
- package/lib/sync/webdav/webdav-transport.js +81 -40
- package/lib/ui/commands.js +5 -11
- package/lib/ui/dsh-profiles-view.d.ts +8 -3
- package/lib/ui/dsh-profiles-view.js +9 -5
- package/lib/ui/foreign-view.d.ts +19 -0
- package/lib/ui/foreign-view.js +24 -0
- package/lib/ui/i18n.d.ts +7 -1
- package/lib/ui/i18n.js +17 -2
- package/lib/ui/menu-placement.js +1 -1
- package/lib/ui/migration-consult-view.d.ts +11 -0
- package/lib/ui/migration-consult-view.js +15 -0
- package/lib/ui/overview-view.d.ts +7 -0
- package/lib/ui/overview-view.js +3 -0
- package/lib/ui/report.d.ts +9 -0
- package/lib/ui/report.js +17 -4
- package/lib/ui/selection-model.d.ts +8 -0
- package/lib/ui/selection-model.js +16 -0
- package/lib/utils/patch-yaml.d.ts +39 -1
- package/lib/utils/patch-yaml.js +82 -2
- package/lib/utils/paths.d.ts +13 -0
- package/lib/utils/paths.js +35 -0
- package/lib/utils/workdir-lock.js +18 -3
- package/package.json +2 -1
- package/src/adapters/mcp.test.ts +29 -0
- package/src/adapters/mcp.ts +43 -12
- package/src/adapters/messages.ts +2 -0
- package/src/adapters/patch-key-guard.ts +29 -0
- package/src/adapters/plugin-data.test.ts +126 -0
- package/src/adapters/plugin-data.ts +97 -26
- package/src/adapters/plugins.test.ts +288 -0
- package/src/adapters/plugins.ts +141 -4
- package/src/cli/actions.test.ts +74 -1
- package/src/cli/actions.ts +27 -246
- package/src/cli/control-state.ts +143 -0
- package/src/cli/index.ts +18 -0
- package/src/cli/web/web.test.ts +27 -0
- package/src/cli/write-gates.ts +149 -0
- package/src/client/about/AboutPanel.tsx +7 -6
- package/src/client/about/release-notes-view.test.ts +17 -0
- package/src/client/about/release-notes-view.ts +49 -24
- package/src/client/chat/ChatEntryView.tsx +2 -2
- package/src/client/chat/rollback-entry-view.ts +6 -1
- package/src/client/common/CommandPalette.tsx +6 -3
- package/src/client/common/ConfirmDialog.tsx +29 -12
- package/src/client/common/ContentPicker.tsx +13 -12
- package/src/client/common/Modal.tsx +12 -5
- package/src/client/common/MoreMenu.tsx +4 -1
- package/src/client/common/RunsCenter.tsx +103 -32
- package/src/client/common/Select.tsx +2 -2
- package/src/client/common/floating-bounds.ts +1 -1
- package/src/client/common/floating-units.test.ts +1 -2
- package/src/client/common/plan-text-redaction.test.ts +188 -3
- package/src/client/common/runs-center-guard.test.ts +60 -0
- package/src/client/common/runs-center-view.test.ts +128 -0
- package/src/client/common/runs-center-view.ts +96 -0
- package/src/client/common/section-title-action.test.ts +66 -0
- package/src/client/common/ui.tsx +93 -30
- package/src/client/config-manager.module.css +1507 -272
- package/src/client/consult/ConsultCard.tsx +7 -6
- package/src/client/environment/EnvironmentPanel.tsx +20 -21
- package/src/client/environment/maintenance/DiskUsageCard.tsx +65 -91
- package/src/client/environment/profiles-incomplete-ui.test.ts +8 -8
- package/src/client/export/ExportView.tsx +7 -16
- package/src/client/history/HistoryPanel.tsx +88 -28
- package/src/client/history/history-locales.ts +3 -3
- package/src/client/home/BackupScheduleCard.tsx +35 -30
- package/src/client/home/HomePanel.tsx +45 -10
- package/src/client/import/ConflictList.tsx +13 -13
- package/src/client/import/ForeignImportView.tsx +32 -13
- package/src/client/import/ImportWizardView.tsx +2 -3
- package/src/client/import/PathMappingForm.tsx +4 -4
- package/src/client/import/PathPickerDialog.tsx +2 -1
- package/src/client/import/foreign-import-view-guard.test.ts +1 -1
- package/src/client/import/import-wizard-steps.tsx +51 -39
- package/src/client/import/use-import-wizard-controller.test.ts +129 -0
- package/src/client/import/use-import-wizard-controller.ts +116 -22
- package/src/client/library/ArtifactRow.tsx +2 -2
- package/src/client/library/BackupInspectView.tsx +19 -15
- package/src/client/library/LibraryActions.tsx +56 -16
- package/src/client/library/LibraryPanel.tsx +7 -7
- package/src/client/library/RestorePlanView.tsx +13 -8
- package/src/client/locales/about.ts +0 -2
- package/src/client/locales/backup.ts +10 -12
- package/src/client/locales/common.ts +2 -0
- package/src/client/locales/export.ts +5 -12
- package/src/client/locales/foreign.ts +11 -2
- package/src/client/locales/import.ts +3 -2
- package/src/client/locales/overview.ts +4 -0
- package/src/client/locales/profiles.ts +32 -4
- package/src/client/locales/restore.ts +0 -2
- package/src/client/locales/sessions.ts +0 -2
- package/src/client/locales/shell.ts +2 -2
- package/src/client/market/MarketPanel.tsx +38 -20
- package/src/client/market/MyConfigsList.tsx +34 -32
- package/src/client/market/MyConfigsLoginCard.tsx +12 -15
- package/src/client/market/MyConfigsView.tsx +5 -5
- package/src/client/market/MyConfigsWizard.tsx +7 -12
- package/src/client/market/market-locales.ts +0 -6
- package/src/client/market/my-configs-split.test.ts +2 -1
- package/src/client/nav-menu-clip-guard.test.ts +52 -0
- package/src/client/recovery/IncompleteCopiesSection.tsx +1 -3
- package/src/client/recovery/RecoveryPanel.tsx +31 -16
- package/src/client/recovery/RollbackCard.tsx +58 -16
- package/src/client/recovery/RollbackFileChanges.tsx +40 -27
- package/src/client/recovery/SessionHealthCard.tsx +2 -2
- package/src/client/recovery/SessionHealthDialog.tsx +5 -7
- package/src/client/recovery/SessionLayoutSection.tsx +3 -5
- package/src/client/recovery/recovery-locales.ts +12 -8
- package/src/client/run-store.test.ts +30 -0
- package/src/client/run-store.ts +21 -1
- package/src/client/sync/AddChannelCard.tsx +65 -0
- package/src/client/sync/AutosyncCard.tsx +182 -108
- package/src/client/sync/ChannelClearConfirmDialog.tsx +5 -1
- package/src/client/sync/ChannelConfigDialog.tsx +27 -48
- package/src/client/sync/MergePreviewView.tsx +3 -5
- package/src/client/sync/PushReportSections.tsx +35 -0
- package/src/client/sync/SyncChannelEntryCard.tsx +33 -24
- package/src/client/sync/SyncConfirmView.tsx +3 -3
- package/src/client/sync/SyncLogList.tsx +16 -5
- package/src/client/sync/SyncPanel.tsx +153 -159
- package/src/client/sync/SyncProbeRow.tsx +5 -7
- package/src/client/sync/SyncRepositoryPicker.tsx +17 -4
- package/src/client/sync/SyncSecuritySection.tsx +157 -0
- package/src/client/sync/SyncSettingsDialog.tsx +304 -0
- package/src/client/sync/SyncSettingsView.test.ts +26 -8
- package/src/client/sync/WorkDirCard.tsx +2 -4
- package/src/client/sync/config-clear-guard.test.ts +94 -0
- package/src/client/sync/config-clear-guard.ts +98 -0
- package/src/client/sync/config-dirty.test.ts +91 -0
- package/src/client/sync/config-dirty.ts +88 -0
- package/src/client/sync/history-model.test.ts +2 -0
- package/src/client/sync/history-model.ts +3 -0
- package/src/client/sync/merge-request.ts +20 -0
- package/src/client/sync/sync-api.ts +12 -0
- package/src/client/sync/sync-locales.ts +87 -47
- package/src/client/sync/sync-panel-clear.test.ts +44 -0
- package/src/client/sync/sync-view.test.ts +20 -0
- package/src/client/sync/sync-view.ts +42 -4
- package/src/core/backup.test.ts +61 -1
- package/src/core/backup.ts +21 -4
- package/src/core/boot-rescue.test.ts +35 -0
- package/src/core/boot-rescue.ts +13 -2
- package/src/core/boot-safety.test.ts +25 -0
- package/src/core/boot-safety.ts +37 -2
- package/src/core/conflict-decisions.ts +2 -1
- package/src/core/exporter.ts +21 -1
- package/src/core/journal.test.ts +183 -0
- package/src/core/journal.ts +163 -25
- package/src/core/local-plugin-host.test.ts +68 -2
- package/src/core/local-plugin-host.ts +31 -4
- package/src/core/messages.ts +14 -0
- package/src/core/migration-history.test.ts +27 -0
- package/src/core/migration-history.ts +12 -4
- package/src/core/model-tools.test.ts +67 -0
- package/src/core/model-tools.ts +16 -4
- package/src/core/patch-secret-guard.test.ts +110 -0
- package/src/core/patch-secret-guard.ts +176 -0
- package/src/core/reconcile.ts +32 -4
- package/src/core/reinstall.ts +8 -2
- package/src/core/restore.ts +32 -7
- package/src/core/section-sanitize.ts +37 -0
- package/src/core/snapshot-diff.test.ts +73 -1
- package/src/core/snapshot-diff.ts +66 -21
- package/src/core/startup-barrier.test.ts +64 -0
- package/src/core/startup-barrier.ts +8 -2
- package/src/core/types.ts +27 -1
- package/src/core/update-check.test.ts +40 -0
- package/src/core/update-check.ts +53 -2
- package/src/foreign/claude-code.test.ts +5 -0
- package/src/foreign/claude-plugins.test.ts +57 -0
- package/src/foreign/claude-sessions-bytes.test.ts +7 -1
- package/src/foreign/dsh.test.ts +23 -0
- package/src/foreign/file-budget.test.ts +7 -1
- package/src/foreign/kernel.ts +9 -2
- package/src/foreign/read-claude-plugins.ts +32 -11
- package/src/foreign/read-dsh.ts +33 -2
- package/src/foreign/read-trae.ts +117 -5
- package/src/foreign/session-ir.test.ts +67 -0
- package/src/foreign/session-ir.ts +54 -14
- package/src/foreign/session-read.ts +23 -0
- package/src/foreign/session-source.ts +15 -5
- package/src/foreign/trae-sqlcipher.test.ts +360 -0
- package/src/foreign/trae-sqlcipher.ts +564 -0
- package/src/foreign/trae.test.ts +188 -0
- package/src/foreign/trae.ts +3 -1
- package/src/foreign/truth-table.ts +4 -2
- package/src/foreign/types.ts +10 -1
- package/src/index.ts +1 -1
- package/src/profiles/dsh-profile-copy-rollback.test.ts +58 -4
- package/src/profiles/dsh-profile-io.ts +29 -0
- package/src/profiles/dsh-profile-manager.test.ts +30 -0
- package/src/profiles/dsh-profile-manager.ts +53 -5
- package/src/profiles/dsh-profile-runtime.test.ts +29 -7
- package/src/profiles/dsh-profile-runtime.ts +17 -3
- package/src/profiles/process-control.test.ts +97 -0
- package/src/profiles/process-control.ts +28 -1
- package/src/routes/profiles.ts +2 -1
- package/src/routes/sync.ts +13 -1
- package/src/schema/types.ts +16 -1
- package/src/security/redaction.test.ts +31 -0
- package/src/security/redaction.ts +23 -6
- package/src/sync/autosync-repeat.test.ts +58 -0
- package/src/sync/autosync-repeat.ts +55 -0
- package/src/sync/autosync-scheduler.test.ts +417 -0
- package/src/sync/autosync-scheduler.ts +154 -41
- package/src/sync/baseline-heal.ts +6 -0
- package/src/sync/baseline-record.ts +135 -0
- package/src/sync/blob-store.test.ts +16 -0
- package/src/sync/blob-store.ts +13 -0
- package/src/sync/content-diff.test.ts +95 -0
- package/src/sync/content-diff.ts +79 -0
- package/src/sync/git/git-transport.test.ts +151 -4
- package/src/sync/git/git-transport.ts +143 -27
- package/src/sync/github-auth.test.ts +26 -1
- package/src/sync/github-auth.ts +37 -1
- package/src/sync/merge-apply-plan.ts +117 -0
- package/src/sync/messages.ts +2 -0
- package/src/sync/pending-merge.ts +77 -0
- package/src/sync/s3/s3-delete-and-blob-index.test.ts +249 -0
- package/src/sync/s3/s3-transport.ts +76 -42
- package/src/sync/sync-config.test.ts +39 -12
- package/src/sync/sync-device-identity.test.ts +3 -0
- package/src/sync/sync-engine.test.ts +465 -12
- package/src/sync/sync-engine.ts +130 -135
- package/src/sync/sync-history.ts +7 -0
- package/src/sync/sync-state.ts +48 -0
- package/src/sync/transport.test.ts +13 -1
- package/src/sync/transport.ts +12 -4
- package/src/sync/webdav/webdav-delete-and-blob-index.test.ts +249 -0
- package/src/sync/webdav/webdav-transport.ts +86 -34
- package/src/ui/commands.test.ts +11 -0
- package/src/ui/commands.ts +5 -14
- package/src/ui/dsh-profiles-view.test.ts +16 -0
- package/src/ui/dsh-profiles-view.ts +11 -5
- package/src/ui/foreign-view.test.ts +36 -0
- package/src/ui/foreign-view.ts +46 -0
- package/src/ui/i18n.ts +17 -2
- package/src/ui/menu-placement.ts +1 -1
- package/src/ui/migration-consult-view.test.ts +20 -1
- package/src/ui/migration-consult-view.ts +17 -0
- package/src/ui/overview-view.ts +10 -0
- package/src/ui/report.test.ts +25 -1
- package/src/ui/report.ts +15 -4
- package/src/ui/selection-model.test.ts +15 -1
- package/src/ui/selection-model.ts +18 -0
- package/src/utils/js-yaml4.d.ts +35 -0
- package/src/utils/patch-yaml.test.ts +207 -1
- package/src/utils/patch-yaml.ts +98 -2
- package/src/utils/paths.test.ts +14 -1
- package/src/utils/paths.ts +35 -0
- package/src/utils/workdir-lock.test.ts +69 -0
- package/src/utils/workdir-lock.ts +17 -3
- package/lib/ui/path-mapping.d.ts +0 -38
- package/lib/ui/path-mapping.js +0 -75
- package/src/client/common/InfoHint.tsx +0 -289
- package/src/client/common/info-hint-guard.test.ts +0 -1119
- package/src/client/sync/DecryptPasswordCard.tsx +0 -48
- package/src/client/sync/SecurityOptionsCard.tsx +0 -97
- package/src/client/sync/SyncSectionPickerDialog.tsx +0 -213
- package/src/ui/path-mapping.test.ts +0 -67
- package/src/ui/path-mapping.ts +0 -103
|
@@ -114,6 +114,8 @@ export declare class GitTransport implements SyncTransport {
|
|
|
114
114
|
* 的唯一线索。列表接口把它如实回传,让状态自洽(绝不静默失败)。
|
|
115
115
|
*/
|
|
116
116
|
private readErrors;
|
|
117
|
+
/** 存量工作副本的 sparse cone 是否已确认包含 latest/(issue #141;只补一次,不每次同步都重设) */
|
|
118
|
+
private sparseConeCoversLatest;
|
|
117
119
|
private readonly msg;
|
|
118
120
|
/** repoUrl 是否为网络地址(本地目录仓库 == false):决定要不要额外禁 file 传输(SEC-12)。 */
|
|
119
121
|
private readonly networkRepo;
|
|
@@ -140,6 +142,27 @@ export declare class GitTransport implements SyncTransport {
|
|
|
140
142
|
upload(snapshot: SyncSnapshot): Promise<SyncSnapshotMeta>;
|
|
141
143
|
/** upload 的实体;**调用方必须已持有工作副本锁** */
|
|
142
144
|
private uploadLocked;
|
|
145
|
+
/**
|
|
146
|
+
* 空文件类分区的 git 占位文件(git 不跟踪空目录):
|
|
147
|
+
* 占位文件不参与 manifest.sectionHashes(基于传入数据计算);读回时按名+内容过滤。
|
|
148
|
+
*/
|
|
149
|
+
private writeEmptyFileSectionPlaceholders;
|
|
150
|
+
/**
|
|
151
|
+
* 写 `latest/` 派生视图(issue #141):与 `snapshots/<id>/` 逐文件同布局,manifest 里保留**真实快照 id**
|
|
152
|
+
* (反向识别用)。返回本轮是否真的重建 —— false = 远端已有更新的视图,保持不动。
|
|
153
|
+
*
|
|
154
|
+
* 为什么按整份快照重写而不是拷目录:布局只有 layout.ts 一处权威,重写不会漏掉新增/删除的分区与占位文件;
|
|
155
|
+
* 外置分区只写引用文件(字节在共享 blobs/ 里按内容寻址,不重复落盘、不重复上传)。
|
|
156
|
+
*/
|
|
157
|
+
private writeLatestMirror;
|
|
158
|
+
/**
|
|
159
|
+
* 存量工作副本的 sparse-checkout 面是**旧版本**建的(不含 `latest/`):cone 之外的路径 `git add` 会
|
|
160
|
+
* 拒绝入索引("outside of your sparse-checkout definition")⇒ 派生视图永远推不上去。
|
|
161
|
+
* 首次写 latest/ 前把 cone 补齐一次(克隆时 syncDirs() 已含它,新副本不会走到这里)。
|
|
162
|
+
*
|
|
163
|
+
* 非 sparse 副本(老 git 回落全量 clone)无需处理;读不出配置一律按「无需处理」走,绝不因优化失败。
|
|
164
|
+
*/
|
|
165
|
+
private ensureSparseConeCoversLatest;
|
|
143
166
|
/** 下载快照完整载荷。明文 → 读回散文件目录;加密 → 读回密文单文件。不存在的 id 必须抛错(契约)。 */
|
|
144
167
|
download(id: string): Promise<SyncSnapshot>;
|
|
145
168
|
/** download 的实体;**调用方必须已持有工作副本锁** */
|
|
@@ -283,6 +306,12 @@ export declare class GitTransport implements SyncTransport {
|
|
|
283
306
|
* (后续 push 会自己建分支);有分支但名字对不上则拒绝猜,把远端分支名列出来。
|
|
284
307
|
*/
|
|
285
308
|
private adoptRemoteHistory;
|
|
309
|
+
/**
|
|
310
|
+
* adopt 合并冲突里只放行 latest/(issue #141):派生视图两侧内容不同不算真冲突 ——
|
|
311
|
+
* 以远端的版本收敛(合并方向 origin/<branch> 即 theirs),其它路径一律不放行。
|
|
312
|
+
* 返回 false 表示冲突面不止 latest/,调用方必须 abort。
|
|
313
|
+
*/
|
|
314
|
+
private resolveLatestOnlyMergeConflict;
|
|
286
315
|
/**
|
|
287
316
|
* pull --ff-only 同步远端;无本地提交(全新仓库)或无 upstream 时静默跳过。
|
|
288
317
|
* opts.retryable=true(仅 list / download 等**幂等读**路径传):瞬时网络故障走有限指数退避重试。
|
|
@@ -338,7 +367,7 @@ export declare class GitTransport implements SyncTransport {
|
|
|
338
367
|
/** 子目录前缀下的同步布局相对路径('' 前缀 = 历史布局,逐字不变)。 */
|
|
339
368
|
private relDir;
|
|
340
369
|
/**
|
|
341
|
-
*
|
|
370
|
+
* 四个同步根目录(带前缀,含只读派生视图 latest/):sparse 面、add 路径、adopt 判据都从这里取 ——
|
|
342
371
|
* 任何一处漏加前缀都会让「写入 A、读取 B」(issue #131 的失败面)。
|
|
343
372
|
*/
|
|
344
373
|
private syncDirs;
|
|
@@ -357,6 +386,8 @@ export declare class GitTransport implements SyncTransport {
|
|
|
357
386
|
private assertSafeId;
|
|
358
387
|
private snapshotDir;
|
|
359
388
|
private snapshotsDir;
|
|
389
|
+
/** 明文最新快照的只读派生视图目录(<workDir>/latest/;配了前缀则在 <subdir>/latest/) */
|
|
390
|
+
private latestDir;
|
|
360
391
|
/** 加密快照密文单文件目录(<workDir>/snapshots-encrypted/;配了前缀则在 <subdir>/ 下) */
|
|
361
392
|
private encryptedSnapshotsDir;
|
|
362
393
|
/** 加密快照密文单文件路径(<id>.json) */
|
|
@@ -95,6 +95,17 @@ const SNAPSHOTS_REL = 'snapshots';
|
|
|
95
95
|
/** 加密快照的「密文单文件」目录:整个快照 JSON(含密文载荷)以 <id>.json 提交。
|
|
96
96
|
* 加密快照不写散文件目录(密文无法平铺为明文 JSON 分区;远端已存密文)。 */
|
|
97
97
|
const SNAPSHOTS_ENCRYPTED_REL = 'snapshots-encrypted';
|
|
98
|
+
/**
|
|
99
|
+
* 明文最新快照的**只读派生视图**(issue #141):与 `snapshots/<id>/` 逐文件同布局,供人和 CI 直接读,
|
|
100
|
+
* 不必先知道快照 id。(契约:docs/contracts/sync-channel-v1.md)
|
|
101
|
+
*
|
|
102
|
+
* 四条硬约束,改这里之前先读:
|
|
103
|
+
* - **只写不读**:list()/download()/合并/保留策略/冲突判定一律不把它当快照目录,也不依赖它的存在;
|
|
104
|
+
* - **必须与快照进同一个 commit**:push 之后再单独提交一次就多出一次远端写(正是报告者担心的并发窗口);
|
|
105
|
+
* - 加密快照不写(密文没有明文镜像)—— 由引擎显式告警,绝不静默;
|
|
106
|
+
* - 保留策略剪旧不动它:它永远指向最新那份明文快照。
|
|
107
|
+
*/
|
|
108
|
+
const LATEST_REL = 'latest';
|
|
98
109
|
/**
|
|
99
110
|
* 内容寻址 blob 仓在仓库内的相对目录(P1-4)。
|
|
100
111
|
*
|
|
@@ -104,14 +115,20 @@ const SNAPSHOTS_ENCRYPTED_REL = 'snapshots-encrypted';
|
|
|
104
115
|
*/
|
|
105
116
|
const BLOBS_REL = 'blobs';
|
|
106
117
|
/**
|
|
107
|
-
* 同步仓库(git
|
|
118
|
+
* 同步仓库(git 通道)顶层**只可能出现**这四个条目。issue #104 的 `adopt` 模式拿它当安全判据:
|
|
108
119
|
* 远端分支的顶层出现别的名字 = 这不是本插件的同步仓库,合并它等于把别人的仓库内容搬进工作副本。
|
|
120
|
+
* `latest/` 只是承认「这是本插件写的派生视图」(issue #141),读取路径一律不碰它。
|
|
121
|
+
*
|
|
122
|
+
* 老版本客户端不知道 `latest/` ⇒ 只有在换仓库/远端历史重写时的 adopt 会 fail-closed 拒收
|
|
123
|
+
* (docs/known-issues/known-limits.md 有记录)。
|
|
109
124
|
*/
|
|
110
|
-
const ADOPT_ROOT_ALLOW = new Set([SNAPSHOTS_REL, SNAPSHOTS_ENCRYPTED_REL, BLOBS_REL]);
|
|
125
|
+
const ADOPT_ROOT_ALLOW = new Set([SNAPSHOTS_REL, SNAPSHOTS_ENCRYPTED_REL, BLOBS_REL, LATEST_REL]);
|
|
111
126
|
/**
|
|
112
|
-
*
|
|
127
|
+
* 同步仓库只在这四个顶层目录里写内容 ⇒ partial clone 的 sparse-checkout 面与它同源(issue #122)。
|
|
113
128
|
* 远端仓库比同步内容大几个数量级时(报告者现场:1.8 GB 仓库 / 6 MB 内容),全量 clone 与全量 fetch
|
|
114
|
-
*
|
|
129
|
+
* 都要拉完整对象图,而工作副本真正需要的只有这四个目录。
|
|
130
|
+
* `latest/` 虽是派生物,但它是同一 commit 里的产物:落在 cone 之外 `git add` 会直接拒收入库
|
|
131
|
+
* ("outside of your sparse-checkout definition"),所以必须进 sparse 面。
|
|
115
132
|
*/
|
|
116
133
|
/* 具体的 sparse 面在 `syncDirs()` 里按子目录前缀派生(issue #131),基名与 ADOPT_ROOT_ALLOW 同源。 */
|
|
117
134
|
/**
|
|
@@ -309,6 +326,8 @@ export class GitTransport {
|
|
|
309
326
|
* 的唯一线索。列表接口把它如实回传,让状态自洽(绝不静默失败)。
|
|
310
327
|
*/
|
|
311
328
|
readErrors = [];
|
|
329
|
+
/** 存量工作副本的 sparse cone 是否已确认包含 latest/(issue #141;只补一次,不每次同步都重设) */
|
|
330
|
+
sparseConeCoversLatest = false;
|
|
312
331
|
msg;
|
|
313
332
|
/** repoUrl 是否为网络地址(本地目录仓库 == false):决定要不要额外禁 file 传输(SEC-12)。 */
|
|
314
333
|
networkRepo;
|
|
@@ -447,28 +466,24 @@ export class GitTransport {
|
|
|
447
466
|
await fsx.remove(dir); // 覆盖语义:先清旧目录,避免残留旧文件
|
|
448
467
|
// P1-4:会话等大分区改为内容寻址外置(写进共享 blobs/,快照只留引用)
|
|
449
468
|
await writeSnapshotToDir(snapshot, dir, fsx, { blobs: this.blobSink(fsx), sections: BLOB_SECTIONS });
|
|
450
|
-
// git
|
|
451
|
-
//
|
|
452
|
-
|
|
453
|
-
const plain = snapshot.sections;
|
|
454
|
-
const blobSections = new Set(BLOB_SECTIONS);
|
|
455
|
-
for (const [sid, prefix] of Object.entries(SECTION_FILE_PREFIXES)) {
|
|
456
|
-
// 外置分区不写 <prefix>/ 目录(引用文件已在 writeSnapshotToDir 里写好),无需占位文件
|
|
457
|
-
if (blobSections.has(sid))
|
|
458
|
-
continue;
|
|
459
|
-
const data = plain[sid];
|
|
460
|
-
if (data === undefined || data.files.length > 0)
|
|
461
|
-
continue;
|
|
462
|
-
// joinFs 只接受两个参数,占位路径拼进 prefix 一起传
|
|
463
|
-
await fsx.writeFile(joinFs(dir, `${prefix}${SNAPSHOT_KEEP_FILE}`), new TextEncoder().encode(SNAPSHOT_KEEP_CONTENT));
|
|
464
|
-
}
|
|
469
|
+
// git 不跟踪空目录:为空文件类分区目录写占位文件,保证远端保留目录
|
|
470
|
+
// (否则空分区(如未安装 skills)上传后目录在远端丢失,B 机全新 clone 下载即失败)。
|
|
471
|
+
await this.writeEmptyFileSectionPlaceholders(dir, snapshot, fsx);
|
|
465
472
|
// 同 id 旧密文单文件残留 → 一并清理(形态切换不残留)
|
|
466
473
|
await fsx.remove(this.encryptedSnapshotFile(snapshot.id));
|
|
467
474
|
rel = `${this.relDir(SNAPSHOTS_REL)}/${snapshot.id}`;
|
|
468
475
|
}
|
|
476
|
+
// issue #141:`latest/` 派生视图与快照**进同一个 commit**(绝不在 push 之后补交一次)。
|
|
477
|
+
// 加密快照不写(没有明文镜像,引擎侧显式告警);远端已有更新视图时保持不动(不变量:永远指最新)。
|
|
478
|
+
const latestRel = !encrypted && await this.writeLatestMirror(snapshot, fsx) ? this.relDir(LATEST_REL) : null;
|
|
469
479
|
// blob 仓与快照同一次提交:引用文件与它引用的字节绝不跨 commit 分离
|
|
470
480
|
const hasBlobs = await fsx.exists(this.blobsDir());
|
|
471
|
-
|
|
481
|
+
const addPaths = [rel];
|
|
482
|
+
if (hasBlobs)
|
|
483
|
+
addPaths.push(this.relDir(BLOBS_REL));
|
|
484
|
+
if (latestRel !== null)
|
|
485
|
+
addPaths.push(latestRel);
|
|
486
|
+
await this.runGit(['add', '--', ...addPaths]);
|
|
472
487
|
const diff = await this.runGit(['diff', '--cached', '--quiet'], { allowNonZero: true });
|
|
473
488
|
if (diff.code !== 0) {
|
|
474
489
|
const verb = existed ? 'update' : 'add';
|
|
@@ -477,6 +492,71 @@ export class GitTransport {
|
|
|
477
492
|
}
|
|
478
493
|
return computeSnapshotMeta(snapshot);
|
|
479
494
|
}
|
|
495
|
+
/**
|
|
496
|
+
* 空文件类分区的 git 占位文件(git 不跟踪空目录):
|
|
497
|
+
* 占位文件不参与 manifest.sectionHashes(基于传入数据计算);读回时按名+内容过滤。
|
|
498
|
+
*/
|
|
499
|
+
async writeEmptyFileSectionPlaceholders(dir, snapshot, fsx) {
|
|
500
|
+
const plain = snapshot.sections;
|
|
501
|
+
const blobSections = new Set(BLOB_SECTIONS);
|
|
502
|
+
for (const [sid, prefix] of Object.entries(SECTION_FILE_PREFIXES)) {
|
|
503
|
+
// 外置分区不写 <prefix>/ 目录(引用文件已在 writeSnapshotToDir 里写好),无需占位文件
|
|
504
|
+
if (blobSections.has(sid))
|
|
505
|
+
continue;
|
|
506
|
+
const data = plain[sid];
|
|
507
|
+
if (data === undefined || data.files.length > 0)
|
|
508
|
+
continue;
|
|
509
|
+
// joinFs 只接受两个参数,占位路径拼进 prefix 一起传
|
|
510
|
+
await fsx.writeFile(joinFs(dir, `${prefix}${SNAPSHOT_KEEP_FILE}`), new TextEncoder().encode(SNAPSHOT_KEEP_CONTENT));
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* 写 `latest/` 派生视图(issue #141):与 `snapshots/<id>/` 逐文件同布局,manifest 里保留**真实快照 id**
|
|
515
|
+
* (反向识别用)。返回本轮是否真的重建 —— false = 远端已有更新的视图,保持不动。
|
|
516
|
+
*
|
|
517
|
+
* 为什么按整份快照重写而不是拷目录:布局只有 layout.ts 一处权威,重写不会漏掉新增/删除的分区与占位文件;
|
|
518
|
+
* 外置分区只写引用文件(字节在共享 blobs/ 里按内容寻址,不重复落盘、不重复上传)。
|
|
519
|
+
*/
|
|
520
|
+
async writeLatestMirror(snapshot, fsx) {
|
|
521
|
+
const dir = this.latestDir();
|
|
522
|
+
const existing = await this.readDirManifest(dir);
|
|
523
|
+
// 不变量:latest/ 永远指向最新那份 —— out-of-order 上传(例如补齐更旧的快照)绝不把它回退成旧的
|
|
524
|
+
if (existing !== null && existing.createdAt > snapshot.createdAt)
|
|
525
|
+
return false;
|
|
526
|
+
// 存量工作副本的 sparse 面是旧版本建的(不含 latest/)⇒ 必须在写文件**之前**补齐 cone,否则 add 拒收
|
|
527
|
+
await this.ensureSparseConeCoversLatest();
|
|
528
|
+
await fsx.remove(dir); // 覆盖语义:先清旧视图,避免残留已下线的分区文件
|
|
529
|
+
await writeSnapshotToDir(snapshot, dir, fsx, { blobs: this.blobSink(fsx), sections: BLOB_SECTIONS });
|
|
530
|
+
await this.writeEmptyFileSectionPlaceholders(dir, snapshot, fsx);
|
|
531
|
+
return true;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* 存量工作副本的 sparse-checkout 面是**旧版本**建的(不含 `latest/`):cone 之外的路径 `git add` 会
|
|
535
|
+
* 拒绝入索引("outside of your sparse-checkout definition")⇒ 派生视图永远推不上去。
|
|
536
|
+
* 首次写 latest/ 前把 cone 补齐一次(克隆时 syncDirs() 已含它,新副本不会走到这里)。
|
|
537
|
+
*
|
|
538
|
+
* 非 sparse 副本(老 git 回落全量 clone)无需处理;读不出配置一律按「无需处理」走,绝不因优化失败。
|
|
539
|
+
*/
|
|
540
|
+
async ensureSparseConeCoversLatest() {
|
|
541
|
+
if (this.sparseConeCoversLatest)
|
|
542
|
+
return;
|
|
543
|
+
const flag = await this.runGit(['config', '--get', 'core.sparseCheckout'], { allowNonZero: true });
|
|
544
|
+
if (flag.code !== 0 || flag.stdout.trim() !== 'true') {
|
|
545
|
+
this.sparseConeCoversLatest = true;
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
const latestLine = `/${this.relDir(LATEST_REL)}/`;
|
|
549
|
+
const gitPath = await this.runGit(['rev-parse', '--git-path', 'info/sparse-checkout'], { allowNonZero: true });
|
|
550
|
+
const relPath = gitPath.code === 0 ? gitPath.stdout.trim() : '';
|
|
551
|
+
const abs = relPath === '' ? '' : path.isAbsolute(relPath) ? relPath : path.join(this.o.workDir, relPath);
|
|
552
|
+
const content = abs === '' ? '' : await fs.readFile(abs, 'utf8').catch(() => '');
|
|
553
|
+
if (content.split(/\r?\n/).some((line) => line.trim() === latestLine)) {
|
|
554
|
+
this.sparseConeCoversLatest = true;
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
const res = await this.runGit(['sparse-checkout', 'set', '--cone', ...this.syncDirs()], { allowNonZero: true });
|
|
558
|
+
this.sparseConeCoversLatest = res.code === 0;
|
|
559
|
+
}
|
|
480
560
|
/** 下载快照完整载荷。明文 → 读回散文件目录;加密 → 读回密文单文件。不存在的 id 必须抛错(契约)。 */
|
|
481
561
|
async download(id) {
|
|
482
562
|
return this.withWorkdir(() => this.downloadLocked(id));
|
|
@@ -537,7 +617,13 @@ export class GitTransport {
|
|
|
537
617
|
await fsx.remove(encFile);
|
|
538
618
|
rel = `${this.relDir(SNAPSHOTS_ENCRYPTED_REL)}/${id}.json`;
|
|
539
619
|
}
|
|
540
|
-
|
|
620
|
+
// 不变量:latest/ 绝不指向不存在的快照 —— 删掉的正是它镜像的那份时,同一 commit 里一并移除视图
|
|
621
|
+
// (保留策略永远保住刚 push 的那份,正常裁剪走不到这里;这是用户显式删最新快照的兜底)。
|
|
622
|
+
const mirror = await this.readDirManifest(this.latestDir());
|
|
623
|
+
const dropLatest = mirror !== null && mirror.id === id;
|
|
624
|
+
if (dropLatest)
|
|
625
|
+
await fsx.remove(this.latestDir());
|
|
626
|
+
await this.runGit(dropLatest ? ['add', '-A', '--', rel, this.relDir(LATEST_REL)] : ['add', '-A', '--', rel]);
|
|
541
627
|
const diff = await this.runGit(['diff', '--cached', '--quiet'], { allowNonZero: true });
|
|
542
628
|
if (diff.code !== 0) {
|
|
543
629
|
await this.runGit(['commit', '-m', `sync: delete snapshot ${id}`]);
|
|
@@ -1073,17 +1159,47 @@ export class GitTransport {
|
|
|
1073
1159
|
if (unknownEntries.length > 0) {
|
|
1074
1160
|
throw new GitTransportError(this.msg('sync.git.adoptNotSyncRepo', { entries: unknownEntries.slice(0, 3).join(', ') }), { kind: 'protocol', retryable: false });
|
|
1075
1161
|
}
|
|
1076
|
-
// ③ 合并(不改写任何本地提交);冲突则 abort
|
|
1162
|
+
// ③ 合并(不改写任何本地提交);冲突则 abort 回起点再报错。
|
|
1163
|
+
// latest/ 是派生视图(issue #141):两条历史各有一份内容不同的 latest/ 时是 add/add 冲突,
|
|
1164
|
+
// 但它不该挡住换仓库 —— 派生层以远端为准继续合并,其它任何路径冲突仍整笔 abort。
|
|
1077
1165
|
const mergeRes = await this.runGit(['merge', '--allow-unrelated-histories', '--no-edit', `origin/${branch}`], { allowNonZero: true });
|
|
1078
1166
|
if (mergeRes.code !== 0) {
|
|
1079
|
-
await this.
|
|
1080
|
-
|
|
1167
|
+
const resolved = await this.resolveLatestOnlyMergeConflict();
|
|
1168
|
+
const committed = resolved ? await this.runGit(['commit', '--no-edit'], { allowNonZero: true }) : null;
|
|
1169
|
+
if (committed === null || committed.code !== 0) {
|
|
1170
|
+
await this.runGit(['merge', '--abort'], { allowNonZero: true });
|
|
1171
|
+
throw new GitTransportError(this.msg('sync.git.adoptMergeConflict', { branch }), { kind: 'conflict', retryable: false });
|
|
1172
|
+
}
|
|
1081
1173
|
}
|
|
1082
1174
|
// 让后续 pull --ff-only 有 upstream 可用(忽略失败:分支可能已被删/重命名)
|
|
1083
1175
|
await this.runGit(['branch', '--set-upstream-to', `origin/${branch}`, branch], { allowNonZero: true });
|
|
1084
1176
|
await this.writeLayoutMarker();
|
|
1085
1177
|
this.repoReady = true;
|
|
1086
1178
|
}
|
|
1179
|
+
/**
|
|
1180
|
+
* adopt 合并冲突里只放行 latest/(issue #141):派生视图两侧内容不同不算真冲突 ——
|
|
1181
|
+
* 以远端的版本收敛(合并方向 origin/<branch> 即 theirs),其它路径一律不放行。
|
|
1182
|
+
* 返回 false 表示冲突面不止 latest/,调用方必须 abort。
|
|
1183
|
+
*/
|
|
1184
|
+
async resolveLatestOnlyMergeConflict() {
|
|
1185
|
+
const unmerged = await this.runGit(['diff', '--name-only', '--diff-filter=U'], { allowNonZero: true });
|
|
1186
|
+
if (unmerged.code !== 0)
|
|
1187
|
+
return false;
|
|
1188
|
+
const paths = unmerged.stdout.split('\n').map((line) => line.trim()).filter((line) => line !== '');
|
|
1189
|
+
const latestRel = this.relDir(LATEST_REL);
|
|
1190
|
+
const inLatest = (rel) => rel === latestRel || rel.startsWith(`${latestRel}/`);
|
|
1191
|
+
if (paths.length === 0 || !paths.every(inLatest))
|
|
1192
|
+
return false;
|
|
1193
|
+
for (const rel of paths) {
|
|
1194
|
+
const takeTheirs = await this.runGit(['checkout', '--theirs', '--', rel], { allowNonZero: true });
|
|
1195
|
+
// modify/delete 冲突:theirs 里没有这个文件 = 远端已不再有视图,按删除收敛
|
|
1196
|
+
if (takeTheirs.code !== 0)
|
|
1197
|
+
await this.runGit(['rm', '-f', '--', rel], { allowNonZero: true });
|
|
1198
|
+
else
|
|
1199
|
+
await this.runGit(['add', '--', rel], { allowNonZero: true });
|
|
1200
|
+
}
|
|
1201
|
+
return true;
|
|
1202
|
+
}
|
|
1087
1203
|
/**
|
|
1088
1204
|
* pull --ff-only 同步远端;无本地提交(全新仓库)或无 upstream 时静默跳过。
|
|
1089
1205
|
* opts.retryable=true(仅 list / download 等**幂等读**路径传):瞬时网络故障走有限指数退避重试。
|
|
@@ -1368,11 +1484,11 @@ export class GitTransport {
|
|
|
1368
1484
|
return this.subdir === '' ? base : `${this.subdir}/${base}`;
|
|
1369
1485
|
}
|
|
1370
1486
|
/**
|
|
1371
|
-
*
|
|
1487
|
+
* 四个同步根目录(带前缀,含只读派生视图 latest/):sparse 面、add 路径、adopt 判据都从这里取 ——
|
|
1372
1488
|
* 任何一处漏加前缀都会让「写入 A、读取 B」(issue #131 的失败面)。
|
|
1373
1489
|
*/
|
|
1374
1490
|
syncDirs() {
|
|
1375
|
-
return [this.relDir(SNAPSHOTS_REL), this.relDir(SNAPSHOTS_ENCRYPTED_REL), this.relDir(BLOBS_REL)];
|
|
1491
|
+
return [this.relDir(SNAPSHOTS_REL), this.relDir(SNAPSHOTS_ENCRYPTED_REL), this.relDir(BLOBS_REL), this.relDir(LATEST_REL)];
|
|
1376
1492
|
}
|
|
1377
1493
|
blobsDir() {
|
|
1378
1494
|
return path.join(this.o.workDir, this.relDir(BLOBS_REL));
|
|
@@ -1471,6 +1587,10 @@ export class GitTransport {
|
|
|
1471
1587
|
snapshotsDir() {
|
|
1472
1588
|
return joinFs(this.o.workDir, this.relDir(SNAPSHOTS_REL));
|
|
1473
1589
|
}
|
|
1590
|
+
/** 明文最新快照的只读派生视图目录(<workDir>/latest/;配了前缀则在 <subdir>/latest/) */
|
|
1591
|
+
latestDir() {
|
|
1592
|
+
return joinFs(this.o.workDir, this.relDir(LATEST_REL));
|
|
1593
|
+
}
|
|
1474
1594
|
/** 加密快照密文单文件目录(<workDir>/snapshots-encrypted/;配了前缀则在 <subdir>/ 下) */
|
|
1475
1595
|
encryptedSnapshotsDir() {
|
|
1476
1596
|
return joinFs(this.o.workDir, this.relDir(SNAPSHOTS_ENCRYPTED_REL));
|
|
@@ -98,10 +98,21 @@ export interface DeviceFlowEntry {
|
|
|
98
98
|
/** 过期时刻(epoch ms):now > expiresAt 视为已过期,get 返回 undefined 并清理 */
|
|
99
99
|
expiresAt: number;
|
|
100
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* 同一时刻允许驻留的设备码流上限。正常用户一次只开一个授权流程,这个数只在「反复重开」
|
|
103
|
+
* 或有人刷 start 端点时才会被顶到;有它才有内存上界(过期时间之外的第二重保证)。
|
|
104
|
+
*/
|
|
105
|
+
export declare const DEVICE_FLOW_LIMIT = 32;
|
|
101
106
|
/**
|
|
102
107
|
* 宿主内存设备码登记表(进程生命周期,跨请求共享 —— 与 RunRegistry 同模式)。
|
|
103
108
|
* device_code 的持有者是宿主:UI 只拿 flowId(随机 id),轮询时宿主凭 flowId 取回
|
|
104
|
-
* device_code 去 GitHub 换 token
|
|
109
|
+
* device_code 去 GitHub 换 token。
|
|
110
|
+
*
|
|
111
|
+
* audit-sync sync-P6-6(P3):清理不能只挂在 get() 上 —— 用户开了授权页又直接关掉时,流程
|
|
112
|
+
* 从此不会有人轮询,那条含 device_code 的过期条目会永久驻留。所以**写入路径也清扫**:
|
|
113
|
+
* set() 先淘汰全部过期条目(now > expiresAt),再把总数压到 DEVICE_FLOW_LIMIT 以内
|
|
114
|
+
* (超出时淘汰最早过期的那条 = 最接近失效、最没价值的一条)。get() 的惰性清理保留,
|
|
115
|
+
* 任何时刻表的大小都不超过该上限。
|
|
105
116
|
*/
|
|
106
117
|
export declare class DeviceFlowStore {
|
|
107
118
|
private readonly flows;
|
|
@@ -110,6 +121,11 @@ export declare class DeviceFlowStore {
|
|
|
110
121
|
get size(): number;
|
|
111
122
|
/** 登记一个设备码流;flowId 由调用方生成(随机,不可猜) */
|
|
112
123
|
set(flowId: string, entry: DeviceFlowEntry): void;
|
|
124
|
+
/**
|
|
125
|
+
* 清扫:先删全部过期条目,再在容量满时淘汰最早过期者(保证 set 之后 size <= DEVICE_FLOW_LIMIT)。
|
|
126
|
+
* 先扫过期是关键 —— 否则上限会去淘汰仍在有效期内的流程,把用户的正常授权踢掉。
|
|
127
|
+
*/
|
|
128
|
+
private sweep;
|
|
113
129
|
/** 取回设备码流;过期条目视为不存在并立即清理 */
|
|
114
130
|
get(flowId: string): DeviceFlowEntry | undefined;
|
|
115
131
|
/** 主动移除(取消/完成后清理) */
|
package/lib/sync/github-auth.js
CHANGED
|
@@ -183,10 +183,21 @@ export class GitHubAuthClient {
|
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* 同一时刻允许驻留的设备码流上限。正常用户一次只开一个授权流程,这个数只在「反复重开」
|
|
188
|
+
* 或有人刷 start 端点时才会被顶到;有它才有内存上界(过期时间之外的第二重保证)。
|
|
189
|
+
*/
|
|
190
|
+
export const DEVICE_FLOW_LIMIT = 32;
|
|
186
191
|
/**
|
|
187
192
|
* 宿主内存设备码登记表(进程生命周期,跨请求共享 —— 与 RunRegistry 同模式)。
|
|
188
193
|
* device_code 的持有者是宿主:UI 只拿 flowId(随机 id),轮询时宿主凭 flowId 取回
|
|
189
|
-
* device_code 去 GitHub 换 token
|
|
194
|
+
* device_code 去 GitHub 换 token。
|
|
195
|
+
*
|
|
196
|
+
* audit-sync sync-P6-6(P3):清理不能只挂在 get() 上 —— 用户开了授权页又直接关掉时,流程
|
|
197
|
+
* 从此不会有人轮询,那条含 device_code 的过期条目会永久驻留。所以**写入路径也清扫**:
|
|
198
|
+
* set() 先淘汰全部过期条目(now > expiresAt),再把总数压到 DEVICE_FLOW_LIMIT 以内
|
|
199
|
+
* (超出时淘汰最早过期的那条 = 最接近失效、最没价值的一条)。get() 的惰性清理保留,
|
|
200
|
+
* 任何时刻表的大小都不超过该上限。
|
|
190
201
|
*/
|
|
191
202
|
export class DeviceFlowStore {
|
|
192
203
|
flows = new Map();
|
|
@@ -199,8 +210,33 @@ export class DeviceFlowStore {
|
|
|
199
210
|
}
|
|
200
211
|
/** 登记一个设备码流;flowId 由调用方生成(随机,不可猜) */
|
|
201
212
|
set(flowId, entry) {
|
|
213
|
+
this.sweep();
|
|
202
214
|
this.flows.set(flowId, entry);
|
|
203
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* 清扫:先删全部过期条目,再在容量满时淘汰最早过期者(保证 set 之后 size <= DEVICE_FLOW_LIMIT)。
|
|
218
|
+
* 先扫过期是关键 —— 否则上限会去淘汰仍在有效期内的流程,把用户的正常授权踢掉。
|
|
219
|
+
*/
|
|
220
|
+
sweep() {
|
|
221
|
+
const now = this.now();
|
|
222
|
+
for (const [flowId, entry] of this.flows) {
|
|
223
|
+
if (now > entry.expiresAt)
|
|
224
|
+
this.flows.delete(flowId);
|
|
225
|
+
}
|
|
226
|
+
while (this.flows.size >= DEVICE_FLOW_LIMIT) {
|
|
227
|
+
let oldestId;
|
|
228
|
+
let oldestAt = Number.POSITIVE_INFINITY;
|
|
229
|
+
for (const [flowId, entry] of this.flows) {
|
|
230
|
+
if (entry.expiresAt < oldestAt) {
|
|
231
|
+
oldestAt = entry.expiresAt;
|
|
232
|
+
oldestId = flowId;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (oldestId === undefined)
|
|
236
|
+
return; // 理论不可达:size >= 1 时必能挑出一条
|
|
237
|
+
this.flows.delete(oldestId);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
204
240
|
/** 取回设备码流;过期条目视为不存在并立即清理 */
|
|
205
241
|
get(flowId) {
|
|
206
242
|
const entry = this.flows.get(flowId);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ConfigAdapter, HostContext, ImportDecisions, ImportPlan, PathMapping, Snapshot, SnapshotStore } from '../core/types.ts';
|
|
2
|
+
import type { ReviewQueueItem } from './review-queue.ts';
|
|
3
|
+
export interface PlanMergeApplyInput {
|
|
4
|
+
/** 本次合成的临时 ZIP(合并结果)。 */
|
|
5
|
+
zipPath: string;
|
|
6
|
+
/** 合并路径的映射(merge() 记下的远端 sourceHome + 用户映射,issue #45)。 */
|
|
7
|
+
pathMappings: PathMapping[];
|
|
8
|
+
/** 本次要应用的分区(autoApply + 伴随分区)。 */
|
|
9
|
+
appliedIds: readonly string[];
|
|
10
|
+
/** 复用宿主 Importer 的规划入口(纯计算,零写入)。 */
|
|
11
|
+
createImportPlan: (zipPath: string, decisions: ImportDecisions) => Promise<ImportPlan>;
|
|
12
|
+
/** 待裁决项的告警文案(i18n 留在调用方,键 `sync.mergeHeldConflicts`)。 */
|
|
13
|
+
heldConflictMessage: (count: number, sections: string[]) => string;
|
|
14
|
+
}
|
|
15
|
+
export interface MergeApplyPlan {
|
|
16
|
+
plan: ImportPlan;
|
|
17
|
+
/** 叶级未裁决项的报告面:只给 id/分区/描述,**不带值**(值可能含敏感叶子)。 */
|
|
18
|
+
heldReview: ReviewQueueItem[];
|
|
19
|
+
/** 人读告警(空数组 = 没有待裁决项)。 */
|
|
20
|
+
heldWarnings: string[];
|
|
21
|
+
}
|
|
22
|
+
export declare function planMergeApply(input: PlanMergeApplyInput): Promise<MergeApplyPlan>;
|
|
23
|
+
export type MergeApplySnapshotResult = {
|
|
24
|
+
ok: true;
|
|
25
|
+
store: SnapshotStore;
|
|
26
|
+
snapshot: Snapshot;
|
|
27
|
+
} | {
|
|
28
|
+
ok: false;
|
|
29
|
+
error: unknown;
|
|
30
|
+
};
|
|
31
|
+
/** 执行前兜底快照(拿到 restoreId 给 UI 一键回滚);失败时把原始错误交回调用方决定文案。 */
|
|
32
|
+
export declare function createMergeApplySnapshot(input: {
|
|
33
|
+
ctx: HostContext;
|
|
34
|
+
plan: ImportPlan;
|
|
35
|
+
zipPath: string;
|
|
36
|
+
storeDir: string;
|
|
37
|
+
adapters: ConfigAdapter[];
|
|
38
|
+
}): Promise<MergeApplySnapshotResult>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #136 B:合并落地的「两趟计划 + 待裁决面」,以及执行前的兜底快照。
|
|
3
|
+
*
|
|
4
|
+
* **旧实现的坑**:`strategy: 'replace'` + 空 `resolutions` 规划。冲突只在外部分流到
|
|
5
|
+
* 分区级,而被放行分区里的叶级差异项在计划里是 `Conflict`;`replace` 把它们**不分来源**
|
|
6
|
+
* 统一翻成 `Update` → 落盘,等于「未裁决也按远端覆盖」,且报告 review 恒空 ——
|
|
7
|
+
* 用户既没同意,事后也无从知道。
|
|
8
|
+
*
|
|
9
|
+
* **现口径**:
|
|
10
|
+
* - **分区级裁决 → 逐项 resolutions**:本次要应用的分区(`appliedIds`:autoApply + 会话
|
|
11
|
+
* 伴随的 workspaces)其叶级差异已由分区裁决(useRemote/useMerged/keepLocal)决定,于是
|
|
12
|
+
* 显式给这些项 `useImported`(合并路径的 ZIP 载荷本身就是裁决结果 —— merge 分区的
|
|
13
|
+
* merged 已含双方改动,keepLocal 分区的 merged 就是本机值)。
|
|
14
|
+
* - **没有分区裁决覆盖的项保持 `Conflict`**:不写盘(`planItemWritesTarget()`,
|
|
15
|
+
* `src/core/backup.ts` 拦下),并列进报告的待裁决面 —— 绝不由全局策略暗中落盘。
|
|
16
|
+
* - **两趟计划的理由**:resolutions 要按 **item id** 给,而 id 只有计划才知道(各适配器
|
|
17
|
+
* 自己算)。第一趟用 `merge` + 空 resolutions 只做「探测」,零写入;只有探测出
|
|
18
|
+
* 「可裁决的 Conflict」时才补一遍 resolutions 重算 —— 无差异的常规合并仍然只有一趟。
|
|
19
|
+
*/
|
|
20
|
+
import { createSnapshot, FileSnapshotStore } from '../core/backup.js';
|
|
21
|
+
export async function planMergeApply(input) {
|
|
22
|
+
const probePlan = await input.createImportPlan(input.zipPath, {
|
|
23
|
+
strategy: 'merge',
|
|
24
|
+
resolutions: {},
|
|
25
|
+
pathMappings: input.pathMappings,
|
|
26
|
+
});
|
|
27
|
+
const decidedSections = new Set(input.appliedIds);
|
|
28
|
+
const decidable = probePlan.items.filter((i) => i.kind === 'Conflict' && decidedSections.has(i.adapter));
|
|
29
|
+
let plan = probePlan;
|
|
30
|
+
if (decidable.length > 0) {
|
|
31
|
+
const injected = new Set(decidable.map((i) => i.id));
|
|
32
|
+
const decidedPlan = await input.createImportPlan(input.zipPath, {
|
|
33
|
+
strategy: 'merge',
|
|
34
|
+
resolutions: Object.fromEntries([...injected].map((id) => [id, 'useImported'])),
|
|
35
|
+
pathMappings: input.pathMappings,
|
|
36
|
+
});
|
|
37
|
+
// #136 A:这些 `useImported` 是**分区级**裁决换来的,不是人对这一行的确认 ——
|
|
38
|
+
// 标成 `decidedBy: 'section'`,写回守卫据此只保留被剥空叶子(其余照常落地)。
|
|
39
|
+
// 漏标就会让自动同步(零 UI)把脱敏剥离的空值当用户主动清空写下去。
|
|
40
|
+
plan = {
|
|
41
|
+
...decidedPlan,
|
|
42
|
+
items: decidedPlan.items.map((i) => (i.conflict && injected.has(i.id)
|
|
43
|
+
? { ...i, conflict: { ...i.conflict, decidedBy: 'section' } }
|
|
44
|
+
: i)),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const held = plan.items.filter((i) => i.kind === 'Conflict');
|
|
48
|
+
const heldReview = held.map((i) => ({
|
|
49
|
+
id: i.id,
|
|
50
|
+
sectionId: i.adapter,
|
|
51
|
+
kind: 'key',
|
|
52
|
+
description: i.description,
|
|
53
|
+
}));
|
|
54
|
+
const heldWarnings = held.length === 0
|
|
55
|
+
? []
|
|
56
|
+
: [input.heldConflictMessage(held.length, [...new Set(held.map((i) => i.adapter))])];
|
|
57
|
+
return { plan, heldReview, heldWarnings };
|
|
58
|
+
}
|
|
59
|
+
/** 执行前兜底快照(拿到 restoreId 给 UI 一键回滚);失败时把原始错误交回调用方决定文案。 */
|
|
60
|
+
export async function createMergeApplySnapshot(input) {
|
|
61
|
+
const store = new FileSnapshotStore({ dir: input.storeDir });
|
|
62
|
+
try {
|
|
63
|
+
const snapshot = await createSnapshot({
|
|
64
|
+
ctx: input.ctx,
|
|
65
|
+
plan: input.plan,
|
|
66
|
+
sourceZip: input.zipPath,
|
|
67
|
+
store,
|
|
68
|
+
adapters: input.adapters,
|
|
69
|
+
});
|
|
70
|
+
return { ok: true, store, snapshot };
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
return { ok: false, error };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=merge-apply-plan.js.map
|
package/lib/sync/messages.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare const zh: {
|
|
|
20
20
|
readonly 'sync.layoutBlobRefsNoSink': '快照的 {section} 分区是内容寻址外置形态,但当前通道未提供 blob 仓';
|
|
21
21
|
readonly 'sync.layoutFileSectionDirMissing': '快照缺少文件分区目录 {prefix}({section})';
|
|
22
22
|
readonly 'sync.blobMissing': '内容的 blob 缺失({hash},{path}):远端仓不完整,拒绝降级为空分区';
|
|
23
|
+
readonly 'sync.blobCorrupt': '内容的 blob 校验不符({path}:期望 {hash},实得 {actual},{size} 字节):远端仓已损坏,拒绝写回错误内容';
|
|
23
24
|
readonly 'sync.webdav.blobHashInvalid': '内容哈希形状非法,拒绝写入 blob 仓: {hash}';
|
|
24
25
|
readonly 'sync.scopeDirCreateFailed': '无法创建档案同步目录 {dir}:{reason}';
|
|
25
26
|
readonly 'sync.scopeAdoptFailed': '继承 {file} 失败:{reason}';
|
package/lib/sync/messages.js
CHANGED
|
@@ -40,6 +40,7 @@ export const zh = {
|
|
|
40
40
|
'sync.layoutFileSectionDirMissing': '快照缺少文件分区目录 {prefix}({section})',
|
|
41
41
|
// ---------- 内容寻址 blob 仓 ----------
|
|
42
42
|
'sync.blobMissing': '内容的 blob 缺失({hash},{path}):远端仓不完整,拒绝降级为空分区',
|
|
43
|
+
'sync.blobCorrupt': '内容的 blob 校验不符({path}:期望 {hash},实得 {actual},{size} 字节):远端仓已损坏,拒绝写回错误内容',
|
|
43
44
|
'sync.webdav.blobHashInvalid': '内容哈希形状非法,拒绝写入 blob 仓: {hash}',
|
|
44
45
|
// ---------- 按档案分作用域(sync-scope) ----------
|
|
45
46
|
'sync.scopeDirCreateFailed': '无法创建档案同步目录 {dir}:{reason}',
|
|
@@ -124,6 +125,7 @@ export const en = {
|
|
|
124
125
|
'sync.layoutBlobRefsNoSink': 'Section {section} of the snapshot uses content-addressed external form, but the current channel provides no blob store',
|
|
125
126
|
'sync.layoutFileSectionDirMissing': 'Snapshot is missing the file section directory {prefix} ({section})',
|
|
126
127
|
'sync.blobMissing': 'The blob for {path} is missing ({hash}): the remote store is incomplete, refusing to degrade to an empty section',
|
|
128
|
+
'sync.blobCorrupt': 'The blob for {path} failed its hash check (expected {hash}, got {actual}, {size} bytes): the remote store is corrupted, refusing to write back wrong content',
|
|
127
129
|
'sync.webdav.blobHashInvalid': 'Malformed content hash; refusing to write to the blob store: {hash}',
|
|
128
130
|
'sync.scopeDirCreateFailed': 'Cannot create the profile sync directory {dir}: {reason}',
|
|
129
131
|
'sync.scopeAdoptFailed': 'Failed to adopt {file}: {reason}',
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { PendingMerge, SyncState } from './sync-state.ts';
|
|
2
|
+
import type { SnapshotFs } from './fs.ts';
|
|
3
|
+
import type { MsgFunc } from '../core/messages.ts';
|
|
4
|
+
import type { SectionId } from '../schema/types.ts';
|
|
5
|
+
/** 落盘依赖(与 SyncEngine 的 stateDir / fsx / msg 同源)。 */
|
|
6
|
+
export interface PendingMergeDeps {
|
|
7
|
+
stateDir: string;
|
|
8
|
+
fsx: SnapshotFs;
|
|
9
|
+
msg: MsgFunc;
|
|
10
|
+
}
|
|
11
|
+
/** 组装待裁决记录:同一远端快照上的连续待裁决**保留首次时间**(界面据此讲「挂了多久」)。 */
|
|
12
|
+
export declare function pendingMergeFor(state: SyncState, remoteSnapshotId: string, sections: SectionId[], nowIso: string): PendingMerge;
|
|
13
|
+
/**
|
|
14
|
+
* 基线纪律的**纯状态**写入(不写祖先副本、不碰远端):仅在本机没有任何配置写入时使用。
|
|
15
|
+
*
|
|
16
|
+
* - pending 提供 → 写 pendingMerge;undefined → 清除该字段(「全部裁决完」);
|
|
17
|
+
* - advanceRemoteId 提供 → 把远端指针推进到该快照 id(缺省 = 保持不变)。
|
|
18
|
+
*
|
|
19
|
+
* 为什么不走 recordBaseline:那条路径会重建祖先副本并只带本次应用的分区 —— 在「没有应用任何分区」
|
|
20
|
+
* 或「仍有未裁决冲突」时都会把共同基线改坏(下一轮所有分区都退化成「无祖先 → 冲突」)。
|
|
21
|
+
*/
|
|
22
|
+
export declare function writeMergeBaseline(deps: PendingMergeDeps, opts: {
|
|
23
|
+
pending?: PendingMerge;
|
|
24
|
+
advanceRemoteId?: string;
|
|
25
|
+
}, nowIso: string): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* 把本轮被冲突挡下的分区落成「待裁决」(自动同步冲突分支调用)。
|
|
28
|
+
*
|
|
29
|
+
* - 远端快照 id 取自最近一次 merge();未知(null)或分区为空 → 返回 null 且**不写**:没有远端 id 的
|
|
30
|
+
* 待裁决无法被后续轮次认成「同一件事」,写进去只会让 since 每轮重置,界面永远说不清「挂了多久」。
|
|
31
|
+
* - since 由 pendingMergeFor 决定:同一远端快照上连续冲突保留首次时间。
|
|
32
|
+
* - 清理归推送成功侧(recordBaseline 带 pendingMerge:null):本机真推上去了 = 冲突已有结论。
|
|
33
|
+
*/
|
|
34
|
+
export declare function recordPendingMerge(deps: PendingMergeDeps, remoteSnapshotId: string | null, sections: readonly SectionId[], nowIso: string): Promise<PendingMerge | null>;
|