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
|
@@ -37,6 +37,17 @@ export const SNAPSHOT_DIFF_LIMITS = {
|
|
|
37
37
|
context: 3,
|
|
38
38
|
};
|
|
39
39
|
const ABSENT = { exists: false, bytes: 0, text: '', binary: false, oversized: false, unreadable: false };
|
|
40
|
+
/** 该 errno 是否等于「路径真的不存在」(其余 = 存在但拿不到,绝不能当作不存在)。 */
|
|
41
|
+
function isEnoent(err) {
|
|
42
|
+
return typeof err === 'object' && err !== null && err.code === 'ENOENT';
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 「存在但读不出」的唯一形态(目录 / 无权限 / 被占用 / stat 抛非 ENOENT)。
|
|
46
|
+
* 与 ABSENT(真的不存在)严格区分:判成不存在会让预览把改不了的文件显示成「新增」(审计 P2-6)。
|
|
47
|
+
*/
|
|
48
|
+
function unreadableAt(bytes) {
|
|
49
|
+
return { exists: true, bytes, text: null, binary: false, oversized: false, unreadable: true };
|
|
50
|
+
}
|
|
40
51
|
/** 只探测存在性(预算触顶时用:不读内容,只 stat)。 */
|
|
41
52
|
async function probeExists(opts) {
|
|
42
53
|
let abs;
|
|
@@ -48,30 +59,53 @@ async function probeExists(opts) {
|
|
|
48
59
|
}
|
|
49
60
|
try {
|
|
50
61
|
const stat = await fs.stat(abs);
|
|
51
|
-
return stat.isFile() ? 'exists' : '
|
|
62
|
+
return stat.isFile() ? 'exists' : 'unreadable';
|
|
52
63
|
}
|
|
53
|
-
catch {
|
|
54
|
-
|
|
64
|
+
catch (err) {
|
|
65
|
+
// ENOENT 才是「没有」;EACCES 一类说明路径在,只是拿不到状态
|
|
66
|
+
return isEnoent(err) ? 'absent' : 'unreadable';
|
|
55
67
|
}
|
|
56
68
|
}
|
|
57
|
-
|
|
69
|
+
const REAL_SIDE_IO = {
|
|
70
|
+
stat: (abs) => fs.stat(abs),
|
|
71
|
+
readFile: (abs) => fs.readFile(abs),
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* 读单侧内容。
|
|
75
|
+
*
|
|
76
|
+
* 三种结果必须分开:真的没有(ABSENT)/ 存在但读不出(unreadable)/ 正常读到。
|
|
77
|
+
* 原先整段包一个 try + 末尾 `catch { return ABSENT }`,把「stat 成功、readFile 抛 EACCES」
|
|
78
|
+
* 判成了不存在 —— 预览因此把只读文件显示成「新增」(审计 P2-6)。
|
|
79
|
+
*
|
|
80
|
+
* `io` 参数只为单测注入:Windows 上造不出 EACCES 夹具,而这条分支必须被真正覆盖;
|
|
81
|
+
* 生产调用方一律不传(走 REAL_SIDE_IO)。
|
|
82
|
+
*/
|
|
83
|
+
export async function readSide(abs, maxBytes, io = REAL_SIDE_IO) {
|
|
84
|
+
let stat;
|
|
58
85
|
try {
|
|
59
|
-
|
|
60
|
-
if (!stat.isFile()) {
|
|
61
|
-
return { exists: true, bytes: stat.size, text: null, binary: false, oversized: false, unreadable: true };
|
|
62
|
-
}
|
|
63
|
-
if (stat.size > maxBytes) {
|
|
64
|
-
return { exists: true, bytes: stat.size, text: null, binary: false, oversized: true, unreadable: false };
|
|
65
|
-
}
|
|
66
|
-
const buf = await fs.readFile(abs);
|
|
67
|
-
if (buf.subarray(0, 8192).includes(0)) {
|
|
68
|
-
return { exists: true, bytes: buf.byteLength, text: null, binary: true, oversized: false, unreadable: false };
|
|
69
|
-
}
|
|
70
|
-
return { exists: true, bytes: buf.byteLength, text: buf.toString('utf8'), binary: false, oversized: false, unreadable: false };
|
|
86
|
+
stat = await io.stat(abs);
|
|
71
87
|
}
|
|
72
|
-
catch {
|
|
73
|
-
return ABSENT;
|
|
88
|
+
catch (err) {
|
|
89
|
+
return isEnoent(err) ? ABSENT : unreadableAt(0);
|
|
90
|
+
}
|
|
91
|
+
if (!stat.isFile())
|
|
92
|
+
return unreadableAt(stat.size);
|
|
93
|
+
if (stat.size > maxBytes) {
|
|
94
|
+
return { exists: true, bytes: stat.size, text: null, binary: false, oversized: true, unreadable: false };
|
|
95
|
+
}
|
|
96
|
+
let buf;
|
|
97
|
+
try {
|
|
98
|
+
buf = await io.readFile(abs);
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
// stat 已证明它是普通文件:这里读失败 = 存在但读不出(EACCES/EBUSY/…);
|
|
102
|
+
// stat 与 read 之间被删掉的 ENOENT 仍按「不存在」处理,那才是当时的真实状态
|
|
103
|
+
return isEnoent(err) ? ABSENT : unreadableAt(stat.size);
|
|
104
|
+
}
|
|
105
|
+
if (buf.subarray(0, 8192).includes(0)) {
|
|
106
|
+
return { exists: true, bytes: buf.byteLength, text: null, binary: true, oversized: false, unreadable: false };
|
|
74
107
|
}
|
|
108
|
+
return { exists: true, bytes: buf.byteLength, text: buf.toString('utf8'), binary: false, oversized: false, unreadable: false };
|
|
75
109
|
}
|
|
76
110
|
/** 变更状态判定(恢复类:before 存在 = 修改,不存在 = 新增)。 */
|
|
77
111
|
function statusOf(kind, beforeExists) {
|
|
@@ -184,10 +218,12 @@ export async function summarizeRestoreChanges(opts) {
|
|
|
184
218
|
entry.statSkipped = 'unreadable';
|
|
185
219
|
}
|
|
186
220
|
else {
|
|
187
|
-
|
|
221
|
+
// 「存在但读不出」与 readSide 同口径:算存在(否则会显示成「新增」),只把行数统计标成 unreadable
|
|
222
|
+
const unreadable = probe === 'unreadable';
|
|
223
|
+
entry.beforeExists = probe === 'exists' || unreadable;
|
|
188
224
|
entry.afterExists = restoreKind;
|
|
189
225
|
entry.status = statusOf(action.kind, entry.beforeExists);
|
|
190
|
-
entry.statSkipped = 'budget';
|
|
226
|
+
entry.statSkipped = unreadable ? 'unreadable' : 'budget';
|
|
191
227
|
}
|
|
192
228
|
skipped += 1;
|
|
193
229
|
entries.push(entry);
|
|
@@ -24,8 +24,14 @@ export function classifyStartup(opts) {
|
|
|
24
24
|
const insp = await inspectStartup(opts.store, opts.hooks, opts.env, opts.options ?? {}, opts.lockState);
|
|
25
25
|
let state;
|
|
26
26
|
if (opts.lockState === 'LOCKED') {
|
|
27
|
-
// fresh heartbeat
|
|
28
|
-
|
|
27
|
+
// fresh heartbeat:活锁。判据 = 「另一实例持锁 + 确实有 live 且未到 terminal 的 journal」——
|
|
28
|
+
// 那才是正在跑的操作,分类为 LOCKED_LIVE(不作 recovery/接管,也不启动调度器)。
|
|
29
|
+
// 审计 P3-8:旧实现在这里看 unresolved,但 live 分支恒 unresolved:false(且 LOCKED 下所有
|
|
30
|
+
// journal 都被强制按 live 处理),于是「持锁 + 真正在跑」永远落到 NORMAL;只有 parse 失败
|
|
31
|
+
// 的 corrupt journal(走 quarantine 分支)才碰巧命中 LOCKED_LIVE。现在改用 liveIncomplete。
|
|
32
|
+
state = insp.liveIncomplete.length > 0
|
|
33
|
+
? { kind: 'LOCKED_LIVE', operationId: insp.liveIncomplete[0] }
|
|
34
|
+
: { kind: 'NORMAL' };
|
|
29
35
|
}
|
|
30
36
|
else if (insp.recoveryRequired) {
|
|
31
37
|
state = { kind: 'RECOVERY_REQUIRED', operationId: insp.unresolved[0] };
|
package/lib/core/types.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { EncryptionInfo, Manifest, SectionId, WorkspaceRecord } from '../sc
|
|
|
9
9
|
import type { TombstoneKind } from '../schema/tombstones.ts';
|
|
10
10
|
import type { MutationLockPort } from '../utils/env-lock.ts';
|
|
11
11
|
import type { RecursiveListing } from '../utils/recursive-walk.ts';
|
|
12
|
+
import type { PatchChainRead, PatchWriteOutcome } from './patch-chain.ts';
|
|
12
13
|
import type { Logger } from '../utils/logger.ts';
|
|
13
14
|
import type { MsgFunc } from './messages.ts';
|
|
14
15
|
export interface ExportOptions {
|
|
@@ -405,7 +406,21 @@ export interface PatchFileFacade {
|
|
|
405
406
|
lineId: string;
|
|
406
407
|
raw: unknown;
|
|
407
408
|
}[]>;
|
|
408
|
-
|
|
409
|
+
/**
|
|
410
|
+
* 写回一层 patch 并返回本次的降级记录(issue #144)。
|
|
411
|
+
*
|
|
412
|
+
* 返回 `PatchWriteOutcome` 而不是 `void`:请求 insert、但**生效链上已有别的层**提供该 id 时,
|
|
413
|
+
* 门面会把它降级成顶层覆盖行(否则就是两条 insert 抢同一个 id,插件保存配置时必然报
|
|
414
|
+
* `overridden by a home patch or command-line overlay`)。调用方据此给用户一条 warning。
|
|
415
|
+
*/
|
|
416
|
+
applyPatchChanges(file: string, changes: PatchChange[]): Promise<PatchWriteOutcome>;
|
|
417
|
+
/**
|
|
418
|
+
* 读**整条生效 patch 链**(bundle 层 + profile 层 + home 层)的文档,issue #144。
|
|
419
|
+
*
|
|
420
|
+
* 可选能力:老宿主 / 测试替身不实现 ⇒ 调用方的链判据退化为「两层 patch 文件」的旧口径
|
|
421
|
+
* (fail-open,绝不因为读不到 bundle 层而拒绝写入)。
|
|
422
|
+
*/
|
|
423
|
+
readPatchChain?(): Promise<PatchChainRead>;
|
|
409
424
|
}
|
|
410
425
|
/**
|
|
411
426
|
* 技能摘要(`ctx.skills.list()` 的返回项;DSH `SkillSummary` 的结构子集)。
|
|
@@ -678,6 +693,17 @@ export type SessionFormatDisposition = 'abort' | 'skip' | 'guide';
|
|
|
678
693
|
export interface ConflictDecision {
|
|
679
694
|
itemId: string;
|
|
680
695
|
resolution: ItemResolution;
|
|
696
|
+
/**
|
|
697
|
+
* 这条裁决是**谁**下的(issue #136 A):
|
|
698
|
+
* - `'item'`:用户对该计划项逐项决策(`decisions.resolutions[id]`,含导入页的逐行确认)——
|
|
699
|
+
* 适配器可把它当作「我确实要这一行按导入值写」的确认。
|
|
700
|
+
* - `'section'`:由**分区级**裁决换算而来(合并落地 `planMergeApply` 的 second pass 把
|
|
701
|
+
* 「该分区已裁决」逐项注入成 `useImported`)。分区级裁决决定「分区是否应用」,
|
|
702
|
+
* 不构成对某一行值的确认,写回守卫不得据此清空本机明文。
|
|
703
|
+
* - 缺省:未标注来源。写回守卫按**未确认**处理(默认拒绝清空)—— 忘了标注只会少清空,
|
|
704
|
+
* 不会误清空;确认必须显式写明来源。
|
|
705
|
+
*/
|
|
706
|
+
decidedBy?: 'item' | 'section';
|
|
681
707
|
}
|
|
682
708
|
export interface PathMapping {
|
|
683
709
|
oldPrefix: string;
|
|
@@ -1254,6 +1280,17 @@ export interface ConfigAdapter<TSection = unknown> {
|
|
|
1254
1280
|
/** 读取当前 DSH 该类别配置 → 导出数据(无秘密值)。
|
|
1255
1281
|
* 实现方应尊重 `options.includeItems?.[this.id]`(条目级选择,见 adapters/units.ts)。 */
|
|
1256
1282
|
export(ctx: HostContext, options: ExportOptions): Promise<ExportSection<TSection>>;
|
|
1283
|
+
/**
|
|
1284
|
+
* 可选:脱敏**归属标注**(issue #136 C)—— 把 SecretScanner 的命中路径归属回具体载荷单元。
|
|
1285
|
+
*
|
|
1286
|
+
* 调用点只有一个:`sanitizeSectionData()`(`src/core/section-sanitize.ts`),纯函数语义
|
|
1287
|
+
* (不改入参、不读盘);只做「标注」,绝不把值写回去(脱敏仍是扫描器的职责)。
|
|
1288
|
+
*
|
|
1289
|
+
* plugins 分区用它把 `patch[i].raw.x` 的命中写进第 i 行的 `redactedPaths`:目标机据此区分
|
|
1290
|
+
* 「被剥空」与「用户写空」,写回层才能精确保护本机明文(`src/core/patch-secret-guard.ts`)。
|
|
1291
|
+
* 未实现 = 载荷不含归属信息,写回侧走保守分支。
|
|
1292
|
+
*/
|
|
1293
|
+
annotateRedactions?(sanitized: unknown, hits: SensitiveHit[]): unknown;
|
|
1257
1294
|
/**
|
|
1258
1295
|
* 可选:**只读预览**(`/export-preview` 用)。
|
|
1259
1296
|
*
|
package/lib/core/update-check.js
CHANGED
|
@@ -63,6 +63,55 @@ export function wantsForcedUpdateCheck(url) {
|
|
|
63
63
|
}
|
|
64
64
|
return false;
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* **按字节**有界地读响应体;超过 `maxBytes` 返回 null(调用方给 'registry response too large')。
|
|
68
|
+
*
|
|
69
|
+
* 为什么不是 `text.length`:它数的是 UTF-16 代码单元,一个 CJK 字符占 3 个 UTF-8 字节 ⇒
|
|
70
|
+
* 120KB 的中文响应 `text.length` 只有 40K,上限形同虚设(审计 P11-6)。
|
|
71
|
+
* 顺序:Content-Length 预检(有就先拒,一个字节都不读)→ 流式累计,越界立刻 abort
|
|
72
|
+
* (不把大响应读进内存)→ 没有 body 流的运行时退回 arrayBuffer 量 byteLength。
|
|
73
|
+
*/
|
|
74
|
+
async function readBoundedBody(res, maxBytes, controller) {
|
|
75
|
+
// 防御:真实 Response 一定有 headers/body,但注入的替身(脚本、极简 mock)可能只给 text()。
|
|
76
|
+
// 缺什么就退化成「全量读 + 字节口径判定」——判据不变,只是失去流式提前止损。
|
|
77
|
+
const declared = typeof res.headers?.get === 'function' ? res.headers.get('content-length') : null;
|
|
78
|
+
if (declared !== null) {
|
|
79
|
+
const n = Number(declared);
|
|
80
|
+
if (Number.isFinite(n) && n > maxBytes) {
|
|
81
|
+
controller.abort();
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const body = res.body;
|
|
86
|
+
if (body === null || body === undefined) {
|
|
87
|
+
const bytes = typeof res.arrayBuffer === 'function'
|
|
88
|
+
? new Uint8Array(await res.arrayBuffer())
|
|
89
|
+
: new TextEncoder().encode(await res.text());
|
|
90
|
+
return bytes.byteLength > maxBytes ? null : new TextDecoder('utf-8').decode(bytes);
|
|
91
|
+
}
|
|
92
|
+
const reader = body.getReader();
|
|
93
|
+
const chunks = [];
|
|
94
|
+
let total = 0;
|
|
95
|
+
for (;;) {
|
|
96
|
+
const { done, value } = await reader.read();
|
|
97
|
+
if (done)
|
|
98
|
+
break;
|
|
99
|
+
total += value.byteLength;
|
|
100
|
+
if (total > maxBytes) {
|
|
101
|
+
controller.abort();
|
|
102
|
+
await reader.cancel().catch(() => undefined);
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
chunks.push(value);
|
|
106
|
+
}
|
|
107
|
+
const merged = new Uint8Array(total);
|
|
108
|
+
let at = 0;
|
|
109
|
+
for (const chunk of chunks) {
|
|
110
|
+
merged.set(chunk, at);
|
|
111
|
+
at += chunk.byteLength;
|
|
112
|
+
}
|
|
113
|
+
return new TextDecoder('utf-8').decode(merged);
|
|
114
|
+
}
|
|
66
115
|
/**
|
|
67
116
|
* 探测 npm latest(无缓存、无状态)。任何异常都被收成 `{ ok:false, error }`:
|
|
68
117
|
* 网络错误 / 超时 / 非 2xx / 体积超限 / JSON 畸形 / 版本号形态不认识。
|
|
@@ -81,8 +130,8 @@ export async function probeLatestVersion(deps = {}) {
|
|
|
81
130
|
});
|
|
82
131
|
if (!res.ok)
|
|
83
132
|
return { ok: false, error: `registry returned HTTP ${res.status}` };
|
|
84
|
-
const text = await res
|
|
85
|
-
if (text
|
|
133
|
+
const text = await readBoundedBody(res, UPDATE_CHECK_MAX_BYTES, controller);
|
|
134
|
+
if (text === null)
|
|
86
135
|
return { ok: false, error: 'registry response too large' };
|
|
87
136
|
let payload;
|
|
88
137
|
try {
|
package/lib/foreign/kernel.js
CHANGED
|
@@ -128,8 +128,15 @@ export function stripUserInfo(url) {
|
|
|
128
128
|
const at = rest.indexOf('@');
|
|
129
129
|
if (at < 0)
|
|
130
130
|
return { url, stripped: false };
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
/**
|
|
132
|
+
* userinfo 只可能出现在 authority 段里:@ 若落在第一个 '/'、'?' 或 '#' 之后,
|
|
133
|
+
* 它就是 path/query/fragment 里的普通字符(无路径 URL 的 `?k=a@b` 曾把整条 URL 截成 `https://b`)。
|
|
134
|
+
* 纯字符判定,不用正则。
|
|
135
|
+
*/
|
|
136
|
+
const boundary = [rest.indexOf('/'), rest.indexOf('?'), rest.indexOf('#')]
|
|
137
|
+
.filter((i) => i >= 0)
|
|
138
|
+
.sort((a, b) => a - b)[0];
|
|
139
|
+
if (boundary !== undefined && at > boundary)
|
|
133
140
|
return { url, stripped: false };
|
|
134
141
|
return { url: url.slice(0, scheme + 3) + rest.slice(at + 1), stripped: true };
|
|
135
142
|
}
|
|
@@ -41,6 +41,18 @@ const DEFAULT_MAX_PLUGIN_FILES = 200;
|
|
|
41
41
|
const WALK_MAX_DEPTH = 8;
|
|
42
42
|
/** 跳过原因:符号链接(与 read-claude-code 同码同义) */
|
|
43
43
|
const DETAIL_SYMLINK = 'symlink-skipped';
|
|
44
|
+
/**
|
|
45
|
+
* 走盘并**明确回报是否真的截断**(审计 P7-9)。
|
|
46
|
+
*
|
|
47
|
+
* 共享的 `walkFiles()` 只返回数组,「拿满上限」与「恰好等于上限」在返回值上无法区分 ——
|
|
48
|
+
* 调用方拿长度反推会把「正好 N 个文件」误报成触顶。这里多要一条:拿到 N+1 条才算真截断,
|
|
49
|
+
* 再把多要的那条切掉(共享内核在 `src/foreign/session-read.ts`,本文件不动它)。
|
|
50
|
+
*/
|
|
51
|
+
async function walkFilesChecked(root, options) {
|
|
52
|
+
const probe = await walkFiles(root, { ...options, maxFiles: options.maxFiles + 1 });
|
|
53
|
+
const truncated = probe.length > options.maxFiles;
|
|
54
|
+
return { files: truncated ? probe.slice(0, options.maxFiles) : probe, truncated };
|
|
55
|
+
}
|
|
44
56
|
/** 有上限的整数解析:只用安全正整数(脏值一律回落缺省) */
|
|
45
57
|
function positiveLimit(value, fallback) {
|
|
46
58
|
return typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? value : fallback;
|
|
@@ -295,36 +307,40 @@ async function readPluginAt(pluginDir, specName, marketplace, market, options) {
|
|
|
295
307
|
findings.push({ code: 'source-unreadable', origin: 'plugin:' + specName + '/.mcp.json', detail: mcp.problem });
|
|
296
308
|
}
|
|
297
309
|
/* commands/**:递归计数(只数,不读内容) */
|
|
298
|
-
const
|
|
310
|
+
const commands = await walkFilesChecked(path.join(pluginDir, 'commands'), {
|
|
299
311
|
maxDepth: WALK_MAX_DEPTH,
|
|
300
312
|
maxFiles: options.maxPluginFiles,
|
|
301
313
|
});
|
|
302
|
-
if (
|
|
303
|
-
plugin.commandCount =
|
|
314
|
+
if (commands.files.length > 0) {
|
|
315
|
+
plugin.commandCount = commands.files.length;
|
|
304
316
|
plugin.components.push('commands');
|
|
305
317
|
}
|
|
306
|
-
if (
|
|
318
|
+
if (commands.truncated)
|
|
307
319
|
filesTruncated = true;
|
|
320
|
+
// 上限是「单插件文件数」:只计数的组件也占额度(否则 N 个目录各带 199 个文件仍然全过)
|
|
321
|
+
let countedFiles = filesUsed + commands.files.length;
|
|
308
322
|
/* agents/*.md:只取文件名(不读内容) */
|
|
309
|
-
const
|
|
323
|
+
const agentsWalked = await walkFilesChecked(path.join(pluginDir, 'agents'), {
|
|
310
324
|
maxDepth: 0,
|
|
311
325
|
maxFiles: options.maxPluginFiles,
|
|
312
326
|
match: (name) => name.endsWith('.md'),
|
|
313
327
|
});
|
|
314
|
-
if (
|
|
315
|
-
plugin.agents =
|
|
328
|
+
if (agentsWalked.files.length > 0) {
|
|
329
|
+
plugin.agents = agentsWalked.files.map((file) => file.name).sort();
|
|
316
330
|
plugin.components.push('agents');
|
|
317
331
|
}
|
|
318
|
-
if (
|
|
332
|
+
if (agentsWalked.truncated)
|
|
319
333
|
filesTruncated = true;
|
|
334
|
+
countedFiles += agentsWalked.files.length;
|
|
320
335
|
/* hooks/ 与 hooks.json:**只数文件数**(hooks 是执行面,内容一律不读) */
|
|
321
|
-
const
|
|
336
|
+
const hooksWalked = await walkFilesChecked(path.join(pluginDir, 'hooks'), {
|
|
322
337
|
maxDepth: WALK_MAX_DEPTH,
|
|
323
338
|
maxFiles: options.maxPluginFiles,
|
|
324
339
|
});
|
|
325
|
-
let hookCount =
|
|
326
|
-
if (
|
|
340
|
+
let hookCount = hooksWalked.files.length;
|
|
341
|
+
if (hooksWalked.truncated)
|
|
327
342
|
filesTruncated = true;
|
|
343
|
+
countedFiles += hooksWalked.files.length;
|
|
328
344
|
const hooksJson = await statOrNull(path.join(pluginDir, 'hooks.json'));
|
|
329
345
|
if (hooksJson !== null && hooksJson.isFile())
|
|
330
346
|
hookCount += 1;
|
|
@@ -332,6 +348,8 @@ async function readPluginAt(pluginDir, specName, marketplace, market, options) {
|
|
|
332
348
|
plugin.hookFiles = hookCount;
|
|
333
349
|
plugin.components.push('hooks');
|
|
334
350
|
}
|
|
351
|
+
if (countedFiles > options.maxPluginFiles)
|
|
352
|
+
filesTruncated = true;
|
|
335
353
|
if (filesTruncated) {
|
|
336
354
|
findings.push({
|
|
337
355
|
code: 'source-unreadable',
|
package/lib/foreign/read-dsh.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* detail = too-large / max-logs-reached / session-byte-budget),绝不静默截断。
|
|
23
23
|
*/
|
|
24
24
|
import { envValue, joinFor, normalizePlatform } from './platform-paths.js';
|
|
25
|
-
import { listDirNames, listFileNames, readBytesSafe, statOrNull } from './session-read.js';
|
|
25
|
+
import { listDirNames, listFileNames, readBytesPrefixSafe, readBytesSafe, statOrNull } from './session-read.js';
|
|
26
26
|
import { readLogHeaderFromBytes } from '../utils/session-log.js';
|
|
27
27
|
export const DSH_HOME_ENV = 'DSH_HOME';
|
|
28
28
|
export const DSH_DEFAULT_DIR = '.dsh';
|
|
@@ -30,6 +30,12 @@ export const DSH_SESSIONS_SUBDIR = 'sessions';
|
|
|
30
30
|
const DEFAULT_MAX_LOGS = 2000;
|
|
31
31
|
const DEFAULT_MAX_FILE_BYTES = 32 * 1024 * 1024;
|
|
32
32
|
const DEFAULT_MAX_TOTAL_BYTES = 256 * 1024 * 1024;
|
|
33
|
+
/**
|
|
34
|
+
* 代次嗅探窗口(审计 P7-7):header 是第一行 JSON,64 KiB 覆盖任何真实 cwd/标题组合
|
|
35
|
+
* (首行实测 < 1 KiB)。窗口内解析不出 header 时退回整读,因此这个值只影响「能不能提前
|
|
36
|
+
* 跳过非目标代次」,不会改变任何判定结果。
|
|
37
|
+
*/
|
|
38
|
+
const HEADER_SNIFF_BYTES = 64 * 1024;
|
|
33
39
|
const HEADER_WINDOW_BYTES = 64 * 1024;
|
|
34
40
|
/** DSH_HOME(非空即替换;只报键名)→ 默认 ~/.dsh */
|
|
35
41
|
export function resolveDshHome(opts) {
|
|
@@ -144,6 +150,23 @@ export async function readDshLogs(opts) {
|
|
|
144
150
|
truncated = 'byte-budget';
|
|
145
151
|
break outer;
|
|
146
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* 代次嗅探(审计 P7-7):日志的 header 就在第一行,而 dsh 与 dsh4 两代并存的机器上
|
|
155
|
+
* 一半文件属于「非目标代次」——旧实现为了看那 1 KB header 把 31 MiB 的日志整份读进来
|
|
156
|
+
* 再丢掉。现在先只读头部窗口,判定为别的代次就直接 countedContinue,一次整读都不做。
|
|
157
|
+
*
|
|
158
|
+
* 退化路径保持旧行为:头部窗口解析不出 header(首行比窗口还长 / 读不出)时仍整读一次,
|
|
159
|
+
* 让 log-header-unreadable / log-read-error 这些既有码的触发条件逐字不变。
|
|
160
|
+
*/
|
|
161
|
+
const head = await readBytesPrefixSafe(abs, HEADER_SNIFF_BYTES);
|
|
162
|
+
if (head !== null) {
|
|
163
|
+
const sniffed = dshHeaderOfLogBytes(head);
|
|
164
|
+
const sniffedGeneration = sniffed === undefined ? undefined : dshGenerationOfVersion(sniffed.version);
|
|
165
|
+
if (sniffedGeneration !== undefined && sniffedGeneration !== opts.generation) {
|
|
166
|
+
otherGeneration += 1;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
147
170
|
const data = await readBytesSafe(abs, maxFileBytes);
|
|
148
171
|
if (data === null) {
|
|
149
172
|
findings.push({ code: 'source-unreadable', origin: name, detail: 'log-read-error' });
|
|
@@ -167,8 +190,14 @@ export async function readDshLogs(opts) {
|
|
|
167
190
|
findings.push({ code: 'source-unreadable', origin: name, detail: 'log-header-incomplete' });
|
|
168
191
|
continue;
|
|
169
192
|
}
|
|
170
|
-
if (seen.has(header.id))
|
|
193
|
+
if (seen.has(header.id)) {
|
|
194
|
+
/**
|
|
195
|
+
* 同一 id 出现在两个会话目录(复制/迁移残留):只保留第一个,但**必须留码** ——
|
|
196
|
+
* 静默丢会让「导入少了一条会话」在计划里无从解释(本文件顶部第 21-22 行的硬约束)。
|
|
197
|
+
*/
|
|
198
|
+
findings.push({ code: 'session-id-conflict', origin: header.id, detail: 'duplicate-session-id' });
|
|
171
199
|
continue;
|
|
200
|
+
}
|
|
172
201
|
seen.add(header.id);
|
|
173
202
|
bytesRead += data.length;
|
|
174
203
|
files.push({ id: header.id, cwd: header.cwd, version: header.version, name, data });
|
|
@@ -156,6 +156,12 @@ export function synthesizeDshRows(session, hints, stats, now) {
|
|
|
156
156
|
};
|
|
157
157
|
const closeTurn = () => {
|
|
158
158
|
closeStep();
|
|
159
|
+
/**
|
|
160
|
+
* 回合闭合后再到的结果**不许**回填到本回合的调用上:`openCallIds` 是跨 step 共享的 FIFO,
|
|
161
|
+
* 若不在回合边界清空,下一回合缺 id 的 tool_result 会消费到上一回合已结束的 callId
|
|
162
|
+
* (结果落在 turn N+1、却引用 turn N 的调用,DSH 侧配对不上)。
|
|
163
|
+
*/
|
|
164
|
+
openCallIds.length = 0;
|
|
159
165
|
if (turnOpen) {
|
|
160
166
|
push('turn/end', now, { turn, reason: { kind: 'completed' } });
|
|
161
167
|
turnOpen = false;
|
|
@@ -170,6 +176,16 @@ export function synthesizeDshRows(session, hints, stats, now) {
|
|
|
170
176
|
});
|
|
171
177
|
turnOpen = true;
|
|
172
178
|
};
|
|
179
|
+
/** 发一条**人类** user/message(唯一形状出口:两条路径共用,避免字段漂移) */
|
|
180
|
+
const emitUserMessage = (text, at, id) => {
|
|
181
|
+
push('user/message', at, {
|
|
182
|
+
content: [irTextBlock(text)],
|
|
183
|
+
source: { kind: 'user' },
|
|
184
|
+
role: 'user',
|
|
185
|
+
id,
|
|
186
|
+
}, 'append');
|
|
187
|
+
stats.userMessages++;
|
|
188
|
+
};
|
|
173
189
|
for (const message of session.messages) {
|
|
174
190
|
// time 缺省(源没给可解析时间)→ 用调用方的时间兜底;安全整数校验在 IR 层已完成
|
|
175
191
|
const time = message.passthrough?.['time'];
|
|
@@ -178,6 +194,15 @@ export function synthesizeDshRows(session, hints, stats, now) {
|
|
|
178
194
|
if (message.role === 'assistant') {
|
|
179
195
|
const text = irTextOfBlocks(blocks);
|
|
180
196
|
const calls = blocks.filter((b) => b.type === 'tool_call');
|
|
197
|
+
/**
|
|
198
|
+
* 助手记录里携带的 tool_result:本分支只消费 text/tool_call,这类结果**无处归位**
|
|
199
|
+
* (opencode 等来源把 call 与 result 写进同一条记录,由 `splitToolResults` 先拆开;
|
|
200
|
+
* 没拆到这里的不能静默消失)。计数后丢弃 —— 绝不产出悬空引用,也绝不无声丢内容。
|
|
201
|
+
*/
|
|
202
|
+
const assistantResults = blocks.filter((b) => b.type === 'tool_result');
|
|
203
|
+
if (assistantResults.length > 0) {
|
|
204
|
+
irBump(stats.ignored, 'assistant-tool-result', assistantResults.length);
|
|
205
|
+
}
|
|
181
206
|
const source = message.passthrough?.['source'];
|
|
182
207
|
const m = irStr(source?.['model']);
|
|
183
208
|
if (m !== undefined)
|
|
@@ -186,7 +211,9 @@ export function synthesizeDshRows(session, hints, stats, now) {
|
|
|
186
211
|
const providerName = hints.provider === '' ? 'foreign' : hints.provider;
|
|
187
212
|
const modelName = model === '' ? 'unknown' : model;
|
|
188
213
|
if (text.trim() === '' && calls.length === 0) {
|
|
189
|
-
|
|
214
|
+
// 只有 tool_result 的助手记录已按 assistant-tool-result 计数,不再重复记 assistant-empty
|
|
215
|
+
if (assistantResults.length === 0)
|
|
216
|
+
irBump(stats.ignored, 'assistant-empty');
|
|
190
217
|
continue;
|
|
191
218
|
}
|
|
192
219
|
if (!turnOpen)
|
|
@@ -293,8 +320,18 @@ export function synthesizeDshRows(session, hints, stats, now) {
|
|
|
293
320
|
}
|
|
294
321
|
else {
|
|
295
322
|
const idx = openCallIds.indexOf(callId);
|
|
296
|
-
if (idx >= 0)
|
|
323
|
+
if (idx >= 0) {
|
|
297
324
|
openCallIds.splice(idx, 1);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
/**
|
|
328
|
+
* 非空 id 但不在未决表里 = 悬空引用(调用已在上一回合闭合,或源侧 id 与真正发出的
|
|
329
|
+
* callId 不同)。与「缺 id 且无未决调用」同口径:计数后丢弃,绝不发指向不存在
|
|
330
|
+
* tool/call 的结果(DSH 侧会按损坏流拒读整条会话)。
|
|
331
|
+
*/
|
|
332
|
+
irBump(stats.ignored, 'orphan-tool-result');
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
298
335
|
}
|
|
299
336
|
if (callId === '') {
|
|
300
337
|
irBump(stats.ignored, 'orphan-tool-result');
|
|
@@ -319,6 +356,16 @@ export function synthesizeDshRows(session, hints, stats, now) {
|
|
|
319
356
|
},
|
|
320
357
|
}, 'append');
|
|
321
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* 同一条 user 记录里既有 tool_result 又有 text(Anthropic 形状里很常见:结果块后跟人类补充):
|
|
361
|
+
* 结果先收进当前 step,文本必须**再发一条真正的 user/message** —— 否则这段用户输入
|
|
362
|
+
* 既到不了目标机、也不进 ignored,属于静默丢失。
|
|
363
|
+
*/
|
|
364
|
+
const trailing = irTextOfBlocks(blocks);
|
|
365
|
+
if (trailing.trim() !== '') {
|
|
366
|
+
closeTurn();
|
|
367
|
+
emitUserMessage(trailing, at, message.id);
|
|
368
|
+
}
|
|
322
369
|
messageIndex++;
|
|
323
370
|
continue;
|
|
324
371
|
}
|
|
@@ -329,13 +376,7 @@ export function synthesizeDshRows(session, hints, stats, now) {
|
|
|
329
376
|
continue;
|
|
330
377
|
}
|
|
331
378
|
closeTurn();
|
|
332
|
-
|
|
333
|
-
content: [irTextBlock(text)],
|
|
334
|
-
source: { kind: 'user' },
|
|
335
|
-
role: 'user',
|
|
336
|
-
id: message.id,
|
|
337
|
-
}, 'append');
|
|
338
|
-
stats.userMessages++;
|
|
379
|
+
emitUserMessage(text, at, message.id);
|
|
339
380
|
messageIndex++;
|
|
340
381
|
}
|
|
341
382
|
closeTurn();
|
|
@@ -11,6 +11,14 @@ export declare function isDirectory(p: string): Promise<boolean>;
|
|
|
11
11
|
export declare function isFile(p: string): Promise<boolean>;
|
|
12
12
|
export declare function listDirSafe(p: string): Promise<Dirent[]>;
|
|
13
13
|
export declare function readBytesSafe(p: string, maxBytes?: number): Promise<Uint8Array | null>;
|
|
14
|
+
/**
|
|
15
|
+
* 只读文件**头部窗口**(审计 P7-7):给「先看 header 再决定要不要整读」的场景用。
|
|
16
|
+
*
|
|
17
|
+
* 与 readBytesSafe 的区别只有一点:不超过 maxBytes 时只取前 maxBytes 字节,而不是整份读。
|
|
18
|
+
* 语义仍守四条硬边界(读不到返回 null、绝不抛、超上限不读)。调用方必须自己处理
|
|
19
|
+
* 「头部窗口不足以判定」的退化路径 —— 不要把它当成整份内容。
|
|
20
|
+
*/
|
|
21
|
+
export declare function readBytesPrefixSafe(p: string, maxBytes: number): Promise<Uint8Array | null>;
|
|
14
22
|
export declare function readTextSafe(p: string, maxBytes?: number): Promise<string | null>;
|
|
15
23
|
/** 读 + 解析 JSON:**失败给出稳定原因**(0 字节与畸形必须能区分 —— 前者是空文件码,后者是解析错) */
|
|
16
24
|
export type JsonReadResult = {
|
|
@@ -55,6 +55,32 @@ export async function readBytesSafe(p, maxBytes = DEFAULT_MAX_FILE_BYTES) {
|
|
|
55
55
|
return null;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* 只读文件**头部窗口**(审计 P7-7):给「先看 header 再决定要不要整读」的场景用。
|
|
60
|
+
*
|
|
61
|
+
* 与 readBytesSafe 的区别只有一点:不超过 maxBytes 时只取前 maxBytes 字节,而不是整份读。
|
|
62
|
+
* 语义仍守四条硬边界(读不到返回 null、绝不抛、超上限不读)。调用方必须自己处理
|
|
63
|
+
* 「头部窗口不足以判定」的退化路径 —— 不要把它当成整份内容。
|
|
64
|
+
*/
|
|
65
|
+
export async function readBytesPrefixSafe(p, maxBytes) {
|
|
66
|
+
const st = await statOrNull(p);
|
|
67
|
+
if (st === null || !st.isFile() || maxBytes <= 0)
|
|
68
|
+
return null;
|
|
69
|
+
let handle = null;
|
|
70
|
+
try {
|
|
71
|
+
handle = await fs.open(p, 'r');
|
|
72
|
+
const buf = new Uint8Array(Math.min(maxBytes, st.size));
|
|
73
|
+
const { bytesRead } = await handle.read(buf, 0, buf.byteLength, 0);
|
|
74
|
+
return bytesRead === buf.byteLength ? buf : buf.subarray(0, bytesRead);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
if (handle !== null)
|
|
81
|
+
await handle.close().catch(() => undefined);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
58
84
|
export async function readTextSafe(p, maxBytes = DEFAULT_MAX_FILE_BYTES) {
|
|
59
85
|
const st = await statOrNull(p);
|
|
60
86
|
if (st === null || !st.isFile() || st.size > maxBytes)
|
package/lib/index.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ import { type MsgFunc } from './core/messages.ts';
|
|
|
46
46
|
import { runDshPlugin } from './core/plugin-cli.ts';
|
|
47
47
|
import { type ConfigAdapter, type CredentialsFacade, type FileSystemFacade, type HostContext, type PatchFileFacade, type PluginInfo, type PluginsFacade, type Portability, type SessionMoveResult, type SessionParentRelation, type SessionRewriteResult, type SessionStoreFacade, type SettingsFacade, type SkillStoreFacade, type WorkspaceFacade } from './core/types.ts';
|
|
48
48
|
import { type SelfUpdateOutcome } from './core/self-update.ts';
|
|
49
|
+
import { type PatchChainRead, type PatchWriteOutcome } from './core/patch-chain.ts';
|
|
49
50
|
import { type SessionMetaIndex } from './core/session-meta.ts';
|
|
50
51
|
import { type MutationLockContext, type MutationLockPort } from './utils/env-lock.ts';
|
|
51
52
|
import { type RecursiveListing } from './utils/recursive-walk.ts';
|
|
@@ -75,7 +76,7 @@ export declare const name = "config-manager";
|
|
|
75
76
|
/** Services required before the engine can mount (present in every profile). */
|
|
76
77
|
export declare const inject: string[];
|
|
77
78
|
/** Plugin version, kept in sync with package.json ("version"). */
|
|
78
|
-
export declare const PLUGIN_VERSION = "0.
|
|
79
|
+
export declare const PLUGIN_VERSION = "0.10.0";
|
|
79
80
|
/**
|
|
80
81
|
* Star 引导弹窗指向的 GitHub 仓库(用户引导点 Star 的目标)。
|
|
81
82
|
* 与 package.json 的 repository 字段保持一致;界面不可改(硬编码,参照
|
|
@@ -573,9 +574,13 @@ export declare class DshPatchFileFacade implements PatchFileFacade {
|
|
|
573
574
|
lineId: string;
|
|
574
575
|
raw: unknown;
|
|
575
576
|
action: 'insert' | 'update' | 'remove';
|
|
576
|
-
}[]): Promise<
|
|
577
|
-
/**
|
|
578
|
-
private
|
|
577
|
+
}[]): Promise<PatchWriteOutcome>;
|
|
578
|
+
/** 生效链缓存(见 `utils/patch-chain-read.ts`):一次导入逐行写 patch,不必逐行重读 30+ 个 bundle。 */
|
|
579
|
+
private readonly chainCache;
|
|
580
|
+
/** 读整条生效 patch 链(issue #144):bundle 层 → profile 层 → home 层,宿主合并序。 */
|
|
581
|
+
readPatchChain(): Promise<PatchChainRead>;
|
|
582
|
+
/** 读链失败(profile 清单整体不可读等)→ `null`:判定退化为两层,绝不阻断写入。 */
|
|
583
|
+
private readPatchChainQuietly;
|
|
579
584
|
}
|
|
580
585
|
/** File facade over $DSH_HOME, confined to the home root. */
|
|
581
586
|
export declare class DshFileSystemFacade implements FileSystemFacade {
|