dsh-config-manager 0.8.2 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/adapters/mcp.js +42 -13
- package/lib/adapters/messages.d.ts +1 -0
- package/lib/adapters/messages.js +2 -0
- package/lib/adapters/patch-key-guard.d.ts +23 -0
- package/lib/adapters/patch-key-guard.js +13 -0
- package/lib/adapters/plugin-data.d.ts +19 -5
- package/lib/adapters/plugin-data.js +76 -22
- package/lib/adapters/plugins.d.ts +14 -1
- package/lib/adapters/plugins.js +147 -4
- package/lib/cli/actions.d.ts +7 -105
- package/lib/cli/actions.js +16 -172
- package/lib/cli/control-state.d.ts +54 -0
- package/lib/cli/control-state.js +107 -0
- package/lib/cli/index.js +14 -0
- package/lib/cli/write-gates.d.ts +61 -0
- package/lib/cli/write-gates.js +110 -0
- package/lib/client.d.ts +104 -49
- package/lib/client.js +12536 -12006
- package/lib/core/backup.d.ts +0 -4
- package/lib/core/backup.js +21 -4
- package/lib/core/boot-rescue.d.ts +1 -1
- package/lib/core/boot-rescue.js +12 -1
- package/lib/core/boot-safety.js +37 -2
- package/lib/core/conflict-decisions.js +2 -1
- package/lib/core/exporter.js +22 -1
- package/lib/core/journal.d.ts +54 -4
- package/lib/core/journal.js +158 -35
- package/lib/core/local-plugin-host.d.ts +29 -0
- package/lib/core/local-plugin-host.js +55 -48
- package/lib/core/messages.d.ts +7 -0
- package/lib/core/messages.js +14 -0
- package/lib/core/migration-history.js +16 -9
- package/lib/core/model-tools.d.ts +2 -2
- package/lib/core/model-tools.js +14 -2
- package/lib/core/patch-secret-guard.d.ts +49 -0
- package/lib/core/patch-secret-guard.js +164 -0
- package/lib/core/reconcile.d.ts +8 -0
- package/lib/core/reconcile.js +18 -3
- package/lib/core/reinstall.d.ts +2 -0
- package/lib/core/reinstall.js +6 -2
- package/lib/core/restore.js +31 -6
- package/lib/core/section-sanitize.d.ts +32 -0
- package/lib/core/section-sanitize.js +13 -0
- package/lib/core/snapshot-diff.d.ts +30 -0
- package/lib/core/snapshot-diff.js +56 -20
- package/lib/core/startup-barrier.js +8 -2
- package/lib/core/types.d.ts +22 -0
- package/lib/core/update-check.js +51 -2
- package/lib/foreign/kernel.js +9 -2
- package/lib/foreign/read-claude-plugins.js +29 -11
- package/lib/foreign/read-dsh.js +31 -2
- package/lib/foreign/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 +1 -1
- package/lib/index.js +1 -1
- package/lib/profiles/dsh-profile-io.d.ts +20 -0
- package/lib/profiles/dsh-profile-io.js +27 -0
- package/lib/profiles/dsh-profile-manager.d.ts +27 -0
- package/lib/profiles/dsh-profile-manager.js +45 -4
- package/lib/profiles/dsh-profile-runtime.d.ts +5 -1
- package/lib/profiles/dsh-profile-runtime.js +16 -3
- package/lib/profiles/process-control.d.ts +18 -1
- package/lib/profiles/process-control.js +25 -1
- package/lib/routes/profiles.js +2 -1
- package/lib/routes/sync.js +13 -1
- package/lib/schema/types.d.ts +11 -0
- package/lib/security/redaction.js +22 -6
- package/lib/sync/autosync-repeat.d.ts +27 -0
- package/lib/sync/autosync-repeat.js +23 -0
- package/lib/sync/autosync-scheduler.d.ts +34 -1
- package/lib/sync/autosync-scheduler.js +151 -43
- package/lib/sync/baseline-heal.js +7 -0
- package/lib/sync/baseline-record.d.ts +67 -0
- package/lib/sync/baseline-record.js +74 -0
- package/lib/sync/blob-store.js +13 -0
- package/lib/sync/content-diff.d.ts +39 -0
- package/lib/sync/content-diff.js +46 -0
- package/lib/sync/git/git-transport.d.ts +32 -1
- package/lib/sync/git/git-transport.js +146 -26
- package/lib/sync/github-auth.d.ts +17 -1
- package/lib/sync/github-auth.js +37 -1
- package/lib/sync/merge-apply-plan.d.ts +38 -0
- package/lib/sync/merge-apply-plan.js +76 -0
- package/lib/sync/messages.d.ts +1 -0
- package/lib/sync/messages.js +2 -0
- package/lib/sync/pending-merge.d.ts +34 -0
- package/lib/sync/pending-merge.js +53 -0
- package/lib/sync/s3/s3-transport.d.ts +14 -2
- package/lib/sync/s3/s3-transport.js +72 -48
- package/lib/sync/sync-engine.d.ts +23 -40
- package/lib/sync/sync-engine.js +115 -132
- package/lib/sync/sync-history.d.ts +7 -0
- package/lib/sync/sync-state.d.ts +28 -0
- package/lib/sync/sync-state.js +20 -0
- package/lib/sync/transport.d.ts +12 -3
- package/lib/sync/transport.js +13 -4
- package/lib/sync/webdav/webdav-transport.d.ts +19 -2
- package/lib/sync/webdav/webdav-transport.js +81 -40
- package/lib/ui/commands.js +5 -11
- package/lib/ui/dsh-profiles-view.d.ts +8 -3
- package/lib/ui/dsh-profiles-view.js +9 -5
- package/lib/ui/i18n.d.ts +2 -1
- package/lib/ui/i18n.js +4 -2
- package/lib/ui/menu-placement.js +1 -1
- package/lib/ui/migration-consult-view.d.ts +11 -0
- package/lib/ui/migration-consult-view.js +15 -0
- package/lib/ui/overview-view.d.ts +7 -0
- package/lib/ui/overview-view.js +3 -0
- package/lib/ui/report.d.ts +9 -0
- package/lib/ui/report.js +17 -4
- package/lib/ui/selection-model.d.ts +8 -0
- package/lib/ui/selection-model.js +16 -0
- package/lib/utils/patch-yaml.d.ts +39 -1
- package/lib/utils/patch-yaml.js +82 -2
- package/lib/utils/paths.d.ts +13 -0
- package/lib/utils/paths.js +35 -0
- package/lib/utils/workdir-lock.js +18 -3
- package/package.json +2 -1
- package/src/adapters/mcp.test.ts +29 -0
- package/src/adapters/mcp.ts +43 -12
- package/src/adapters/messages.ts +2 -0
- package/src/adapters/patch-key-guard.ts +29 -0
- package/src/adapters/plugin-data.test.ts +126 -0
- package/src/adapters/plugin-data.ts +97 -26
- package/src/adapters/plugins.test.ts +288 -0
- package/src/adapters/plugins.ts +141 -4
- package/src/cli/actions.test.ts +74 -1
- package/src/cli/actions.ts +27 -246
- package/src/cli/control-state.ts +143 -0
- package/src/cli/index.ts +18 -0
- package/src/cli/web/web.test.ts +27 -0
- package/src/cli/write-gates.ts +149 -0
- package/src/client/about/AboutPanel.tsx +7 -6
- package/src/client/about/release-notes-view.test.ts +17 -0
- package/src/client/about/release-notes-view.ts +49 -24
- package/src/client/chat/ChatEntryView.tsx +2 -2
- package/src/client/chat/rollback-entry-view.ts +6 -1
- package/src/client/common/CommandPalette.tsx +6 -3
- package/src/client/common/ConfirmDialog.tsx +29 -12
- package/src/client/common/ContentPicker.tsx +13 -12
- package/src/client/common/Modal.tsx +12 -5
- package/src/client/common/MoreMenu.tsx +4 -1
- package/src/client/common/RunsCenter.tsx +103 -32
- package/src/client/common/Select.tsx +2 -2
- package/src/client/common/floating-bounds.ts +1 -1
- package/src/client/common/floating-units.test.ts +1 -2
- package/src/client/common/plan-text-redaction.test.ts +188 -3
- package/src/client/common/runs-center-guard.test.ts +60 -0
- package/src/client/common/runs-center-view.test.ts +128 -0
- package/src/client/common/runs-center-view.ts +96 -0
- package/src/client/common/section-title-action.test.ts +66 -0
- package/src/client/common/ui.tsx +93 -30
- package/src/client/config-manager.module.css +1507 -272
- package/src/client/consult/ConsultCard.tsx +7 -6
- package/src/client/environment/EnvironmentPanel.tsx +20 -21
- package/src/client/environment/maintenance/DiskUsageCard.tsx +65 -91
- package/src/client/environment/profiles-incomplete-ui.test.ts +8 -8
- package/src/client/export/ExportView.tsx +7 -16
- package/src/client/history/HistoryPanel.tsx +88 -28
- package/src/client/history/history-locales.ts +3 -3
- package/src/client/home/BackupScheduleCard.tsx +35 -30
- package/src/client/home/HomePanel.tsx +45 -10
- package/src/client/import/ConflictList.tsx +13 -13
- package/src/client/import/ForeignImportView.tsx +7 -6
- package/src/client/import/ImportWizardView.tsx +2 -3
- package/src/client/import/PathMappingForm.tsx +4 -4
- package/src/client/import/PathPickerDialog.tsx +2 -1
- package/src/client/import/import-wizard-steps.tsx +51 -39
- package/src/client/import/use-import-wizard-controller.test.ts +129 -0
- package/src/client/import/use-import-wizard-controller.ts +116 -22
- package/src/client/library/ArtifactRow.tsx +2 -2
- package/src/client/library/BackupInspectView.tsx +19 -15
- package/src/client/library/LibraryActions.tsx +56 -16
- package/src/client/library/LibraryPanel.tsx +7 -7
- package/src/client/library/RestorePlanView.tsx +13 -8
- package/src/client/locales/about.ts +0 -2
- package/src/client/locales/backup.ts +10 -12
- package/src/client/locales/common.ts +2 -0
- package/src/client/locales/export.ts +5 -12
- package/src/client/locales/foreign.ts +2 -2
- package/src/client/locales/import.ts +3 -2
- package/src/client/locales/overview.ts +4 -0
- package/src/client/locales/profiles.ts +32 -4
- package/src/client/locales/restore.ts +0 -2
- package/src/client/locales/sessions.ts +0 -2
- package/src/client/locales/shell.ts +2 -2
- package/src/client/market/MarketPanel.tsx +38 -20
- package/src/client/market/MyConfigsList.tsx +34 -32
- package/src/client/market/MyConfigsLoginCard.tsx +12 -15
- package/src/client/market/MyConfigsView.tsx +5 -5
- package/src/client/market/MyConfigsWizard.tsx +7 -12
- package/src/client/market/market-locales.ts +0 -6
- package/src/client/market/my-configs-split.test.ts +2 -1
- package/src/client/nav-menu-clip-guard.test.ts +52 -0
- package/src/client/recovery/IncompleteCopiesSection.tsx +1 -3
- package/src/client/recovery/RecoveryPanel.tsx +31 -16
- package/src/client/recovery/RollbackCard.tsx +58 -16
- package/src/client/recovery/RollbackFileChanges.tsx +40 -27
- package/src/client/recovery/SessionHealthCard.tsx +2 -2
- package/src/client/recovery/SessionHealthDialog.tsx +5 -7
- package/src/client/recovery/SessionLayoutSection.tsx +3 -5
- package/src/client/recovery/recovery-locales.ts +12 -8
- package/src/client/run-store.test.ts +30 -0
- package/src/client/run-store.ts +21 -1
- package/src/client/sync/AddChannelCard.tsx +65 -0
- package/src/client/sync/AutosyncCard.tsx +182 -108
- package/src/client/sync/ChannelClearConfirmDialog.tsx +5 -1
- package/src/client/sync/ChannelConfigDialog.tsx +27 -48
- package/src/client/sync/MergePreviewView.tsx +3 -5
- package/src/client/sync/PushReportSections.tsx +35 -0
- package/src/client/sync/SyncChannelEntryCard.tsx +33 -24
- package/src/client/sync/SyncConfirmView.tsx +3 -3
- package/src/client/sync/SyncLogList.tsx +16 -5
- package/src/client/sync/SyncPanel.tsx +153 -159
- package/src/client/sync/SyncProbeRow.tsx +5 -7
- package/src/client/sync/SyncRepositoryPicker.tsx +17 -4
- package/src/client/sync/SyncSecuritySection.tsx +157 -0
- package/src/client/sync/SyncSettingsDialog.tsx +304 -0
- package/src/client/sync/SyncSettingsView.test.ts +26 -8
- package/src/client/sync/WorkDirCard.tsx +2 -4
- package/src/client/sync/config-clear-guard.test.ts +94 -0
- package/src/client/sync/config-clear-guard.ts +98 -0
- package/src/client/sync/config-dirty.test.ts +91 -0
- package/src/client/sync/config-dirty.ts +88 -0
- package/src/client/sync/history-model.test.ts +2 -0
- package/src/client/sync/history-model.ts +3 -0
- package/src/client/sync/merge-request.ts +20 -0
- package/src/client/sync/sync-api.ts +12 -0
- package/src/client/sync/sync-locales.ts +87 -47
- package/src/client/sync/sync-panel-clear.test.ts +44 -0
- package/src/client/sync/sync-view.test.ts +20 -0
- package/src/client/sync/sync-view.ts +42 -4
- package/src/core/backup.test.ts +61 -1
- package/src/core/backup.ts +21 -4
- package/src/core/boot-rescue.test.ts +35 -0
- package/src/core/boot-rescue.ts +13 -2
- package/src/core/boot-safety.test.ts +25 -0
- package/src/core/boot-safety.ts +37 -2
- package/src/core/conflict-decisions.ts +2 -1
- package/src/core/exporter.ts +21 -1
- package/src/core/journal.test.ts +183 -0
- package/src/core/journal.ts +163 -25
- package/src/core/local-plugin-host.test.ts +68 -2
- package/src/core/local-plugin-host.ts +31 -4
- package/src/core/messages.ts +14 -0
- package/src/core/migration-history.test.ts +27 -0
- package/src/core/migration-history.ts +12 -4
- package/src/core/model-tools.test.ts +67 -0
- package/src/core/model-tools.ts +16 -4
- package/src/core/patch-secret-guard.test.ts +110 -0
- package/src/core/patch-secret-guard.ts +176 -0
- package/src/core/reconcile.ts +32 -4
- package/src/core/reinstall.ts +8 -2
- package/src/core/restore.ts +32 -7
- package/src/core/section-sanitize.ts +37 -0
- package/src/core/snapshot-diff.test.ts +73 -1
- package/src/core/snapshot-diff.ts +66 -21
- package/src/core/startup-barrier.test.ts +64 -0
- package/src/core/startup-barrier.ts +8 -2
- package/src/core/types.ts +27 -1
- package/src/core/update-check.test.ts +40 -0
- package/src/core/update-check.ts +53 -2
- package/src/foreign/claude-code.test.ts +5 -0
- package/src/foreign/claude-plugins.test.ts +57 -0
- package/src/foreign/claude-sessions-bytes.test.ts +7 -1
- package/src/foreign/dsh.test.ts +23 -0
- package/src/foreign/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.ts +1 -1
- package/src/profiles/dsh-profile-copy-rollback.test.ts +58 -4
- package/src/profiles/dsh-profile-io.ts +29 -0
- package/src/profiles/dsh-profile-manager.test.ts +30 -0
- package/src/profiles/dsh-profile-manager.ts +53 -5
- package/src/profiles/dsh-profile-runtime.test.ts +29 -7
- package/src/profiles/dsh-profile-runtime.ts +17 -3
- package/src/profiles/process-control.test.ts +97 -0
- package/src/profiles/process-control.ts +28 -1
- package/src/routes/profiles.ts +2 -1
- package/src/routes/sync.ts +13 -1
- package/src/schema/types.ts +16 -1
- package/src/security/redaction.test.ts +31 -0
- package/src/security/redaction.ts +23 -6
- package/src/sync/autosync-repeat.test.ts +58 -0
- package/src/sync/autosync-repeat.ts +55 -0
- package/src/sync/autosync-scheduler.test.ts +417 -0
- package/src/sync/autosync-scheduler.ts +154 -41
- package/src/sync/baseline-heal.ts +6 -0
- package/src/sync/baseline-record.ts +135 -0
- package/src/sync/blob-store.test.ts +16 -0
- package/src/sync/blob-store.ts +13 -0
- package/src/sync/content-diff.test.ts +95 -0
- package/src/sync/content-diff.ts +79 -0
- package/src/sync/git/git-transport.test.ts +151 -4
- package/src/sync/git/git-transport.ts +143 -27
- package/src/sync/github-auth.test.ts +26 -1
- package/src/sync/github-auth.ts +37 -1
- package/src/sync/merge-apply-plan.ts +117 -0
- package/src/sync/messages.ts +2 -0
- package/src/sync/pending-merge.ts +77 -0
- package/src/sync/s3/s3-delete-and-blob-index.test.ts +249 -0
- package/src/sync/s3/s3-transport.ts +76 -42
- package/src/sync/sync-config.test.ts +39 -12
- package/src/sync/sync-device-identity.test.ts +3 -0
- package/src/sync/sync-engine.test.ts +465 -12
- package/src/sync/sync-engine.ts +130 -135
- package/src/sync/sync-history.ts +7 -0
- package/src/sync/sync-state.ts +48 -0
- package/src/sync/transport.test.ts +13 -1
- package/src/sync/transport.ts +12 -4
- package/src/sync/webdav/webdav-delete-and-blob-index.test.ts +249 -0
- package/src/sync/webdav/webdav-transport.ts +86 -34
- package/src/ui/commands.test.ts +11 -0
- package/src/ui/commands.ts +5 -14
- package/src/ui/dsh-profiles-view.test.ts +16 -0
- package/src/ui/dsh-profiles-view.ts +11 -5
- package/src/ui/i18n.ts +4 -2
- package/src/ui/menu-placement.ts +1 -1
- package/src/ui/migration-consult-view.test.ts +20 -1
- package/src/ui/migration-consult-view.ts +17 -0
- package/src/ui/overview-view.ts +10 -0
- package/src/ui/report.test.ts +25 -1
- package/src/ui/report.ts +15 -4
- package/src/ui/selection-model.test.ts +15 -1
- package/src/ui/selection-model.ts +18 -0
- package/src/utils/js-yaml4.d.ts +35 -0
- package/src/utils/patch-yaml.test.ts +207 -1
- package/src/utils/patch-yaml.ts +98 -2
- package/src/utils/paths.test.ts +14 -1
- package/src/utils/paths.ts +35 -0
- package/src/utils/workdir-lock.test.ts +69 -0
- package/src/utils/workdir-lock.ts +17 -3
- package/lib/ui/path-mapping.d.ts +0 -38
- package/lib/ui/path-mapping.js +0 -75
- package/src/client/common/InfoHint.tsx +0 -289
- package/src/client/common/info-hint-guard.test.ts +0 -1119
- package/src/client/sync/DecryptPasswordCard.tsx +0 -48
- package/src/client/sync/SecurityOptionsCard.tsx +0 -97
- package/src/client/sync/SyncSectionPickerDialog.tsx +0 -213
- package/src/ui/path-mapping.test.ts +0 -67
- package/src/ui/path-mapping.ts +0 -103
|
@@ -94,8 +94,23 @@ interface SideRead {
|
|
|
94
94
|
|
|
95
95
|
const ABSENT: SideRead = { exists: false, bytes: 0, text: '', binary: false, oversized: false, unreadable: false };
|
|
96
96
|
|
|
97
|
+
/** 该 errno 是否等于「路径真的不存在」(其余 = 存在但拿不到,绝不能当作不存在)。 */
|
|
98
|
+
function isEnoent(err: unknown): boolean {
|
|
99
|
+
return typeof err === 'object' && err !== null && (err as { code?: unknown }).code === 'ENOENT';
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 「存在但读不出」的唯一形态(目录 / 无权限 / 被占用 / stat 抛非 ENOENT)。
|
|
104
|
+
* 与 ABSENT(真的不存在)严格区分:判成不存在会让预览把改不了的文件显示成「新增」(审计 P2-6)。
|
|
105
|
+
*/
|
|
106
|
+
function unreadableAt(bytes: number): SideRead {
|
|
107
|
+
return { exists: true, bytes, text: null, binary: false, oversized: false, unreadable: true };
|
|
108
|
+
}
|
|
109
|
+
|
|
97
110
|
/** 只探测存在性(预算触顶时用:不读内容,只 stat)。 */
|
|
98
|
-
async function probeExists(
|
|
111
|
+
async function probeExists(
|
|
112
|
+
opts: { homeDir: string; target: string; msg: MsgFunc },
|
|
113
|
+
): Promise<'exists' | 'absent' | 'unreadable' | 'escape'> {
|
|
99
114
|
let abs: string;
|
|
100
115
|
try {
|
|
101
116
|
abs = homeAbs(opts.homeDir, opts.target, opts.msg);
|
|
@@ -104,29 +119,57 @@ async function probeExists(opts: { homeDir: string; target: string; msg: MsgFunc
|
|
|
104
119
|
}
|
|
105
120
|
try {
|
|
106
121
|
const stat = await fs.stat(abs);
|
|
107
|
-
return stat.isFile() ? 'exists' : '
|
|
108
|
-
} catch {
|
|
109
|
-
|
|
122
|
+
return stat.isFile() ? 'exists' : 'unreadable';
|
|
123
|
+
} catch (err) {
|
|
124
|
+
// ENOENT 才是「没有」;EACCES 一类说明路径在,只是拿不到状态
|
|
125
|
+
return isEnoent(err) ? 'absent' : 'unreadable';
|
|
110
126
|
}
|
|
111
127
|
}
|
|
112
128
|
|
|
113
|
-
|
|
129
|
+
/** readSide 依赖的最小 fs 能力(默认 = 真 fs)。 */
|
|
130
|
+
export interface SideReadIo {
|
|
131
|
+
stat(abs: string): Promise<{ isFile(): boolean; size: number }>;
|
|
132
|
+
readFile(abs: string): Promise<Buffer>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const REAL_SIDE_IO: SideReadIo = {
|
|
136
|
+
stat: (abs) => fs.stat(abs),
|
|
137
|
+
readFile: (abs) => fs.readFile(abs),
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 读单侧内容。
|
|
142
|
+
*
|
|
143
|
+
* 三种结果必须分开:真的没有(ABSENT)/ 存在但读不出(unreadable)/ 正常读到。
|
|
144
|
+
* 原先整段包一个 try + 末尾 `catch { return ABSENT }`,把「stat 成功、readFile 抛 EACCES」
|
|
145
|
+
* 判成了不存在 —— 预览因此把只读文件显示成「新增」(审计 P2-6)。
|
|
146
|
+
*
|
|
147
|
+
* `io` 参数只为单测注入:Windows 上造不出 EACCES 夹具,而这条分支必须被真正覆盖;
|
|
148
|
+
* 生产调用方一律不传(走 REAL_SIDE_IO)。
|
|
149
|
+
*/
|
|
150
|
+
export async function readSide(abs: string, maxBytes: number, io: SideReadIo = REAL_SIDE_IO): Promise<SideRead> {
|
|
151
|
+
let stat: { isFile(): boolean; size: number };
|
|
114
152
|
try {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
153
|
+
stat = await io.stat(abs);
|
|
154
|
+
} catch (err) {
|
|
155
|
+
return isEnoent(err) ? ABSENT : unreadableAt(0);
|
|
156
|
+
}
|
|
157
|
+
if (!stat.isFile()) return unreadableAt(stat.size);
|
|
158
|
+
if (stat.size > maxBytes) {
|
|
159
|
+
return { exists: true, bytes: stat.size, text: null, binary: false, oversized: true, unreadable: false };
|
|
160
|
+
}
|
|
161
|
+
let buf: Buffer;
|
|
162
|
+
try {
|
|
163
|
+
buf = await io.readFile(abs);
|
|
164
|
+
} catch (err) {
|
|
165
|
+
// stat 已证明它是普通文件:这里读失败 = 存在但读不出(EACCES/EBUSY/…);
|
|
166
|
+
// stat 与 read 之间被删掉的 ENOENT 仍按「不存在」处理,那才是当时的真实状态
|
|
167
|
+
return isEnoent(err) ? ABSENT : unreadableAt(stat.size);
|
|
168
|
+
}
|
|
169
|
+
if (buf.subarray(0, 8192).includes(0)) {
|
|
170
|
+
return { exists: true, bytes: buf.byteLength, text: null, binary: true, oversized: false, unreadable: false };
|
|
129
171
|
}
|
|
172
|
+
return { exists: true, bytes: buf.byteLength, text: buf.toString('utf8'), binary: false, oversized: false, unreadable: false };
|
|
130
173
|
}
|
|
131
174
|
|
|
132
175
|
/** 变更状态判定(恢复类:before 存在 = 修改,不存在 = 新增)。 */
|
|
@@ -252,10 +295,12 @@ export async function summarizeRestoreChanges(opts: {
|
|
|
252
295
|
entry.status = 'skip';
|
|
253
296
|
entry.statSkipped = 'unreadable';
|
|
254
297
|
} else {
|
|
255
|
-
|
|
298
|
+
// 「存在但读不出」与 readSide 同口径:算存在(否则会显示成「新增」),只把行数统计标成 unreadable
|
|
299
|
+
const unreadable = probe === 'unreadable';
|
|
300
|
+
entry.beforeExists = probe === 'exists' || unreadable;
|
|
256
301
|
entry.afterExists = restoreKind;
|
|
257
302
|
entry.status = statusOf(action.kind, entry.beforeExists);
|
|
258
|
-
entry.statSkipped = 'budget';
|
|
303
|
+
entry.statSkipped = unreadable ? 'unreadable' : 'budget';
|
|
259
304
|
}
|
|
260
305
|
skipped += 1;
|
|
261
306
|
entries.push(entry);
|
|
@@ -8,7 +8,12 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import test from 'node:test';
|
|
10
10
|
import assert from 'node:assert/strict';
|
|
11
|
+
import fssync from 'node:fs';
|
|
12
|
+
import os from 'node:os';
|
|
13
|
+
import path from 'node:path';
|
|
11
14
|
import { resolveStartupSafeMode, classifyStartup, FAIL_CLOSED_STARTUP } from './startup-barrier.ts';
|
|
15
|
+
import { JournalStore, createJournalEntry } from './journal.ts';
|
|
16
|
+
import type { ReconcileEnv, ReconcileProbeHooks } from './reconcile.ts';
|
|
12
17
|
|
|
13
18
|
test('issue #87:NORMAL + 无活锁者 + 陈旧 blocked 标记 → 解除(内存标志与 durable 标记一起复位)', () => {
|
|
14
19
|
assert.deepEqual(
|
|
@@ -67,3 +72,62 @@ test('issue #87:classifyStartup 仍是分类唯一来源(形状自检,防
|
|
|
67
72
|
});
|
|
68
73
|
assert.equal(typeof classifier.classify, 'function');
|
|
69
74
|
});
|
|
75
|
+
|
|
76
|
+
// ---------- P3-8:LOCKED_LIVE 的判据是「持锁 + live 且未 terminal 的 journal」 ----------
|
|
77
|
+
|
|
78
|
+
function tmpDir(t: test.TestContext): string {
|
|
79
|
+
const dir = fssync.mkdtempSync(path.join(os.tmpdir(), 'sb-'));
|
|
80
|
+
t.after(() => fssync.rmSync(dir, { recursive: true, force: true }));
|
|
81
|
+
return dir;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const probeHooks: ReconcileProbeHooks = {
|
|
85
|
+
verifyStepFingerprint: async () => 'before-match',
|
|
86
|
+
probeExternal: async () => 'not-installed',
|
|
87
|
+
snapshotExists: async () => true,
|
|
88
|
+
};
|
|
89
|
+
// 保守 env:真实进程探测恒 false(LOCKED 下由 inspectStartup 强制按 live 处理)
|
|
90
|
+
const probeEnv: ReconcileEnv = { environmentFingerprint: 'fp', isLiveOwner: async () => false };
|
|
91
|
+
|
|
92
|
+
function journalStore(dir: string): JournalStore {
|
|
93
|
+
return new JournalStore({ transactionsDir: path.join(dir, 'transactions') });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
test('审计 P3-8:另一实例持锁 + 存在真正在跑的 journal(live 且未 terminal)→ LOCKED_LIVE(旧实现给 NORMAL)', async (t) => {
|
|
97
|
+
const dir = tmpDir(t);
|
|
98
|
+
const store = journalStore(dir);
|
|
99
|
+
const operationId = '00000000-0000-4000-8000-0000000000a1';
|
|
100
|
+
await store.create(createJournalEntry(
|
|
101
|
+
'import-apply',
|
|
102
|
+
{ operationId, ownerInstanceId: 'other-instance', lockId: 'lock-1', packageVersion: '0.1.80', environmentFingerprint: 'fp' },
|
|
103
|
+
'2026-01-01T00:00:00.000Z',
|
|
104
|
+
));
|
|
105
|
+
// 进行中(非 terminal):另一个存活实例正在 apply
|
|
106
|
+
await store.update(operationId, (cur) => ({ ...cur, state: 'APPLYING' }));
|
|
107
|
+
|
|
108
|
+
const { state } = await classifyStartup({
|
|
109
|
+
store, hooks: probeHooks, env: probeEnv, lockState: 'LOCKED',
|
|
110
|
+
}).classify();
|
|
111
|
+
|
|
112
|
+
assert.equal(state.kind, 'LOCKED_LIVE', `持锁 + 真正在跑必须分类为 LOCKED_LIVE;实际 ${state.kind}`);
|
|
113
|
+
assert.equal(state.kind === 'LOCKED_LIVE' ? state.operationId : undefined, operationId, '必须指出是哪条 live op');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('审计 P3-8 对照:持锁但 active 里只有已 terminal 的 journal → NORMAL(不误报 LOCKED_LIVE)', async (t) => {
|
|
117
|
+
const dir = tmpDir(t);
|
|
118
|
+
const store = journalStore(dir);
|
|
119
|
+
const operationId = '00000000-0000-4000-8000-0000000000a2';
|
|
120
|
+
await store.create(createJournalEntry(
|
|
121
|
+
'import-apply',
|
|
122
|
+
{ operationId, ownerInstanceId: 'other-instance', lockId: 'lock-1', packageVersion: '0.1.80', environmentFingerprint: 'fp' },
|
|
123
|
+
'2026-01-01T00:00:00.000Z',
|
|
124
|
+
));
|
|
125
|
+
await store.update(operationId, (cur) => ({ ...cur, state: 'COMMITTED' }));
|
|
126
|
+
|
|
127
|
+
const { state } = await classifyStartup({
|
|
128
|
+
store, hooks: probeHooks, env: probeEnv, lockState: 'LOCKED',
|
|
129
|
+
}).classify();
|
|
130
|
+
|
|
131
|
+
assert.equal(state.kind, 'NORMAL', '没有未收敛的 live op ⇒ 不存在「正在跑的操作」可报');
|
|
132
|
+
});
|
|
133
|
+
|
|
@@ -44,8 +44,14 @@ export function classifyStartup(opts: {
|
|
|
44
44
|
const insp = await inspectStartup(opts.store, opts.hooks, opts.env, opts.options ?? {}, opts.lockState);
|
|
45
45
|
let state: StartupRecoveryState;
|
|
46
46
|
if (opts.lockState === 'LOCKED') {
|
|
47
|
-
// fresh heartbeat
|
|
48
|
-
|
|
47
|
+
// fresh heartbeat:活锁。判据 = 「另一实例持锁 + 确实有 live 且未到 terminal 的 journal」——
|
|
48
|
+
// 那才是正在跑的操作,分类为 LOCKED_LIVE(不作 recovery/接管,也不启动调度器)。
|
|
49
|
+
// 审计 P3-8:旧实现在这里看 unresolved,但 live 分支恒 unresolved:false(且 LOCKED 下所有
|
|
50
|
+
// journal 都被强制按 live 处理),于是「持锁 + 真正在跑」永远落到 NORMAL;只有 parse 失败
|
|
51
|
+
// 的 corrupt journal(走 quarantine 分支)才碰巧命中 LOCKED_LIVE。现在改用 liveIncomplete。
|
|
52
|
+
state = insp.liveIncomplete.length > 0
|
|
53
|
+
? { kind: 'LOCKED_LIVE', operationId: insp.liveIncomplete[0] }
|
|
54
|
+
: { kind: 'NORMAL' };
|
|
49
55
|
} else if (insp.recoveryRequired) {
|
|
50
56
|
state = { kind: 'RECOVERY_REQUIRED', operationId: insp.unresolved[0] };
|
|
51
57
|
} else if (insp.unresolved.length > 0 || insp.safeModeRequired) {
|
package/src/core/types.ts
CHANGED
|
@@ -673,7 +673,21 @@ export type GlobalConflictStrategy = 'merge' | 'replace' | 'skipExisting';
|
|
|
673
673
|
*/
|
|
674
674
|
export type SessionFormatDisposition = 'abort' | 'skip' | 'guide';
|
|
675
675
|
|
|
676
|
-
export interface ConflictDecision {
|
|
676
|
+
export interface ConflictDecision {
|
|
677
|
+
itemId: string;
|
|
678
|
+
resolution: ItemResolution;
|
|
679
|
+
/**
|
|
680
|
+
* 这条裁决是**谁**下的(issue #136 A):
|
|
681
|
+
* - `'item'`:用户对该计划项逐项决策(`decisions.resolutions[id]`,含导入页的逐行确认)——
|
|
682
|
+
* 适配器可把它当作「我确实要这一行按导入值写」的确认。
|
|
683
|
+
* - `'section'`:由**分区级**裁决换算而来(合并落地 `planMergeApply` 的 second pass 把
|
|
684
|
+
* 「该分区已裁决」逐项注入成 `useImported`)。分区级裁决决定「分区是否应用」,
|
|
685
|
+
* 不构成对某一行值的确认,写回守卫不得据此清空本机明文。
|
|
686
|
+
* - 缺省:未标注来源。写回守卫按**未确认**处理(默认拒绝清空)—— 忘了标注只会少清空,
|
|
687
|
+
* 不会误清空;确认必须显式写明来源。
|
|
688
|
+
*/
|
|
689
|
+
decidedBy?: 'item' | 'section';
|
|
690
|
+
}
|
|
677
691
|
|
|
678
692
|
export interface PathMapping {
|
|
679
693
|
oldPrefix: string;
|
|
@@ -1230,6 +1244,18 @@ export interface ConfigAdapter<TSection = unknown> {
|
|
|
1230
1244
|
* 实现方应尊重 `options.includeItems?.[this.id]`(条目级选择,见 adapters/units.ts)。 */
|
|
1231
1245
|
export(ctx: HostContext, options: ExportOptions): Promise<ExportSection<TSection>>;
|
|
1232
1246
|
|
|
1247
|
+
/**
|
|
1248
|
+
* 可选:脱敏**归属标注**(issue #136 C)—— 把 SecretScanner 的命中路径归属回具体载荷单元。
|
|
1249
|
+
*
|
|
1250
|
+
* 调用点只有一个:`sanitizeSectionData()`(`src/core/section-sanitize.ts`),纯函数语义
|
|
1251
|
+
* (不改入参、不读盘);只做「标注」,绝不把值写回去(脱敏仍是扫描器的职责)。
|
|
1252
|
+
*
|
|
1253
|
+
* plugins 分区用它把 `patch[i].raw.x` 的命中写进第 i 行的 `redactedPaths`:目标机据此区分
|
|
1254
|
+
* 「被剥空」与「用户写空」,写回层才能精确保护本机明文(`src/core/patch-secret-guard.ts`)。
|
|
1255
|
+
* 未实现 = 载荷不含归属信息,写回侧走保守分支。
|
|
1256
|
+
*/
|
|
1257
|
+
annotateRedactions?(sanitized: unknown, hits: SensitiveHit[]): unknown;
|
|
1258
|
+
|
|
1233
1259
|
/**
|
|
1234
1260
|
* 可选:**只读预览**(`/export-preview` 用)。
|
|
1235
1261
|
*
|
|
@@ -147,3 +147,43 @@ test('UpdateChecker:失败不写缓存(下次仍会重试),且失败结
|
|
|
147
147
|
assert.equal(good.ok, true, '失败不进缓存 → 下一次恢复后可以直接成功');
|
|
148
148
|
assert.equal(good.ok === true ? good.info.latest : null, '2.0.0');
|
|
149
149
|
});
|
|
150
|
+
|
|
151
|
+
/* ---------------- 审计 P11-6:体积上限必须按字节,且不把大响应读进内存 ---------------- */
|
|
152
|
+
|
|
153
|
+
test('P11-6 回归:上限按**字节**判定 —— CJK 120KB 响应不得因 text.length 只有 40K 被放行', async () => {
|
|
154
|
+
// 一个 CJK 字符占 3 个 UTF-8 字节:旧实现用 text.length(UTF-16 代码单元)判上限 ⇒ 120KB 的中文
|
|
155
|
+
// 响应只数到 40K,上限形同虚设。这里同时钉住两个事实:字节超限、代码单元不超限。
|
|
156
|
+
const cjk = JSON.stringify({ version: '9.9.9', description: '中'.repeat(40_000) });
|
|
157
|
+
assert.ok(cjk.length <= UPDATE_CHECK_MAX_BYTES, '前提:代码单元没超限(旧口径会放行)');
|
|
158
|
+
assert.ok(new TextEncoder().encode(cjk).byteLength > UPDATE_CHECK_MAX_BYTES, '前提:字节数超限');
|
|
159
|
+
const r = await probeLatestVersion({ fetchImpl: stubFetch(cjk).impl });
|
|
160
|
+
assert.deepEqual(r, { ok: false, error: 'registry response too large' });
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('P11-6:Content-Length 声明超限时直接拒绝(一个字节都不读)', async () => {
|
|
164
|
+
// 不用真 Response:undici 的 Response 构造期就会 pull 一次流(实测),用它证不了「没读」。
|
|
165
|
+
// 这里用 getter 记账:只要实现碰了 body / arrayBuffer 就会抛错并计数。
|
|
166
|
+
let bodyReads = 0;
|
|
167
|
+
const impl = (async () => ({
|
|
168
|
+
ok: true,
|
|
169
|
+
status: 200,
|
|
170
|
+
headers: new Headers({ 'content-length': String(UPDATE_CHECK_MAX_BYTES + 1) }),
|
|
171
|
+
get body(): ReadableStream<Uint8Array> | null {
|
|
172
|
+
bodyReads += 1;
|
|
173
|
+
throw new Error('body must not be read');
|
|
174
|
+
},
|
|
175
|
+
arrayBuffer: async () => {
|
|
176
|
+
bodyReads += 1;
|
|
177
|
+
throw new Error('body must not be read');
|
|
178
|
+
},
|
|
179
|
+
})) as unknown as typeof fetch;
|
|
180
|
+
const r = await probeLatestVersion({ fetchImpl: impl });
|
|
181
|
+
assert.deepEqual(r, { ok: false, error: 'registry response too large' });
|
|
182
|
+
assert.equal(bodyReads, 0, '有 Content-Length 就先拒,不把大响应读进内存');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test('P11-6:小体量 CJK 响应照常解析(字节口径不误伤)', async () => {
|
|
186
|
+
const body = JSON.stringify({ version: '9.9.9', description: '中文说明'.repeat(100) });
|
|
187
|
+
const r = await probeLatestVersion({ fetchImpl: stubFetch(body).impl });
|
|
188
|
+
assert.deepEqual(r, { ok: true, version: '9.9.9' });
|
|
189
|
+
});
|
package/src/core/update-check.ts
CHANGED
|
@@ -93,6 +93,57 @@ export interface UpdateCheckDeps {
|
|
|
93
93
|
/** 探测结果(内部用):成功给版本号,失败给原因 */
|
|
94
94
|
type ProbeResult = { ok: true; version: string } | { ok: false; error: string }
|
|
95
95
|
|
|
96
|
+
/**
|
|
97
|
+
* **按字节**有界地读响应体;超过 `maxBytes` 返回 null(调用方给 'registry response too large')。
|
|
98
|
+
*
|
|
99
|
+
* 为什么不是 `text.length`:它数的是 UTF-16 代码单元,一个 CJK 字符占 3 个 UTF-8 字节 ⇒
|
|
100
|
+
* 120KB 的中文响应 `text.length` 只有 40K,上限形同虚设(审计 P11-6)。
|
|
101
|
+
* 顺序:Content-Length 预检(有就先拒,一个字节都不读)→ 流式累计,越界立刻 abort
|
|
102
|
+
* (不把大响应读进内存)→ 没有 body 流的运行时退回 arrayBuffer 量 byteLength。
|
|
103
|
+
*/
|
|
104
|
+
async function readBoundedBody(
|
|
105
|
+
res: Response, maxBytes: number, controller: AbortController,
|
|
106
|
+
): Promise<string | null> {
|
|
107
|
+
// 防御:真实 Response 一定有 headers/body,但注入的替身(脚本、极简 mock)可能只给 text()。
|
|
108
|
+
// 缺什么就退化成「全量读 + 字节口径判定」——判据不变,只是失去流式提前止损。
|
|
109
|
+
const declared = typeof res.headers?.get === 'function' ? res.headers.get('content-length') : null
|
|
110
|
+
if (declared !== null) {
|
|
111
|
+
const n = Number(declared)
|
|
112
|
+
if (Number.isFinite(n) && n > maxBytes) {
|
|
113
|
+
controller.abort()
|
|
114
|
+
return null
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const body = (res as { body?: ReadableStream<Uint8Array> | null }).body
|
|
118
|
+
if (body === null || body === undefined) {
|
|
119
|
+
const bytes = typeof res.arrayBuffer === 'function'
|
|
120
|
+
? new Uint8Array(await res.arrayBuffer())
|
|
121
|
+
: new TextEncoder().encode(await res.text())
|
|
122
|
+
return bytes.byteLength > maxBytes ? null : new TextDecoder('utf-8').decode(bytes)
|
|
123
|
+
}
|
|
124
|
+
const reader = body.getReader()
|
|
125
|
+
const chunks: Uint8Array[] = []
|
|
126
|
+
let total = 0
|
|
127
|
+
for (;;) {
|
|
128
|
+
const { done, value } = await reader.read()
|
|
129
|
+
if (done) break
|
|
130
|
+
total += value.byteLength
|
|
131
|
+
if (total > maxBytes) {
|
|
132
|
+
controller.abort()
|
|
133
|
+
await reader.cancel().catch(() => undefined)
|
|
134
|
+
return null
|
|
135
|
+
}
|
|
136
|
+
chunks.push(value)
|
|
137
|
+
}
|
|
138
|
+
const merged = new Uint8Array(total)
|
|
139
|
+
let at = 0
|
|
140
|
+
for (const chunk of chunks) {
|
|
141
|
+
merged.set(chunk, at)
|
|
142
|
+
at += chunk.byteLength
|
|
143
|
+
}
|
|
144
|
+
return new TextDecoder('utf-8').decode(merged)
|
|
145
|
+
}
|
|
146
|
+
|
|
96
147
|
/**
|
|
97
148
|
* 探测 npm latest(无缓存、无状态)。任何异常都被收成 `{ ok:false, error }`:
|
|
98
149
|
* 网络错误 / 超时 / 非 2xx / 体积超限 / JSON 畸形 / 版本号形态不认识。
|
|
@@ -109,8 +160,8 @@ export async function probeLatestVersion(deps: UpdateCheckDeps = {}): Promise<Pr
|
|
|
109
160
|
headers: { accept: 'application/json' },
|
|
110
161
|
})
|
|
111
162
|
if (!res.ok) return { ok: false, error: `registry returned HTTP ${res.status}` }
|
|
112
|
-
const text = await res
|
|
113
|
-
if (text
|
|
163
|
+
const text = await readBoundedBody(res, UPDATE_CHECK_MAX_BYTES, controller)
|
|
164
|
+
if (text === null) return { ok: false, error: 'registry response too large' }
|
|
114
165
|
let payload: unknown
|
|
115
166
|
try {
|
|
116
167
|
payload = JSON.parse(text) as unknown
|
|
@@ -55,6 +55,11 @@ test('t0 frontmatter 切分与 URL userinfo 剥离的边界', () => {
|
|
|
55
55
|
assert.equal(frontmatterProblem(['---', 'name: a', 'description: ok', '---', 'body'].join(NL)), null);
|
|
56
56
|
assert.deepEqual(stripUserInfo('https://u:p@h/mcp'), { url: 'https://h/mcp', stripped: true });
|
|
57
57
|
assert.deepEqual(stripUserInfo('https://h/path@x'), { url: 'https://h/path@x', stripped: false });
|
|
58
|
+
// 无路径 URL 的 query 里出现 @ 不是 userinfo(曾把整条 URL 截成 https://b)
|
|
59
|
+
assert.deepEqual(stripUserInfo('https://h?k=a@b'), { url: 'https://h?k=a@b', stripped: false });
|
|
60
|
+
assert.deepEqual(stripUserInfo('https://h?email=a@b&x=1'), { url: 'https://h?email=a@b&x=1', stripped: false });
|
|
61
|
+
assert.deepEqual(stripUserInfo('https://h#a@b'), { url: 'https://h#a@b', stripped: false });
|
|
62
|
+
assert.deepEqual(stripUserInfo('https://u:p@h?k=1'), { url: 'https://h?k=1', stripped: true });
|
|
58
63
|
assert.deepEqual(stripUserInfo('npx'), { url: 'npx', stripped: false });
|
|
59
64
|
});
|
|
60
65
|
|
|
@@ -219,6 +219,63 @@ test('单插件文件数触顶报 max-plugin-files-reached,且载荷里不超
|
|
|
219
219
|
});
|
|
220
220
|
});
|
|
221
221
|
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* 审计 P7-9(边界回归):文件数**恰好等于**上限不是截断。
|
|
225
|
+
*
|
|
226
|
+
* 旧实现拿 walkFiles 返回数组的长度反推「是否触顶」(length >= maxPluginFiles)—— 共享内核
|
|
227
|
+
* 最多只返回 maxFiles 条,于是「正好 N 个」必然被误报成 max-plugin-files-reached。
|
|
228
|
+
* 现在由 walkFilesChecked 多要一条来取证:N+1 条才算真截断。
|
|
229
|
+
*/
|
|
230
|
+
test('审计 P7-9(边界回归):文件数恰好等于上限时不报触顶,超过上限才报', async () => {
|
|
231
|
+
await withClaudeDir(async (claudeDir) => {
|
|
232
|
+
const marketDir = path.join(claudeDir, 'plugins', 'marketplaces', 'm');
|
|
233
|
+
await write(path.join(marketDir, '.claude-plugin', 'marketplace.json'), JSON.stringify({
|
|
234
|
+
name: 'm',
|
|
235
|
+
plugins: [{ name: 'exact', source: { source: 'github', repo: 'acme/exact' } }],
|
|
236
|
+
}));
|
|
237
|
+
/** 只带 commands/ 的极简插件:文件总数可精确控制 */
|
|
238
|
+
const makePlugin = async (name: string, commandFiles: number): Promise<string> => {
|
|
239
|
+
const dir = path.join(marketDir, 'plugins', name);
|
|
240
|
+
await write(path.join(dir, '.claude-plugin', 'plugin.json'), JSON.stringify({ name }));
|
|
241
|
+
for (let k = 0; k < commandFiles; k += 1) {
|
|
242
|
+
await write(path.join(dir, 'commands', 'c' + String(k) + '.md'), 'cmd ' + String(k));
|
|
243
|
+
}
|
|
244
|
+
return dir;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// 恰好 2 个文件 + 上限 2 → 没有被截断,不得报码(旧实现会误报)
|
|
248
|
+
await makePlugin('exact', 2);
|
|
249
|
+
const atLimit = await readClaudePlugins({
|
|
250
|
+
claudeDir,
|
|
251
|
+
settings: { enabledPlugins: { 'exact@m': true } },
|
|
252
|
+
limits: { maxPluginFiles: 2 },
|
|
253
|
+
});
|
|
254
|
+
const exact = pluginOf(atLimit, 'exact');
|
|
255
|
+
assert.ok(exact !== undefined, '插件必须产出:' + JSON.stringify(atLimit.skipped));
|
|
256
|
+
assert.equal(exact.commandCount, 2, '恰好等于上限时必须完整计数');
|
|
257
|
+
assert.equal(
|
|
258
|
+
exact.readFindings?.find((f) => f.detail === 'max-plugin-files-reached'),
|
|
259
|
+
undefined,
|
|
260
|
+
'恰好等于上限不是截断,实际 findings:' + JSON.stringify(exact.readFindings),
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
// 3 个文件 + 上限 2 → 真的截断了:必须报码,且计数不超过上限
|
|
264
|
+
await makePlugin('over', 3);
|
|
265
|
+
const overLimit = await readClaudePlugins({
|
|
266
|
+
claudeDir,
|
|
267
|
+
settings: { enabledPlugins: { 'over@m': true } },
|
|
268
|
+
limits: { maxPluginFiles: 2 },
|
|
269
|
+
});
|
|
270
|
+
const over = pluginOf(overLimit, 'over');
|
|
271
|
+
assert.ok(over !== undefined, '插件必须产出:' + JSON.stringify(overLimit.skipped));
|
|
272
|
+
const finding = over.readFindings?.find((f) => f.detail === 'max-plugin-files-reached');
|
|
273
|
+
assert.ok(finding !== undefined, '真触顶必须报码:' + JSON.stringify(over.readFindings));
|
|
274
|
+
assert.equal(finding.count, 2);
|
|
275
|
+
assert.ok((over.commandCount ?? 0) <= 2, '截断后计数不得带超过上限的条目');
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
222
279
|
test('plugin.json 解析失败:回落目录名并报码(绝不猜字段)', async () => {
|
|
223
280
|
await withClaudeDir(async (claudeDir) => {
|
|
224
281
|
const pluginDir = path.join(claudeDir, 'plugins', 'marketplaces', 'm', 'plugins', 'broken');
|
|
@@ -204,7 +204,13 @@ const GOLDEN: Record<string, string> = {
|
|
|
204
204
|
'frames-crossing-64k': '7518:d8be900e191b4a2c2c70819790bc0434bc8bffcbfbafbb00016b09bc04edaa8a',
|
|
205
205
|
'orphan-empty-and-unknown': '339:7492bd869daacad62ee75688ad8816e23af259215a360d01de9917cdffadc727',
|
|
206
206
|
'title-only-no-events': 'skip:session-empty',
|
|
207
|
-
|
|
207
|
+
/**
|
|
208
|
+
* 2026-11-14 有意更新(**理由**):审计 P7-4 修掉了「tool_result 带未知 id 仍照发」的悬空引用。
|
|
209
|
+
* 本案的 tool_use 没有 id → 合成器铸了 fallback callId,而结果的 tool_use_id 是 'toolu_x',
|
|
210
|
+
* 两者对不上:旧实现发出一条指向不存在 tool/call 的 tool/result(743 字节),
|
|
211
|
+
* 现在按 orphan-tool-result 计数丢弃(666 字节,少一行 result 事件)。
|
|
212
|
+
*/
|
|
213
|
+
'no-uuid-fallback-ids': '666:88cb76a5a087644466de41f7ace7d82e8e9a1595df271855c963d0688728112f',
|
|
208
214
|
'timestamps-numeric-and-unparsable': '728:64308bcdea6fc439ed190dd56cad74354e9f53f1274821d97a57bc519f3505ce',
|
|
209
215
|
'unicode-and-max-id': '729:a8a5abaca4dc7ab15c499b1c38655972283def0bedd3bb73bc87558e22ef51c7',
|
|
210
216
|
'skip-unsupported-version': 'skip:session-format-unsupported',
|
package/src/foreign/dsh.test.ts
CHANGED
|
@@ -145,6 +145,29 @@ test('dsh t4 扫描:按首帧版本过滤代次(v4 只计数、不进 skip
|
|
|
145
145
|
}
|
|
146
146
|
});
|
|
147
147
|
|
|
148
|
+
test('dsh t4b 同一 id 出现在两个会话目录:保留第一个但必须报 session-id-conflict', async (t) => {
|
|
149
|
+
if (!zstdAvailable()) {
|
|
150
|
+
t.skip('本宿主 Node 无 zstd');
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const root = await tmpRoot('dsh-dup');
|
|
154
|
+
try {
|
|
155
|
+
for (const projectKey of ['--p-a--', '--p-b--']) {
|
|
156
|
+
const dir = path.join('.dsh', 'sessions', projectKey, 'dup-id');
|
|
157
|
+
await fs.mkdir(path.join(root, dir), { recursive: true });
|
|
158
|
+
await fs.writeFile(path.join(root, dir, 'session.v3.jsonl.zstd'), logBytes(headerOf('dup-id', '/p/' + projectKey, 3), [{ seq: 0 }]));
|
|
159
|
+
}
|
|
160
|
+
const read = await readDshLogs({ homeDir: root, env: {}, platform: HOST, generation: 'v3' });
|
|
161
|
+
assert.equal(read.files.length, 1, '同 id 只保留第一个(绝不后写覆盖先写)');
|
|
162
|
+
const conflict = (read.readFindings ?? []).find((s) => s.code === 'session-id-conflict');
|
|
163
|
+
assert.ok(conflict !== undefined, '丢弃必须留码:' + JSON.stringify(read.readFindings));
|
|
164
|
+
assert.equal(conflict.origin, 'dup-id');
|
|
165
|
+
assert.equal(read.extraCounts?.['dsh.logs.scanned'], 2);
|
|
166
|
+
} finally {
|
|
167
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
148
171
|
test('dsh t5 直通判定顺序:版本未知 → id 非法 → 版本不等 → cwd 缺失 → 通过', () => {
|
|
149
172
|
const good: DshSessionLogFile = { id: 'sess-a', cwd: '/home/u/proj', version: 3, name: 'session.v3.jsonl.zstd', data: new Uint8Array([1]) };
|
|
150
173
|
assert.equal(transcodeDshLog(good, undefined).skip?.code, 'session-format-version-unknown');
|
package/src/foreign/kernel.ts
CHANGED
|
@@ -123,8 +123,15 @@ export function stripUserInfo(url: string): { url: string; stripped: boolean } {
|
|
|
123
123
|
const rest = url.slice(scheme + 3);
|
|
124
124
|
const at = rest.indexOf('@');
|
|
125
125
|
if (at < 0) return { url, stripped: false };
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
/**
|
|
127
|
+
* userinfo 只可能出现在 authority 段里:@ 若落在第一个 '/'、'?' 或 '#' 之后,
|
|
128
|
+
* 它就是 path/query/fragment 里的普通字符(无路径 URL 的 `?k=a@b` 曾把整条 URL 截成 `https://b`)。
|
|
129
|
+
* 纯字符判定,不用正则。
|
|
130
|
+
*/
|
|
131
|
+
const boundary = [rest.indexOf('/'), rest.indexOf('?'), rest.indexOf('#')]
|
|
132
|
+
.filter((i) => i >= 0)
|
|
133
|
+
.sort((a, b) => a - b)[0];
|
|
134
|
+
if (boundary !== undefined && at > boundary) return { url, stripped: false };
|
|
128
135
|
return { url: url.slice(0, scheme + 3) + rest.slice(at + 1), stripped: true };
|
|
129
136
|
}
|
|
130
137
|
|
|
@@ -46,6 +46,22 @@ const WALK_MAX_DEPTH = 8;
|
|
|
46
46
|
/** 跳过原因:符号链接(与 read-claude-code 同码同义) */
|
|
47
47
|
const DETAIL_SYMLINK = 'symlink-skipped';
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* 走盘并**明确回报是否真的截断**(审计 P7-9)。
|
|
51
|
+
*
|
|
52
|
+
* 共享的 `walkFiles()` 只返回数组,「拿满上限」与「恰好等于上限」在返回值上无法区分 ——
|
|
53
|
+
* 调用方拿长度反推会把「正好 N 个文件」误报成触顶。这里多要一条:拿到 N+1 条才算真截断,
|
|
54
|
+
* 再把多要的那条切掉(共享内核在 `src/foreign/session-read.ts`,本文件不动它)。
|
|
55
|
+
*/
|
|
56
|
+
async function walkFilesChecked(
|
|
57
|
+
root: string,
|
|
58
|
+
options: { maxDepth?: number; maxFiles: number; match?: (name: string) => boolean },
|
|
59
|
+
): Promise<{ files: Awaited<ReturnType<typeof walkFiles>>; truncated: boolean }> {
|
|
60
|
+
const probe = await walkFiles(root, { ...options, maxFiles: options.maxFiles + 1 });
|
|
61
|
+
const truncated = probe.length > options.maxFiles;
|
|
62
|
+
return { files: truncated ? probe.slice(0, options.maxFiles) : probe, truncated };
|
|
63
|
+
}
|
|
64
|
+
|
|
49
65
|
export interface ClaudePluginReadLimits {
|
|
50
66
|
/** 启用的插件数上限(默认 50) */
|
|
51
67
|
readonly maxPlugins?: number;
|
|
@@ -353,41 +369,46 @@ async function readPluginAt(
|
|
|
353
369
|
}
|
|
354
370
|
|
|
355
371
|
/* commands/**:递归计数(只数,不读内容) */
|
|
356
|
-
const
|
|
372
|
+
const commands = await walkFilesChecked(path.join(pluginDir, 'commands'), {
|
|
357
373
|
maxDepth: WALK_MAX_DEPTH,
|
|
358
374
|
maxFiles: options.maxPluginFiles,
|
|
359
375
|
});
|
|
360
|
-
if (
|
|
361
|
-
plugin.commandCount =
|
|
376
|
+
if (commands.files.length > 0) {
|
|
377
|
+
plugin.commandCount = commands.files.length;
|
|
362
378
|
plugin.components.push('commands');
|
|
363
379
|
}
|
|
364
|
-
if (
|
|
380
|
+
if (commands.truncated) filesTruncated = true;
|
|
381
|
+
// 上限是「单插件文件数」:只计数的组件也占额度(否则 N 个目录各带 199 个文件仍然全过)
|
|
382
|
+
let countedFiles = filesUsed + commands.files.length;
|
|
365
383
|
|
|
366
384
|
/* agents/*.md:只取文件名(不读内容) */
|
|
367
|
-
const
|
|
385
|
+
const agentsWalked = await walkFilesChecked(path.join(pluginDir, 'agents'), {
|
|
368
386
|
maxDepth: 0,
|
|
369
387
|
maxFiles: options.maxPluginFiles,
|
|
370
388
|
match: (name) => name.endsWith('.md'),
|
|
371
389
|
});
|
|
372
|
-
if (
|
|
373
|
-
plugin.agents =
|
|
390
|
+
if (agentsWalked.files.length > 0) {
|
|
391
|
+
plugin.agents = agentsWalked.files.map((file) => file.name).sort();
|
|
374
392
|
plugin.components.push('agents');
|
|
375
393
|
}
|
|
376
|
-
if (
|
|
394
|
+
if (agentsWalked.truncated) filesTruncated = true;
|
|
395
|
+
countedFiles += agentsWalked.files.length;
|
|
377
396
|
|
|
378
397
|
/* hooks/ 与 hooks.json:**只数文件数**(hooks 是执行面,内容一律不读) */
|
|
379
|
-
const
|
|
398
|
+
const hooksWalked = await walkFilesChecked(path.join(pluginDir, 'hooks'), {
|
|
380
399
|
maxDepth: WALK_MAX_DEPTH,
|
|
381
400
|
maxFiles: options.maxPluginFiles,
|
|
382
401
|
});
|
|
383
|
-
let hookCount =
|
|
384
|
-
if (
|
|
402
|
+
let hookCount = hooksWalked.files.length;
|
|
403
|
+
if (hooksWalked.truncated) filesTruncated = true;
|
|
404
|
+
countedFiles += hooksWalked.files.length;
|
|
385
405
|
const hooksJson = await statOrNull(path.join(pluginDir, 'hooks.json'));
|
|
386
406
|
if (hooksJson !== null && hooksJson.isFile()) hookCount += 1;
|
|
387
407
|
if (hookCount > 0) {
|
|
388
408
|
plugin.hookFiles = hookCount;
|
|
389
409
|
plugin.components.push('hooks');
|
|
390
410
|
}
|
|
411
|
+
if (countedFiles > options.maxPluginFiles) filesTruncated = true;
|
|
391
412
|
|
|
392
413
|
if (filesTruncated) {
|
|
393
414
|
findings.push({
|