dsh-config-manager 0.1.69 → 0.1.71
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/README.md +59 -18
- package/README.zh-CN.md +29 -9
- package/lib/adapters/credentials.js +6 -3
- package/lib/adapters/file-collection.d.ts +21 -1
- package/lib/adapters/file-collection.js +32 -8
- package/lib/adapters/mcp.d.ts +12 -2
- package/lib/adapters/mcp.js +30 -13
- package/lib/adapters/plugin-files.d.ts +8 -0
- package/lib/adapters/plugin-files.js +36 -4
- package/lib/adapters/plugins.d.ts +28 -2
- package/lib/adapters/plugins.js +204 -55
- package/lib/adapters/prompts.d.ts +12 -2
- package/lib/adapters/prompts.js +34 -19
- package/lib/adapters/providers.js +5 -4
- package/lib/adapters/self.d.ts +20 -0
- package/lib/adapters/self.js +73 -0
- package/lib/adapters/sessions.d.ts +8 -0
- package/lib/adapters/sessions.js +47 -1
- package/lib/adapters/settings.d.ts +21 -3
- package/lib/adapters/settings.js +44 -7
- package/lib/adapters/skills.d.ts +36 -4
- package/lib/adapters/skills.js +222 -3
- package/lib/adapters/test-helpers.d.ts +31 -2
- package/lib/adapters/test-helpers.js +42 -5
- package/lib/adapters/workspaces.js +97 -5
- package/lib/cli/actions.d.ts +50 -3
- package/lib/cli/actions.js +103 -11
- package/lib/cli/help.d.ts +65 -0
- package/lib/cli/help.js +517 -0
- package/lib/cli/import-source.d.ts +32 -0
- package/lib/cli/import-source.js +178 -0
- package/lib/cli/index.d.ts +18 -2
- package/lib/cli/index.js +118 -90
- package/lib/cli/web/client-script.d.ts +8 -0
- package/lib/cli/web/client-script.js +11 -0
- package/lib/cli/web/http.d.ts +5 -0
- package/lib/cli/web/http.js +2 -1
- package/lib/cli/web/page.d.ts +16 -6
- package/lib/cli/web/page.js +102 -25
- package/lib/cli/web/routes.js +24 -5
- package/lib/cli/web/server.js +23 -2
- package/lib/client.d.ts +1019 -36
- package/lib/client.js +5522 -1564
- package/lib/core/analyzer.d.ts +15 -1
- package/lib/core/analyzer.js +114 -13
- package/lib/core/backup-plan.js +17 -1
- package/lib/core/backup.d.ts +8 -0
- package/lib/core/backup.js +28 -6
- package/lib/core/cache-cleaner.d.ts +10 -0
- package/lib/core/cache-cleaner.js +63 -22
- package/lib/core/checkpoint.d.ts +362 -0
- package/lib/core/checkpoint.js +1309 -0
- package/lib/core/journal.d.ts +37 -0
- package/lib/core/journal.js +69 -0
- package/lib/core/messages.d.ts +13 -0
- package/lib/core/messages.js +26 -0
- package/lib/core/model-tools.js +3 -0
- package/lib/core/patch-layers.d.ts +83 -0
- package/lib/core/patch-layers.js +110 -0
- package/lib/core/restore.d.ts +21 -0
- package/lib/core/restore.js +37 -3
- package/lib/core/rollback.js +6 -3
- package/lib/core/self-update.d.ts +52 -0
- package/lib/core/self-update.js +70 -0
- package/lib/core/session-health.d.ts +29 -5
- package/lib/core/session-health.js +28 -3
- package/lib/core/types.d.ts +126 -0
- package/lib/foreign/antigravity.d.ts +28 -0
- package/lib/foreign/antigravity.js +157 -0
- package/lib/foreign/bundle.d.ts +25 -0
- package/lib/foreign/bundle.js +79 -0
- package/lib/foreign/chatgpt.d.ts +6 -0
- package/lib/foreign/chatgpt.js +25 -0
- package/lib/foreign/claude-code.d.ts +3 -0
- package/lib/foreign/claude-code.js +85 -0
- package/lib/foreign/claude-sessions.d.ts +108 -0
- package/lib/foreign/claude-sessions.js +299 -0
- package/lib/foreign/cline.d.ts +6 -0
- package/lib/foreign/cline.js +27 -0
- package/lib/foreign/codex.d.ts +83 -0
- package/lib/foreign/codex.js +348 -0
- package/lib/foreign/continue.d.ts +9 -0
- package/lib/foreign/continue.js +65 -0
- package/lib/foreign/copilot.d.ts +39 -0
- package/lib/foreign/copilot.js +95 -0
- package/lib/foreign/crush.d.ts +11 -0
- package/lib/foreign/crush.js +57 -0
- package/lib/foreign/cursor.d.ts +87 -0
- package/lib/foreign/cursor.js +171 -0
- package/lib/foreign/dsh.d.ts +30 -0
- package/lib/foreign/dsh.js +101 -0
- package/lib/foreign/dsh4.d.ts +3 -0
- package/lib/foreign/dsh4.js +13 -0
- package/lib/foreign/gemini.d.ts +7 -0
- package/lib/foreign/gemini.js +44 -0
- package/lib/foreign/goose.d.ts +11 -0
- package/lib/foreign/goose.js +53 -0
- package/lib/foreign/grokbuild.d.ts +8 -0
- package/lib/foreign/grokbuild.js +25 -0
- package/lib/foreign/hermes.d.ts +2 -0
- package/lib/foreign/hermes.js +78 -0
- package/lib/foreign/kernel.d.ts +132 -0
- package/lib/foreign/kernel.js +569 -0
- package/lib/foreign/kilocode.d.ts +11 -0
- package/lib/foreign/kilocode.js +51 -0
- package/lib/foreign/kimi.d.ts +7 -0
- package/lib/foreign/kimi.js +47 -0
- package/lib/foreign/mimocode.d.ts +11 -0
- package/lib/foreign/mimocode.js +51 -0
- package/lib/foreign/openclaw.d.ts +7 -0
- package/lib/foreign/openclaw.js +46 -0
- package/lib/foreign/opencode.d.ts +11 -0
- package/lib/foreign/opencode.js +52 -0
- package/lib/foreign/pi.d.ts +7 -0
- package/lib/foreign/pi.js +48 -0
- package/lib/foreign/platform-paths.d.ts +66 -0
- package/lib/foreign/platform-paths.js +141 -0
- package/lib/foreign/qoder.d.ts +10 -0
- package/lib/foreign/qoder.js +49 -0
- package/lib/foreign/qwen.d.ts +7 -0
- package/lib/foreign/qwen.js +45 -0
- package/lib/foreign/read-antigravity.d.ts +57 -0
- package/lib/foreign/read-antigravity.js +504 -0
- package/lib/foreign/read-chatgpt.d.ts +20 -0
- package/lib/foreign/read-chatgpt.js +509 -0
- package/lib/foreign/read-claude-code.d.ts +24 -0
- package/lib/foreign/read-claude-code.js +234 -0
- package/lib/foreign/read-cline.d.ts +53 -0
- package/lib/foreign/read-cline.js +479 -0
- package/lib/foreign/read-codex.d.ts +75 -0
- package/lib/foreign/read-codex.js +842 -0
- package/lib/foreign/read-continue.d.ts +87 -0
- package/lib/foreign/read-continue.js +489 -0
- package/lib/foreign/read-copilot.d.ts +42 -0
- package/lib/foreign/read-copilot.js +267 -0
- package/lib/foreign/read-crush.d.ts +54 -0
- package/lib/foreign/read-crush.js +478 -0
- package/lib/foreign/read-cursor.d.ts +141 -0
- package/lib/foreign/read-cursor.js +705 -0
- package/lib/foreign/read-dsh.d.ts +43 -0
- package/lib/foreign/read-dsh.js +205 -0
- package/lib/foreign/read-dsh4.d.ts +14 -0
- package/lib/foreign/read-dsh4.js +27 -0
- package/lib/foreign/read-gemini.d.ts +55 -0
- package/lib/foreign/read-gemini.js +273 -0
- package/lib/foreign/read-goose.d.ts +25 -0
- package/lib/foreign/read-goose.js +322 -0
- package/lib/foreign/read-grokbuild.d.ts +34 -0
- package/lib/foreign/read-grokbuild.js +455 -0
- package/lib/foreign/read-hermes.d.ts +74 -0
- package/lib/foreign/read-hermes.js +690 -0
- package/lib/foreign/read-kilocode.d.ts +17 -0
- package/lib/foreign/read-kilocode.js +46 -0
- package/lib/foreign/read-kimi.d.ts +63 -0
- package/lib/foreign/read-kimi.js +719 -0
- package/lib/foreign/read-mimocode.d.ts +12 -0
- package/lib/foreign/read-mimocode.js +56 -0
- package/lib/foreign/read-openclaw.d.ts +51 -0
- package/lib/foreign/read-openclaw.js +445 -0
- package/lib/foreign/read-opencode.d.ts +150 -0
- package/lib/foreign/read-opencode.js +896 -0
- package/lib/foreign/read-pi.d.ts +56 -0
- package/lib/foreign/read-pi.js +411 -0
- package/lib/foreign/read-qoder.d.ts +54 -0
- package/lib/foreign/read-qoder.js +317 -0
- package/lib/foreign/read-qwen.d.ts +40 -0
- package/lib/foreign/read-qwen.js +326 -0
- package/lib/foreign/read-reasonix.d.ts +66 -0
- package/lib/foreign/read-reasonix.js +537 -0
- package/lib/foreign/read-teleagent.d.ts +15 -0
- package/lib/foreign/read-teleagent.js +68 -0
- package/lib/foreign/read-trae.d.ts +67 -0
- package/lib/foreign/read-trae.js +492 -0
- package/lib/foreign/read-vibe.d.ts +28 -0
- package/lib/foreign/read-vibe.js +364 -0
- package/lib/foreign/read-workbuddy.d.ts +49 -0
- package/lib/foreign/read-workbuddy.js +346 -0
- package/lib/foreign/read-zcode.d.ts +12 -0
- package/lib/foreign/read-zcode.js +38 -0
- package/lib/foreign/read-zed.d.ts +30 -0
- package/lib/foreign/read-zed.js +473 -0
- package/lib/foreign/reasonix.d.ts +6 -0
- package/lib/foreign/reasonix.js +20 -0
- package/lib/foreign/registry.d.ts +196 -0
- package/lib/foreign/registry.js +573 -0
- package/lib/foreign/session-ir.d.ts +186 -0
- package/lib/foreign/session-ir.js +427 -0
- package/lib/foreign/session-read.d.ts +102 -0
- package/lib/foreign/session-read.js +254 -0
- package/lib/foreign/session-source.d.ts +216 -0
- package/lib/foreign/session-source.js +453 -0
- package/lib/foreign/source-modules.d.ts +45 -0
- package/lib/foreign/source-modules.js +52 -0
- package/lib/foreign/sqlite.d.ts +61 -0
- package/lib/foreign/sqlite.js +404 -0
- package/lib/foreign/teleagent.d.ts +11 -0
- package/lib/foreign/teleagent.js +53 -0
- package/lib/foreign/trae.d.ts +6 -0
- package/lib/foreign/trae.js +20 -0
- package/lib/foreign/truth-table.d.ts +62 -0
- package/lib/foreign/truth-table.js +333 -0
- package/lib/foreign/types.d.ts +272 -0
- package/lib/foreign/types.js +2 -0
- package/lib/foreign/vibe.d.ts +6 -0
- package/lib/foreign/vibe.js +23 -0
- package/lib/foreign/workbuddy.d.ts +7 -0
- package/lib/foreign/workbuddy.js +45 -0
- package/lib/foreign/zcode.d.ts +11 -0
- package/lib/foreign/zcode.js +51 -0
- package/lib/foreign/zed.d.ts +11 -0
- package/lib/foreign/zed.js +53 -0
- package/lib/index.d.ts +154 -13
- package/lib/index.js +661 -84
- package/lib/market/github-repos.d.ts +28 -0
- package/lib/market/github-repos.js +43 -1
- package/lib/market/types.d.ts +1 -3
- package/lib/profiles/dsh-profile-manager.d.ts +54 -2
- package/lib/profiles/dsh-profile-manager.js +182 -11
- package/lib/profiles/dsh-profile-shared.d.ts +47 -0
- package/lib/profiles/dsh-profile-shared.js +15 -1
- package/lib/profiles/index.d.ts +1 -1
- package/lib/profiles/index.js +1 -1
- package/lib/routes/consult.js +51 -5
- package/lib/routes/foreign-context.d.ts +43 -0
- package/lib/routes/foreign-context.js +65 -0
- package/lib/routes/foreign.d.ts +11 -0
- package/lib/routes/foreign.js +208 -0
- package/lib/routes/import.d.ts +8 -0
- package/lib/routes/import.js +22 -1
- package/lib/routes/index.d.ts +2 -2
- package/lib/routes/index.js +4 -0
- package/lib/routes/kit.d.ts +4 -3
- package/lib/routes/market.js +0 -1
- package/lib/routes/prefs.d.ts +2 -1
- package/lib/routes/prefs.js +14 -2
- package/lib/routes/recovery.js +363 -3
- package/lib/routes/session-export.d.ts +117 -0
- package/lib/routes/session-export.js +270 -0
- package/lib/routes/snapshots.js +12 -2
- package/lib/routes/sync.js +82 -10
- package/lib/security/redaction.d.ts +14 -0
- package/lib/security/redaction.js +24 -9
- package/lib/security/secret-scanner.d.ts +27 -0
- package/lib/security/secret-scanner.js +54 -1
- package/lib/sync/autosync-scheduler.d.ts +13 -1
- package/lib/sync/autosync-scheduler.js +49 -26
- package/lib/sync/backup-files.js +6 -0
- package/lib/sync/gist/gist-transport.d.ts +91 -0
- package/lib/sync/gist/gist-transport.js +406 -0
- package/lib/sync/gist/messages.d.ts +22 -0
- package/lib/sync/gist/messages.js +46 -0
- package/lib/sync/s3/messages.d.ts +53 -0
- package/lib/sync/s3/messages.js +83 -0
- package/lib/sync/s3/s3-providers.d.ts +78 -0
- package/lib/sync/s3/s3-providers.js +156 -0
- package/lib/sync/s3/s3-transport.d.ts +126 -0
- package/lib/sync/s3/s3-transport.js +551 -0
- package/lib/sync/s3/sigv4.d.ts +107 -0
- package/lib/sync/s3/sigv4.js +196 -0
- package/lib/sync/sync-config.d.ts +250 -4
- package/lib/sync/sync-config.js +658 -57
- package/lib/sync/sync-engine.d.ts +1 -0
- package/lib/sync/sync-engine.js +4 -2
- package/lib/sync/sync-history.d.ts +1 -1
- package/lib/sync/webdav/webdav-transport.d.ts +31 -3
- package/lib/sync/webdav/webdav-transport.js +102 -18
- package/lib/ui/commands.d.ts +4 -3
- package/lib/ui/commands.js +41 -9
- package/lib/ui/disk-usage-view.d.ts +44 -0
- package/lib/ui/disk-usage-view.js +55 -1
- package/lib/ui/dsh-profiles-view.d.ts +53 -0
- package/lib/ui/dsh-profiles-view.js +56 -0
- package/lib/ui/foreign-view.d.ts +162 -0
- package/lib/ui/foreign-view.js +225 -0
- package/lib/ui/i18n.d.ts +77 -0
- package/lib/ui/i18n.js +164 -0
- package/lib/ui/session-inventory-view.d.ts +106 -0
- package/lib/ui/session-inventory-view.js +58 -0
- package/lib/ui/session-layout-view.d.ts +265 -0
- package/lib/ui/session-layout-view.js +271 -0
- package/lib/ui/sync-repository-picker.d.ts +98 -0
- package/lib/ui/sync-repository-picker.js +145 -0
- package/lib/ui/sync-settings-view.d.ts +143 -4
- package/lib/ui/sync-settings-view.js +231 -7
- package/lib/ui/types.d.ts +47 -0
- package/lib/utils/asar-read.d.ts +113 -0
- package/lib/utils/asar-read.js +523 -0
- package/lib/utils/env-lock.js +7 -2
- package/lib/utils/patch-yaml.d.ts +25 -0
- package/lib/utils/patch-yaml.js +62 -0
- package/lib/utils/paths.d.ts +10 -1
- package/lib/utils/paths.js +24 -3
- package/lib/utils/recursive-walk.js +12 -13
- package/lib/utils/session-format.d.ts +35 -2
- package/lib/utils/session-format.js +131 -5
- package/lib/utils/session-health-scan.d.ts +7 -1
- package/lib/utils/session-health-scan.js +369 -12
- package/lib/utils/session-layout-repair-service.d.ts +98 -0
- package/lib/utils/session-layout-repair-service.js +457 -0
- package/lib/utils/session-log-repair.d.ts +27 -0
- package/lib/utils/session-log-repair.js +233 -62
- package/lib/utils/session-repair-service.d.ts +32 -3
- package/lib/utils/session-repair-service.js +148 -9
- package/lib/utils/session-row-facts.d.ts +73 -0
- package/lib/utils/session-row-facts.js +182 -0
- package/lib/utils/session-verify.d.ts +118 -0
- package/lib/utils/session-verify.js +705 -0
- package/lib/utils/shared-constants.d.ts +59 -0
- package/lib/utils/shared-constants.js +71 -0
- package/package.json +1 -1
- package/src/adapters/credentials.test.ts +27 -0
- package/src/adapters/credentials.ts +6 -3
- package/src/adapters/file-collection.ts +33 -8
- package/src/adapters/files.test.ts +222 -0
- package/src/adapters/mcp.test.ts +43 -0
- package/src/adapters/mcp.ts +37 -14
- package/src/adapters/plugin-files.ts +34 -4
- package/src/adapters/plugins.test.ts +241 -0
- package/src/adapters/plugins.ts +201 -53
- package/src/adapters/prompts.test.ts +49 -0
- package/src/adapters/prompts.ts +41 -20
- package/src/adapters/providers.test.ts +16 -0
- package/src/adapters/providers.ts +4 -3
- package/src/adapters/self.test.ts +77 -0
- package/src/adapters/self.ts +75 -0
- package/src/adapters/sessions.test.ts +77 -0
- package/src/adapters/sessions.ts +47 -1
- package/src/adapters/settings.test.ts +78 -0
- package/src/adapters/settings.ts +42 -6
- package/src/adapters/skills.ts +221 -3
- package/src/adapters/test-helpers.ts +43 -5
- package/src/adapters/workspaces-dup-id.test.ts +144 -0
- package/src/adapters/workspaces.test.ts +10 -0
- package/src/adapters/workspaces.ts +97 -5
- package/src/cli/actions.test.ts +117 -2
- package/src/cli/actions.ts +132 -12
- package/src/cli/help.ts +570 -0
- package/src/cli/import-source.test.ts +193 -0
- package/src/cli/import-source.ts +229 -0
- package/src/cli/index.ts +129 -94
- package/src/cli/web/client-script.ts +12 -0
- package/src/cli/web/console-fixes.test.ts +36 -0
- package/src/cli/web/http.ts +7 -1
- package/src/cli/web/page.ts +108 -25
- package/src/cli/web/routes.ts +23 -4
- package/src/cli/web/script-anchor.test.ts +33 -0
- package/src/cli/web/server.ts +28 -2
- package/src/cli/web/web.test.ts +447 -4
- package/src/client/ConfigManagerSection.tsx +118 -63
- package/src/client/about/AboutPanel.tsx +42 -3
- package/src/client/about/PluginUpdateDialog.tsx +185 -0
- package/src/client/about/ReleaseBody.tsx +144 -0
- package/src/client/about/ReleaseNotesDialog.tsx +3 -130
- package/src/client/about/about-view.ts +7 -5
- package/src/client/about/plugin-update-view.test.ts +25 -0
- package/src/client/about/plugin-update-view.ts +26 -0
- package/src/client/about/release-notes-view.test.ts +33 -0
- package/src/client/about/release-notes-view.ts +34 -0
- package/src/client/api.ts +145 -1
- package/src/client/common/Icon.tsx +3 -0
- package/src/client/common/RunsCenter.tsx +8 -2
- package/src/client/common/Select.tsx +9 -2
- package/src/client/common/info-hint-guard.test.ts +63 -18
- package/src/client/common/plan-text-redaction.test.ts +193 -8
- package/src/client/common/routes.ts +15 -0
- package/src/client/config-manager.module.css +506 -354
- package/src/client/css-scale-guard.test.ts +122 -0
- package/src/client/css-token-guard.test.ts +82 -0
- package/src/client/environment/EnvironmentPanel.tsx +45 -16
- package/src/client/{snapshots → environment/maintenance}/DiskUsageCard.tsx +21 -17
- package/src/client/environment/profiles-incomplete-ui.test.ts +103 -0
- package/src/client/export/ExportView.tsx +9 -2
- package/src/client/{snapshots → home}/BackupScheduleCard.tsx +13 -4
- package/src/client/home/HomePanel.tsx +69 -157
- package/src/client/icon-layer-guard.test.ts +1 -1
- package/src/client/import/ForeignImportView.tsx +318 -0
- package/src/client/import/ImportWizardView.tsx +3 -1
- package/src/client/import/foreign-import-view-guard.test.ts +195 -0
- package/src/client/import/import-file-select.test.ts +6 -6
- package/src/client/import/import-wizard-steps.tsx +17 -1
- package/src/client/import/use-import-wizard-controller.ts +3 -3
- package/src/client/index.ts +1 -1
- package/src/client/library/LibraryActions.tsx +31 -34
- package/src/client/library/LibraryPanel.tsx +4 -1
- package/src/client/{snapshots → library}/RestorePlanView.tsx +1 -1
- package/src/client/{snapshots → library}/files-layout.test.ts +2 -2
- package/src/client/{snapshots → library}/report-dismiss.test.ts +26 -3
- package/src/client/library/task-panel-visibility.test.ts +25 -17
- package/src/client/locales.ts +278 -36
- package/src/client/lucide-icons.d.ts +1 -0
- package/src/client/market/MarketPanel.tsx +11 -2
- package/src/client/recovery/IncompleteCopiesSection.tsx +132 -0
- package/src/client/recovery/RecoveryPanel.tsx +486 -59
- package/src/client/recovery/recovery-api.ts +30 -0
- package/src/client/recovery/recovery-incomplete-copies.test.ts +151 -0
- package/src/client/recovery/recovery-locales.test.ts +88 -0
- package/src/client/recovery/recovery-locales.ts +321 -6
- package/src/client/recovery/recovery-panel-layout.test.ts +52 -0
- package/src/client/recovery/recovery-view.ts +92 -2
- package/src/client/run-store.test.ts +201 -89
- package/src/client/run-store.ts +114 -143
- package/src/client/session-export/session-export-view.test.ts +103 -0
- package/src/client/session-export/session-export-view.ts +118 -0
- package/src/client/sync/ChannelConfigDialog.tsx +219 -14
- package/src/client/sync/SyncChannelEntryCard.tsx +52 -4
- package/src/client/sync/SyncLogList.tsx +1 -1
- package/src/client/sync/SyncPanel.tsx +166 -102
- package/src/client/sync/SyncRepositoryPicker.tsx +216 -0
- package/src/client/sync/SyncSettingsView.test.ts +6 -1
- package/src/client/sync/history-model.test.ts +94 -57
- package/src/client/sync/history-model.ts +44 -25
- package/src/client/sync/sync-api.test.ts +56 -0
- package/src/client/sync/sync-api.ts +92 -0
- package/src/client/sync/sync-locales.ts +162 -2
- package/src/client/sync/sync-view.test.ts +3 -8
- package/src/client/sync/sync-view.ts +111 -21
- package/src/core/analyzer-cache.test.ts +47 -0
- package/src/core/analyzer.ts +115 -14
- package/src/core/backup-plan.test.ts +35 -0
- package/src/core/backup-plan.ts +19 -1
- package/src/core/backup.test.ts +37 -1
- package/src/core/backup.ts +27 -6
- package/src/core/cache-cleaner.test.ts +120 -1
- package/src/core/cache-cleaner.ts +59 -22
- package/src/core/checkpoint.test.ts +665 -0
- package/src/core/checkpoint.ts +1614 -0
- package/src/core/credential-plan-consistency.test.ts +93 -0
- package/src/core/incident-wiring.test.ts +6 -2
- package/src/core/journal.test.ts +70 -0
- package/src/core/journal.ts +68 -0
- package/src/core/messages.ts +26 -0
- package/src/core/model-tools.ts +3 -0
- package/src/core/patch-layers.test.ts +94 -0
- package/src/core/patch-layers.ts +150 -0
- package/src/core/restore.ts +59 -3
- package/src/core/rollback.ts +6 -3
- package/src/core/section-content-consistency.test.ts +185 -0
- package/src/core/self-update.test.ts +110 -0
- package/src/core/self-update.ts +118 -0
- package/src/core/session-health.test.ts +91 -1
- package/src/core/session-health.ts +56 -9
- package/src/core/types.ts +127 -1
- package/src/foreign/antigravity.test.ts +271 -0
- package/src/foreign/antigravity.ts +188 -0
- package/src/foreign/bundle.ts +108 -0
- package/src/foreign/chatgpt.test.ts +279 -0
- package/src/foreign/chatgpt.ts +30 -0
- package/src/foreign/claude-code.test.ts +234 -0
- package/src/foreign/claude-code.ts +106 -0
- package/src/foreign/claude-sessions-bytes.test.ts +227 -0
- package/src/foreign/claude-sessions.test.ts +180 -0
- package/src/foreign/claude-sessions.ts +461 -0
- package/src/foreign/cline.test.ts +274 -0
- package/src/foreign/cline.ts +32 -0
- package/src/foreign/codex.test.ts +585 -0
- package/src/foreign/codex.ts +409 -0
- package/src/foreign/continue.test.ts +365 -0
- package/src/foreign/continue.ts +73 -0
- package/src/foreign/copilot.test.ts +273 -0
- package/src/foreign/copilot.ts +133 -0
- package/src/foreign/crush.test.ts +234 -0
- package/src/foreign/crush.ts +66 -0
- package/src/foreign/cursor.test.ts +509 -0
- package/src/foreign/cursor.ts +259 -0
- package/src/foreign/dsh.test.ts +198 -0
- package/src/foreign/dsh.ts +117 -0
- package/src/foreign/dsh4.test.ts +127 -0
- package/src/foreign/dsh4.ts +15 -0
- package/src/foreign/file-budget.test.ts +256 -0
- package/src/foreign/fixtures/antigravity/README.md +18 -0
- package/src/foreign/fixtures/antigravity/basic/gemini/antigravity/mcp_config.json +13 -0
- package/src/foreign/fixtures/antigravity/basic/gemini/config/mcp_config.json +24 -0
- package/src/foreign/fixtures/antigravity/empty/gemini/antigravity/mcp_config.json +0 -0
- package/src/foreign/fixtures/antigravity/empty/gemini/antigravity/mcp_oauth_tokens.json +0 -0
- package/src/foreign/fixtures/antigravity/empty/gemini/config/mcp_config.json +0 -0
- package/src/foreign/fixtures/codex/README.md +31 -0
- package/src/foreign/fixtures/codex/basic/.agents/skills/hello/SKILL.md +6 -0
- package/src/foreign/fixtures/codex/basic/.agents/skills/wrapper/nested/SKILL.md +6 -0
- package/src/foreign/fixtures/codex/basic/.codex/AGENTS.md +4 -0
- package/src/foreign/fixtures/codex/basic/.codex/config.toml +28 -0
- package/src/foreign/fixtures/codex/malformed/.codex/config.toml +3 -0
- package/src/foreign/fixtures/codex/override/.codex/AGENTS.md +1 -0
- package/src/foreign/fixtures/codex/override/.codex/AGENTS.override.md +3 -0
- package/src/foreign/fixtures/codex/sessions/.codex/archived_sessions/rollout-2026-10-05T09-00-00-22222222-2222-4222-8222-222222222222.jsonl +2 -0
- package/src/foreign/fixtures/codex/sessions/.codex/sessions/2026/10/06/rollout-2026-10-06T10-00-00-11111111-1111-4111-8111-111111111111.jsonl +15 -0
- package/src/foreign/fixtures/codex/sessions/.codex/sessions/2026/10/06/rollout-2026-10-06T11-00-00-33333333-3333-4333-8333-333333333333.jsonl +2 -0
- package/src/foreign/fixtures/codex/sessions/.codex/sessions/2026/10/06/rollout-2026-10-06T11-30-00-55555555-5555-4555-8555-555555555555.jsonl +2 -0
- package/src/foreign/fixtures/codex/sessions/.codex/sessions/2026/10/06/rollout-2026-10-06T12-00-00-44444444-4444-4444-8444-444444444444.jsonl +2 -0
- package/src/foreign/fixtures/codex/sessions/.codex/sessions/notes.jsonl +1 -0
- package/src/foreign/fixtures/copilot/README.md +22 -0
- package/src/foreign/fixtures/copilot/basic/copilot-instructions.md +3 -0
- package/src/foreign/fixtures/copilot/basic/instructions/empty.instructions.md +1 -0
- package/src/foreign/fixtures/copilot/basic/instructions/repo.instructions.md +5 -0
- package/src/foreign/fixtures/copilot/basic/mcp-config.json +24 -0
- package/src/foreign/fixtures/copilot/basic/skills/hello/SKILL.md +6 -0
- package/src/foreign/fixtures/copilot/overridden/mcp-config.json +10 -0
- package/src/foreign/fixtures/cursor/README.md +17 -0
- package/src/foreign/fixtures/cursor/alt/.cursor/mcp.json +5 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/mcp.json +18 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/rules/agent.mdc +5 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/rules/always.mdc +6 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/rules/auto.mdc +7 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/rules/manual.mdc +3 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/skills/.hidden/SKILL.md +6 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/skills/hello/SKILL.md +6 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/skills/wrapper/nested/SKILL.md +6 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/skills/wrapper/nested/notes.md +1 -0
- package/src/foreign/fixtures/cursor/basic/.cursorrules +1 -0
- package/src/foreign/fixtures/cursor/basic/project/.cursor/mcp.json +9 -0
- package/src/foreign/fixtures/cursor/basic/project/.cursor/rules/project-always.mdc +5 -0
- package/src/foreign/fixtures/cursor/basic/project/.cursor/skills/hello/SKILL.md +6 -0
- package/src/foreign/fixtures/cursor/basic/project/.cursorrules +1 -0
- package/src/foreign/fixtures/cursor/empty/.cursor/mcp.json +0 -0
- package/src/foreign/fixtures/cursor/malformed/.cursor/mcp.json +3 -0
- package/src/foreign/fixtures/cursor/malformed/.cursor/rules/broken.mdc +6 -0
- package/src/foreign/fixtures/cursor/shape/.cursor/mcp.json +3 -0
- package/src/foreign/fixtures/hermes/README.md +14 -0
- package/src/foreign/fixtures/hermes/basic/SOUL.md +3 -0
- package/src/foreign/fixtures/hermes/basic/config.yaml +48 -0
- package/src/foreign/fixtures/hermes/basic/dotenv.fixture +1 -0
- package/src/foreign/fixtures/hermes/basic/memories/MEMORY.md +1 -0
- package/src/foreign/fixtures/hermes/basic/memories/USER.md +1 -0
- package/src/foreign/fixtures/hermes/basic/skills/se-team-design/SKILL.md +6 -0
- package/src/foreign/fixtures/hermes/basic/skills/se-team-design/examples/usage.md +1 -0
- package/src/foreign/fixtures/hermes/basic/skills/software-development/dogfood/SKILL.md +6 -0
- package/src/foreign/fixtures/hermes/basic/skills/software-development/dogfood/notes.md +1 -0
- package/src/foreign/fixtures/hermes/basic/state.db +1 -0
- package/src/foreign/fixtures/hermes/empty/config.yaml +0 -0
- package/src/foreign/gemini.test.ts +291 -0
- package/src/foreign/gemini.ts +52 -0
- package/src/foreign/goose.test.ts +196 -0
- package/src/foreign/goose.ts +62 -0
- package/src/foreign/grokbuild.test.ts +246 -0
- package/src/foreign/grokbuild.ts +30 -0
- package/src/foreign/hermes.test.ts +545 -0
- package/src/foreign/hermes.ts +86 -0
- package/src/foreign/kernel-credentials.test.ts +88 -0
- package/src/foreign/kernel-workspaces.test.ts +88 -0
- package/src/foreign/kernel.ts +584 -0
- package/src/foreign/kilocode.test.ts +186 -0
- package/src/foreign/kilocode.ts +60 -0
- package/src/foreign/kimi.test.ts +259 -0
- package/src/foreign/kimi.ts +55 -0
- package/src/foreign/mcp-value-shape.test.ts +286 -0
- package/src/foreign/mimocode.test.ts +178 -0
- package/src/foreign/mimocode.ts +60 -0
- package/src/foreign/openclaw.test.ts +248 -0
- package/src/foreign/openclaw.ts +54 -0
- package/src/foreign/opencode.test.ts +376 -0
- package/src/foreign/opencode.ts +61 -0
- package/src/foreign/pi.test.ts +275 -0
- package/src/foreign/pi.ts +56 -0
- package/src/foreign/platform-paths.ts +156 -0
- package/src/foreign/qoder.test.ts +266 -0
- package/src/foreign/qoder.ts +57 -0
- package/src/foreign/qwen.test.ts +203 -0
- package/src/foreign/qwen.ts +53 -0
- package/src/foreign/read-antigravity.ts +569 -0
- package/src/foreign/read-chatgpt.ts +506 -0
- package/src/foreign/read-claude-code.ts +264 -0
- package/src/foreign/read-cline.ts +517 -0
- package/src/foreign/read-codex.ts +823 -0
- package/src/foreign/read-continue.ts +557 -0
- package/src/foreign/read-copilot.ts +304 -0
- package/src/foreign/read-crush.ts +503 -0
- package/src/foreign/read-cursor.ts +778 -0
- package/src/foreign/read-dsh.ts +215 -0
- package/src/foreign/read-dsh4.ts +35 -0
- package/src/foreign/read-gemini.ts +306 -0
- package/src/foreign/read-goose.ts +333 -0
- package/src/foreign/read-grokbuild.ts +475 -0
- package/src/foreign/read-hermes.ts +724 -0
- package/src/foreign/read-kilocode.ts +55 -0
- package/src/foreign/read-kimi.ts +768 -0
- package/src/foreign/read-mimocode.ts +66 -0
- package/src/foreign/read-openclaw.ts +505 -0
- package/src/foreign/read-opencode.ts +994 -0
- package/src/foreign/read-pi.ts +459 -0
- package/src/foreign/read-qoder.ts +351 -0
- package/src/foreign/read-qwen.ts +342 -0
- package/src/foreign/read-reasonix.ts +590 -0
- package/src/foreign/read-teleagent.ts +82 -0
- package/src/foreign/read-trae.ts +488 -0
- package/src/foreign/read-vibe.ts +353 -0
- package/src/foreign/read-workbuddy.ts +374 -0
- package/src/foreign/read-zcode.ts +48 -0
- package/src/foreign/read-zed.ts +479 -0
- package/src/foreign/reasonix.test.ts +336 -0
- package/src/foreign/reasonix.ts +25 -0
- package/src/foreign/registry.test.ts +377 -0
- package/src/foreign/registry.ts +750 -0
- package/src/foreign/session-ir.test.ts +189 -0
- package/src/foreign/session-ir.ts +614 -0
- package/src/foreign/session-read.ts +295 -0
- package/src/foreign/session-source.ts +625 -0
- package/src/foreign/skill-file-caps.test.ts +171 -0
- package/src/foreign/source-modules.ts +86 -0
- package/src/foreign/source-registry.test.ts +190 -0
- package/src/foreign/sqlite.test.ts +313 -0
- package/src/foreign/sqlite.ts +446 -0
- package/src/foreign/teleagent.test.ts +147 -0
- package/src/foreign/teleagent.ts +62 -0
- package/src/foreign/trae.test.ts +316 -0
- package/src/foreign/trae.ts +25 -0
- package/src/foreign/truncation-report.test.ts +238 -0
- package/src/foreign/truth-table.ts +453 -0
- package/src/foreign/types.ts +312 -0
- package/src/foreign/vibe.test.ts +209 -0
- package/src/foreign/vibe.ts +28 -0
- package/src/foreign/workbuddy.test.ts +207 -0
- package/src/foreign/workbuddy.ts +53 -0
- package/src/foreign/zcode.test.ts +224 -0
- package/src/foreign/zcode.ts +60 -0
- package/src/foreign/zed.test.ts +240 -0
- package/src/foreign/zed.ts +62 -0
- package/src/index.facade.test.ts +254 -16
- package/src/index.ts +704 -82
- package/src/market/github-repos.test.ts +98 -1
- package/src/market/github-repos.ts +63 -1
- package/src/market/types.ts +3 -3
- package/src/profiles/dsh-profile-incomplete-copy.test.ts +177 -0
- package/src/profiles/dsh-profile-manager.test.ts +37 -0
- package/src/profiles/dsh-profile-manager.ts +188 -13
- package/src/profiles/dsh-profile-shared.ts +55 -1
- package/src/profiles/index.ts +2 -1
- package/src/routes/consult.ts +53 -4
- package/src/routes/foreign-context.ts +89 -0
- package/src/routes/foreign.test.ts +443 -0
- package/src/routes/foreign.ts +226 -0
- package/src/routes/import.ts +23 -1
- package/src/routes/index.ts +6 -2
- package/src/routes/kit.ts +4 -3
- package/src/routes/market.ts +0 -1
- package/src/routes/prefs.ts +15 -1
- package/src/routes/recovery.test.ts +167 -0
- package/src/routes/recovery.ts +331 -1
- package/src/routes/session-export.ts +308 -0
- package/src/routes/snapshots.ts +12 -2
- package/src/routes/sync.ts +91 -7
- package/src/security/redaction.test.ts +149 -0
- package/src/security/redaction.ts +25 -9
- package/src/security/secret-scanner.test.ts +186 -0
- package/src/security/secret-scanner.ts +57 -1
- package/src/sync/autosync-risk-tier.test.ts +61 -0
- package/src/sync/autosync-scheduler.test.ts +48 -1
- package/src/sync/autosync-scheduler.ts +50 -26
- package/src/sync/backup-files.ts +5 -0
- package/src/sync/gist/gist-msgkeys-catalog.test.ts +33 -0
- package/src/sync/gist/gist-msgkeys.test.ts +71 -0
- package/src/sync/gist/gist-transport.test.ts +308 -0
- package/src/sync/gist/gist-transport.ts +550 -0
- package/src/sync/gist/messages.ts +49 -0
- package/src/sync/retention-prune-all-off.test.ts +50 -0
- package/src/sync/s3/cloud-config.test.ts +283 -0
- package/src/sync/s3/messages.ts +102 -0
- package/src/sync/s3/s3-delete-index-404.test.ts +170 -0
- package/src/sync/s3/s3-delete-index-unreadable.test.ts +141 -0
- package/src/sync/s3/s3-msgkeys.test.ts +101 -0
- package/src/sync/s3/s3-providers.ts +213 -0
- package/src/sync/s3/s3-transport.test.ts +394 -0
- package/src/sync/s3/s3-transport.ts +651 -0
- package/src/sync/s3/s3-upload-index-404.test.ts +171 -0
- package/src/sync/s3/sigv4.test.ts +219 -0
- package/src/sync/s3/sigv4.ts +283 -0
- package/src/sync/sync-config.test.ts +237 -5
- package/src/sync/sync-config.ts +841 -52
- package/src/sync/sync-engine-download-tombstone.test.ts +73 -0
- package/src/sync/sync-engine.ts +5 -3
- package/src/sync/sync-history.ts +1 -1
- package/src/sync/webdav/webdav-delete-index-404.test.ts +178 -0
- package/src/sync/webdav/webdav-delete-index-unreadable.test.ts +143 -0
- package/src/sync/webdav/webdav-msgkeys.test.ts +53 -0
- package/src/sync/webdav/webdav-transport.test.ts +9 -5
- package/src/sync/webdav/webdav-transport.ts +99 -17
- package/src/sync/webdav/webdav-upload-index-404.test.ts +177 -0
- package/src/ui/commands.test.ts +4 -1
- package/src/ui/commands.ts +46 -12
- package/src/ui/disk-usage-view.test.ts +63 -1
- package/src/ui/disk-usage-view.ts +93 -1
- package/src/ui/dsh-profiles-incomplete-view.test.ts +102 -0
- package/src/ui/dsh-profiles-view.ts +94 -0
- package/src/ui/foreign-view.test.ts +241 -0
- package/src/ui/foreign-view.ts +362 -0
- package/src/ui/i18n.ts +164 -0
- package/src/ui/mid-ellipsis.test.ts +5 -10
- package/src/ui/session-inventory-view.test.ts +142 -2
- package/src/ui/session-inventory-view.ts +127 -0
- package/src/ui/session-layout-view.test.ts +361 -0
- package/src/ui/session-layout-view.ts +444 -0
- package/src/ui/sync-repository-picker.test.ts +130 -0
- package/src/ui/sync-repository-picker.ts +180 -0
- package/src/ui/sync-settings-view.test.ts +166 -0
- package/src/ui/sync-settings-view.ts +319 -9
- package/src/ui/types.ts +42 -0
- package/src/utils/asar-read.test.ts +330 -0
- package/src/utils/asar-read.ts +606 -0
- package/src/utils/env-lock.test.ts +55 -0
- package/src/utils/env-lock.ts +6 -1
- package/src/utils/patch-yaml.test.ts +112 -0
- package/src/utils/patch-yaml.ts +72 -0
- package/src/utils/paths.test.ts +63 -0
- package/src/utils/paths.ts +25 -3
- package/src/utils/recursive-walk.test.ts +20 -0
- package/src/utils/recursive-walk.ts +12 -13
- package/src/utils/session-format.test.ts +113 -2
- package/src/utils/session-format.ts +127 -5
- package/src/utils/session-health-scan.test.ts +364 -1
- package/src/utils/session-health-scan.ts +434 -15
- package/src/utils/session-layout-repair-service.test.ts +362 -0
- package/src/utils/session-layout-repair-service.ts +568 -0
- package/src/utils/session-log-repair.test.ts +260 -1
- package/src/utils/session-log-repair.ts +294 -55
- package/src/utils/session-repair-service.test.ts +148 -1
- package/src/utils/session-repair-service.ts +165 -10
- package/src/utils/session-row-facts.test.ts +159 -0
- package/src/utils/session-row-facts.ts +187 -0
- package/src/utils/session-verify.test.ts +762 -0
- package/src/utils/session-verify.ts +784 -0
- package/src/utils/shared-constants.ts +82 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* m-gist-channel:GitHub Gist 通道(SyncTransport 的 gist 实现)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独一条通道:GitHub Gist 的 REST API 只靠一个 token 就能读写远端口袋仓库
|
|
5
|
+
* (竞品 \`@dickpy/dsh-cloud-sync\` 的 \`type:'gist'\` 走 token + gistId 同一族),
|
|
6
|
+
* 对「本机没有 git 二进制 / 只有一个 GitHub 账号」的用户是成本最低的远端。
|
|
7
|
+
*
|
|
8
|
+
* 远端布局(gist 是**扁平文件**命名空间,故用文件名前缀隔离):
|
|
9
|
+
* <filePrefix>-index.json —— 索引(SyncSnapshotMeta 数组)
|
|
10
|
+
* <filePrefix>-<id>.json —— 单个快照的完整载荷(SyncSnapshot 序列化)
|
|
11
|
+
* 缺省 filePrefix = \`dsh-sync\`(改前缀 = 同一 gist 里换一套互不干扰的同步数据)。
|
|
12
|
+
*
|
|
13
|
+
* 设计:
|
|
14
|
+
* - list:GET /gists/{id} → 取索引文件内容(内容被 GitHub 截断时回落 raw_url)→ 按 createdAt 升序;
|
|
15
|
+
* - upload:GET 当前 gist → 快照级跳过(同 id 且 sections hash 全等 → 零 PATCH)→
|
|
16
|
+
* 一次 PATCH 同时写快照文件与索引(索引最后落盘:快照成功才更新索引);
|
|
17
|
+
* - download:从 gist 载荷取文件内容;\`truncated: true\` 时回落 \`raw_url\`(跨源跳转剥离 Authorization);
|
|
18
|
+
* - delete:PATCH 里把快照文件置 null(GitHub 的删除语义)+ 写回合并后的索引;
|
|
19
|
+
* - 认证:\`Authorization: Bearer <token>\`(token 只从注入的 \`credentials.getToken()\` 读取,
|
|
20
|
+
* 绝不进日志 / 不进错误消息 / 不落盘;raw 下载不带 token —— gh 的 raw 地址本身不可猜且跨源)。
|
|
21
|
+
*
|
|
22
|
+
* **不做 blob 外置**(与 S3/WebDAV 通道的差别,刻意为之):gist 一次 GET 就把**全部文件内容**
|
|
23
|
+
* 吐回来、单文件内容超限会被截断、且文件数有上限 —— 把会话逐文件外置到 gist 会同时撞上这三条;
|
|
24
|
+
* 本通道定位是「配置类分区的低门槛远端」。会话这类大分区请走 git / webdav / s3 通道。
|
|
25
|
+
*/
|
|
26
|
+
import { requestOnce } from '../../utils/proxy.js';
|
|
27
|
+
import { parseJsonSafe } from '../../utils/json.js';
|
|
28
|
+
import { deserializeSnapshot, serializeSnapshot } from '../snapshot-json.js';
|
|
29
|
+
import { classifyHttpStatus, classifyNetworkErrorText, computeSnapshotMeta, DEFAULT_SYNC_TIMEOUT_MS, sectionsEqual, SyncTransportError, withSyncRetry, } from '../transport.js';
|
|
30
|
+
import { gistMsg } from './messages.js';
|
|
31
|
+
import { composeMsg } from '../s3/messages.js';
|
|
32
|
+
/** 快照 id 安全字符集:字母数字开头,仅 . _ -;防文件名注入 */
|
|
33
|
+
const SAFE_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
34
|
+
/** 保留 id(与索引文件名冲突) */
|
|
35
|
+
const RESERVED_IDS = new Set(['index']);
|
|
36
|
+
/** 缺省 GitHub API 根 */
|
|
37
|
+
export const GIST_DEFAULT_API_BASE_URL = 'https://api.github.com';
|
|
38
|
+
/** 缺省文件前缀 */
|
|
39
|
+
export const GIST_DEFAULT_FILE_PREFIX = 'dsh-sync';
|
|
40
|
+
/** GitHub API 版本(显式固定,避免随 GitHub 默认值漂移) */
|
|
41
|
+
const GITHUB_API_VERSION = '2022-11-28';
|
|
42
|
+
/** 错误消息里截取的响应体最大长度 */
|
|
43
|
+
const ERR_BODY_MAX = 500;
|
|
44
|
+
/** 跟随的重定向上限(gist raw 地址可能 302 到 CDN 直链) */
|
|
45
|
+
const MAX_REDIRECTS = 3;
|
|
46
|
+
const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
|
|
47
|
+
const REDACTED = '[REDACTED]';
|
|
48
|
+
/** Gist 通道错误:继承统一错误基类(kind / retryable / status 对上层可见)。 */
|
|
49
|
+
export class GistTransportError extends SyncTransportError {
|
|
50
|
+
constructor(message, opts = {}) {
|
|
51
|
+
super(message, opts);
|
|
52
|
+
this.name = 'GistTransportError';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** 缺省请求实现:经 utils/proxy 的出站请求(代理感知,零全局副作用),**不跟随重定向**。 */
|
|
56
|
+
const defaultRequest = async (method, url, options = {}) => {
|
|
57
|
+
const headers = {
|
|
58
|
+
'User-Agent': 'DSH-Config-Manager (Gist Client)',
|
|
59
|
+
...(options.headers ?? {}),
|
|
60
|
+
};
|
|
61
|
+
const timeoutMs = options.timeoutMs ?? 0;
|
|
62
|
+
let res;
|
|
63
|
+
try {
|
|
64
|
+
res = await requestOnce({
|
|
65
|
+
method,
|
|
66
|
+
url,
|
|
67
|
+
headers,
|
|
68
|
+
...(options.body !== undefined ? { body: options.body } : {}),
|
|
69
|
+
...(timeoutMs > 0 ? { timeoutMs } : {}),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
if (err instanceof Error && /timed out/i.test(err.message) && err.name !== 'TimeoutError') {
|
|
74
|
+
const timeoutError = new Error(err.message);
|
|
75
|
+
timeoutError.name = 'TimeoutError';
|
|
76
|
+
throw timeoutError;
|
|
77
|
+
}
|
|
78
|
+
throw err;
|
|
79
|
+
}
|
|
80
|
+
const responseHeaders = {};
|
|
81
|
+
res.headers.forEach((value, key) => { responseHeaders[key] = value; });
|
|
82
|
+
return {
|
|
83
|
+
status: res.status,
|
|
84
|
+
ok: res.status >= 200 && res.status < 300,
|
|
85
|
+
headers: responseHeaders,
|
|
86
|
+
text: async () => res.body.toString('utf8'),
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/** Gist id 形状(GitHub 为十六进制串) */
|
|
90
|
+
const GIST_ID_RE = /^[0-9a-f]{5,64}$/i;
|
|
91
|
+
/** 实现 SyncTransport 的 GitHub Gist 通道。 */
|
|
92
|
+
export class GistTransport {
|
|
93
|
+
type = 'gist';
|
|
94
|
+
o;
|
|
95
|
+
constructor(options) {
|
|
96
|
+
// t90(同 t79 口径):宿主 msg 是 **core 目录**的翻译器,`sync.gist.*` 键只在本地目录里
|
|
97
|
+
//(core 命中 0)⇒ 直接用会显示裸键名。composeMsg = 宿主优先 → 本地目录兜底 → 两边都没有才回退键名。
|
|
98
|
+
const msg = composeMsg(options.msg, gistMsg);
|
|
99
|
+
const gistId = typeof options.gistId === 'string' ? options.gistId.trim() : '';
|
|
100
|
+
if (gistId === '')
|
|
101
|
+
throw new GistTransportError(msg('sync.gist.gistIdRequired'));
|
|
102
|
+
if (!GIST_ID_RE.test(gistId))
|
|
103
|
+
throw new GistTransportError(msg('sync.gist.gistIdInvalid', { id: gistId }));
|
|
104
|
+
if (options.credentials === null || typeof options.credentials !== 'object'
|
|
105
|
+
|| typeof options.credentials.getToken !== 'function') {
|
|
106
|
+
throw new GistTransportError(msg('sync.gist.tokenRequired'));
|
|
107
|
+
}
|
|
108
|
+
const apiBaseUrl = (options.apiBaseUrl ?? GIST_DEFAULT_API_BASE_URL).trim().replace(/\/+$/, '');
|
|
109
|
+
let parsedBase;
|
|
110
|
+
try {
|
|
111
|
+
parsedBase = new URL(apiBaseUrl);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
throw new GistTransportError(msg('sync.gist.apiBaseUrlInvalid', { url: apiBaseUrl }));
|
|
115
|
+
}
|
|
116
|
+
if ((parsedBase.protocol !== 'http:' && parsedBase.protocol !== 'https:')
|
|
117
|
+
|| parsedBase.username !== '' || parsedBase.password !== '') {
|
|
118
|
+
throw new GistTransportError(msg('sync.gist.apiBaseUrlInvalid', { url: apiBaseUrl }));
|
|
119
|
+
}
|
|
120
|
+
const filePrefix = (options.filePrefix ?? GIST_DEFAULT_FILE_PREFIX).trim().replace(/^\/+/, '').replace(/\/+$/, '');
|
|
121
|
+
if (filePrefix === '' || filePrefix.includes('/') || filePrefix.includes('..')) {
|
|
122
|
+
throw new GistTransportError(msg('sync.gist.filePrefixInvalid', { prefix: filePrefix }));
|
|
123
|
+
}
|
|
124
|
+
this.o = {
|
|
125
|
+
gistId,
|
|
126
|
+
credentials: options.credentials,
|
|
127
|
+
apiBaseUrl,
|
|
128
|
+
filePrefix,
|
|
129
|
+
request: options.request ?? defaultRequest,
|
|
130
|
+
timeoutMs: options.timeoutMs ?? DEFAULT_SYNC_TIMEOUT_MS,
|
|
131
|
+
retry: options.retry ?? {},
|
|
132
|
+
msg,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/** gist 里的文件名(非密;供 UI/排障显示) */
|
|
136
|
+
get indexFileName() {
|
|
137
|
+
return this.o.filePrefix + '-index.json';
|
|
138
|
+
}
|
|
139
|
+
/** 列出远端已有快照(按 createdAt 升序);索引文件缺失视为空 gist。 */
|
|
140
|
+
async list() {
|
|
141
|
+
return await withSyncRetry(async () => {
|
|
142
|
+
const token = await this.tokenOnce();
|
|
143
|
+
const files = await this.readGistFiles(token);
|
|
144
|
+
const raw = await this.readFileText(files, this.indexFileName, token);
|
|
145
|
+
if (raw === null)
|
|
146
|
+
return [];
|
|
147
|
+
return this.parseIndex(raw, this.gistUrl(), token);
|
|
148
|
+
}, this.o.retry);
|
|
149
|
+
}
|
|
150
|
+
/** 上传快照(同 id 覆盖,幂等友好);内容未变时零 PATCH 直接返回远端 meta。 */
|
|
151
|
+
async upload(snapshot) {
|
|
152
|
+
this.assertSafeId(snapshot.id);
|
|
153
|
+
const token = await this.tokenOnce();
|
|
154
|
+
const meta = computeSnapshotMeta(snapshot);
|
|
155
|
+
const files = await this.readGistFiles(token);
|
|
156
|
+
const idxRaw = await this.readFileText(files, this.indexFileName, token);
|
|
157
|
+
const idxBefore = idxRaw === null ? [] : this.parseIndex(idxRaw, this.gistUrl(), token);
|
|
158
|
+
const existing = idxBefore.find((m) => m.id === snapshot.id);
|
|
159
|
+
if (existing !== undefined && sectionsEqual(existing, meta))
|
|
160
|
+
return existing;
|
|
161
|
+
const merged = idxBefore.filter((m) => m.id !== snapshot.id);
|
|
162
|
+
merged.push(meta);
|
|
163
|
+
merged.sort((a, b) => (a.createdAt < b.createdAt ? -1 : a.createdAt > b.createdAt ? 1 : 0));
|
|
164
|
+
// 一次 PATCH 写两个文件:快照先、索引后(索引是「有哪些快照」的权威视图)
|
|
165
|
+
const body = JSON.stringify({
|
|
166
|
+
files: {
|
|
167
|
+
[this.snapshotFileName(snapshot.id)]: { content: serializeSnapshot(snapshot) },
|
|
168
|
+
[this.indexFileName]: { content: JSON.stringify(merged) },
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
const res = await this.send('PATCH', this.gistUrl(), token, { body });
|
|
172
|
+
if (!res.ok) {
|
|
173
|
+
throw new GistTransportError(await this.failText('PATCH', this.gistUrl(), res, token), this.classify(res.status, await this.safeText(res)));
|
|
174
|
+
}
|
|
175
|
+
return meta;
|
|
176
|
+
}
|
|
177
|
+
/** 下载快照完整载荷;不存在的 id 必须抛错(契约)。 */
|
|
178
|
+
async download(id) {
|
|
179
|
+
this.assertSafeId(id);
|
|
180
|
+
return await withSyncRetry(async () => {
|
|
181
|
+
const token = await this.tokenOnce();
|
|
182
|
+
const files = await this.readGistFiles(token);
|
|
183
|
+
const fileName = this.snapshotFileName(id);
|
|
184
|
+
const entry = files[fileName];
|
|
185
|
+
if (entry === undefined) {
|
|
186
|
+
throw new GistTransportError(this.o.msg('sync.gist.fileMissing', { file: fileName }), { kind: 'notfound', retryable: false, status: 404 });
|
|
187
|
+
}
|
|
188
|
+
const raw = await this.readFileText(files, fileName, token);
|
|
189
|
+
if (raw === null) {
|
|
190
|
+
throw new GistTransportError(this.o.msg('sync.gist.fileMissing', { file: fileName }), { kind: 'notfound', retryable: false, status: 404 });
|
|
191
|
+
}
|
|
192
|
+
return this.parseSnapshot(raw, id);
|
|
193
|
+
}, this.o.retry);
|
|
194
|
+
}
|
|
195
|
+
/** 删除远端快照(不存在视为成功):PATCH 置 null + 写回摘除后的索引。 */
|
|
196
|
+
async delete(id) {
|
|
197
|
+
this.assertSafeId(id);
|
|
198
|
+
const token = await this.tokenOnce();
|
|
199
|
+
const files = await this.readGistFiles(token);
|
|
200
|
+
const idxRaw = await this.readFileText(files, this.indexFileName, token);
|
|
201
|
+
const idx = idxRaw === null ? [] : this.parseIndex(idxRaw, this.gistUrl(), token);
|
|
202
|
+
const fileName = this.snapshotFileName(id);
|
|
203
|
+
const existed = files[fileName] !== undefined;
|
|
204
|
+
const remaining = idx.filter((m) => m.id !== id);
|
|
205
|
+
if (!existed && remaining.length === idx.length)
|
|
206
|
+
return; // 文件与索引都没有 → 静默成功,不发 PATCH
|
|
207
|
+
const body = JSON.stringify({
|
|
208
|
+
files: {
|
|
209
|
+
[fileName]: null,
|
|
210
|
+
[this.indexFileName]: { content: JSON.stringify(remaining) },
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
const res = await this.send('PATCH', this.gistUrl(), token, { body });
|
|
214
|
+
if (!res.ok) {
|
|
215
|
+
throw new GistTransportError(await this.failText('PATCH', this.gistUrl(), res, token), this.classify(res.status, await this.safeText(res)));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/* ---------------- 内部实现 ---------------- */
|
|
219
|
+
assertSafeId(id) {
|
|
220
|
+
if (typeof id !== 'string' || !SAFE_ID_RE.test(id) || RESERVED_IDS.has(id)) {
|
|
221
|
+
throw new GistTransportError(this.o.msg('sync.gist.invalidSnapshotId', { id: JSON.stringify(id) }));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
gistUrl() {
|
|
225
|
+
return this.o.apiBaseUrl + '/gists/' + this.o.gistId;
|
|
226
|
+
}
|
|
227
|
+
snapshotFileName(id) {
|
|
228
|
+
return this.o.filePrefix + '-' + id + '.json';
|
|
229
|
+
}
|
|
230
|
+
/** 读取一次 token(失败 → 空串:请求按未认证失败,原因如实带回) */
|
|
231
|
+
async tokenOnce() {
|
|
232
|
+
try {
|
|
233
|
+
return await this.o.credentials.getToken();
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return '';
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/** 发送一次请求(注入 GitHub 认证头);网络错误/超时归一 */
|
|
240
|
+
async send(method, url, token, opts = {}) {
|
|
241
|
+
const headers = opts.raw === true
|
|
242
|
+
? { accept: 'application/vnd.github.raw', 'User-Agent': 'DSH-Config-Manager (Gist Client)' }
|
|
243
|
+
: {
|
|
244
|
+
accept: 'application/vnd.github+json',
|
|
245
|
+
'content-type': 'application/json',
|
|
246
|
+
'X-GitHub-Api-Version': GITHUB_API_VERSION,
|
|
247
|
+
...(token !== '' ? { authorization: 'Bearer ' + token } : {}),
|
|
248
|
+
};
|
|
249
|
+
try {
|
|
250
|
+
return await this.o.request(method, url, {
|
|
251
|
+
headers,
|
|
252
|
+
...(opts.body !== undefined ? { body: opts.body } : {}),
|
|
253
|
+
timeoutMs: this.o.timeoutMs,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
catch (err) {
|
|
257
|
+
if (this.isTimeout(err)) {
|
|
258
|
+
throw new GistTransportError(this.o.msg('sync.gist.timeout', { method, url, timeout: String(this.o.timeoutMs) }), { kind: 'timeout', retryable: true, cause: err });
|
|
259
|
+
}
|
|
260
|
+
const rawMsg = err instanceof Error
|
|
261
|
+
? (err.cause ? err.message + ' (' + String(err.cause.message ?? err.cause) + ')' : err.message)
|
|
262
|
+
: String(err);
|
|
263
|
+
throw new GistTransportError(this.o.msg('sync.gist.requestError', { method, url, err: this.mask(rawMsg, token) }), { ...classifyNetworkErrorText(rawMsg), cause: err });
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/** 读 gist(含全部文件条目);404 → 明确「gist 不存在或无权访问」 */
|
|
267
|
+
async readGistFiles(token) {
|
|
268
|
+
const url = this.gistUrl();
|
|
269
|
+
const res = await this.send('GET', url, token);
|
|
270
|
+
if (res.status === 404) {
|
|
271
|
+
throw new GistTransportError(this.o.msg('sync.gist.gistMissing', { id: this.o.gistId, status: '404' }), { kind: 'notfound', retryable: false, status: 404 });
|
|
272
|
+
}
|
|
273
|
+
if (!res.ok) {
|
|
274
|
+
const body = await this.safeText(res);
|
|
275
|
+
throw new GistTransportError(await this.failText('GET', url, res, token, body), this.classify(res.status, body));
|
|
276
|
+
}
|
|
277
|
+
let parsed;
|
|
278
|
+
try {
|
|
279
|
+
parsed = parseJsonSafe(await res.text());
|
|
280
|
+
}
|
|
281
|
+
catch (err) {
|
|
282
|
+
throw new GistTransportError(this.o.msg('sync.gist.indexInvalid', { url, err: this.mask(String(err?.message ?? ''), token) }), { kind: 'protocol', retryable: false });
|
|
283
|
+
}
|
|
284
|
+
const files = parsed?.files;
|
|
285
|
+
if (files === null || typeof files !== 'object' || Array.isArray(files)) {
|
|
286
|
+
throw new GistTransportError(this.o.msg('sync.gist.indexInvalid', { url, err: 'files missing' }), { kind: 'protocol', retryable: false });
|
|
287
|
+
}
|
|
288
|
+
return files;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* 取某个文件的内容:gist 载荷里直接有就用它;被 GitHub 截断(\`truncated\`)或内容缺失时
|
|
292
|
+
* 回落 \`raw_url\` 重新下载(跨源跳转剥离 Authorization —— gh 的 raw 地址本身不可猜)。
|
|
293
|
+
* 文件不存在 → null(调用方按各自语义处理)。
|
|
294
|
+
*/
|
|
295
|
+
async readFileText(files, fileName, token) {
|
|
296
|
+
const entry = files[fileName];
|
|
297
|
+
if (entry === undefined)
|
|
298
|
+
return null;
|
|
299
|
+
if (entry.truncated !== true && typeof entry.content === 'string')
|
|
300
|
+
return entry.content;
|
|
301
|
+
const rawUrl = typeof entry.raw_url === 'string' && entry.raw_url !== '' ? entry.raw_url : '';
|
|
302
|
+
if (rawUrl === '') {
|
|
303
|
+
throw new GistTransportError(this.o.msg('sync.gist.contentTruncated', { file: fileName, err: 'raw_url missing' }), { kind: 'protocol', retryable: false });
|
|
304
|
+
}
|
|
305
|
+
return await this.fetchRaw(rawUrl, fileName, token);
|
|
306
|
+
}
|
|
307
|
+
/** 下载 raw 内容(最多跟随 MAX_REDIRECTS 跳;raw 请求不带 token) */
|
|
308
|
+
async fetchRaw(rawUrl, fileName, token) {
|
|
309
|
+
let url = rawUrl;
|
|
310
|
+
for (let hop = 0; hop <= MAX_REDIRECTS; hop += 1) {
|
|
311
|
+
const res = await this.send('GET', url, '', { raw: true });
|
|
312
|
+
if (REDIRECT_STATUSES.has(res.status)) {
|
|
313
|
+
const location = res.headers?.['location'];
|
|
314
|
+
if (typeof location === 'string' && location !== '') {
|
|
315
|
+
try {
|
|
316
|
+
url = new URL(location, url).toString();
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
catch {
|
|
320
|
+
/* Location 非法 → 当作最终响应处理 */
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (!res.ok) {
|
|
325
|
+
throw new GistTransportError(this.o.msg('sync.gist.rawFetchFailed', { url, status: String(res.status) }), { ...classifyHttpStatus(res.status), status: res.status });
|
|
326
|
+
}
|
|
327
|
+
return await res.text();
|
|
328
|
+
}
|
|
329
|
+
throw new GistTransportError(this.o.msg('sync.gist.tooManyRedirects', { url: rawUrl, n: String(MAX_REDIRECTS) }), { kind: 'protocol', retryable: false });
|
|
330
|
+
}
|
|
331
|
+
parseIndex(raw, url, token) {
|
|
332
|
+
let parsed;
|
|
333
|
+
try {
|
|
334
|
+
parsed = parseJsonSafe(raw);
|
|
335
|
+
}
|
|
336
|
+
catch (err) {
|
|
337
|
+
throw new GistTransportError(this.o.msg('sync.gist.indexInvalid', { url, err: this.mask(String(err?.message ?? ''), token) }), { kind: 'protocol', retryable: false });
|
|
338
|
+
}
|
|
339
|
+
if (!Array.isArray(parsed)) {
|
|
340
|
+
throw new GistTransportError(this.o.msg('sync.gist.indexInvalid', { url, err: 'not an array' }), { kind: 'protocol', retryable: false });
|
|
341
|
+
}
|
|
342
|
+
const valid = (m) => typeof m === 'object' && m !== null
|
|
343
|
+
&& typeof m.id === 'string'
|
|
344
|
+
&& typeof m.createdAt === 'string'
|
|
345
|
+
&& typeof m.manifest === 'object' && m.manifest !== null
|
|
346
|
+
&& typeof m.sections === 'object' && m.sections !== null;
|
|
347
|
+
if (!parsed.every(valid)) {
|
|
348
|
+
throw new GistTransportError(this.o.msg('sync.gist.indexInvalid', { url, err: 'invalid entry' }), { kind: 'protocol', retryable: false });
|
|
349
|
+
}
|
|
350
|
+
const metas = parsed;
|
|
351
|
+
metas.sort((a, b) => (a.createdAt < b.createdAt ? -1 : a.createdAt > b.createdAt ? 1 : 0));
|
|
352
|
+
return metas;
|
|
353
|
+
}
|
|
354
|
+
parseSnapshot(raw, id) {
|
|
355
|
+
try {
|
|
356
|
+
return deserializeSnapshot(raw);
|
|
357
|
+
}
|
|
358
|
+
catch (err) {
|
|
359
|
+
throw new GistTransportError(this.o.msg('sync.gist.snapshotInvalid', { id, err: this.mask(String(err?.message ?? ''), '') }), { kind: 'protocol', retryable: false });
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/** HTTP 状态 + 响应体 → 错误分类(GitHub 的限流是 403 + rate limit 文案 → 当可重试的 server 故障) */
|
|
363
|
+
classify(status, body) {
|
|
364
|
+
if (status === 403 && /rate limit|secondary rate/i.test(body)) {
|
|
365
|
+
return { kind: 'server', retryable: true, status };
|
|
366
|
+
}
|
|
367
|
+
return classifyHttpStatus(status);
|
|
368
|
+
}
|
|
369
|
+
/** 读响应体(失败 → 空串;不因读体失败而丢掉真正的 HTTP 状态原因) */
|
|
370
|
+
async safeText(res) {
|
|
371
|
+
try {
|
|
372
|
+
return (await res.text()).slice(0, ERR_BODY_MAX);
|
|
373
|
+
}
|
|
374
|
+
catch {
|
|
375
|
+
return '';
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
async failText(method, url, res, token, prefetched) {
|
|
379
|
+
const body = prefetched ?? await this.safeText(res);
|
|
380
|
+
return this.o.msg('sync.gist.requestFailed', {
|
|
381
|
+
method,
|
|
382
|
+
url,
|
|
383
|
+
status: String(res.status),
|
|
384
|
+
err: this.mask(body, token),
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
isTimeout(err) {
|
|
388
|
+
const name = err?.name ?? '';
|
|
389
|
+
if (name === 'TimeoutError')
|
|
390
|
+
return true;
|
|
391
|
+
if (name === 'AbortError')
|
|
392
|
+
return true;
|
|
393
|
+
if (typeof DOMException !== 'undefined' && err instanceof DOMException && name === 'AbortError')
|
|
394
|
+
return true;
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
/** 错误消息脱敏:token(原文与 URL 编码形态)一律替换 */
|
|
398
|
+
mask(text, token) {
|
|
399
|
+
if (!token)
|
|
400
|
+
return text;
|
|
401
|
+
let out = text.split(token).join(REDACTED);
|
|
402
|
+
out = out.split(encodeURIComponent(token)).join(REDACTED);
|
|
403
|
+
return out;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
//# sourceMappingURL=gist-transport.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { MsgFunc } from '../../core/msg-types.ts';
|
|
2
|
+
export declare const gistZh: {
|
|
3
|
+
readonly 'sync.gist.gistIdRequired': 'gistId 必须是非空字符串(在 GitHub 上新建一个(私密)gist 后填入其 id)';
|
|
4
|
+
readonly 'sync.gist.gistIdInvalid': 'gistId 不合法: {id}(GitHub gist id 是十六进制串)';
|
|
5
|
+
readonly 'sync.gist.apiBaseUrlInvalid': '无法解析 GitHub API 根地址(必须是合法 http(s) URL,且不含用户名/密码): {url}';
|
|
6
|
+
readonly 'sync.gist.tokenRequired': 'credentials 必须提供 getToken()';
|
|
7
|
+
readonly 'sync.gist.filePrefixInvalid': 'gist 文件名前缀不合法: {prefix}(不得为空、不得含斜杠或 ..)';
|
|
8
|
+
readonly 'sync.gist.invalidSnapshotId': '非法快照 id: {id}(仅允许字母数字开头,字符限 . _ -)';
|
|
9
|
+
readonly 'sync.gist.gistMissing': 'Gist {id} 不存在或当前令牌无权访问(HTTP {status})';
|
|
10
|
+
readonly 'sync.gist.fileMissing': 'Gist 里缺少快照文件 {file}(可能被手工删除)';
|
|
11
|
+
readonly 'sync.gist.contentTruncated': 'Gist 文件 {file} 内容被截断,raw 下载也失败: {err}';
|
|
12
|
+
readonly 'sync.gist.rawFetchFailed': '下载 gist 文件原文失败({url},HTTP {status})';
|
|
13
|
+
readonly 'sync.gist.tooManyRedirects': '{url} 重定向超过 {n} 次上限,疑似跳转循环';
|
|
14
|
+
readonly 'sync.gist.requestFailed': '{method} {url} 失败 (HTTP {status}): {err}';
|
|
15
|
+
readonly 'sync.gist.requestError': '{method} {url} 请求出错: {err}';
|
|
16
|
+
readonly 'sync.gist.timeout': '{method} {url} 请求超时({timeout}ms)';
|
|
17
|
+
readonly 'sync.gist.indexInvalid': '{url} 解析失败或结构非法: {err}';
|
|
18
|
+
readonly 'sync.gist.snapshotInvalid': '快照 {id} 解析失败或结构非法: {err}';
|
|
19
|
+
};
|
|
20
|
+
export declare const gistEn: Record<keyof typeof gistZh, string>;
|
|
21
|
+
/** 缺省(zh)Gist 通道翻译器。 */
|
|
22
|
+
export declare const gistMsg: MsgFunc;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub Gist 通道(批次3 Q2)的模块内双语消息目录(zh 源 / en 镜像)。
|
|
3
|
+
* 与 \`src/sync/s3/messages.ts\` 同一套纪律与同一份工厂(\`makeCatalogMsg\`):
|
|
4
|
+
* 键先落在这里(写作用域不含 \`src/core/messages.ts\`),汇报里按同一张表交给字典拥有者并入。
|
|
5
|
+
* 纪律:用户可见字符串不得硬编码在通道实现里;token 值永不进消息。
|
|
6
|
+
*/
|
|
7
|
+
import { makeCatalogMsg } from '../s3/messages.js';
|
|
8
|
+
export const gistZh = {
|
|
9
|
+
'sync.gist.gistIdRequired': 'gistId 必须是非空字符串(在 GitHub 上新建一个(私密)gist 后填入其 id)',
|
|
10
|
+
'sync.gist.gistIdInvalid': 'gistId 不合法: {id}(GitHub gist id 是十六进制串)',
|
|
11
|
+
'sync.gist.apiBaseUrlInvalid': '无法解析 GitHub API 根地址(必须是合法 http(s) URL,且不含用户名/密码): {url}',
|
|
12
|
+
'sync.gist.tokenRequired': 'credentials 必须提供 getToken()',
|
|
13
|
+
'sync.gist.filePrefixInvalid': 'gist 文件名前缀不合法: {prefix}(不得为空、不得含斜杠或 ..)',
|
|
14
|
+
'sync.gist.invalidSnapshotId': '非法快照 id: {id}(仅允许字母数字开头,字符限 . _ -)',
|
|
15
|
+
'sync.gist.gistMissing': 'Gist {id} 不存在或当前令牌无权访问(HTTP {status})',
|
|
16
|
+
'sync.gist.fileMissing': 'Gist 里缺少快照文件 {file}(可能被手工删除)',
|
|
17
|
+
'sync.gist.contentTruncated': 'Gist 文件 {file} 内容被截断,raw 下载也失败: {err}',
|
|
18
|
+
'sync.gist.rawFetchFailed': '下载 gist 文件原文失败({url},HTTP {status})',
|
|
19
|
+
'sync.gist.tooManyRedirects': '{url} 重定向超过 {n} 次上限,疑似跳转循环',
|
|
20
|
+
'sync.gist.requestFailed': '{method} {url} 失败 (HTTP {status}): {err}',
|
|
21
|
+
'sync.gist.requestError': '{method} {url} 请求出错: {err}',
|
|
22
|
+
'sync.gist.timeout': '{method} {url} 请求超时({timeout}ms)',
|
|
23
|
+
'sync.gist.indexInvalid': '{url} 解析失败或结构非法: {err}',
|
|
24
|
+
'sync.gist.snapshotInvalid': '快照 {id} 解析失败或结构非法: {err}',
|
|
25
|
+
};
|
|
26
|
+
export const gistEn = {
|
|
27
|
+
'sync.gist.gistIdRequired': 'gistId must be a non-empty string (create a (secret) gist on GitHub and paste its id)',
|
|
28
|
+
'sync.gist.gistIdInvalid': 'Invalid gistId: {id} (a GitHub gist id is a hexadecimal string)',
|
|
29
|
+
'sync.gist.apiBaseUrlInvalid': 'Cannot parse the GitHub API base URL (must be a valid http(s) URL without username/password): {url}',
|
|
30
|
+
'sync.gist.tokenRequired': 'credentials must provide getToken()',
|
|
31
|
+
'sync.gist.filePrefixInvalid': 'Invalid gist file name prefix: {prefix} (must not be empty or contain slashes or ..)',
|
|
32
|
+
'sync.gist.invalidSnapshotId': 'Invalid snapshot id: {id} (must start alphanumeric; only . _ - allowed)',
|
|
33
|
+
'sync.gist.gistMissing': 'Gist {id} does not exist or the current token cannot access it (HTTP {status})',
|
|
34
|
+
'sync.gist.fileMissing': 'The gist is missing snapshot file {file} (it may have been deleted manually)',
|
|
35
|
+
'sync.gist.contentTruncated': 'Gist file {file} is truncated and the raw download also failed: {err}',
|
|
36
|
+
'sync.gist.rawFetchFailed': 'Failed to download the raw gist file ({url}, HTTP {status})',
|
|
37
|
+
'sync.gist.tooManyRedirects': '{url} exceeded {n} redirects, possible redirect loop',
|
|
38
|
+
'sync.gist.requestFailed': '{method} {url} failed (HTTP {status}): {err}',
|
|
39
|
+
'sync.gist.requestError': '{method} {url} request error: {err}',
|
|
40
|
+
'sync.gist.timeout': '{method} {url} request timed out ({timeout}ms)',
|
|
41
|
+
'sync.gist.indexInvalid': '{url} failed to parse or is structurally invalid: {err}',
|
|
42
|
+
'sync.gist.snapshotInvalid': 'Snapshot {id} failed to parse or is structurally invalid: {err}',
|
|
43
|
+
};
|
|
44
|
+
/** 缺省(zh)Gist 通道翻译器。 */
|
|
45
|
+
export const gistMsg = makeCatalogMsg(gistZh, gistEn, 'zh');
|
|
46
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* S3 兼容系通道(批次3 Q2)的**模块内双语消息目录**(zh 源 / en 镜像)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么不写进 \`src/core/messages.ts\`:批次3 的写作用域只含 \`src/sync/s3|gist|sync-config.ts\`,
|
|
5
|
+
* 而 \`src/core/*\` 属他人 in-flight 工作区。本目录与 core 的同名目录**同形同纪律**
|
|
6
|
+
* (zh 为源、en 为 \`Record<keyof typeof zh, string>\` —— 缺键/多键即编译错误、{param} 插值、
|
|
7
|
+
* 未知键回退 zh 再回退键名),因此后续把键并入 \`src/core/messages.ts\` 是逐行搬迁,无需改写调用点。
|
|
8
|
+
*
|
|
9
|
+
* 纪律:**任何用户可见字符串都不得写在通道实现里**(含错误消息);密钥值永不进消息
|
|
10
|
+
* (脱敏由通道层在拼消息前完成)。
|
|
11
|
+
*/
|
|
12
|
+
import type { MsgFunc } from '../../core/msg-types.ts';
|
|
13
|
+
export declare const s3Zh: {
|
|
14
|
+
readonly 'sync.s3.providerUnknown': '未知的 S3 兼容通道: {provider}';
|
|
15
|
+
readonly 'sync.s3.endpointRequired': '对象存储 endpoint 必须是非空字符串(自建网关请填完整 http(s) 地址)';
|
|
16
|
+
readonly 'sync.s3.endpointInvalid': '无法解析对象存储 endpoint(必须是合法 http(s) URL): {url}';
|
|
17
|
+
readonly 'sync.s3.endpointUserinfo': '请勿在 endpoint 中包含用户名/密码(AccessKey 走凭据字段,不会拼入地址)';
|
|
18
|
+
readonly 'sync.s3.regionRequired': '通道 {provider} 必须提供 region(V4 签名的作用域需要它)';
|
|
19
|
+
readonly 'sync.s3.bucketRequired': 'bucket 必须是非空字符串';
|
|
20
|
+
readonly 'sync.s3.bucketInvalid': '桶名不合法: {bucket}(3-63 位小写字母/数字/点/连字符,首尾必须是字母或数字)';
|
|
21
|
+
readonly 'sync.s3.prefixInvalid': '对象键前缀不合法: {prefix}(不得以 / 开头,不得含 .. 或反斜杠)';
|
|
22
|
+
readonly 'sync.s3.accessKeyIdRequired': 'accessKeyId 必须是非空字符串';
|
|
23
|
+
readonly 'sync.s3.credentialsRequired': 'credentials 必须提供 getSecretAccessKey()';
|
|
24
|
+
readonly 'sync.s3.invalidSnapshotId': '非法快照 id: {id}(仅允许字母数字开头,字符限 . _ -)';
|
|
25
|
+
readonly 'sync.s3.snapshotMissing': '快照 {id} 不存在({url})';
|
|
26
|
+
readonly 'sync.s3.requestFailed': '{method} {url} 失败 (HTTP {status}): {err}';
|
|
27
|
+
readonly 'sync.s3.requestError': '{method} {url} 请求出错: {err}';
|
|
28
|
+
readonly 'sync.s3.timeout': '{method} {url} 请求超时({timeout}ms)';
|
|
29
|
+
readonly 'sync.s3.indexInvalid': '{url} 解析失败或结构非法: {err}';
|
|
30
|
+
readonly 'sync.s3.snapshotInvalid': '快照 {id} 解析失败或结构非法: {err}';
|
|
31
|
+
readonly 'sync.s3.indexMissingWithContent': '远端已有内容但索引 {url} 缺失(HTTP 404):拒绝以空集合覆盖权威索引,本次上传已中止(零写入)';
|
|
32
|
+
};
|
|
33
|
+
export declare const s3En: Record<keyof typeof s3Zh, string>;
|
|
34
|
+
/**
|
|
35
|
+
* 构造「目录驱动」的 MsgFunc(s3 与 gist 两个新通道共用这一份)。
|
|
36
|
+
* en → en 目录(缺键回退 zh);其余 → zh;未知键回退键名(绝不抛错)。
|
|
37
|
+
*/
|
|
38
|
+
export declare function makeCatalogMsg(zh: Record<string, string>, en: Record<string, string>, lang?: string): MsgFunc;
|
|
39
|
+
/** 缺省(zh)S3 通道翻译器。 */
|
|
40
|
+
export declare const s3Msg: MsgFunc;
|
|
41
|
+
/**
|
|
42
|
+
* 把「宿主传入的翻译器」与本地目录**合并**(t79):
|
|
43
|
+
* - **宿主优先**:宿主(`ConfigManagerHostContext.this.msg = makeMsg(language)`,见 src/index.ts:1500)
|
|
44
|
+
* 掌握 core 全量键与当前语言,它认得就照它;
|
|
45
|
+
* - **本地兜底**:`sync.s3.*` 这类键**只存在于本模块**(core 目录里一个都没有),宿主必然查不到
|
|
46
|
+
* —— 直接用它会出现「界面显示裸键名」(makeMsg 的未知键回退就是键名本身)。回退本地目录即可拿到文案;
|
|
47
|
+
* - 两边都没有 ⇒ 仍回退键名(保持 makeMsg 的既有边界,绝不抛错)。
|
|
48
|
+
*
|
|
49
|
+
* 同一个 helper 也供 WebDAV 侧使用(`composeMsg(options.msg, zhMsg)`:宿主缺键时回退 core zh,而不是裸键名)。
|
|
50
|
+
* 已知取舍:宿主语言为 en 时,本地目录的键仍出 zh 文案(本地目录缺语言上下文)—— 比裸键名好,
|
|
51
|
+
* 但不等同于完整 en 本地化;要彻底解决得把语言传进传输层(越界,登记为观察)。
|
|
52
|
+
*/
|
|
53
|
+
export declare function composeMsg(host: MsgFunc | undefined, local: MsgFunc): MsgFunc;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export const s3Zh = {
|
|
2
|
+
'sync.s3.providerUnknown': '未知的 S3 兼容通道: {provider}',
|
|
3
|
+
'sync.s3.endpointRequired': '对象存储 endpoint 必须是非空字符串(自建网关请填完整 http(s) 地址)',
|
|
4
|
+
'sync.s3.endpointInvalid': '无法解析对象存储 endpoint(必须是合法 http(s) URL): {url}',
|
|
5
|
+
'sync.s3.endpointUserinfo': '请勿在 endpoint 中包含用户名/密码(AccessKey 走凭据字段,不会拼入地址)',
|
|
6
|
+
'sync.s3.regionRequired': '通道 {provider} 必须提供 region(V4 签名的作用域需要它)',
|
|
7
|
+
'sync.s3.bucketRequired': 'bucket 必须是非空字符串',
|
|
8
|
+
'sync.s3.bucketInvalid': '桶名不合法: {bucket}(3-63 位小写字母/数字/点/连字符,首尾必须是字母或数字)',
|
|
9
|
+
'sync.s3.prefixInvalid': '对象键前缀不合法: {prefix}(不得以 / 开头,不得含 .. 或反斜杠)',
|
|
10
|
+
'sync.s3.accessKeyIdRequired': 'accessKeyId 必须是非空字符串',
|
|
11
|
+
'sync.s3.credentialsRequired': 'credentials 必须提供 getSecretAccessKey()',
|
|
12
|
+
'sync.s3.invalidSnapshotId': '非法快照 id: {id}(仅允许字母数字开头,字符限 . _ -)',
|
|
13
|
+
'sync.s3.snapshotMissing': '快照 {id} 不存在({url})',
|
|
14
|
+
'sync.s3.requestFailed': '{method} {url} 失败 (HTTP {status}): {err}',
|
|
15
|
+
'sync.s3.requestError': '{method} {url} 请求出错: {err}',
|
|
16
|
+
'sync.s3.timeout': '{method} {url} 请求超时({timeout}ms)',
|
|
17
|
+
'sync.s3.indexInvalid': '{url} 解析失败或结构非法: {err}',
|
|
18
|
+
'sync.s3.snapshotInvalid': '快照 {id} 解析失败或结构非法: {err}',
|
|
19
|
+
'sync.s3.indexMissingWithContent': '远端已有内容但索引 {url} 缺失(HTTP 404):拒绝以空集合覆盖权威索引,本次上传已中止(零写入)',
|
|
20
|
+
};
|
|
21
|
+
export const s3En = {
|
|
22
|
+
'sync.s3.providerUnknown': 'Unknown S3-compatible channel: {provider}',
|
|
23
|
+
'sync.s3.endpointRequired': 'Object storage endpoint must be a non-empty string (use the full http(s) URL for self-hosted gateways)',
|
|
24
|
+
'sync.s3.endpointInvalid': 'Cannot parse the object storage endpoint (must be a valid http(s) URL): {url}',
|
|
25
|
+
'sync.s3.endpointUserinfo': 'Do not include a username/password in the endpoint (the AccessKey goes into the credential field, never the URL)',
|
|
26
|
+
'sync.s3.regionRequired': 'Channel {provider} requires a region (the V4 credential scope needs it)',
|
|
27
|
+
'sync.s3.bucketRequired': 'bucket must be a non-empty string',
|
|
28
|
+
'sync.s3.bucketInvalid': 'Invalid bucket name: {bucket} (3-63 lowercase letters/digits/dots/hyphens, must start and end with a letter or digit)',
|
|
29
|
+
'sync.s3.prefixInvalid': 'Invalid object key prefix: {prefix} (must not start with / and must not contain .. or backslashes)',
|
|
30
|
+
'sync.s3.accessKeyIdRequired': 'accessKeyId must be a non-empty string',
|
|
31
|
+
'sync.s3.credentialsRequired': 'credentials must provide getSecretAccessKey()',
|
|
32
|
+
'sync.s3.invalidSnapshotId': 'Invalid snapshot id: {id} (must start alphanumeric; only . _ - allowed)',
|
|
33
|
+
'sync.s3.snapshotMissing': 'Snapshot {id} does not exist ({url})',
|
|
34
|
+
'sync.s3.requestFailed': '{method} {url} failed (HTTP {status}): {err}',
|
|
35
|
+
'sync.s3.requestError': '{method} {url} request error: {err}',
|
|
36
|
+
'sync.s3.timeout': '{method} {url} request timed out ({timeout}ms)',
|
|
37
|
+
'sync.s3.indexInvalid': '{url} failed to parse or is structurally invalid: {err}',
|
|
38
|
+
'sync.s3.snapshotInvalid': 'Snapshot {id} failed to parse or is structurally invalid: {err}',
|
|
39
|
+
'sync.s3.indexMissingWithContent': 'The remote already has content but index {url} is missing (HTTP 404): refusing to overwrite the authoritative index with an empty set; this upload was aborted (zero writes)',
|
|
40
|
+
};
|
|
41
|
+
/** 插值:{param} → 形参值;缺参原样保留(与 core/messages.ts 同口径)。 */
|
|
42
|
+
function interpolate(template, params) {
|
|
43
|
+
if (params === undefined)
|
|
44
|
+
return template;
|
|
45
|
+
return template.replace(/\{(\w+)\}/g, (match, key) => {
|
|
46
|
+
const value = params[key];
|
|
47
|
+
return value === undefined ? match : String(value);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 构造「目录驱动」的 MsgFunc(s3 与 gist 两个新通道共用这一份)。
|
|
52
|
+
* en → en 目录(缺键回退 zh);其余 → zh;未知键回退键名(绝不抛错)。
|
|
53
|
+
*/
|
|
54
|
+
export function makeCatalogMsg(zh, en, lang) {
|
|
55
|
+
const useEn = lang === 'en';
|
|
56
|
+
return (key, params) => {
|
|
57
|
+
const template = (useEn ? en[key] ?? zh[key] : zh[key]) ?? key;
|
|
58
|
+
return interpolate(template, params);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** 缺省(zh)S3 通道翻译器。 */
|
|
62
|
+
export const s3Msg = makeCatalogMsg(s3Zh, s3En, 'zh');
|
|
63
|
+
/**
|
|
64
|
+
* 把「宿主传入的翻译器」与本地目录**合并**(t79):
|
|
65
|
+
* - **宿主优先**:宿主(`ConfigManagerHostContext.this.msg = makeMsg(language)`,见 src/index.ts:1500)
|
|
66
|
+
* 掌握 core 全量键与当前语言,它认得就照它;
|
|
67
|
+
* - **本地兜底**:`sync.s3.*` 这类键**只存在于本模块**(core 目录里一个都没有),宿主必然查不到
|
|
68
|
+
* —— 直接用它会出现「界面显示裸键名」(makeMsg 的未知键回退就是键名本身)。回退本地目录即可拿到文案;
|
|
69
|
+
* - 两边都没有 ⇒ 仍回退键名(保持 makeMsg 的既有边界,绝不抛错)。
|
|
70
|
+
*
|
|
71
|
+
* 同一个 helper 也供 WebDAV 侧使用(`composeMsg(options.msg, zhMsg)`:宿主缺键时回退 core zh,而不是裸键名)。
|
|
72
|
+
* 已知取舍:宿主语言为 en 时,本地目录的键仍出 zh 文案(本地目录缺语言上下文)—— 比裸键名好,
|
|
73
|
+
* 但不等同于完整 en 本地化;要彻底解决得把语言传进传输层(越界,登记为观察)。
|
|
74
|
+
*/
|
|
75
|
+
export function composeMsg(host, local) {
|
|
76
|
+
if (host === undefined)
|
|
77
|
+
return local;
|
|
78
|
+
return (key, params) => {
|
|
79
|
+
const fromHost = host(key, params);
|
|
80
|
+
return fromHost === key ? local(key, params) : fromHost;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=messages.js.map
|