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/src/cli/index.ts
CHANGED
|
@@ -174,24 +174,18 @@ const WEB_REJECTED_FLAGS = new Set([
|
|
|
174
174
|
'--wipe-config', '--version', '--json', '--fix',
|
|
175
175
|
]);
|
|
176
176
|
|
|
177
|
-
/** recover-stale-lock
|
|
177
|
+
/** recover-stale-lock 专用解析:接受 --data-dir / --data-root(用于定位 locks 目录) */
|
|
178
178
|
function parseCliDataDir(argv: readonly string[]): ParseResult {
|
|
179
179
|
const options: CliOptions = { command: 'recover-stale-lock', dryRun: false, profile: 'web', yes: false, list: false, wipeConfig: false, json: false, positionals: [] };
|
|
180
180
|
for (let i = 1; i < argv.length; i += 1) {
|
|
181
181
|
const flag = argv[i]!;
|
|
182
|
-
if (flag === '--help' || flag === '-h') {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (
|
|
186
|
-
const value =
|
|
187
|
-
if (value === undefined || value === '' || value.startsWith('-')) {
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
options.dataDir = value;
|
|
191
|
-
i += 1;
|
|
192
|
-
} else if (flag.startsWith('--data-dir=')) {
|
|
193
|
-
options.dataDir = flag.slice('--data-dir='.length);
|
|
194
|
-
if (options.dataDir === '') return { ok: false, error: '参数 --data-dir 缺少值 / missing value for --data-dir' };
|
|
182
|
+
if (flag === '--help' || flag === '-h') return { ok: true, options: { ...options, command: 'help', helpTopic: 'recover-stale-lock' } };
|
|
183
|
+
const at = flag.indexOf('=');
|
|
184
|
+
const name = at >= 0 ? flag.slice(0, at) : flag;
|
|
185
|
+
if (name === '--data-dir' || name === '--data-root') {
|
|
186
|
+
const value = at >= 0 ? flag.slice(at + 1) : argv[++i];
|
|
187
|
+
if (value === undefined || value === '' || value.startsWith('-')) return { ok: false, error: `参数 ${name} 缺少值 / missing value for ${name}` };
|
|
188
|
+
if (name === '--data-dir') options.dataDir = value; else options.dataRoot = value;
|
|
195
189
|
} else {
|
|
196
190
|
return { ok: false, error: `未知参数 / unknown flag: ${flag}` };
|
|
197
191
|
}
|
|
@@ -199,19 +193,9 @@ function parseCliDataDir(argv: readonly string[]): ParseResult {
|
|
|
199
193
|
return { ok: true, options };
|
|
200
194
|
}
|
|
201
195
|
|
|
202
|
-
/*
|
|
203
|
-
* 「本机有没有 DSH 在跑」的判据已抽到 src/cli/actions.ts 的 readRunningInstances
|
|
204
|
-
* (救急台网页与 sessions repair 的安全门共用同一实现;旧实现把快照目录当 dataDir 用,
|
|
205
|
-
* 缺省路径下找不到心跳 → 门形同虚设,已一并修正)。
|
|
206
|
-
*/
|
|
207
|
-
|
|
196
|
+
/* 「本机有没有 DSH 在跑」的判据已抽到 src/cli/actions.ts 的 readRunningInstances */
|
|
208
197
|
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* sessions 专用解析:sessions repair [--home <dir>] [--fix] [--keep <dir>] [--map old=new]... [--json]
|
|
212
|
-
*
|
|
213
|
-
* 与 recover-stale-lock 同样的姿态:独立解析器,只接受本动作真正有意义的参数(绝不悄悄忽略)。
|
|
214
|
-
*/
|
|
198
|
+
/** sessions 专用解析:sessions list|doctor|repair [--home <dir>] [--data-dir <dir>] [--data-root <dir>] [--fix] [--keep <dir>] [--map old=new]... [--json] */
|
|
215
199
|
function parseCliSessions(argv: readonly string[]): ParseResult {
|
|
216
200
|
const options: CliOptions = {
|
|
217
201
|
command: 'sessions', dryRun: false, profile: 'web', yes: false, list: false,
|
|
@@ -219,41 +203,26 @@ function parseCliSessions(argv: readonly string[]): ParseResult {
|
|
|
219
203
|
};
|
|
220
204
|
const rest = argv.slice(1);
|
|
221
205
|
const action = rest[0];
|
|
222
|
-
if (action === undefined) return { ok: false, error: 'sessions
|
|
223
|
-
if (action === '--help' || action === '-h') {
|
|
224
|
-
return { ok: true, options: { ...options, command: 'help', helpTopic: 'sessions' } };
|
|
225
|
-
}
|
|
226
|
-
// T6:三个只读/安全动作 —— list(列出会话)/ doctor(体检)/ repair(预览或 --fix 执行)
|
|
206
|
+
if (action === undefined) return { ok: false, error: 'sessions 需要子动作(list / doctor / repair)/ missing action' };
|
|
207
|
+
if (action === '--help' || action === '-h') return { ok: true, options: { ...options, command: 'help', helpTopic: 'sessions' } };
|
|
227
208
|
if (action !== 'repair' && action !== 'list' && action !== 'doctor') {
|
|
228
209
|
return { ok: false, error: 'sessions 只支持 list / doctor / repair / unsupported action: ' + action };
|
|
229
210
|
}
|
|
230
211
|
options.positionals.push(action);
|
|
231
212
|
for (let i = 1; i < rest.length; i += 1) {
|
|
232
213
|
const flag = rest[i]!;
|
|
233
|
-
if (flag === '--help' || flag === '-h') {
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
if (flag === '--fix') { options.fix = true; continue; }
|
|
237
|
-
if (flag === '--apply') { options.fix = true; continue; } // --apply 是 --fix 的可读别名(T6)
|
|
214
|
+
if (flag === '--help' || flag === '-h') return { ok: true, options: { ...options, command: 'help', helpTopic: 'sessions' } };
|
|
215
|
+
if (flag === '--fix' || flag === '--apply') { options.fix = true; continue; }
|
|
238
216
|
if (flag === '--json') { options.json = true; continue; }
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
if (flag === '--home') options.home = value;
|
|
245
|
-
else if (flag === '--keep') options.keep = value;
|
|
246
|
-
else options.maps!.push(value);
|
|
247
|
-
i += 1;
|
|
248
|
-
continue;
|
|
249
|
-
}
|
|
250
|
-
if (flag.startsWith('--home=') || flag.startsWith('--keep=') || flag.startsWith('--map=')) {
|
|
251
|
-
const at = flag.indexOf('=');
|
|
252
|
-
const name = flag.slice(0, at);
|
|
253
|
-
const value = flag.slice(at + 1);
|
|
254
|
-
if (value === '') return { ok: false, error: '参数 ' + name + ' 缺少值 / missing value for ' + name };
|
|
217
|
+
const at = flag.indexOf('=');
|
|
218
|
+
const name = at >= 0 ? flag.slice(0, at) : flag;
|
|
219
|
+
if (name === '--home' || name === '--keep' || name === '--map' || name === '--data-dir' || name === '--data-root') {
|
|
220
|
+
const value = at >= 0 ? flag.slice(at + 1) : rest[++i];
|
|
221
|
+
if (value === undefined || value === '' || value.startsWith('-')) return { ok: false, error: '参数 ' + name + ' 缺少值 / missing value for ' + name };
|
|
255
222
|
if (name === '--home') options.home = value;
|
|
256
223
|
else if (name === '--keep') options.keep = value;
|
|
224
|
+
else if (name === '--data-dir') options.dataDir = value;
|
|
225
|
+
else if (name === '--data-root') options.dataRoot = value;
|
|
257
226
|
else options.maps!.push(value);
|
|
258
227
|
continue;
|
|
259
228
|
}
|
|
@@ -262,13 +231,7 @@ function parseCliSessions(argv: readonly string[]): ParseResult {
|
|
|
262
231
|
return { ok: true, options };
|
|
263
232
|
}
|
|
264
233
|
|
|
265
|
-
/**
|
|
266
|
-
* import 专用解析:`import --from <source> [--dry-run] [--out <path>] [--cwd <dir>] [--data-dir <dir>]`
|
|
267
|
-
*
|
|
268
|
-
* 与 sessions / recover-stale-lock 同样的姿态:只接受本动作真正有意义的参数(绝不悄悄忽略)。
|
|
269
|
-
* `--from` 的值在这里**不做词表校验**:未知来源要由运行层给出「可用来源清单」——
|
|
270
|
-
* 那需要真实注册表(CLI 与宿主共用同一份装配,见 src/foreign/registry.ts)。
|
|
271
|
-
*/
|
|
234
|
+
/** import 专用解析:import --from <source> [--dry-run] [--out <path>] [--cwd <dir>] [--data-dir <dir>] */
|
|
272
235
|
function parseCliImport(argv: readonly string[]): ParseResult {
|
|
273
236
|
const options: CliOptions = {
|
|
274
237
|
command: 'import', dryRun: false, profile: 'web', yes: false, list: false,
|
|
@@ -278,23 +241,18 @@ function parseCliImport(argv: readonly string[]): ParseResult {
|
|
|
278
241
|
for (let i = 0; i < rest.length; i += 1) {
|
|
279
242
|
const flag = rest[i]!;
|
|
280
243
|
if (flag === '--help' || flag === '-h') return { ok: true, options: { ...options, command: 'help', helpTopic: 'import' } };
|
|
281
|
-
if (flag === '--dry-run') {
|
|
282
|
-
options.dryRun = true;
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
244
|
+
if (flag === '--dry-run') { options.dryRun = true; continue; }
|
|
285
245
|
const at = flag.indexOf('=');
|
|
286
246
|
const name = at >= 0 ? flag.slice(0, at) : flag;
|
|
287
|
-
const isValueFlag = name === '--from' || name === '--cwd' || name === '--out' || name === '--data-dir';
|
|
247
|
+
const isValueFlag = name === '--from' || name === '--cwd' || name === '--out' || name === '--data-dir' || name === '--data-root';
|
|
288
248
|
if (isValueFlag) {
|
|
289
|
-
const value = at >= 0 ? flag.slice(at + 1) : rest[i
|
|
290
|
-
if (value === undefined || value === '' || value.startsWith('-')) {
|
|
291
|
-
return { ok: false, error: '参数 ' + name + ' 缺少值 / missing value for ' + name };
|
|
292
|
-
}
|
|
249
|
+
const value = at >= 0 ? flag.slice(at + 1) : rest[++i];
|
|
250
|
+
if (value === undefined || value === '' || value.startsWith('-')) return { ok: false, error: '参数 ' + name + ' 缺少值 / missing value for ' + name };
|
|
293
251
|
if (name === '--from') options.from = value;
|
|
294
252
|
else if (name === '--cwd') options.cwd = value;
|
|
295
253
|
else if (name === '--out') options.out = value;
|
|
254
|
+
else if (name === '--data-root') options.dataRoot = value;
|
|
296
255
|
else options.dataDir = value;
|
|
297
|
-
if (at < 0) i += 1;
|
|
298
256
|
continue;
|
|
299
257
|
}
|
|
300
258
|
return { ok: false, error: '未知参数 / unknown flag: ' + flag };
|
|
@@ -334,8 +292,18 @@ export function parseCli(argv: readonly string[]): ParseResult { const command
|
|
|
334
292
|
|
|
335
293
|
const options: CliOptions = { command, dryRun: false, profile: 'web', yes: false, list: false, wipeConfig: false, json: false, positionals: [] };
|
|
336
294
|
const rest = argv.slice(1);
|
|
295
|
+
const takeValue = (flagName: string, idx: number, inline: string | undefined): { ok: true; value: string; nextIdx: number } | { ok: false; error: string } => {
|
|
296
|
+
const val = inline ?? rest[idx + 1];
|
|
297
|
+
if (val === undefined || val === '' || (inline === undefined && val.startsWith('-'))) {
|
|
298
|
+
return { ok: false, error: `参数 ${flagName} 缺少值 / missing value for ${flagName}` };
|
|
299
|
+
}
|
|
300
|
+
return { ok: true, value: val, nextIdx: inline === undefined ? idx + 1 : idx };
|
|
301
|
+
};
|
|
337
302
|
for (let i = 0; i < rest.length; i += 1) {
|
|
338
|
-
const
|
|
303
|
+
const rawFlag = rest[i]!;
|
|
304
|
+
const eq = rawFlag.startsWith('-') ? rawFlag.indexOf('=') : -1;
|
|
305
|
+
const flag = eq > 0 ? rawFlag.slice(0, eq) : rawFlag;
|
|
306
|
+
const inline = eq > 0 ? rawFlag.slice(eq + 1) : undefined;
|
|
339
307
|
if (flag === '--help' || flag === '-h') {
|
|
340
308
|
return { ok: true, options: { ...options, command: 'help', helpTopic: command } };
|
|
341
309
|
}
|
|
@@ -389,26 +357,22 @@ export function parseCli(argv: readonly string[]): ParseResult { const command
|
|
|
389
357
|
if (command !== 'web') {
|
|
390
358
|
return { ok: false, error: `${command} 子命令不支持参数 / flag not allowed here: ${flag}` };
|
|
391
359
|
}
|
|
392
|
-
const
|
|
393
|
-
if (
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
options.home = value;
|
|
397
|
-
i += 1;
|
|
360
|
+
const v = takeValue('--home', i, inline);
|
|
361
|
+
if (!v.ok) return v;
|
|
362
|
+
options.home = v.value;
|
|
363
|
+
i = v.nextIdx;
|
|
398
364
|
continue;
|
|
399
365
|
}
|
|
400
366
|
if (flag === '--port' || flag === '--idle-timeout') {
|
|
401
|
-
const
|
|
402
|
-
if (
|
|
403
|
-
|
|
404
|
-
}
|
|
405
|
-
const parsed = Number(value);
|
|
367
|
+
const v = takeValue(flag, i, inline);
|
|
368
|
+
if (!v.ok) return v;
|
|
369
|
+
const parsed = Number(v.value);
|
|
406
370
|
if (!Number.isInteger(parsed) || parsed < 0 || (flag === '--port' && parsed > 65535)) {
|
|
407
371
|
return { ok: false, error: `参数 ${flag} 需要 0 以上的整数 / ${flag} expects a non-negative integer` };
|
|
408
372
|
}
|
|
409
373
|
if (flag === '--port') options.port = parsed;
|
|
410
374
|
else options.idleTimeoutMin = parsed;
|
|
411
|
-
i
|
|
375
|
+
i = v.nextIdx;
|
|
412
376
|
continue;
|
|
413
377
|
}
|
|
414
378
|
if (flag === '--dry-run') {
|
|
@@ -428,29 +392,25 @@ export function parseCli(argv: readonly string[]): ParseResult { const command
|
|
|
428
392
|
continue;
|
|
429
393
|
}
|
|
430
394
|
if (flag === '--version') {
|
|
431
|
-
const
|
|
432
|
-
if (
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
options.version = value;
|
|
436
|
-
i += 1;
|
|
395
|
+
const v = takeValue('--version', i, inline);
|
|
396
|
+
if (!v.ok) return v;
|
|
397
|
+
options.version = v.value;
|
|
398
|
+
i = v.nextIdx;
|
|
437
399
|
continue;
|
|
438
400
|
}
|
|
439
401
|
const key = VALUE_FLAGS.get(flag);
|
|
440
402
|
if (key === undefined) {
|
|
441
403
|
return { ok: false, error: `未知参数 / unknown flag: ${flag}` };
|
|
442
404
|
}
|
|
443
|
-
const
|
|
444
|
-
if (
|
|
445
|
-
return { ok: false, error: `参数 ${flag} 缺少值 / missing value for ${flag}` };
|
|
446
|
-
}
|
|
405
|
+
const v = takeValue(flag, i, inline);
|
|
406
|
+
if (!v.ok) return v;
|
|
447
407
|
if (key === 'sections') {
|
|
448
408
|
// 分区名提前校验:未知/离线不可用的分区一律在这里拒绝(不留到收集阶段才报)
|
|
449
|
-
const parsed = parseSectionsArg(value);
|
|
409
|
+
const parsed = parseSectionsArg(v.value);
|
|
450
410
|
if (!parsed.ok) return { ok: false, error: parsed.error };
|
|
451
411
|
}
|
|
452
|
-
options[key] = value;
|
|
453
|
-
i
|
|
412
|
+
options[key] = v.value;
|
|
413
|
+
i = v.nextIdx;
|
|
454
414
|
}
|
|
455
415
|
return { ok: true, options };
|
|
456
416
|
}
|
|
@@ -740,10 +700,22 @@ function createDefaultExec(platform: NodeJS.Platform = process.platform): Exec {
|
|
|
740
700
|
let defaultRl: ReturnType<typeof createInterface> | undefined;
|
|
741
701
|
/** 缺省交互提问(懒建真实 readline;注入 ask 时不会创建)。 */
|
|
742
702
|
async function defaultAsk(prompt: string): Promise<string> {
|
|
703
|
+
if (processStdin.readableEnded) {
|
|
704
|
+
throw new Error('CLI_STDIN_EOF');
|
|
705
|
+
}
|
|
743
706
|
if (defaultRl === undefined) {
|
|
744
707
|
defaultRl = createInterface({ input: processStdin, output: processStdout });
|
|
745
708
|
}
|
|
746
|
-
|
|
709
|
+
try {
|
|
710
|
+
return await defaultRl.question(prompt);
|
|
711
|
+
} catch (err) {
|
|
712
|
+
const code = err && typeof err === 'object' ? (err as { code?: unknown }).code : undefined;
|
|
713
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
714
|
+
if (code === 'ERR_USE_AFTER_CLOSE' || msg.includes('readline was closed') || msg.includes('closed')) {
|
|
715
|
+
throw new Error('CLI_STDIN_EOF');
|
|
716
|
+
}
|
|
717
|
+
throw err;
|
|
718
|
+
}
|
|
747
719
|
}
|
|
748
720
|
function closeDefaultAsk(): void {
|
|
749
721
|
if (defaultRl !== undefined) {
|
|
@@ -805,16 +777,35 @@ async function runReinstall(
|
|
|
805
777
|
defaults.add('plugins');
|
|
806
778
|
defaults.add('data');
|
|
807
779
|
}
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
if (!parseConfirmInput(await ask('输入 YES 确认继续 / type YES to continue> '))) {
|
|
815
|
-
io.log('已取消 / cancelled');
|
|
780
|
+
if (deps.ask === undefined && !processStdin.isTTY) {
|
|
781
|
+
if (options.dryRun) {
|
|
782
|
+
selection = defaults;
|
|
783
|
+
} else {
|
|
784
|
+
io.error('错误:reinstall 是破坏性操作,在非交互终端(stdin 非 TTY)下默认拒绝,不会挂起等待确认。');
|
|
785
|
+
io.error('下一步:先运行 `dcm reinstall --dry-run` 预览步骤;确认后再传 `--yes` 显式放行。');
|
|
816
786
|
return 1;
|
|
817
787
|
}
|
|
788
|
+
} else {
|
|
789
|
+
try {
|
|
790
|
+
selection = await interactiveReinstallSelect(defaults, io, ask);
|
|
791
|
+
const hasDestructive = [...selection].some((id) =>
|
|
792
|
+
REINSTALL_ITEMS.find((it) => it.id === id)?.destructive === true,
|
|
793
|
+
);
|
|
794
|
+
if (hasDestructive || options.wipeConfig) {
|
|
795
|
+
io.log('⚠ 所选动作包含清除 ~/.dsh 数据的危险步骤(执行前会先做 .reinstall-backup 备份)。/ WARNING: destructive ~/.dsh actions selected');
|
|
796
|
+
if (!parseConfirmInput(await ask('输入 YES 确认继续 / type YES to continue> '))) {
|
|
797
|
+
io.log('已取消 / cancelled');
|
|
798
|
+
return 1;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
} catch (err) {
|
|
802
|
+
if (err instanceof Error && err.message === 'CLI_STDIN_EOF') {
|
|
803
|
+
io.error('错误:标准输入已结束(EOF),无法读取交互确认,已取消执行。');
|
|
804
|
+
io.error('下一步:在交互终端运行,或用 `--dry-run` 预览 / `--yes` 非交互执行。');
|
|
805
|
+
return 1;
|
|
806
|
+
}
|
|
807
|
+
throw err;
|
|
808
|
+
}
|
|
818
809
|
}
|
|
819
810
|
}
|
|
820
811
|
|
|
@@ -833,6 +824,19 @@ async function runReinstall(
|
|
|
833
824
|
return 1;
|
|
834
825
|
}
|
|
835
826
|
|
|
827
|
+
// AGENTS「CLI 与救急台同一道写入门」第三道:DSH 未运行。
|
|
828
|
+
// 清空 settings/plugins/data 会删掉运行中实例的 profiles 与 sessions(审计 P11-5)。
|
|
829
|
+
if (plan.wipeConfig) {
|
|
830
|
+
const runningGate = await checkWriteGates(
|
|
831
|
+
resolveControlRoots({ dataRoot: options.dataRoot, dataDir: options.dataDir }, env),
|
|
832
|
+
{ needsDshStopped: true },
|
|
833
|
+
);
|
|
834
|
+
if (!runningGate.ok) {
|
|
835
|
+
io.error(`拒绝执行:${runningGate.reason}`);
|
|
836
|
+
return 1;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
836
840
|
// 执行(Phase 2 锁:reinstall 卸载/清扫/重装属 GLOBAL destructive,必须成功获取环境锁)
|
|
837
841
|
const lockHome = resolveDshHome(env);
|
|
838
842
|
const lock = new EnvironmentLockManager({
|
|
@@ -889,6 +893,11 @@ async function runReinstall(
|
|
|
889
893
|
const reason = err instanceof Error ? err.message : String(err);
|
|
890
894
|
failed.push({ label: step.label, command: step.command, reason });
|
|
891
895
|
io.error(`✘ ${step.label} — ${reason}`);
|
|
896
|
+
// 备份步(critical)失败时后面的清空没有抢救副本:中止剩余步骤(审计 P11-7)。
|
|
897
|
+
if (step.critical === true) {
|
|
898
|
+
io.error('✘ 兜底备份失败,已中止后续清空步骤(未删除任何 ~/.dsh 数据)/ backup failed, aborting remaining steps');
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
892
901
|
}
|
|
893
902
|
}
|
|
894
903
|
};
|
|
@@ -930,8 +939,14 @@ export async function runCli(
|
|
|
930
939
|
): Promise<number> {
|
|
931
940
|
const parsed = parseCli(argv);
|
|
932
941
|
if (!parsed.ok) {
|
|
933
|
-
io.error(parsed.error);
|
|
934
|
-
|
|
942
|
+
io.error(`错误:${parsed.error}`);
|
|
943
|
+
const subcmd = argv[0];
|
|
944
|
+
if (subcmd !== undefined && !subcmd.startsWith('-') && renderCommandHelp(subcmd, CLI_EXPORTER_VERSION) !== null) {
|
|
945
|
+
io.error(`下一步:运行 \`dcm ${subcmd} --help\` 查看该命令的参数与示例。`);
|
|
946
|
+
} else {
|
|
947
|
+
io.error('下一步:运行 `dcm --help` 查看可用命令与示例。');
|
|
948
|
+
printUsage(io);
|
|
949
|
+
}
|
|
935
950
|
return 1;
|
|
936
951
|
}
|
|
937
952
|
const { options } = parsed;
|
|
@@ -1454,7 +1469,8 @@ if (isDirectRun) {
|
|
|
1454
1469
|
process.exitCode = code;
|
|
1455
1470
|
})
|
|
1456
1471
|
.catch((err) => {
|
|
1457
|
-
console.error(
|
|
1472
|
+
console.error(`错误:dsh-config-manager 执行失败(${err instanceof Error ? err.message : String(err)})。`);
|
|
1473
|
+
console.error('下一步:检查输入参数、路径权限或运行 `dcm --help` 查看正确用法。');
|
|
1458
1474
|
process.exitCode = 1;
|
|
1459
1475
|
});
|
|
1460
1476
|
}
|
|
@@ -80,7 +80,7 @@ interface ScanResult {
|
|
|
80
80
|
* 返回值里必须带 rootReadable:会话根存在但读不出来时,空列表只能说明「扫描失败」,
|
|
81
81
|
* 调用方据此拒绝给出「无需修复」+ exit 0(读不到 ≠ 无会话 —— 验收 F2 同口径)。
|
|
82
82
|
*/
|
|
83
|
-
async function scanSessions(sessionsRoot: string, io: SessionsRepairIo): Promise<ScanResult> {
|
|
83
|
+
async function scanSessions(sessionsRoot: string, io: SessionsRepairIo, json = false): Promise<ScanResult> {
|
|
84
84
|
const out: ScannedSession[] = [];
|
|
85
85
|
let projectDirs: import('node:fs').Dirent[];
|
|
86
86
|
try {
|
|
@@ -97,8 +97,10 @@ async function scanSessions(sessionsRoot: string, io: SessionsRepairIo): Promise
|
|
|
97
97
|
if (!entry.isDirectory()) continue;
|
|
98
98
|
const projectKey = entry.name;
|
|
99
99
|
if (!PROJECT_KEY_RE.test(projectKey)) {
|
|
100
|
-
// 不是 DSH 的 projectKey
|
|
101
|
-
|
|
100
|
+
// 不是 DSH 的 projectKey 形状:原样说明并跳过(--json 下走 stderr,不污染 stdout JSON)
|
|
101
|
+
const skipMsg = '跳过非 projectKey 目录 / skip non-projectKey dir: ' + projectKey;
|
|
102
|
+
if (json) io.error(skipMsg);
|
|
103
|
+
else io.log(skipMsg);
|
|
102
104
|
continue;
|
|
103
105
|
}
|
|
104
106
|
const projectDir = join(sessionsRoot, projectKey);
|
|
@@ -139,17 +141,30 @@ async function quarantineDirFor(sessionsRoot: string, stamp: string, action: Ses
|
|
|
139
141
|
* --fix 时只要有失败/冲突/回滚就返回 1。
|
|
140
142
|
*/
|
|
141
143
|
export async function runSessionsRepair(options: SessionsRepairOptions, io: SessionsRepairIo): Promise<number> {
|
|
144
|
+
const logHuman = (line: string): void => {
|
|
145
|
+
if (options.json) io.error(line);
|
|
146
|
+
else io.log(line);
|
|
147
|
+
};
|
|
142
148
|
const sessionsRoot = join(options.home, 'sessions');
|
|
143
149
|
if (!(await exists(sessionsRoot))) {
|
|
144
|
-
|
|
150
|
+
const message = '找不到会话根目录 / sessions root not found: ' + sessionsRoot;
|
|
151
|
+
io.error(message);
|
|
145
152
|
io.error('用 --home <DSH_HOME> 指定正确的 DSH home;缺省取 $DSH_HOME(~/.dsh)。');
|
|
153
|
+
if (options.json) {
|
|
154
|
+
io.log(JSON.stringify({ ok: false, dryRun: options.fix !== true, home: options.home, root: sessionsRoot, error: message }, null, 2));
|
|
155
|
+
}
|
|
146
156
|
return 1;
|
|
147
157
|
}
|
|
148
158
|
const parsed = parseRepairMaps(options.maps);
|
|
149
159
|
for (const error of parsed.errors) io.error(error);
|
|
150
|
-
if (parsed.errors.length > 0)
|
|
160
|
+
if (parsed.errors.length > 0) {
|
|
161
|
+
if (options.json) {
|
|
162
|
+
io.log(JSON.stringify({ ok: false, dryRun: options.fix !== true, home: options.home, errors: parsed.errors }, null, 2));
|
|
163
|
+
}
|
|
164
|
+
return 1;
|
|
165
|
+
}
|
|
151
166
|
|
|
152
|
-
const scan = await scanSessions(sessionsRoot, io);
|
|
167
|
+
const scan = await scanSessions(sessionsRoot, io, options.json);
|
|
153
168
|
if (!scan.rootReadable) {
|
|
154
169
|
// 「读不到」≠「没有会话」:根存在但读不出来时,空扫描结果只说明**扫描失败** ——
|
|
155
170
|
// 绝不能给出「无需修复」+ exit 0(那等于把「读不到」说成「没问题」),--json 也不得回 ok:true。
|
|
@@ -175,8 +190,8 @@ export async function runSessionsRepair(options: SessionsRepairOptions, io: Sess
|
|
|
175
190
|
return 0;
|
|
176
191
|
}
|
|
177
192
|
|
|
178
|
-
|
|
179
|
-
|
|
193
|
+
logHuman('会话根 / sessions root: ' + sessionsRoot);
|
|
194
|
+
logHuman(
|
|
180
195
|
'扫描 ' + String(plan.summary.scanned) + ' 条会话:位置正确 ' + String(plan.summary.ok)
|
|
181
196
|
+ ',待搬家 ' + String(plan.summary.move)
|
|
182
197
|
+ ',待改写+搬家 ' + String(plan.summary.rewriteMove)
|
|
@@ -187,15 +202,16 @@ export async function runSessionsRepair(options: SessionsRepairOptions, io: Sess
|
|
|
187
202
|
if (action.kind === 'ok') continue;
|
|
188
203
|
const move = action.toProjectKey === undefined ? '' : ' → ' + action.toProjectKey;
|
|
189
204
|
const rewrite = action.rewrite === undefined ? '' : '(改写首帧 cwd: ' + action.rewrite.from + ' → ' + action.rewrite.to + ')';
|
|
190
|
-
|
|
205
|
+
logHuman(' [' + action.kind + '] ' + action.sessionId + ' ' + action.fromProjectKey + move + rewrite + ' reason=' + action.reason);
|
|
191
206
|
}
|
|
192
207
|
if (!options.fix) {
|
|
193
|
-
if (pending)
|
|
194
|
-
else
|
|
208
|
+
if (pending) logHuman('以上为计划(零写入)。加 --fix 执行;重复 id 需用 --keep <目录> 指定保留哪一份。');
|
|
209
|
+
else logHuman('无需修复。/ nothing to repair.');
|
|
195
210
|
return 0;
|
|
196
211
|
}
|
|
197
212
|
|
|
198
213
|
let failures = 0;
|
|
214
|
+
const results: Array<{ sessionId: string; kind: SessionRepairAction['kind']; ok: boolean; targetDir?: string; error?: string }> = [];
|
|
199
215
|
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
200
216
|
for (const action of plan.actions) {
|
|
201
217
|
if (!action.applies) {
|
|
@@ -206,12 +222,15 @@ export async function runSessionsRepair(options: SessionsRepairOptions, io: Sess
|
|
|
206
222
|
if (action.kind === 'quarantine') {
|
|
207
223
|
const target = await quarantineDirFor(sessionsRoot, stamp, action);
|
|
208
224
|
if (await exists(target)) {
|
|
209
|
-
|
|
225
|
+
const msg = '隔离目标已存在,跳过 / quarantine target exists: ' + target;
|
|
226
|
+
io.error(msg);
|
|
227
|
+
results.push({ sessionId: action.sessionId, kind: action.kind, ok: false, error: msg });
|
|
210
228
|
failures += 1;
|
|
211
229
|
continue;
|
|
212
230
|
}
|
|
213
231
|
await fs.rename(action.dir, target);
|
|
214
|
-
|
|
232
|
+
logHuman('已隔离重复副本 / quarantined duplicate: ' + action.dir + ' → ' + target);
|
|
233
|
+
results.push({ sessionId: action.sessionId, kind: action.kind, ok: true, targetDir: target });
|
|
215
234
|
continue;
|
|
216
235
|
}
|
|
217
236
|
// move / rewrite-move
|
|
@@ -219,7 +238,9 @@ export async function runSessionsRepair(options: SessionsRepairOptions, io: Sess
|
|
|
219
238
|
if (action.rewrite !== undefined) {
|
|
220
239
|
const result = await rewriteSessionLogDir(action.dir, action.rewrite.to);
|
|
221
240
|
if (!result.ok) {
|
|
222
|
-
|
|
241
|
+
const msg = '改写首帧失败(未搬目录)/ rewrite failed: ' + action.sessionId + ' reason=' + String(result.reason);
|
|
242
|
+
io.error(msg);
|
|
243
|
+
results.push({ sessionId: action.sessionId, kind: action.kind, ok: false, error: msg });
|
|
223
244
|
failures += 1;
|
|
224
245
|
continue;
|
|
225
246
|
}
|
|
@@ -229,37 +250,49 @@ export async function runSessionsRepair(options: SessionsRepairOptions, io: Sess
|
|
|
229
250
|
? undefined
|
|
230
251
|
: join(sessionsRoot, action.toProjectKey, action.sessionId);
|
|
231
252
|
if (targetDir === undefined) {
|
|
232
|
-
|
|
253
|
+
const msg = '缺少目标 projectKey,跳过 / missing target projectKey: ' + action.sessionId;
|
|
254
|
+
io.error(msg);
|
|
255
|
+
results.push({ sessionId: action.sessionId, kind: action.kind, ok: false, error: msg });
|
|
233
256
|
failures += 1;
|
|
234
257
|
continue;
|
|
235
258
|
}
|
|
236
259
|
if (await exists(targetDir)) {
|
|
237
|
-
|
|
260
|
+
const msg = '目标目录已存在,拒绝覆盖 / target exists: ' + targetDir;
|
|
261
|
+
io.error(msg);
|
|
238
262
|
if (rewritten && action.rewrite !== undefined) {
|
|
239
263
|
const back = await rewriteSessionLogDir(action.dir, action.rewrite.from);
|
|
240
264
|
io.error(back.ok ? '已回滚首帧改写 / rewrite rolled back' : '回滚失败(请人工检查)/ rollback FAILED');
|
|
241
265
|
}
|
|
266
|
+
results.push({ sessionId: action.sessionId, kind: action.kind, ok: false, error: msg });
|
|
242
267
|
failures += 1;
|
|
243
268
|
continue;
|
|
244
269
|
}
|
|
245
270
|
await fs.mkdir(join(targetDir, '..'), { recursive: true });
|
|
246
271
|
await fs.rename(action.dir, targetDir);
|
|
247
272
|
if (!(await exists(targetDir)) || await exists(action.dir)) {
|
|
248
|
-
|
|
273
|
+
const msg = '搬迁自检失败 / post-move check failed: ' + action.dir;
|
|
274
|
+
io.error(msg);
|
|
275
|
+
results.push({ sessionId: action.sessionId, kind: action.kind, ok: false, error: msg });
|
|
249
276
|
failures += 1;
|
|
250
277
|
continue;
|
|
251
278
|
}
|
|
252
|
-
|
|
253
|
-
|
|
279
|
+
logHuman('已归位 / moved: ' + action.sessionId + ' ' + action.fromProjectKey + ' → ' + action.toProjectKey);
|
|
280
|
+
logHuman(' 会话目录 / dir: ' + targetDir);
|
|
254
281
|
if (rewritten) {
|
|
255
|
-
|
|
282
|
+
logHuman(' 已改写首帧 cwd(其余帧逐字节保留);DSH 侧工作区登记请启动 DSH 后在「会话归位」卡片执行。');
|
|
256
283
|
}
|
|
284
|
+
results.push({ sessionId: action.sessionId, kind: action.kind, ok: true, targetDir });
|
|
257
285
|
} catch (error) {
|
|
258
|
-
|
|
286
|
+
const msg = '修复失败 / repair failed: ' + action.sessionId + ' ' + (error instanceof Error ? error.message : String(error));
|
|
287
|
+
io.error(msg);
|
|
288
|
+
results.push({ sessionId: action.sessionId, kind: action.kind, ok: false, error: msg });
|
|
259
289
|
failures += 1;
|
|
260
290
|
}
|
|
261
291
|
}
|
|
262
|
-
|
|
292
|
+
logHuman(failures === 0 ? '完成(无失败)/ done' : '完成但有 ' + String(failures) + ' 项失败 / done with failures');
|
|
293
|
+
if (options.json) {
|
|
294
|
+
io.log(JSON.stringify({ ok: failures === 0, dryRun: false, home: options.home, sessionsRoot, failures, summary: plan.summary, results }, null, 2));
|
|
295
|
+
}
|
|
263
296
|
return failures === 0 ? 0 : 1;
|
|
264
297
|
}
|
|
265
298
|
|
|
@@ -51,6 +51,41 @@ export const CONSOLE_SCRIPT = `(function () {
|
|
|
51
51
|
node = node.parentNode;
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
+
function copyText(text, btn) {
|
|
55
|
+
var done = function () {
|
|
56
|
+
var orig = btn.getAttribute('data-dcm-orig') || btn.textContent || '复制';
|
|
57
|
+
if (!btn.getAttribute('data-dcm-orig')) btn.setAttribute('data-dcm-orig', orig);
|
|
58
|
+
btn.setAttribute('data-copied', '1');
|
|
59
|
+
btn.textContent = '已复制 ✓';
|
|
60
|
+
if (typeof window.setTimeout === 'function') {
|
|
61
|
+
window.setTimeout(function () {
|
|
62
|
+
btn.removeAttribute('data-copied');
|
|
63
|
+
btn.textContent = orig;
|
|
64
|
+
}, 1200);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
|
|
68
|
+
navigator.clipboard.writeText(text).then(done, function () { fallbackCopy(text, done); });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
fallbackCopy(text, done);
|
|
72
|
+
}
|
|
73
|
+
function fallbackCopy(text, done) {
|
|
74
|
+
try {
|
|
75
|
+
var ta = document.createElement('textarea');
|
|
76
|
+
ta.value = text;
|
|
77
|
+
ta.setAttribute('readonly', '');
|
|
78
|
+
ta.style.position = 'fixed';
|
|
79
|
+
ta.style.opacity = '0';
|
|
80
|
+
document.body.appendChild(ta);
|
|
81
|
+
ta.select();
|
|
82
|
+
document.execCommand('copy');
|
|
83
|
+
document.body.removeChild(ta);
|
|
84
|
+
done();
|
|
85
|
+
} catch (e) {
|
|
86
|
+
// 剪贴板不可用时静默退出,不打断页面交互
|
|
87
|
+
}
|
|
88
|
+
}
|
|
54
89
|
// 离线救急台的**唯一**客户端脚本:只做两件事 —— ① 会话内状态恢复(sessionStorage,dcm: 前缀)
|
|
55
90
|
// ② 把确认表单从 details 升级成原生 dialog 元素。禁用 JS 时两者都不参与,页面回落到纯 HTML。
|
|
56
91
|
var PREFIX = 'dcm:';
|
|
@@ -114,12 +149,30 @@ export const CONSOLE_SCRIPT = `(function () {
|
|
|
114
149
|
}
|
|
115
150
|
function onField(event) {
|
|
116
151
|
var el = event.target;
|
|
152
|
+
if (el && el.required && typeof el.setAttribute === 'function') {
|
|
153
|
+
el.setAttribute('aria-invalid', String(el.value || '').trim() === '' ? 'true' : 'false');
|
|
154
|
+
}
|
|
117
155
|
if (!persistable(el)) return;
|
|
118
156
|
if (el.type === 'checkbox' || el.type === 'radio') writeJson(fieldKey(el), { checked: el.checked === true });
|
|
119
157
|
else writeJson(fieldKey(el), { value: String(el.value) });
|
|
120
158
|
}
|
|
121
159
|
document.addEventListener('change', onField, true);
|
|
122
160
|
document.addEventListener('input', onField, true);
|
|
161
|
+
document.addEventListener('submit', function (event) {
|
|
162
|
+
var form = event.target;
|
|
163
|
+
if (!form || form.tagName !== 'FORM') return;
|
|
164
|
+
form.setAttribute('aria-busy', 'true');
|
|
165
|
+
if (typeof form.querySelector !== 'function') return;
|
|
166
|
+
var btn = form.querySelector('button[type="submit"]');
|
|
167
|
+
if (!btn || btn.disabled) return;
|
|
168
|
+
btn.disabled = true;
|
|
169
|
+
var spin = document.createElement('span');
|
|
170
|
+
spin.className = 'btnSpinner';
|
|
171
|
+
spin.setAttribute('aria-hidden', 'true');
|
|
172
|
+
btn.textContent = '';
|
|
173
|
+
btn.appendChild(spin);
|
|
174
|
+
btn.appendChild(document.createTextNode('执行中…'));
|
|
175
|
+
}, true);
|
|
123
176
|
function detailsState() {
|
|
124
177
|
var list = document.querySelectorAll('details[data-dcm-persist]');
|
|
125
178
|
for (var i = 0; i < list.length; i++) {
|
|
@@ -217,14 +270,27 @@ export const CONSOLE_SCRIPT = `(function () {
|
|
|
217
270
|
for (var i = 0; i < list.length; i++) enhanceOne(list[i]);
|
|
218
271
|
}
|
|
219
272
|
document.addEventListener('click', function (event) {
|
|
273
|
+
var menus = document.querySelectorAll('details[data-dcm-nav-group][open]');
|
|
274
|
+
for (var m = 0; m < menus.length; m++) {
|
|
275
|
+
var menu = menus[m];
|
|
276
|
+
if (typeof menu.contains === 'function' && (!menu.contains(event.target) || (event.target && event.target.tagName === 'A'))) {
|
|
277
|
+
menu.open = false;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
220
280
|
var node = event.target;
|
|
221
281
|
while (node !== null && node !== document) {
|
|
222
|
-
if (typeof node.hasAttribute === 'function'
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
|
|
282
|
+
if (typeof node.hasAttribute === 'function') {
|
|
283
|
+
if (node.hasAttribute('data-dcm-copy')) {
|
|
284
|
+
copyText(String(node.getAttribute('data-dcm-copy') || ''), node);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (node.hasAttribute('data-dcm-back')) {
|
|
288
|
+
if (window.history.length > 1) {
|
|
289
|
+
event.preventDefault();
|
|
290
|
+
window.history.back();
|
|
291
|
+
}
|
|
292
|
+
return;
|
|
226
293
|
}
|
|
227
|
-
return;
|
|
228
294
|
}
|
|
229
295
|
node = node.parentNode;
|
|
230
296
|
}
|