dsh-config-manager 0.8.2 → 0.10.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 +51 -15
- 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 +204 -6
- package/lib/adapters/prompts.js +15 -4
- package/lib/adapters/test-helpers.d.ts +15 -1
- package/lib/adapters/test-helpers.js +11 -0
- 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/help.d.ts +1 -1
- package/lib/cli/help.js +21 -14
- package/lib/cli/index.js +132 -104
- package/lib/cli/sessions-repair.js +58 -22
- package/lib/cli/web/client-script.d.ts +1 -1
- package/lib/cli/web/client-script.js +71 -5
- package/lib/cli/web/page.d.ts +9 -19
- package/lib/cli/web/page.js +277 -173
- package/lib/cli/web/routes.js +85 -25
- package/lib/cli/write-gates.d.ts +61 -0
- package/lib/cli/write-gates.js +110 -0
- package/lib/client.d.ts +196 -75
- package/lib/client.js +8139 -7487
- 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 +17 -0
- package/lib/core/messages.js +34 -0
- package/lib/core/migration-history.js +16 -9
- package/lib/core/model-tools.d.ts +2 -2
- package/lib/core/model-tools.js +20 -2
- package/lib/core/patch-chain.d.ts +65 -0
- package/lib/core/patch-chain.js +100 -0
- package/lib/core/patch-document.d.ts +32 -4
- package/lib/core/patch-document.js +48 -17
- 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 +38 -1
- package/lib/core/update-check.js +51 -2
- package/lib/foreign/kernel.js +9 -2
- package/lib/foreign/read-claude-plugins.js +29 -11
- package/lib/foreign/read-dsh.js +31 -2
- package/lib/foreign/session-ir.js +50 -9
- package/lib/foreign/session-read.d.ts +8 -0
- package/lib/foreign/session-read.js +26 -0
- package/lib/index.d.ts +9 -4
- package/lib/index.js +42 -47
- 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 +19 -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 +47 -2
- package/lib/sync/autosync-scheduler.js +217 -53
- 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/local-changes.d.ts +15 -0
- package/lib/sync/local-changes.js +39 -0
- package/lib/sync/merge-apply-plan.d.ts +38 -0
- package/lib/sync/merge-apply-plan.js +76 -0
- package/lib/sync/merge-keyed.d.ts +68 -0
- package/lib/sync/merge-keyed.js +124 -0
- package/lib/sync/messages.d.ts +1 -0
- package/lib/sync/messages.js +2 -0
- package/lib/sync/patch-line-identity.d.ts +19 -0
- package/lib/sync/patch-line-identity.js +99 -0
- package/lib/sync/pending-merge.d.ts +41 -0
- package/lib/sync/pending-merge.js +61 -0
- package/lib/sync/plugin-removals.d.ts +15 -15
- package/lib/sync/plugin-removals.js +134 -83
- package/lib/sync/push-skip.d.ts +55 -0
- package/lib/sync/push-skip.js +70 -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 +44 -51
- package/lib/sync/sync-engine.js +160 -194
- 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/sync/workspace-merge.d.ts +8 -2
- package/lib/ui/artifact-view.d.ts +1 -1
- 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 +14 -0
- package/lib/ui/foreign-view.js +34 -0
- package/lib/ui/i18n.d.ts +7 -1
- package/lib/ui/i18n.js +15 -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 +10 -2
- package/lib/ui/selection-model.js +23 -3
- package/lib/utils/async-once.d.ts +11 -0
- package/lib/utils/async-once.js +15 -0
- package/lib/utils/patch-chain-read.d.ts +51 -0
- package/lib/utils/patch-chain-read.js +240 -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 +3 -2
- package/src/adapters/mcp.test.ts +29 -0
- package/src/adapters/mcp.ts +52 -14
- 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 +403 -0
- package/src/adapters/plugins.ts +198 -8
- package/src/adapters/prompts.ts +15 -4
- package/src/adapters/test-helpers.ts +15 -1
- 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/help.ts +21 -14
- package/src/cli/index.ts +123 -107
- package/src/cli/sessions-repair.ts +55 -22
- package/src/cli/web/client-script.ts +71 -5
- package/src/cli/web/page.ts +327 -208
- package/src/cli/web/routes.ts +85 -25
- package/src/cli/web/web.test.ts +65 -0
- package/src/cli/write-gates.ts +149 -0
- package/src/client/ConfigManagerSection.tsx +8 -4
- package/src/client/about/AboutPanel.tsx +9 -12
- package/src/client/about/release-notes-view.test.ts +17 -0
- package/src/client/about/release-notes-view.ts +49 -24
- package/src/client/api.ts +2 -1
- 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 +24 -24
- 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 +190 -5
- 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 +1515 -270
- package/src/client/consult/ConsultCard.tsx +7 -6
- package/src/client/environment/EnvironmentPanel.tsx +22 -25
- package/src/client/environment/maintenance/DiskUsageCard.tsx +69 -96
- 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 +77 -69
- package/src/client/home/HomePanel.tsx +47 -12
- package/src/client/import/ConflictList.tsx +13 -13
- package/src/client/import/ForeignImportView.tsx +67 -9
- package/src/client/import/ImportWizardView.tsx +4 -4
- package/src/client/import/PathMappingForm.tsx +36 -9
- package/src/client/import/PathPickerDialog.tsx +2 -1
- package/src/client/import/import-wizard-split.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 +21 -15
- package/src/client/library/LibraryActions.tsx +116 -28
- package/src/client/library/LibraryPanel.tsx +14 -15
- package/src/client/library/RestorePlanView.tsx +13 -8
- package/src/client/locales/about.ts +0 -2
- package/src/client/locales/backup.ts +15 -12
- package/src/client/locales/common.ts +2 -0
- package/src/client/locales/export.ts +5 -12
- package/src/client/locales/foreign.ts +4 -2
- package/src/client/locales/import.ts +5 -2
- package/src/client/locales/overview.ts +4 -0
- package/src/client/locales/profiles.ts +32 -4
- package/src/client/locales/restore.ts +2 -2
- package/src/client/locales/sessions.ts +0 -2
- package/src/client/locales/shell.ts +2 -2
- package/src/client/market/MarketImportReview.tsx +4 -4
- package/src/client/market/MarketPanel.tsx +58 -56
- package/src/client/market/MyConfigsList.tsx +34 -32
- package/src/client/market/MyConfigsLoginCard.tsx +12 -15
- package/src/client/market/MyConfigsView.tsx +8 -15
- 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 +35 -22
- package/src/client/recovery/RollbackCard.tsx +132 -75
- 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/recovery/rollback-enabled.ts +29 -0
- package/src/client/recovery/use-recovery-write.ts +5 -0
- 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 +184 -108
- package/src/client/sync/ChannelClearConfirmDialog.tsx +5 -1
- package/src/client/sync/ChannelConfigDialog.tsx +27 -48
- package/src/client/sync/MergePreviewView.tsx +5 -7
- package/src/client/sync/PushPreviewCard.tsx +2 -1
- package/src/client/sync/PushReportSections.tsx +35 -0
- package/src/client/sync/SyncChannelEntryCard.tsx +33 -24
- package/src/client/sync/SyncConfirmView.tsx +130 -133
- package/src/client/sync/SyncLogList.tsx +29 -14
- package/src/client/sync/SyncPanel.tsx +188 -185
- 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 +293 -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 +5 -0
- package/src/client/sync/merge-request.ts +20 -0
- package/src/client/sync/sync-api.ts +13 -1
- package/src/client/sync/sync-locales.ts +95 -47
- package/src/client/sync/sync-panel-clear.test.ts +44 -0
- package/src/client/sync/sync-push-preview.test.ts +9 -0
- package/src/client/sync/sync-view.test.ts +20 -0
- package/src/client/sync/sync-view.ts +76 -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 +34 -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 +22 -4
- package/src/core/patch-chain.test.ts +83 -0
- package/src/core/patch-chain.ts +150 -0
- package/src/core/patch-document.test.ts +48 -1
- package/src/core/patch-document.ts +66 -15
- package/src/core/patch-layers.test.ts +1 -1
- 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/smoke.test.ts +2 -1
- 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 +43 -2
- package/src/core/update-check.test.ts +40 -0
- package/src/core/update-check.ts +53 -2
- package/src/foreign/claude-code.test.ts +5 -0
- package/src/foreign/claude-plugins.test.ts +57 -0
- package/src/foreign/claude-sessions-bytes.test.ts +7 -1
- package/src/foreign/dsh.test.ts +23 -0
- package/src/foreign/kernel.ts +9 -2
- package/src/foreign/read-claude-plugins.ts +32 -11
- package/src/foreign/read-dsh.ts +33 -2
- package/src/foreign/session-ir.test.ts +67 -0
- package/src/foreign/session-ir.ts +54 -14
- package/src/foreign/session-read.ts +23 -0
- package/src/index.facade.test.ts +186 -6
- package/src/index.ts +53 -47
- 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 +19 -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/security/security.test.ts +1 -1
- package/src/sync/autosync-repeat.test.ts +58 -0
- package/src/sync/autosync-repeat.ts +55 -0
- package/src/sync/autosync-scheduler.test.ts +515 -0
- package/src/sync/autosync-scheduler.ts +225 -51
- 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/local-changes.ts +40 -0
- package/src/sync/merge-apply-plan.ts +117 -0
- package/src/sync/merge-keyed.test.ts +167 -0
- package/src/sync/merge-keyed.ts +160 -0
- package/src/sync/messages.ts +3 -0
- package/src/sync/patch-line-identity.test.ts +73 -0
- package/src/sync/patch-line-identity.ts +105 -0
- package/src/sync/pending-merge.test.ts +41 -0
- package/src/sync/pending-merge.ts +85 -0
- package/src/sync/plugin-removals.test.ts +199 -39
- package/src/sync/plugin-removals.ts +150 -64
- package/src/sync/push-skip.test.ts +326 -0
- package/src/sync/push-skip.ts +102 -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 +189 -193
- 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/sync/workspace-merge.ts +9 -2
- package/src/ui/artifact-view.ts +1 -1
- 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 +49 -0
- package/src/ui/foreign-view.ts +47 -0
- package/src/ui/i18n.ts +15 -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 +29 -1
- package/src/ui/selection-model.ts +25 -4
- package/src/utils/async-once.ts +14 -0
- package/src/utils/js-yaml4.d.ts +35 -0
- package/src/utils/patch-chain-read.test.ts +171 -0
- package/src/utils/patch-chain-read.ts +259 -0
- package/src/utils/patch-yaml.test.ts +215 -3
- package/src/utils/patch-yaml.ts +98 -2
- package/src/utils/paths.test.ts +14 -1
- package/src/utils/paths.ts +35 -0
- package/src/utils/workdir-lock.test.ts +69 -0
- package/src/utils/workdir-lock.ts +17 -3
- package/lib/ui/path-mapping.d.ts +0 -38
- package/lib/ui/path-mapping.js +0 -75
- package/src/client/common/InfoHint.tsx +0 -289
- package/src/client/common/info-hint-guard.test.ts +0 -1119
- package/src/client/sync/DecryptPasswordCard.tsx +0 -48
- package/src/client/sync/SecurityOptionsCard.tsx +0 -97
- package/src/client/sync/SyncSectionPickerDialog.tsx +0 -213
- package/src/ui/path-mapping.test.ts +0 -67
- package/src/ui/path-mapping.ts +0 -103
package/lib/cli/index.js
CHANGED
|
@@ -83,26 +83,23 @@ const WEB_REJECTED_FLAGS = new Set([
|
|
|
83
83
|
'--id', '--settings', '--dry-run', '--sections', '--out', '--yes', '--list',
|
|
84
84
|
'--wipe-config', '--version', '--json', '--fix',
|
|
85
85
|
]);
|
|
86
|
-
/** recover-stale-lock
|
|
86
|
+
/** recover-stale-lock 专用解析:接受 --data-dir / --data-root(用于定位 locks 目录) */
|
|
87
87
|
function parseCliDataDir(argv) {
|
|
88
88
|
const options = { command: 'recover-stale-lock', dryRun: false, profile: 'web', yes: false, list: false, wipeConfig: false, json: false, positionals: [] };
|
|
89
89
|
for (let i = 1; i < argv.length; i += 1) {
|
|
90
90
|
const flag = argv[i];
|
|
91
|
-
if (flag === '--help' || flag === '-h')
|
|
91
|
+
if (flag === '--help' || flag === '-h')
|
|
92
92
|
return { ok: true, options: { ...options, command: 'help', helpTopic: 'recover-stale-lock' } };
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
options.dataDir = flag.slice('--data-dir='.length);
|
|
104
|
-
if (options.dataDir === '')
|
|
105
|
-
return { ok: false, error: '参数 --data-dir 缺少值 / missing value for --data-dir' };
|
|
93
|
+
const at = flag.indexOf('=');
|
|
94
|
+
const name = at >= 0 ? flag.slice(0, at) : flag;
|
|
95
|
+
if (name === '--data-dir' || name === '--data-root') {
|
|
96
|
+
const value = at >= 0 ? flag.slice(at + 1) : argv[++i];
|
|
97
|
+
if (value === undefined || value === '' || value.startsWith('-'))
|
|
98
|
+
return { ok: false, error: `参数 ${name} 缺少值 / missing value for ${name}` };
|
|
99
|
+
if (name === '--data-dir')
|
|
100
|
+
options.dataDir = value;
|
|
101
|
+
else
|
|
102
|
+
options.dataRoot = value;
|
|
106
103
|
}
|
|
107
104
|
else {
|
|
108
105
|
return { ok: false, error: `未知参数 / unknown flag: ${flag}` };
|
|
@@ -110,16 +107,8 @@ function parseCliDataDir(argv) {
|
|
|
110
107
|
}
|
|
111
108
|
return { ok: true, options };
|
|
112
109
|
}
|
|
113
|
-
/*
|
|
114
|
-
|
|
115
|
-
* (救急台网页与 sessions repair 的安全门共用同一实现;旧实现把快照目录当 dataDir 用,
|
|
116
|
-
* 缺省路径下找不到心跳 → 门形同虚设,已一并修正)。
|
|
117
|
-
*/
|
|
118
|
-
/**
|
|
119
|
-
* sessions 专用解析:sessions repair [--home <dir>] [--fix] [--keep <dir>] [--map old=new]... [--json]
|
|
120
|
-
*
|
|
121
|
-
* 与 recover-stale-lock 同样的姿态:独立解析器,只接受本动作真正有意义的参数(绝不悄悄忽略)。
|
|
122
|
-
*/
|
|
110
|
+
/* 「本机有没有 DSH 在跑」的判据已抽到 src/cli/actions.ts 的 readRunningInstances */
|
|
111
|
+
/** sessions 专用解析:sessions list|doctor|repair [--home <dir>] [--data-dir <dir>] [--data-root <dir>] [--fix] [--keep <dir>] [--map old=new]... [--json] */
|
|
123
112
|
function parseCliSessions(argv) {
|
|
124
113
|
const options = {
|
|
125
114
|
command: 'sessions', dryRun: false, profile: 'web', yes: false, list: false,
|
|
@@ -128,56 +117,39 @@ function parseCliSessions(argv) {
|
|
|
128
117
|
const rest = argv.slice(1);
|
|
129
118
|
const action = rest[0];
|
|
130
119
|
if (action === undefined)
|
|
131
|
-
return { ok: false, error: 'sessions
|
|
132
|
-
if (action === '--help' || action === '-h')
|
|
120
|
+
return { ok: false, error: 'sessions 需要子动作(list / doctor / repair)/ missing action' };
|
|
121
|
+
if (action === '--help' || action === '-h')
|
|
133
122
|
return { ok: true, options: { ...options, command: 'help', helpTopic: 'sessions' } };
|
|
134
|
-
}
|
|
135
|
-
// T6:三个只读/安全动作 —— list(列出会话)/ doctor(体检)/ repair(预览或 --fix 执行)
|
|
136
123
|
if (action !== 'repair' && action !== 'list' && action !== 'doctor') {
|
|
137
124
|
return { ok: false, error: 'sessions 只支持 list / doctor / repair / unsupported action: ' + action };
|
|
138
125
|
}
|
|
139
126
|
options.positionals.push(action);
|
|
140
127
|
for (let i = 1; i < rest.length; i += 1) {
|
|
141
128
|
const flag = rest[i];
|
|
142
|
-
if (flag === '--help' || flag === '-h')
|
|
129
|
+
if (flag === '--help' || flag === '-h')
|
|
143
130
|
return { ok: true, options: { ...options, command: 'help', helpTopic: 'sessions' } };
|
|
144
|
-
|
|
145
|
-
if (flag === '--fix') {
|
|
131
|
+
if (flag === '--fix' || flag === '--apply') {
|
|
146
132
|
options.fix = true;
|
|
147
133
|
continue;
|
|
148
134
|
}
|
|
149
|
-
if (flag === '--apply') {
|
|
150
|
-
options.fix = true;
|
|
151
|
-
continue;
|
|
152
|
-
} // --apply 是 --fix 的可读别名(T6)
|
|
153
135
|
if (flag === '--json') {
|
|
154
136
|
options.json = true;
|
|
155
137
|
continue;
|
|
156
138
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (flag === '--home')
|
|
163
|
-
options.home = value;
|
|
164
|
-
else if (flag === '--keep')
|
|
165
|
-
options.keep = value;
|
|
166
|
-
else
|
|
167
|
-
options.maps.push(value);
|
|
168
|
-
i += 1;
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
if (flag.startsWith('--home=') || flag.startsWith('--keep=') || flag.startsWith('--map=')) {
|
|
172
|
-
const at = flag.indexOf('=');
|
|
173
|
-
const name = flag.slice(0, at);
|
|
174
|
-
const value = flag.slice(at + 1);
|
|
175
|
-
if (value === '')
|
|
139
|
+
const at = flag.indexOf('=');
|
|
140
|
+
const name = at >= 0 ? flag.slice(0, at) : flag;
|
|
141
|
+
if (name === '--home' || name === '--keep' || name === '--map' || name === '--data-dir' || name === '--data-root') {
|
|
142
|
+
const value = at >= 0 ? flag.slice(at + 1) : rest[++i];
|
|
143
|
+
if (value === undefined || value === '' || value.startsWith('-'))
|
|
176
144
|
return { ok: false, error: '参数 ' + name + ' 缺少值 / missing value for ' + name };
|
|
177
145
|
if (name === '--home')
|
|
178
146
|
options.home = value;
|
|
179
147
|
else if (name === '--keep')
|
|
180
148
|
options.keep = value;
|
|
149
|
+
else if (name === '--data-dir')
|
|
150
|
+
options.dataDir = value;
|
|
151
|
+
else if (name === '--data-root')
|
|
152
|
+
options.dataRoot = value;
|
|
181
153
|
else
|
|
182
154
|
options.maps.push(value);
|
|
183
155
|
continue;
|
|
@@ -186,13 +158,7 @@ function parseCliSessions(argv) {
|
|
|
186
158
|
}
|
|
187
159
|
return { ok: true, options };
|
|
188
160
|
}
|
|
189
|
-
/**
|
|
190
|
-
* import 专用解析:`import --from <source> [--dry-run] [--out <path>] [--cwd <dir>] [--data-dir <dir>]`
|
|
191
|
-
*
|
|
192
|
-
* 与 sessions / recover-stale-lock 同样的姿态:只接受本动作真正有意义的参数(绝不悄悄忽略)。
|
|
193
|
-
* `--from` 的值在这里**不做词表校验**:未知来源要由运行层给出「可用来源清单」——
|
|
194
|
-
* 那需要真实注册表(CLI 与宿主共用同一份装配,见 src/foreign/registry.ts)。
|
|
195
|
-
*/
|
|
161
|
+
/** import 专用解析:import --from <source> [--dry-run] [--out <path>] [--cwd <dir>] [--data-dir <dir>] */
|
|
196
162
|
function parseCliImport(argv) {
|
|
197
163
|
const options = {
|
|
198
164
|
command: 'import', dryRun: false, profile: 'web', yes: false, list: false,
|
|
@@ -209,22 +175,21 @@ function parseCliImport(argv) {
|
|
|
209
175
|
}
|
|
210
176
|
const at = flag.indexOf('=');
|
|
211
177
|
const name = at >= 0 ? flag.slice(0, at) : flag;
|
|
212
|
-
const isValueFlag = name === '--from' || name === '--cwd' || name === '--out' || name === '--data-dir';
|
|
178
|
+
const isValueFlag = name === '--from' || name === '--cwd' || name === '--out' || name === '--data-dir' || name === '--data-root';
|
|
213
179
|
if (isValueFlag) {
|
|
214
|
-
const value = at >= 0 ? flag.slice(at + 1) : rest[i
|
|
215
|
-
if (value === undefined || value === '' || value.startsWith('-'))
|
|
180
|
+
const value = at >= 0 ? flag.slice(at + 1) : rest[++i];
|
|
181
|
+
if (value === undefined || value === '' || value.startsWith('-'))
|
|
216
182
|
return { ok: false, error: '参数 ' + name + ' 缺少值 / missing value for ' + name };
|
|
217
|
-
}
|
|
218
183
|
if (name === '--from')
|
|
219
184
|
options.from = value;
|
|
220
185
|
else if (name === '--cwd')
|
|
221
186
|
options.cwd = value;
|
|
222
187
|
else if (name === '--out')
|
|
223
188
|
options.out = value;
|
|
189
|
+
else if (name === '--data-root')
|
|
190
|
+
options.dataRoot = value;
|
|
224
191
|
else
|
|
225
192
|
options.dataDir = value;
|
|
226
|
-
if (at < 0)
|
|
227
|
-
i += 1;
|
|
228
193
|
continue;
|
|
229
194
|
}
|
|
230
195
|
return { ok: false, error: '未知参数 / unknown flag: ' + flag };
|
|
@@ -266,8 +231,18 @@ export function parseCli(argv) {
|
|
|
266
231
|
}
|
|
267
232
|
const options = { command, dryRun: false, profile: 'web', yes: false, list: false, wipeConfig: false, json: false, positionals: [] };
|
|
268
233
|
const rest = argv.slice(1);
|
|
234
|
+
const takeValue = (flagName, idx, inline) => {
|
|
235
|
+
const val = inline ?? rest[idx + 1];
|
|
236
|
+
if (val === undefined || val === '' || (inline === undefined && val.startsWith('-'))) {
|
|
237
|
+
return { ok: false, error: `参数 ${flagName} 缺少值 / missing value for ${flagName}` };
|
|
238
|
+
}
|
|
239
|
+
return { ok: true, value: val, nextIdx: inline === undefined ? idx + 1 : idx };
|
|
240
|
+
};
|
|
269
241
|
for (let i = 0; i < rest.length; i += 1) {
|
|
270
|
-
const
|
|
242
|
+
const rawFlag = rest[i];
|
|
243
|
+
const eq = rawFlag.startsWith('-') ? rawFlag.indexOf('=') : -1;
|
|
244
|
+
const flag = eq > 0 ? rawFlag.slice(0, eq) : rawFlag;
|
|
245
|
+
const inline = eq > 0 ? rawFlag.slice(eq + 1) : undefined;
|
|
271
246
|
if (flag === '--help' || flag === '-h') {
|
|
272
247
|
return { ok: true, options: { ...options, command: 'help', helpTopic: command } };
|
|
273
248
|
}
|
|
@@ -321,20 +296,18 @@ export function parseCli(argv) {
|
|
|
321
296
|
if (command !== 'web') {
|
|
322
297
|
return { ok: false, error: `${command} 子命令不支持参数 / flag not allowed here: ${flag}` };
|
|
323
298
|
}
|
|
324
|
-
const
|
|
325
|
-
if (
|
|
326
|
-
return
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
i += 1;
|
|
299
|
+
const v = takeValue('--home', i, inline);
|
|
300
|
+
if (!v.ok)
|
|
301
|
+
return v;
|
|
302
|
+
options.home = v.value;
|
|
303
|
+
i = v.nextIdx;
|
|
330
304
|
continue;
|
|
331
305
|
}
|
|
332
306
|
if (flag === '--port' || flag === '--idle-timeout') {
|
|
333
|
-
const
|
|
334
|
-
if (
|
|
335
|
-
return
|
|
336
|
-
|
|
337
|
-
const parsed = Number(value);
|
|
307
|
+
const v = takeValue(flag, i, inline);
|
|
308
|
+
if (!v.ok)
|
|
309
|
+
return v;
|
|
310
|
+
const parsed = Number(v.value);
|
|
338
311
|
if (!Number.isInteger(parsed) || parsed < 0 || (flag === '--port' && parsed > 65535)) {
|
|
339
312
|
return { ok: false, error: `参数 ${flag} 需要 0 以上的整数 / ${flag} expects a non-negative integer` };
|
|
340
313
|
}
|
|
@@ -342,7 +315,7 @@ export function parseCli(argv) {
|
|
|
342
315
|
options.port = parsed;
|
|
343
316
|
else
|
|
344
317
|
options.idleTimeoutMin = parsed;
|
|
345
|
-
i
|
|
318
|
+
i = v.nextIdx;
|
|
346
319
|
continue;
|
|
347
320
|
}
|
|
348
321
|
if (flag === '--dry-run') {
|
|
@@ -362,30 +335,28 @@ export function parseCli(argv) {
|
|
|
362
335
|
continue;
|
|
363
336
|
}
|
|
364
337
|
if (flag === '--version') {
|
|
365
|
-
const
|
|
366
|
-
if (
|
|
367
|
-
return
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
i += 1;
|
|
338
|
+
const v = takeValue('--version', i, inline);
|
|
339
|
+
if (!v.ok)
|
|
340
|
+
return v;
|
|
341
|
+
options.version = v.value;
|
|
342
|
+
i = v.nextIdx;
|
|
371
343
|
continue;
|
|
372
344
|
}
|
|
373
345
|
const key = VALUE_FLAGS.get(flag);
|
|
374
346
|
if (key === undefined) {
|
|
375
347
|
return { ok: false, error: `未知参数 / unknown flag: ${flag}` };
|
|
376
348
|
}
|
|
377
|
-
const
|
|
378
|
-
if (
|
|
379
|
-
return
|
|
380
|
-
}
|
|
349
|
+
const v = takeValue(flag, i, inline);
|
|
350
|
+
if (!v.ok)
|
|
351
|
+
return v;
|
|
381
352
|
if (key === 'sections') {
|
|
382
353
|
// 分区名提前校验:未知/离线不可用的分区一律在这里拒绝(不留到收集阶段才报)
|
|
383
|
-
const parsed = parseSectionsArg(value);
|
|
354
|
+
const parsed = parseSectionsArg(v.value);
|
|
384
355
|
if (!parsed.ok)
|
|
385
356
|
return { ok: false, error: parsed.error };
|
|
386
357
|
}
|
|
387
|
-
options[key] = value;
|
|
388
|
-
i
|
|
358
|
+
options[key] = v.value;
|
|
359
|
+
i = v.nextIdx;
|
|
389
360
|
}
|
|
390
361
|
return { ok: true, options };
|
|
391
362
|
}
|
|
@@ -640,10 +611,23 @@ function createDefaultExec(platform = process.platform) {
|
|
|
640
611
|
let defaultRl;
|
|
641
612
|
/** 缺省交互提问(懒建真实 readline;注入 ask 时不会创建)。 */
|
|
642
613
|
async function defaultAsk(prompt) {
|
|
614
|
+
if (processStdin.readableEnded) {
|
|
615
|
+
throw new Error('CLI_STDIN_EOF');
|
|
616
|
+
}
|
|
643
617
|
if (defaultRl === undefined) {
|
|
644
618
|
defaultRl = createInterface({ input: processStdin, output: processStdout });
|
|
645
619
|
}
|
|
646
|
-
|
|
620
|
+
try {
|
|
621
|
+
return await defaultRl.question(prompt);
|
|
622
|
+
}
|
|
623
|
+
catch (err) {
|
|
624
|
+
const code = err && typeof err === 'object' ? err.code : undefined;
|
|
625
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
626
|
+
if (code === 'ERR_USE_AFTER_CLOSE' || msg.includes('readline was closed') || msg.includes('closed')) {
|
|
627
|
+
throw new Error('CLI_STDIN_EOF');
|
|
628
|
+
}
|
|
629
|
+
throw err;
|
|
630
|
+
}
|
|
647
631
|
}
|
|
648
632
|
function closeDefaultAsk() {
|
|
649
633
|
if (defaultRl !== undefined) {
|
|
@@ -693,15 +677,37 @@ async function runReinstall(options, io, env, deps) {
|
|
|
693
677
|
defaults.add('plugins');
|
|
694
678
|
defaults.add('data');
|
|
695
679
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
io.
|
|
680
|
+
if (deps.ask === undefined && !processStdin.isTTY) {
|
|
681
|
+
if (options.dryRun) {
|
|
682
|
+
selection = defaults;
|
|
683
|
+
}
|
|
684
|
+
else {
|
|
685
|
+
io.error('错误:reinstall 是破坏性操作,在非交互终端(stdin 非 TTY)下默认拒绝,不会挂起等待确认。');
|
|
686
|
+
io.error('下一步:先运行 `dcm reinstall --dry-run` 预览步骤;确认后再传 `--yes` 显式放行。');
|
|
702
687
|
return 1;
|
|
703
688
|
}
|
|
704
689
|
}
|
|
690
|
+
else {
|
|
691
|
+
try {
|
|
692
|
+
selection = await interactiveReinstallSelect(defaults, io, ask);
|
|
693
|
+
const hasDestructive = [...selection].some((id) => REINSTALL_ITEMS.find((it) => it.id === id)?.destructive === true);
|
|
694
|
+
if (hasDestructive || options.wipeConfig) {
|
|
695
|
+
io.log('⚠ 所选动作包含清除 ~/.dsh 数据的危险步骤(执行前会先做 .reinstall-backup 备份)。/ WARNING: destructive ~/.dsh actions selected');
|
|
696
|
+
if (!parseConfirmInput(await ask('输入 YES 确认继续 / type YES to continue> '))) {
|
|
697
|
+
io.log('已取消 / cancelled');
|
|
698
|
+
return 1;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
catch (err) {
|
|
703
|
+
if (err instanceof Error && err.message === 'CLI_STDIN_EOF') {
|
|
704
|
+
io.error('错误:标准输入已结束(EOF),无法读取交互确认,已取消执行。');
|
|
705
|
+
io.error('下一步:在交互终端运行,或用 `--dry-run` 预览 / `--yes` 非交互执行。');
|
|
706
|
+
return 1;
|
|
707
|
+
}
|
|
708
|
+
throw err;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
705
711
|
}
|
|
706
712
|
const plan = await buildReinstallPlan(selection, options.version ?? 'latest', exec, env);
|
|
707
713
|
if (options.dryRun) {
|
|
@@ -715,6 +721,15 @@ async function runReinstall(options, io, env, deps) {
|
|
|
715
721
|
io.error(`拒绝执行:${safeMsg}`);
|
|
716
722
|
return 1;
|
|
717
723
|
}
|
|
724
|
+
// AGENTS「CLI 与救急台同一道写入门」第三道:DSH 未运行。
|
|
725
|
+
// 清空 settings/plugins/data 会删掉运行中实例的 profiles 与 sessions(审计 P11-5)。
|
|
726
|
+
if (plan.wipeConfig) {
|
|
727
|
+
const runningGate = await checkWriteGates(resolveControlRoots({ dataRoot: options.dataRoot, dataDir: options.dataDir }, env), { needsDshStopped: true });
|
|
728
|
+
if (!runningGate.ok) {
|
|
729
|
+
io.error(`拒绝执行:${runningGate.reason}`);
|
|
730
|
+
return 1;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
718
733
|
// 执行(Phase 2 锁:reinstall 卸载/清扫/重装属 GLOBAL destructive,必须成功获取环境锁)
|
|
719
734
|
const lockHome = resolveDshHome(env);
|
|
720
735
|
const lock = new EnvironmentLockManager({
|
|
@@ -773,6 +788,11 @@ async function runReinstall(options, io, env, deps) {
|
|
|
773
788
|
const reason = err instanceof Error ? err.message : String(err);
|
|
774
789
|
failed.push({ label: step.label, command: step.command, reason });
|
|
775
790
|
io.error(`✘ ${step.label} — ${reason}`);
|
|
791
|
+
// 备份步(critical)失败时后面的清空没有抢救副本:中止剩余步骤(审计 P11-7)。
|
|
792
|
+
if (step.critical === true) {
|
|
793
|
+
io.error('✘ 兜底备份失败,已中止后续清空步骤(未删除任何 ~/.dsh 数据)/ backup failed, aborting remaining steps');
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
776
796
|
}
|
|
777
797
|
}
|
|
778
798
|
};
|
|
@@ -810,8 +830,15 @@ async function runReinstall(options, io, env, deps) {
|
|
|
810
830
|
export async function runCli(argv, io = defaultIo, env = process.env, deps = {}) {
|
|
811
831
|
const parsed = parseCli(argv);
|
|
812
832
|
if (!parsed.ok) {
|
|
813
|
-
io.error(parsed.error);
|
|
814
|
-
|
|
833
|
+
io.error(`错误:${parsed.error}`);
|
|
834
|
+
const subcmd = argv[0];
|
|
835
|
+
if (subcmd !== undefined && !subcmd.startsWith('-') && renderCommandHelp(subcmd, CLI_EXPORTER_VERSION) !== null) {
|
|
836
|
+
io.error(`下一步:运行 \`dcm ${subcmd} --help\` 查看该命令的参数与示例。`);
|
|
837
|
+
}
|
|
838
|
+
else {
|
|
839
|
+
io.error('下一步:运行 `dcm --help` 查看可用命令与示例。');
|
|
840
|
+
printUsage(io);
|
|
841
|
+
}
|
|
815
842
|
return 1;
|
|
816
843
|
}
|
|
817
844
|
const { options } = parsed;
|
|
@@ -1290,7 +1317,8 @@ if (isDirectRun) {
|
|
|
1290
1317
|
process.exitCode = code;
|
|
1291
1318
|
})
|
|
1292
1319
|
.catch((err) => {
|
|
1293
|
-
console.error(
|
|
1320
|
+
console.error(`错误:dsh-config-manager 执行失败(${err instanceof Error ? err.message : String(err)})。`);
|
|
1321
|
+
console.error('下一步:检查输入参数、路径权限或运行 `dcm --help` 查看正确用法。');
|
|
1294
1322
|
process.exitCode = 1;
|
|
1295
1323
|
});
|
|
1296
1324
|
}
|
|
@@ -47,7 +47,7 @@ export function parseRepairMaps(maps) {
|
|
|
47
47
|
* 返回值里必须带 rootReadable:会话根存在但读不出来时,空列表只能说明「扫描失败」,
|
|
48
48
|
* 调用方据此拒绝给出「无需修复」+ exit 0(读不到 ≠ 无会话 —— 验收 F2 同口径)。
|
|
49
49
|
*/
|
|
50
|
-
async function scanSessions(sessionsRoot, io) {
|
|
50
|
+
async function scanSessions(sessionsRoot, io, json = false) {
|
|
51
51
|
const out = [];
|
|
52
52
|
let projectDirs;
|
|
53
53
|
try {
|
|
@@ -66,8 +66,12 @@ async function scanSessions(sessionsRoot, io) {
|
|
|
66
66
|
continue;
|
|
67
67
|
const projectKey = entry.name;
|
|
68
68
|
if (!PROJECT_KEY_RE.test(projectKey)) {
|
|
69
|
-
// 不是 DSH 的 projectKey
|
|
70
|
-
|
|
69
|
+
// 不是 DSH 的 projectKey 形状:原样说明并跳过(--json 下走 stderr,不污染 stdout JSON)
|
|
70
|
+
const skipMsg = '跳过非 projectKey 目录 / skip non-projectKey dir: ' + projectKey;
|
|
71
|
+
if (json)
|
|
72
|
+
io.error(skipMsg);
|
|
73
|
+
else
|
|
74
|
+
io.log(skipMsg);
|
|
71
75
|
continue;
|
|
72
76
|
}
|
|
73
77
|
const projectDir = join(sessionsRoot, projectKey);
|
|
@@ -109,18 +113,32 @@ async function quarantineDirFor(sessionsRoot, stamp, action) {
|
|
|
109
113
|
* --fix 时只要有失败/冲突/回滚就返回 1。
|
|
110
114
|
*/
|
|
111
115
|
export async function runSessionsRepair(options, io) {
|
|
116
|
+
const logHuman = (line) => {
|
|
117
|
+
if (options.json)
|
|
118
|
+
io.error(line);
|
|
119
|
+
else
|
|
120
|
+
io.log(line);
|
|
121
|
+
};
|
|
112
122
|
const sessionsRoot = join(options.home, 'sessions');
|
|
113
123
|
if (!(await exists(sessionsRoot))) {
|
|
114
|
-
|
|
124
|
+
const message = '找不到会话根目录 / sessions root not found: ' + sessionsRoot;
|
|
125
|
+
io.error(message);
|
|
115
126
|
io.error('用 --home <DSH_HOME> 指定正确的 DSH home;缺省取 $DSH_HOME(~/.dsh)。');
|
|
127
|
+
if (options.json) {
|
|
128
|
+
io.log(JSON.stringify({ ok: false, dryRun: options.fix !== true, home: options.home, root: sessionsRoot, error: message }, null, 2));
|
|
129
|
+
}
|
|
116
130
|
return 1;
|
|
117
131
|
}
|
|
118
132
|
const parsed = parseRepairMaps(options.maps);
|
|
119
133
|
for (const error of parsed.errors)
|
|
120
134
|
io.error(error);
|
|
121
|
-
if (parsed.errors.length > 0)
|
|
135
|
+
if (parsed.errors.length > 0) {
|
|
136
|
+
if (options.json) {
|
|
137
|
+
io.log(JSON.stringify({ ok: false, dryRun: options.fix !== true, home: options.home, errors: parsed.errors }, null, 2));
|
|
138
|
+
}
|
|
122
139
|
return 1;
|
|
123
|
-
|
|
140
|
+
}
|
|
141
|
+
const scan = await scanSessions(sessionsRoot, io, options.json);
|
|
124
142
|
if (!scan.rootReadable) {
|
|
125
143
|
// 「读不到」≠「没有会话」:根存在但读不出来时,空扫描结果只说明**扫描失败** ——
|
|
126
144
|
// 绝不能给出「无需修复」+ exit 0(那等于把「读不到」说成「没问题」),--json 也不得回 ok:true。
|
|
@@ -144,8 +162,8 @@ export async function runSessionsRepair(options, io) {
|
|
|
144
162
|
io.log(JSON.stringify({ ok: true, dryRun: true, home: options.home, summary: plan.summary, actions: plan.actions }, null, 2));
|
|
145
163
|
return 0;
|
|
146
164
|
}
|
|
147
|
-
|
|
148
|
-
|
|
165
|
+
logHuman('会话根 / sessions root: ' + sessionsRoot);
|
|
166
|
+
logHuman('扫描 ' + String(plan.summary.scanned) + ' 条会话:位置正确 ' + String(plan.summary.ok)
|
|
149
167
|
+ ',待搬家 ' + String(plan.summary.move)
|
|
150
168
|
+ ',待改写+搬家 ' + String(plan.summary.rewriteMove)
|
|
151
169
|
+ ',跳过 ' + String(plan.summary.skip)
|
|
@@ -155,16 +173,17 @@ export async function runSessionsRepair(options, io) {
|
|
|
155
173
|
continue;
|
|
156
174
|
const move = action.toProjectKey === undefined ? '' : ' → ' + action.toProjectKey;
|
|
157
175
|
const rewrite = action.rewrite === undefined ? '' : '(改写首帧 cwd: ' + action.rewrite.from + ' → ' + action.rewrite.to + ')';
|
|
158
|
-
|
|
176
|
+
logHuman(' [' + action.kind + '] ' + action.sessionId + ' ' + action.fromProjectKey + move + rewrite + ' reason=' + action.reason);
|
|
159
177
|
}
|
|
160
178
|
if (!options.fix) {
|
|
161
179
|
if (pending)
|
|
162
|
-
|
|
180
|
+
logHuman('以上为计划(零写入)。加 --fix 执行;重复 id 需用 --keep <目录> 指定保留哪一份。');
|
|
163
181
|
else
|
|
164
|
-
|
|
182
|
+
logHuman('无需修复。/ nothing to repair.');
|
|
165
183
|
return 0;
|
|
166
184
|
}
|
|
167
185
|
let failures = 0;
|
|
186
|
+
const results = [];
|
|
168
187
|
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
169
188
|
for (const action of plan.actions) {
|
|
170
189
|
if (!action.applies) {
|
|
@@ -176,12 +195,15 @@ export async function runSessionsRepair(options, io) {
|
|
|
176
195
|
if (action.kind === 'quarantine') {
|
|
177
196
|
const target = await quarantineDirFor(sessionsRoot, stamp, action);
|
|
178
197
|
if (await exists(target)) {
|
|
179
|
-
|
|
198
|
+
const msg = '隔离目标已存在,跳过 / quarantine target exists: ' + target;
|
|
199
|
+
io.error(msg);
|
|
200
|
+
results.push({ sessionId: action.sessionId, kind: action.kind, ok: false, error: msg });
|
|
180
201
|
failures += 1;
|
|
181
202
|
continue;
|
|
182
203
|
}
|
|
183
204
|
await fs.rename(action.dir, target);
|
|
184
|
-
|
|
205
|
+
logHuman('已隔离重复副本 / quarantined duplicate: ' + action.dir + ' → ' + target);
|
|
206
|
+
results.push({ sessionId: action.sessionId, kind: action.kind, ok: true, targetDir: target });
|
|
185
207
|
continue;
|
|
186
208
|
}
|
|
187
209
|
// move / rewrite-move
|
|
@@ -189,7 +211,9 @@ export async function runSessionsRepair(options, io) {
|
|
|
189
211
|
if (action.rewrite !== undefined) {
|
|
190
212
|
const result = await rewriteSessionLogDir(action.dir, action.rewrite.to);
|
|
191
213
|
if (!result.ok) {
|
|
192
|
-
|
|
214
|
+
const msg = '改写首帧失败(未搬目录)/ rewrite failed: ' + action.sessionId + ' reason=' + String(result.reason);
|
|
215
|
+
io.error(msg);
|
|
216
|
+
results.push({ sessionId: action.sessionId, kind: action.kind, ok: false, error: msg });
|
|
193
217
|
failures += 1;
|
|
194
218
|
continue;
|
|
195
219
|
}
|
|
@@ -199,38 +223,50 @@ export async function runSessionsRepair(options, io) {
|
|
|
199
223
|
? undefined
|
|
200
224
|
: join(sessionsRoot, action.toProjectKey, action.sessionId);
|
|
201
225
|
if (targetDir === undefined) {
|
|
202
|
-
|
|
226
|
+
const msg = '缺少目标 projectKey,跳过 / missing target projectKey: ' + action.sessionId;
|
|
227
|
+
io.error(msg);
|
|
228
|
+
results.push({ sessionId: action.sessionId, kind: action.kind, ok: false, error: msg });
|
|
203
229
|
failures += 1;
|
|
204
230
|
continue;
|
|
205
231
|
}
|
|
206
232
|
if (await exists(targetDir)) {
|
|
207
|
-
|
|
233
|
+
const msg = '目标目录已存在,拒绝覆盖 / target exists: ' + targetDir;
|
|
234
|
+
io.error(msg);
|
|
208
235
|
if (rewritten && action.rewrite !== undefined) {
|
|
209
236
|
const back = await rewriteSessionLogDir(action.dir, action.rewrite.from);
|
|
210
237
|
io.error(back.ok ? '已回滚首帧改写 / rewrite rolled back' : '回滚失败(请人工检查)/ rollback FAILED');
|
|
211
238
|
}
|
|
239
|
+
results.push({ sessionId: action.sessionId, kind: action.kind, ok: false, error: msg });
|
|
212
240
|
failures += 1;
|
|
213
241
|
continue;
|
|
214
242
|
}
|
|
215
243
|
await fs.mkdir(join(targetDir, '..'), { recursive: true });
|
|
216
244
|
await fs.rename(action.dir, targetDir);
|
|
217
245
|
if (!(await exists(targetDir)) || await exists(action.dir)) {
|
|
218
|
-
|
|
246
|
+
const msg = '搬迁自检失败 / post-move check failed: ' + action.dir;
|
|
247
|
+
io.error(msg);
|
|
248
|
+
results.push({ sessionId: action.sessionId, kind: action.kind, ok: false, error: msg });
|
|
219
249
|
failures += 1;
|
|
220
250
|
continue;
|
|
221
251
|
}
|
|
222
|
-
|
|
223
|
-
|
|
252
|
+
logHuman('已归位 / moved: ' + action.sessionId + ' ' + action.fromProjectKey + ' → ' + action.toProjectKey);
|
|
253
|
+
logHuman(' 会话目录 / dir: ' + targetDir);
|
|
224
254
|
if (rewritten) {
|
|
225
|
-
|
|
255
|
+
logHuman(' 已改写首帧 cwd(其余帧逐字节保留);DSH 侧工作区登记请启动 DSH 后在「会话归位」卡片执行。');
|
|
226
256
|
}
|
|
257
|
+
results.push({ sessionId: action.sessionId, kind: action.kind, ok: true, targetDir });
|
|
227
258
|
}
|
|
228
259
|
catch (error) {
|
|
229
|
-
|
|
260
|
+
const msg = '修复失败 / repair failed: ' + action.sessionId + ' ' + (error instanceof Error ? error.message : String(error));
|
|
261
|
+
io.error(msg);
|
|
262
|
+
results.push({ sessionId: action.sessionId, kind: action.kind, ok: false, error: msg });
|
|
230
263
|
failures += 1;
|
|
231
264
|
}
|
|
232
265
|
}
|
|
233
|
-
|
|
266
|
+
logHuman(failures === 0 ? '完成(无失败)/ done' : '完成但有 ' + String(failures) + ' 项失败 / done with failures');
|
|
267
|
+
if (options.json) {
|
|
268
|
+
io.log(JSON.stringify({ ok: failures === 0, dryRun: false, home: options.home, sessionsRoot, failures, summary: plan.summary, results }, null, 2));
|
|
269
|
+
}
|
|
234
270
|
return failures === 0 ? 0 : 1;
|
|
235
271
|
}
|
|
236
272
|
//# sourceMappingURL=sessions-repair.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** 客户端脚本原文(page.ts 内联进 <script>;不得含字面量 </script 或 <!--)。 */
|
|
2
|
-
export declare const CONSOLE_SCRIPT = "(function () {\n 'use strict';\n\n // ---- \u4E09\u6001\u4E3B\u9898\uFF1A\u81EA\u52A8 / \u6D45\u8272 / \u6DF1\u8272 ----\n // \u4E3A\u4EC0\u4E48\u653E\u5728\u6700\u524D\u9762\uFF1A\u5B83\u8981\u5728**\u9996\u5E27\u4E4B\u524D**\u628A data-theme \u843D\u5230 <html> \u4E0A\uFF0C\u5426\u5219\u5F3A\u5236\u4E3B\u9898\u4F1A\u5148\u95EA\u4E00\u4E0B\u3002\n // \u4E3A\u4EC0\u4E48\u7528 cookie \u800C\u4E0D\u662F storage\uFF1Acookie \u4E0D\u533A\u5206\u7AEF\u53E3\uFF0C\u800C\u6551\u6025\u53F0\u6BCF\u6B21\u542F\u52A8\u6362\u968F\u673A\u7AEF\u53E3 \u2014\u2014 \u53EA\u6709 cookie \u80FD\u8DE8\u6B21\u8BB0\u4F4F\u3002\n var THEME_KEY = 'dcm-theme';\n var THEME_MODES = ['auto', 'light', 'dark'];\n function readTheme() {\n var parts = ('; ' + document.cookie).split('; ' + THEME_KEY + '=');\n if (parts.length < 2) return 'auto';\n var value = String(parts[1]).split(';')[0];\n return THEME_MODES.indexOf(value) === -1 ? 'auto' : value;\n }\n function applyTheme(mode, persist) {\n var next = THEME_MODES.indexOf(mode) === -1 ? 'auto' : mode;\n document.documentElement.setAttribute('data-theme', next);\n var list = document.querySelectorAll('[data-dcm-theme]');\n for (var i = 0; i < list.length; i++) {\n list[i].setAttribute('aria-pressed', list[i].getAttribute('data-dcm-theme') === next ? 'true' : 'false');\n }\n if (persist === true) {\n // \u975E\u654F\u611F\u504F\u597D\uFF08\u4E0D\u542B\u4EFB\u4F55\u5BC6\u94A5/\u8DEF\u5F84\uFF09\uFF1Bcookie \u88AB\u7981\u7528\u65F6\u9759\u9ED8\u964D\u7EA7\u4E3A\u300C\u672C\u6B21\u6709\u6548\u300D\n document.cookie = THEME_KEY + '=' + next + '; path=/; max-age=31536000; SameSite=Lax';\n }\n }\n // \u6709\u811A\u672C = \u5F00\u5173\u53EF\u7528\uFF1B\u65E0\u811A\u672C\u65F6\u5B83\u88AB CSS \u9690\u85CF\uFF0C\u9875\u9762\u56DE\u843D\u5230 prefers-color-scheme \u7684\u81EA\u52A8\u6A21\u5F0F\n document.documentElement.setAttribute('data-dcm-js', '1');\n applyTheme(readTheme(), false);\n document.addEventListener('click', function (event) {\n var node = event.target;\n while (node !== null && node !== document) {\n if (typeof node.hasAttribute === 'function' && node.hasAttribute('data-dcm-theme')) {\n applyTheme(String(node.getAttribute('data-dcm-theme')), true);\n return;\n }\n node = node.parentNode;\n }\n });\n // \u79BB\u7EBF\u6551\u6025\u53F0\u7684**\u552F\u4E00**\u5BA2\u6237\u7AEF\u811A\u672C\uFF1A\u53EA\u505A\u4E24\u4EF6\u4E8B \u2014\u2014 \u2460 \u4F1A\u8BDD\u5185\u72B6\u6001\u6062\u590D\uFF08sessionStorage\uFF0Cdcm: \u524D\u7F00\uFF09\n // \u2461 \u628A\u786E\u8BA4\u8868\u5355\u4ECE details \u5347\u7EA7\u6210\u539F\u751F dialog \u5143\u7D20\u3002\u7981\u7528 JS \u65F6\u4E24\u8005\u90FD\u4E0D\u53C2\u4E0E\uFF0C\u9875\u9762\u56DE\u843D\u5230\u7EAF HTML\u3002\n var PREFIX = 'dcm:';\n // \u663E\u5F0F\u9ED1\u540D\u5355\uFF08\u4E0D\u662F\u300C\u9760\u6CA1\u5199\u8FDB\u53BB\u300D\uFF09\uFF1A\u8FD9\u4E9B type \u4E00\u5F8B\u4E0D\u843D storage\n var BLOCKED_TYPES = { password: 1, hidden: 1, file: 1, submit: 1, button: 1, reset: 1, image: 1 };\n // \u663E\u5F0F\u9ED1\u540D\u5355\uFF08\u6309\u5B57\u6BB5\u540D\uFF09\uFF1Atoken / \u5BC6\u7801 / \u673A\u5BC6 / \u51ED\u636E / \u91CD\u88C5\u786E\u8BA4\u7801 / cookie \u4E00\u5F8B\u4E0D\u843D storage\n var BLOCKED_NAMES = /(token|password|passwd|secret|credential|phrase|cookie|apikey|authorization)/i;\n var store = null;\n try {\n store = window.sessionStorage;\n store.setItem(PREFIX + 'probe', '1');\n store.removeItem(PREFIX + 'probe');\n } catch (error) {\n store = null;\n }\n function readJson(key) {\n if (store === null) return null;\n try {\n var raw = store.getItem(key);\n return raw === null ? null : JSON.parse(raw);\n } catch (error) {\n return null;\n }\n }\n function writeJson(key, value) {\n if (store === null) return;\n try {\n store.setItem(key, JSON.stringify(value));\n } catch (error) {\n // \u914D\u989D\u5DF2\u6EE1 / \u9690\u79C1\u6A21\u5F0F\uFF1A\u9759\u9ED8\u964D\u7EA7\uFF0C\u9875\u9762\u7167\u5E38\u53EF\u7528\n }\n }\n function pageKey() {\n return location.pathname + location.search;\n }\n function persistable(el) {\n if (!el || typeof el.name !== 'string' || el.name === '') return false;\n var type = (el.type || '').toLowerCase();\n if (BLOCKED_TYPES[type] === 1) return false;\n if (BLOCKED_NAMES.test(el.name)) return false;\n if (typeof el.id === 'string' && el.id !== '' && BLOCKED_NAMES.test(el.id)) return false;\n return true;\n }\n function fieldKey(el) {\n var scope = el.form ? String(el.form.getAttribute('action') || '') : '';\n return PREFIX + 'field:' + pageKey() + ':' + scope + ':' + el.name + (el.type === 'radio' ? '=' + String(el.value) : '');\n }\n function restoreFields() {\n var list = document.querySelectorAll('input, select, textarea');\n for (var i = 0; i < list.length; i++) {\n var el = list[i];\n if (!persistable(el)) continue;\n var saved = readJson(fieldKey(el));\n if (saved === null) continue;\n if (el.type === 'checkbox' || el.type === 'radio') {\n if (typeof saved.checked === 'boolean') el.checked = saved.checked;\n } else if (typeof saved.value === 'string') {\n el.value = saved.value;\n }\n }\n }\n function onField(event) {\n var el = event.target;\n if (!persistable(el)) return;\n if (el.type === 'checkbox' || el.type === 'radio') writeJson(fieldKey(el), { checked: el.checked === true });\n else writeJson(fieldKey(el), { value: String(el.value) });\n }\n document.addEventListener('change', onField, true);\n document.addEventListener('input', onField, true);\n function detailsState() {\n var list = document.querySelectorAll('details[data-dcm-persist]');\n for (var i = 0; i < list.length; i++) {\n var details = list[i];\n var id = details.getAttribute('data-dcm-persist') || String(i);\n var saved = readJson(PREFIX + 'open:' + pageKey() + ':' + id);\n if (typeof saved === 'boolean') details.open = saved;\n }\n }\n document.addEventListener('toggle', function (event) {\n var details = event.target;\n if (!details || details.tagName !== 'DETAILS') return;\n var id = details.getAttribute('data-dcm-persist');\n if (id === null) return;\n writeJson(PREFIX + 'open:' + pageKey() + ':' + id, details.open === true);\n }, true);\n function scrollKey() {\n return PREFIX + 'scroll:' + pageKey();\n }\n var navType = '';\n try {\n var entries = performance.getEntriesByType('navigation');\n if (entries.length > 0) navType = String(entries[0].type || '');\n } catch (error) {\n navType = '';\n }\n function currentScroll() {\n return window.pageYOffset || document.documentElement.scrollTop || 0;\n }\n var scrollTimer = null;\n function saveScroll() {\n writeJson(scrollKey(), { y: Math.round(currentScroll()), t: Date.now() });\n }\n window.addEventListener('scroll', function () {\n if (scrollTimer !== null) return;\n scrollTimer = window.setTimeout(function () {\n scrollTimer = null;\n saveScroll();\n }, 150);\n }, { passive: true });\n window.addEventListener('pagehide', saveScroll);\n document.addEventListener('visibilitychange', function () {\n if (document.visibilityState === 'hidden') saveScroll();\n });\n function restoreScroll() {\n var saved = readJson(scrollKey());\n if (saved === null || typeof saved.y !== 'number' || saved.y <= 0) return;\n window.scrollTo(0, saved.y);\n }\n // \u53EA\u5728\u300C\u5237\u65B0\u300D\u4E0E\u300C\u540E\u9000/\u524D\u8FDB\u300D\u6062\u590D\uFF1A\u666E\u901A\u65B0\u5BFC\u822A\uFF08type=navigate\uFF09\u4ECE\u9876\u90E8\u5F00\u59CB\n if (navType === '' || navType === 'reload' || navType === 'back_forward') {\n window.requestAnimationFrame(function () {\n window.requestAnimationFrame(restoreScroll);\n });\n }\n function enhanceOne(details) {\n var form = details.querySelector('form');\n if (form === null) return;\n var summary = details.querySelector('summary');\n var dialog = document.createElement('dialog');\n dialog.className = 'dcmDialog';\n var body = details.querySelector('.confirmBody');\n if (body !== null) {\n while (body.firstChild !== null) dialog.appendChild(body.firstChild);\n } else {\n dialog.appendChild(form);\n }\n var footer = document.createElement('div');\n footer.className = 'dialogFooter';\n var cancel = document.createElement('button');\n cancel.type = 'button';\n cancel.className = 'btnPlain';\n cancel.textContent = '\u53D6\u6D88';\n cancel.addEventListener('click', function () { dialog.close(); });\n footer.appendChild(cancel);\n dialog.appendChild(footer);\n dialog.addEventListener('click', function (event) {\n if (event.target === dialog) dialog.close();\n });\n document.body.appendChild(dialog);\n var trigger = document.createElement('button');\n trigger.type = 'button';\n trigger.setAttribute('data-dcm-trigger', '');\n trigger.className = summary === null ? 'btnPrimary' : summary.className;\n trigger.textContent = summary === null ? '\u786E\u8BA4\u6267\u884C' : String(summary.textContent || '\u786E\u8BA4\u6267\u884C');\n trigger.addEventListener('click', function () {\n if (dialog.open) dialog.close();\n else dialog.showModal();\n });\n if (details.parentNode !== null) details.parentNode.replaceChild(trigger, details);\n }\n function enhanceDialogs() {\n if (typeof document.createElement('dialog').showModal !== 'function') return;\n var list = document.querySelectorAll('details[data-dcm-confirm]');\n for (var i = 0; i < list.length; i++) enhanceOne(list[i]);\n }\n document.addEventListener('click', function (event) {\n var node = event.target;\n while (node !== null && node !== document) {\n if (typeof node.hasAttribute === 'function' && node.hasAttribute('data-dcm-back')) {\n if (window.history.length > 1) {\n event.preventDefault();\n window.history.back();\n }\n return;\n }\n node = node.parentNode;\n }\n });\n function boot() {\n applyTheme(readTheme(), false); // DOM \u5230\u4F4D\u540E\u628A\u5F00\u5173\u7684\u9009\u4E2D\u6001\u5BF9\u9F50\uFF08\u9996\u5E27\u90A3\u6761\u5DF2\u7ECF\u8BBE\u8FC7 data-theme\uFF09\n detailsState();\n enhanceDialogs();\n restoreFields();\n }\n if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot);\n else boot();\n})();";
|
|
2
|
+
export declare const CONSOLE_SCRIPT = "(function () {\n 'use strict';\n\n // ---- \u4E09\u6001\u4E3B\u9898\uFF1A\u81EA\u52A8 / \u6D45\u8272 / \u6DF1\u8272 ----\n // \u4E3A\u4EC0\u4E48\u653E\u5728\u6700\u524D\u9762\uFF1A\u5B83\u8981\u5728**\u9996\u5E27\u4E4B\u524D**\u628A data-theme \u843D\u5230 <html> \u4E0A\uFF0C\u5426\u5219\u5F3A\u5236\u4E3B\u9898\u4F1A\u5148\u95EA\u4E00\u4E0B\u3002\n // \u4E3A\u4EC0\u4E48\u7528 cookie \u800C\u4E0D\u662F storage\uFF1Acookie \u4E0D\u533A\u5206\u7AEF\u53E3\uFF0C\u800C\u6551\u6025\u53F0\u6BCF\u6B21\u542F\u52A8\u6362\u968F\u673A\u7AEF\u53E3 \u2014\u2014 \u53EA\u6709 cookie \u80FD\u8DE8\u6B21\u8BB0\u4F4F\u3002\n var THEME_KEY = 'dcm-theme';\n var THEME_MODES = ['auto', 'light', 'dark'];\n function readTheme() {\n var parts = ('; ' + document.cookie).split('; ' + THEME_KEY + '=');\n if (parts.length < 2) return 'auto';\n var value = String(parts[1]).split(';')[0];\n return THEME_MODES.indexOf(value) === -1 ? 'auto' : value;\n }\n function applyTheme(mode, persist) {\n var next = THEME_MODES.indexOf(mode) === -1 ? 'auto' : mode;\n document.documentElement.setAttribute('data-theme', next);\n var list = document.querySelectorAll('[data-dcm-theme]');\n for (var i = 0; i < list.length; i++) {\n list[i].setAttribute('aria-pressed', list[i].getAttribute('data-dcm-theme') === next ? 'true' : 'false');\n }\n if (persist === true) {\n // \u975E\u654F\u611F\u504F\u597D\uFF08\u4E0D\u542B\u4EFB\u4F55\u5BC6\u94A5/\u8DEF\u5F84\uFF09\uFF1Bcookie \u88AB\u7981\u7528\u65F6\u9759\u9ED8\u964D\u7EA7\u4E3A\u300C\u672C\u6B21\u6709\u6548\u300D\n document.cookie = THEME_KEY + '=' + next + '; path=/; max-age=31536000; SameSite=Lax';\n }\n }\n // \u6709\u811A\u672C = \u5F00\u5173\u53EF\u7528\uFF1B\u65E0\u811A\u672C\u65F6\u5B83\u88AB CSS \u9690\u85CF\uFF0C\u9875\u9762\u56DE\u843D\u5230 prefers-color-scheme \u7684\u81EA\u52A8\u6A21\u5F0F\n document.documentElement.setAttribute('data-dcm-js', '1');\n applyTheme(readTheme(), false);\n document.addEventListener('click', function (event) {\n var node = event.target;\n while (node !== null && node !== document) {\n if (typeof node.hasAttribute === 'function' && node.hasAttribute('data-dcm-theme')) {\n applyTheme(String(node.getAttribute('data-dcm-theme')), true);\n return;\n }\n node = node.parentNode;\n }\n });\n function copyText(text, btn) {\n var done = function () {\n var orig = btn.getAttribute('data-dcm-orig') || btn.textContent || '\u590D\u5236';\n if (!btn.getAttribute('data-dcm-orig')) btn.setAttribute('data-dcm-orig', orig);\n btn.setAttribute('data-copied', '1');\n btn.textContent = '\u5DF2\u590D\u5236 \u2713';\n if (typeof window.setTimeout === 'function') {\n window.setTimeout(function () {\n btn.removeAttribute('data-copied');\n btn.textContent = orig;\n }, 1200);\n }\n };\n if (typeof navigator !== 'undefined' && navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {\n navigator.clipboard.writeText(text).then(done, function () { fallbackCopy(text, done); });\n return;\n }\n fallbackCopy(text, done);\n }\n function fallbackCopy(text, done) {\n try {\n var ta = document.createElement('textarea');\n ta.value = text;\n ta.setAttribute('readonly', '');\n ta.style.position = 'fixed';\n ta.style.opacity = '0';\n document.body.appendChild(ta);\n ta.select();\n document.execCommand('copy');\n document.body.removeChild(ta);\n done();\n } catch (e) {\n // \u526A\u8D34\u677F\u4E0D\u53EF\u7528\u65F6\u9759\u9ED8\u9000\u51FA\uFF0C\u4E0D\u6253\u65AD\u9875\u9762\u4EA4\u4E92\n }\n }\n // \u79BB\u7EBF\u6551\u6025\u53F0\u7684**\u552F\u4E00**\u5BA2\u6237\u7AEF\u811A\u672C\uFF1A\u53EA\u505A\u4E24\u4EF6\u4E8B \u2014\u2014 \u2460 \u4F1A\u8BDD\u5185\u72B6\u6001\u6062\u590D\uFF08sessionStorage\uFF0Cdcm: \u524D\u7F00\uFF09\n // \u2461 \u628A\u786E\u8BA4\u8868\u5355\u4ECE details \u5347\u7EA7\u6210\u539F\u751F dialog \u5143\u7D20\u3002\u7981\u7528 JS \u65F6\u4E24\u8005\u90FD\u4E0D\u53C2\u4E0E\uFF0C\u9875\u9762\u56DE\u843D\u5230\u7EAF HTML\u3002\n var PREFIX = 'dcm:';\n // \u663E\u5F0F\u9ED1\u540D\u5355\uFF08\u4E0D\u662F\u300C\u9760\u6CA1\u5199\u8FDB\u53BB\u300D\uFF09\uFF1A\u8FD9\u4E9B type \u4E00\u5F8B\u4E0D\u843D storage\n var BLOCKED_TYPES = { password: 1, hidden: 1, file: 1, submit: 1, button: 1, reset: 1, image: 1 };\n // \u663E\u5F0F\u9ED1\u540D\u5355\uFF08\u6309\u5B57\u6BB5\u540D\uFF09\uFF1Atoken / \u5BC6\u7801 / \u673A\u5BC6 / \u51ED\u636E / \u91CD\u88C5\u786E\u8BA4\u7801 / cookie \u4E00\u5F8B\u4E0D\u843D storage\n var BLOCKED_NAMES = /(token|password|passwd|secret|credential|phrase|cookie|apikey|authorization)/i;\n var store = null;\n try {\n store = window.sessionStorage;\n store.setItem(PREFIX + 'probe', '1');\n store.removeItem(PREFIX + 'probe');\n } catch (error) {\n store = null;\n }\n function readJson(key) {\n if (store === null) return null;\n try {\n var raw = store.getItem(key);\n return raw === null ? null : JSON.parse(raw);\n } catch (error) {\n return null;\n }\n }\n function writeJson(key, value) {\n if (store === null) return;\n try {\n store.setItem(key, JSON.stringify(value));\n } catch (error) {\n // \u914D\u989D\u5DF2\u6EE1 / \u9690\u79C1\u6A21\u5F0F\uFF1A\u9759\u9ED8\u964D\u7EA7\uFF0C\u9875\u9762\u7167\u5E38\u53EF\u7528\n }\n }\n function pageKey() {\n return location.pathname + location.search;\n }\n function persistable(el) {\n if (!el || typeof el.name !== 'string' || el.name === '') return false;\n var type = (el.type || '').toLowerCase();\n if (BLOCKED_TYPES[type] === 1) return false;\n if (BLOCKED_NAMES.test(el.name)) return false;\n if (typeof el.id === 'string' && el.id !== '' && BLOCKED_NAMES.test(el.id)) return false;\n return true;\n }\n function fieldKey(el) {\n var scope = el.form ? String(el.form.getAttribute('action') || '') : '';\n return PREFIX + 'field:' + pageKey() + ':' + scope + ':' + el.name + (el.type === 'radio' ? '=' + String(el.value) : '');\n }\n function restoreFields() {\n var list = document.querySelectorAll('input, select, textarea');\n for (var i = 0; i < list.length; i++) {\n var el = list[i];\n if (!persistable(el)) continue;\n var saved = readJson(fieldKey(el));\n if (saved === null) continue;\n if (el.type === 'checkbox' || el.type === 'radio') {\n if (typeof saved.checked === 'boolean') el.checked = saved.checked;\n } else if (typeof saved.value === 'string') {\n el.value = saved.value;\n }\n }\n }\n function onField(event) {\n var el = event.target;\n if (el && el.required && typeof el.setAttribute === 'function') {\n el.setAttribute('aria-invalid', String(el.value || '').trim() === '' ? 'true' : 'false');\n }\n if (!persistable(el)) return;\n if (el.type === 'checkbox' || el.type === 'radio') writeJson(fieldKey(el), { checked: el.checked === true });\n else writeJson(fieldKey(el), { value: String(el.value) });\n }\n document.addEventListener('change', onField, true);\n document.addEventListener('input', onField, true);\n document.addEventListener('submit', function (event) {\n var form = event.target;\n if (!form || form.tagName !== 'FORM') return;\n form.setAttribute('aria-busy', 'true');\n if (typeof form.querySelector !== 'function') return;\n var btn = form.querySelector('button[type=\"submit\"]');\n if (!btn || btn.disabled) return;\n btn.disabled = true;\n var spin = document.createElement('span');\n spin.className = 'btnSpinner';\n spin.setAttribute('aria-hidden', 'true');\n btn.textContent = '';\n btn.appendChild(spin);\n btn.appendChild(document.createTextNode('\u6267\u884C\u4E2D\u2026'));\n }, true);\n function detailsState() {\n var list = document.querySelectorAll('details[data-dcm-persist]');\n for (var i = 0; i < list.length; i++) {\n var details = list[i];\n var id = details.getAttribute('data-dcm-persist') || String(i);\n var saved = readJson(PREFIX + 'open:' + pageKey() + ':' + id);\n if (typeof saved === 'boolean') details.open = saved;\n }\n }\n document.addEventListener('toggle', function (event) {\n var details = event.target;\n if (!details || details.tagName !== 'DETAILS') return;\n var id = details.getAttribute('data-dcm-persist');\n if (id === null) return;\n writeJson(PREFIX + 'open:' + pageKey() + ':' + id, details.open === true);\n }, true);\n function scrollKey() {\n return PREFIX + 'scroll:' + pageKey();\n }\n var navType = '';\n try {\n var entries = performance.getEntriesByType('navigation');\n if (entries.length > 0) navType = String(entries[0].type || '');\n } catch (error) {\n navType = '';\n }\n function currentScroll() {\n return window.pageYOffset || document.documentElement.scrollTop || 0;\n }\n var scrollTimer = null;\n function saveScroll() {\n writeJson(scrollKey(), { y: Math.round(currentScroll()), t: Date.now() });\n }\n window.addEventListener('scroll', function () {\n if (scrollTimer !== null) return;\n scrollTimer = window.setTimeout(function () {\n scrollTimer = null;\n saveScroll();\n }, 150);\n }, { passive: true });\n window.addEventListener('pagehide', saveScroll);\n document.addEventListener('visibilitychange', function () {\n if (document.visibilityState === 'hidden') saveScroll();\n });\n function restoreScroll() {\n var saved = readJson(scrollKey());\n if (saved === null || typeof saved.y !== 'number' || saved.y <= 0) return;\n window.scrollTo(0, saved.y);\n }\n // \u53EA\u5728\u300C\u5237\u65B0\u300D\u4E0E\u300C\u540E\u9000/\u524D\u8FDB\u300D\u6062\u590D\uFF1A\u666E\u901A\u65B0\u5BFC\u822A\uFF08type=navigate\uFF09\u4ECE\u9876\u90E8\u5F00\u59CB\n if (navType === '' || navType === 'reload' || navType === 'back_forward') {\n window.requestAnimationFrame(function () {\n window.requestAnimationFrame(restoreScroll);\n });\n }\n function enhanceOne(details) {\n var form = details.querySelector('form');\n if (form === null) return;\n var summary = details.querySelector('summary');\n var dialog = document.createElement('dialog');\n dialog.className = 'dcmDialog';\n var body = details.querySelector('.confirmBody');\n if (body !== null) {\n while (body.firstChild !== null) dialog.appendChild(body.firstChild);\n } else {\n dialog.appendChild(form);\n }\n var footer = document.createElement('div');\n footer.className = 'dialogFooter';\n var cancel = document.createElement('button');\n cancel.type = 'button';\n cancel.className = 'btnPlain';\n cancel.textContent = '\u53D6\u6D88';\n cancel.addEventListener('click', function () { dialog.close(); });\n footer.appendChild(cancel);\n dialog.appendChild(footer);\n dialog.addEventListener('click', function (event) {\n if (event.target === dialog) dialog.close();\n });\n document.body.appendChild(dialog);\n var trigger = document.createElement('button');\n trigger.type = 'button';\n trigger.setAttribute('data-dcm-trigger', '');\n trigger.className = summary === null ? 'btnPrimary' : summary.className;\n trigger.textContent = summary === null ? '\u786E\u8BA4\u6267\u884C' : String(summary.textContent || '\u786E\u8BA4\u6267\u884C');\n trigger.addEventListener('click', function () {\n if (dialog.open) dialog.close();\n else dialog.showModal();\n });\n if (details.parentNode !== null) details.parentNode.replaceChild(trigger, details);\n }\n function enhanceDialogs() {\n if (typeof document.createElement('dialog').showModal !== 'function') return;\n var list = document.querySelectorAll('details[data-dcm-confirm]');\n for (var i = 0; i < list.length; i++) enhanceOne(list[i]);\n }\n document.addEventListener('click', function (event) {\n var menus = document.querySelectorAll('details[data-dcm-nav-group][open]');\n for (var m = 0; m < menus.length; m++) {\n var menu = menus[m];\n if (typeof menu.contains === 'function' && (!menu.contains(event.target) || (event.target && event.target.tagName === 'A'))) {\n menu.open = false;\n }\n }\n var node = event.target;\n while (node !== null && node !== document) {\n if (typeof node.hasAttribute === 'function') {\n if (node.hasAttribute('data-dcm-copy')) {\n copyText(String(node.getAttribute('data-dcm-copy') || ''), node);\n return;\n }\n if (node.hasAttribute('data-dcm-back')) {\n if (window.history.length > 1) {\n event.preventDefault();\n window.history.back();\n }\n return;\n }\n }\n node = node.parentNode;\n }\n });\n function boot() {\n applyTheme(readTheme(), false); // DOM \u5230\u4F4D\u540E\u628A\u5F00\u5173\u7684\u9009\u4E2D\u6001\u5BF9\u9F50\uFF08\u9996\u5E27\u90A3\u6761\u5DF2\u7ECF\u8BBE\u8FC7 data-theme\uFF09\n detailsState();\n enhanceDialogs();\n restoreFields();\n }\n if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot);\n else boot();\n})();";
|
|
3
3
|
/**
|
|
4
4
|
* 从本文件的**源码文本**里抽出 CONSOLE_SCRIPT 模板串(测试用;**唯一实现**)。
|
|
5
5
|
*
|