dsh-config-manager 0.8.1 → 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 +122 -50
- package/lib/client.js +12676 -12091
- 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/read-trae.d.ts +11 -0
- package/lib/foreign/read-trae.js +124 -4
- 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/foreign/session-source.d.ts +12 -4
- package/lib/foreign/session-source.js +5 -3
- package/lib/foreign/trae-sqlcipher.d.ts +127 -0
- package/lib/foreign/trae-sqlcipher.js +519 -0
- package/lib/foreign/trae.js +3 -1
- package/lib/foreign/truth-table.js +3 -2
- package/lib/foreign/types.d.ts +9 -1
- 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/foreign-view.d.ts +19 -0
- package/lib/ui/foreign-view.js +24 -0
- package/lib/ui/i18n.d.ts +7 -1
- package/lib/ui/i18n.js +17 -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 +32 -13
- 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/foreign-import-view-guard.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 +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 +11 -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/file-budget.test.ts +7 -1
- 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/read-trae.ts +117 -5
- 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/foreign/session-source.ts +15 -5
- package/src/foreign/trae-sqlcipher.test.ts +360 -0
- package/src/foreign/trae-sqlcipher.ts +564 -0
- package/src/foreign/trae.test.ts +188 -0
- package/src/foreign/trae.ts +3 -1
- package/src/foreign/truth-table.ts +4 -2
- package/src/foreign/types.ts +10 -1
- 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/foreign-view.test.ts +36 -0
- package/src/ui/foreign-view.ts +46 -0
- package/src/ui/i18n.ts +17 -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
package/lib/foreign/read-trae.js
CHANGED
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
* · 会话容器的字段级 schema **未取证**:本层用**结构自证**的窄口径(必须有「消息数组 + 至少一条
|
|
22
22
|
* 带 role/type 的消息」)识别会话,容器必须自带字符串 id(否则铸稳定兜底 id);cwd 只认明文
|
|
23
23
|
* 绝对路径字段,找不到就交给下游落 session-missing-cwd(**绝不猜 cwd**)。
|
|
24
|
+
*
|
|
25
|
+
* 2.3.x 起多了一条通道(issue #134):会话迁到 `<User>/ModularData/ai-agent/database.db`,
|
|
26
|
+
* **整库 SQLCipher 加密**。解密、临时明文、页头校验都在 trae-sqlcipher.ts(只交出中性行);
|
|
27
|
+
* 本文件只负责「读表结果 → 统一会话形态」的语义映射(role/正文/cwd 口径与旧通道**同一份代码**)。
|
|
28
|
+
* 两条通道按会话 id 去重、**先加密库后旧库**(迁移后的库才是权威),并存时只计一份。
|
|
24
29
|
*/
|
|
25
30
|
import { isAbsoluteFor, joinFor, normalizePlatform, vscodeUserDataDir } from './platform-paths.js';
|
|
26
31
|
import { isFile, listDirNames, statOrNull } from './session-read.js';
|
|
@@ -30,6 +35,7 @@ import { cellBytes, cellText, openSqliteIfShape, sqliteCapability } from './sqli
|
|
|
30
35
|
// SQLite 批的**唯一**时间口径(秒/毫秒自适应 + 安全整数)在本文件的共享模块里,不再抄第二份
|
|
31
36
|
import { msTime } from './read-opencode.js';
|
|
32
37
|
import { isRecord } from '../utils/guards.js';
|
|
38
|
+
import { probeTraeEncryptedDatabase, readTraeEncryptedDatabase, traeDbPathFor, traeDbSkipOf } from './trae-sqlcipher.js';
|
|
33
39
|
/** 四个发行版名(顺序 = chat-import traeUserDataDirs 的判定顺序) */
|
|
34
40
|
export const TRAE_PRODUCTS = ['Trae', 'Trae CN', 'TRAE SOLO CN', 'TRAE SOLO'];
|
|
35
41
|
export const TRAE_VSCDB_NAME = 'state.vscdb';
|
|
@@ -406,12 +412,66 @@ export async function readTrae(opts) {
|
|
|
406
412
|
extraCounts: { 'trae.vscdb': 0 },
|
|
407
413
|
};
|
|
408
414
|
}
|
|
415
|
+
const extraSkips = [];
|
|
416
|
+
let truncated = false;
|
|
417
|
+
// ① 加密库通道(2.3.x):先读 —— 迁移后的库才是权威,同 id 冲突以它为准
|
|
418
|
+
const encryptedDbs = [];
|
|
419
|
+
for (const userDir of traeUserDataDirs(opts)) {
|
|
420
|
+
const dbPath = traeDbPathFor(userDir, platform);
|
|
421
|
+
if (await isFile(dbPath))
|
|
422
|
+
encryptedDbs.push(dbPath);
|
|
423
|
+
}
|
|
424
|
+
let encryptedSessions = 0;
|
|
425
|
+
for (const dbPath of encryptedDbs) {
|
|
426
|
+
const outcome = await readTraeEncryptedDatabase(dbPath, {
|
|
427
|
+
env: opts.env,
|
|
428
|
+
platform,
|
|
429
|
+
...(opts.maxEncryptedDbBytes !== undefined ? { maxBytes: opts.maxEncryptedDbBytes } : {}),
|
|
430
|
+
maxSessions: maxFiles,
|
|
431
|
+
});
|
|
432
|
+
// 密钥错/超限/截断/表结构不符 ⇒ 稳定码(绝不静默 0 会话);旧库有货时继续走旧库
|
|
433
|
+
if (outcome.problem !== undefined) {
|
|
434
|
+
extraSkips.push(traeDbSkipOf(outcome.problem));
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
if (outcome.dropped !== undefined && outcome.dropped > 0) {
|
|
438
|
+
findings.push({ code: 'source-unreadable', origin: 'trae', detail: 'encrypted-row-json-error', count: outcome.dropped });
|
|
439
|
+
}
|
|
440
|
+
if (outcome.skipped !== undefined && outcome.skipped > 0) {
|
|
441
|
+
findings.push({ code: 'source-unreadable', origin: 'trae', detail: 'encrypted-session-without-id', count: outcome.skipped });
|
|
442
|
+
}
|
|
443
|
+
if (outcome.truncated === true)
|
|
444
|
+
truncated = true;
|
|
445
|
+
for (const session of outcome.sessions) {
|
|
446
|
+
if (files.length >= maxFiles) {
|
|
447
|
+
truncated = true;
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
const id = isSafeIrId(session.id) ? session.id : safeFragment('trae-db-' + session.id);
|
|
451
|
+
if (seen.has(id))
|
|
452
|
+
continue;
|
|
453
|
+
const ignored = {};
|
|
454
|
+
const parsed = recordsOf(session.items, ignored);
|
|
455
|
+
seen.add(id);
|
|
456
|
+
files.push({
|
|
457
|
+
id,
|
|
458
|
+
cwd: session.cwd,
|
|
459
|
+
createdAt: session.createdAt,
|
|
460
|
+
title: session.title ?? '',
|
|
461
|
+
records: parsed.records,
|
|
462
|
+
raw: parsed.raw,
|
|
463
|
+
bad: 0,
|
|
464
|
+
ignored,
|
|
465
|
+
});
|
|
466
|
+
encryptedSessions += 1;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
// ② 旧 state.vscdb 通道(保留):同 id 已被加密库计入的不再重复
|
|
409
470
|
const dbs = [];
|
|
410
471
|
for (const userDir of traeUserDataDirs(opts)) {
|
|
411
472
|
dbs.push(...await traeVscdbPaths(userDir, platform));
|
|
412
473
|
}
|
|
413
474
|
let candidateKeys = 0;
|
|
414
|
-
let truncated = false;
|
|
415
475
|
for (const dbPath of dbs) {
|
|
416
476
|
if (files.length >= maxFiles) {
|
|
417
477
|
truncated = true;
|
|
@@ -471,8 +531,8 @@ export async function readTrae(opts) {
|
|
|
471
531
|
if (truncated)
|
|
472
532
|
break;
|
|
473
533
|
}
|
|
474
|
-
|
|
475
|
-
if (files.length === 0 && candidateKeys === 0 && dbs.length > 0) {
|
|
534
|
+
// 加密库存在时,「旧库没有候选键」不是用户需要的解释(真因已由 trae-db-* 说明)
|
|
535
|
+
if (files.length === 0 && candidateKeys === 0 && dbs.length > 0 && encryptedDbs.length === 0) {
|
|
476
536
|
extraSkips.push({ code: 'sessions-not-migrated', origin: 'trae', detail: 'chat-storage-key-not-found' });
|
|
477
537
|
}
|
|
478
538
|
else if (files.length === 0 && candidateKeys > 0) {
|
|
@@ -486,7 +546,67 @@ export async function readTrae(opts) {
|
|
|
486
546
|
files,
|
|
487
547
|
readFindings: findings,
|
|
488
548
|
extraSkips,
|
|
489
|
-
extraCounts: {
|
|
549
|
+
extraCounts: {
|
|
550
|
+
'trae.vscdb': dbs.length,
|
|
551
|
+
'trae.chatStorageKeys': candidateKeys,
|
|
552
|
+
'trae.encryptedDb': encryptedDbs.length,
|
|
553
|
+
'trae.encryptedSessions': encryptedSessions,
|
|
554
|
+
},
|
|
490
555
|
};
|
|
491
556
|
}
|
|
557
|
+
/**
|
|
558
|
+
* detect 期的**轻量预告**(issue #134 的第二半):让 `/foreign-sources` 在用户点导入前就把
|
|
559
|
+
* 「为什么这里没有会话」摆出来,而不是等 build 的 400 才闪一下。
|
|
560
|
+
*
|
|
561
|
+
* 代价(刻意接受):只读**页头**与 **ItemTable 的 key 列**,绝不读正文、绝不枚举会话 ——
|
|
562
|
+
* 4 个发行版的加密库最多各解密 1 页,旧库只是 `SELECT key`。因此 detect 仍是有界的只读探测。
|
|
563
|
+
*/
|
|
564
|
+
export async function traeDetectSkips(opts) {
|
|
565
|
+
const platform = normalizePlatform(opts.platform);
|
|
566
|
+
const skips = [];
|
|
567
|
+
let encryptedFound = 0;
|
|
568
|
+
for (const userDir of traeUserDataDirs(opts)) {
|
|
569
|
+
const dbPath = traeDbPathFor(userDir, platform);
|
|
570
|
+
if (!await isFile(dbPath))
|
|
571
|
+
continue;
|
|
572
|
+
encryptedFound += 1;
|
|
573
|
+
const problem = await probeTraeEncryptedDatabase(dbPath, {
|
|
574
|
+
env: opts.env,
|
|
575
|
+
...(opts.maxEncryptedDbBytes !== undefined ? { maxBytes: opts.maxEncryptedDbBytes } : {}),
|
|
576
|
+
});
|
|
577
|
+
if (problem !== null)
|
|
578
|
+
skips.push(traeDbSkipOf(problem));
|
|
579
|
+
}
|
|
580
|
+
// 加密库在场时不再猜旧库:迁移后旧库多半只是残留,混进「没有候选键」会误导用户
|
|
581
|
+
if (encryptedFound > 0)
|
|
582
|
+
return skips;
|
|
583
|
+
const capability = await sqliteCapability();
|
|
584
|
+
if (!capability.available)
|
|
585
|
+
return skips;
|
|
586
|
+
const dbs = [];
|
|
587
|
+
for (const userDir of traeUserDataDirs(opts)) {
|
|
588
|
+
dbs.push(...await traeVscdbPaths(userDir, platform));
|
|
589
|
+
}
|
|
590
|
+
if (dbs.length === 0)
|
|
591
|
+
return skips;
|
|
592
|
+
let candidateKeys = 0;
|
|
593
|
+
for (const dbPath of dbs) {
|
|
594
|
+
const db = await openSqliteIfShape(dbPath, { ItemTable: ['key'] });
|
|
595
|
+
if (db === null)
|
|
596
|
+
continue;
|
|
597
|
+
const rows = db.all('SELECT key FROM ItemTable');
|
|
598
|
+
db.close();
|
|
599
|
+
if (rows === null)
|
|
600
|
+
continue;
|
|
601
|
+
for (const row of rows) {
|
|
602
|
+
const key = cellText(row, 'key');
|
|
603
|
+
if (key !== undefined && isTraeChatStorageKey(key))
|
|
604
|
+
candidateKeys += 1;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
if (candidateKeys === 0) {
|
|
608
|
+
skips.push({ code: 'sessions-not-migrated', origin: 'trae', detail: 'chat-storage-key-not-found' });
|
|
609
|
+
}
|
|
610
|
+
return skips;
|
|
611
|
+
}
|
|
492
612
|
//# sourceMappingURL=read-trae.js.map
|
|
@@ -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)
|
|
@@ -191,8 +191,14 @@ export interface SessionSourceWiring<TFile extends {
|
|
|
191
191
|
readonly probePaths: (opts: RootProbeOptions) => readonly string[];
|
|
192
192
|
/** 命中即报 source-location-overridden 的环境变量(只报键名,绝不报值) */
|
|
193
193
|
readonly probeEnvKeys?: readonly string[] | undefined;
|
|
194
|
-
/**
|
|
195
|
-
|
|
194
|
+
/**
|
|
195
|
+
* 探测期的附加提示(如 chatgpt 的「无自动根」)。
|
|
196
|
+
*
|
|
197
|
+
* 允许返回 Promise:少数来源需要**有界**地读一点内容才能给出可判定的预告(trae 的加密库
|
|
198
|
+
* 只解密第 1 页、旧库只读 key 列)。这类探测必须自证「有界、只读、不枚举会话」,
|
|
199
|
+
* 否则 detect 会被 30 个来源拖慢。
|
|
200
|
+
*/
|
|
201
|
+
readonly probeSkips?: ((opts: RootProbeOptions, probed: readonly string[]) => readonly ForeignSkip[] | Promise<readonly ForeignSkip[]>) | undefined;
|
|
196
202
|
readonly read: (opts: SessionSourceHostOptions) => Promise<SessionReadOutcome<TFile>>;
|
|
197
203
|
readonly draftOf: (file: TFile) => SessionDraft | {
|
|
198
204
|
readonly skip: {
|
|
@@ -205,8 +211,10 @@ export interface SessionSourceWiring<TFile extends {
|
|
|
205
211
|
/**
|
|
206
212
|
* 把一个会话来源装配成 `ForeignSource`。
|
|
207
213
|
*
|
|
208
|
-
* **detect
|
|
209
|
-
* detect,任何一处读全文都会把面板拖慢;真正的枚举发生在 build
|
|
214
|
+
* **detect 默认只 stat 真值表里的位置**(绝不读内容、绝不枚举会话)—— 界面对 30 个来源各调一次
|
|
215
|
+
* detect,任何一处读全文都会把面板拖慢;真正的枚举发生在 build。唯一例外是来源在 `probeSkips`
|
|
216
|
+
* 里显式声明的**有界轻量探测**(trae:加密库只解密第 1 页、旧库只读 key 列),因为它们要回答的
|
|
217
|
+
* 正是「为什么这里没有会话」,而这件事只有看内容才知道。
|
|
210
218
|
*
|
|
211
219
|
* platform 的兜底只在**这一处**:`ctx.platform ?? process.platform`(装配层碰运行平台是允许的,
|
|
212
220
|
* 真值表函数本身一律显式收参)。
|
|
@@ -400,8 +400,10 @@ export function recordIdOf(raw, index) {
|
|
|
400
400
|
/**
|
|
401
401
|
* 把一个会话来源装配成 `ForeignSource`。
|
|
402
402
|
*
|
|
403
|
-
* **detect
|
|
404
|
-
* detect,任何一处读全文都会把面板拖慢;真正的枚举发生在 build
|
|
403
|
+
* **detect 默认只 stat 真值表里的位置**(绝不读内容、绝不枚举会话)—— 界面对 30 个来源各调一次
|
|
404
|
+
* detect,任何一处读全文都会把面板拖慢;真正的枚举发生在 build。唯一例外是来源在 `probeSkips`
|
|
405
|
+
* 里显式声明的**有界轻量探测**(trae:加密库只解密第 1 页、旧库只读 key 列),因为它们要回答的
|
|
406
|
+
* 正是「为什么这里没有会话」,而这件事只有看内容才知道。
|
|
405
407
|
*
|
|
406
408
|
* platform 的兜底只在**这一处**:`ctx.platform ?? process.platform`(装配层碰运行平台是允许的,
|
|
407
409
|
* 真值表函数本身一律显式收参)。
|
|
@@ -425,7 +427,7 @@ export function sessionSourceOf(wiring) {
|
|
|
425
427
|
if (envValue(ctx.env, key) !== undefined)
|
|
426
428
|
skipped.push({ code: 'source-location-overridden', origin: key });
|
|
427
429
|
}
|
|
428
|
-
skipped.push(...(wiring.probeSkips?.(opts, probed.paths) ?? []));
|
|
430
|
+
skipped.push(...((await wiring.probeSkips?.(opts, probed.paths)) ?? []));
|
|
429
431
|
return { found: probed.paths.length > 0, paths: [...probed.paths], skipped };
|
|
430
432
|
},
|
|
431
433
|
async build(ctx) {
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { ForeignPlatform } from './platform-paths.ts';
|
|
2
|
+
import type { ForeignSkip } from './types.ts';
|
|
3
|
+
/** 加密库相对 `<User>` 的路径段(4 个发行版共用同一命名) */
|
|
4
|
+
export declare const TRAE_DB_REL_SEGMENTS: readonly string[];
|
|
5
|
+
/** SQLCipher 4.x 的页大小(该库固定 4096) */
|
|
6
|
+
export declare const TRAE_DB_PAGE_SIZE = 4096;
|
|
7
|
+
/** 每页尾保留字节:IV(16) + HMAC-SHA512(64) */
|
|
8
|
+
export declare const TRAE_DB_RESERVE_BYTES = 80;
|
|
9
|
+
/** IV 长度(AES 块大小) */
|
|
10
|
+
export declare const TRAE_DB_IV_BYTES = 16;
|
|
11
|
+
/** 第 1 页开头的 salt 长度(不是密文,也不参与解密) */
|
|
12
|
+
export declare const TRAE_DB_SALT_BYTES = 16;
|
|
13
|
+
/** raw AES-256 密钥长度 */
|
|
14
|
+
export declare const TRAE_DB_KEY_BYTES = 32;
|
|
15
|
+
/**
|
|
16
|
+
* 缺省密钥:参考实现 xitula/trae-session-export 公开的 raw key 常量。
|
|
17
|
+
*
|
|
18
|
+
* **为什么可以内置**:它是产品级的固定 key(不是用户口令),参考实现公开分发;本插件只读、
|
|
19
|
+
* 且不写回任何 Trae 数据。换版后 key 变化 ⇒ 页头校验失败 ⇒ `trae-db-key-invalid`(可判定)。
|
|
20
|
+
*/
|
|
21
|
+
export declare const TRAE_DB_DEFAULT_KEY = "3605f6691095a993f03d5009c918352ef5be31ae31e8f000212b81ff058da773";
|
|
22
|
+
/** 覆盖密钥的环境变量名(只报键名,绝不回显值) */
|
|
23
|
+
export declare const TRAE_DB_KEY_ENV = "DCM_TRAE_DB_KEY";
|
|
24
|
+
/**
|
|
25
|
+
* 加密库的体积上限(**按来源独立**,2 GiB 覆盖 1.4 GB 量级;超限走既有 copy-too-large 语义)。
|
|
26
|
+
* 刻意不碰 sqlite.ts 的 `DEFAULT_MAX_COPY_BYTES`(1 GiB,全局兜底)。
|
|
27
|
+
*/
|
|
28
|
+
export declare const TRAE_DB_MAX_BYTES: number;
|
|
29
|
+
/** 会话表(调研确证) */
|
|
30
|
+
export declare const TRAE_DB_TABLE_SESSION = "chat_session";
|
|
31
|
+
/** 正文表(调研确证:消息在 `messages` 的 `raw_messages[]`) */
|
|
32
|
+
export declare const TRAE_DB_TABLE_HISTORY = "history_v2";
|
|
33
|
+
/** 表结构**最小**签名:只钉确证过的表与列,其余列按候选自证 */
|
|
34
|
+
export declare const TRAE_DB_REQUIRED_SCHEMA: Readonly<Record<string, readonly string[]>>;
|
|
35
|
+
/** 会话上限(与 read-trae 的 MAX_SESSIONS 同量级;由调用方再收窄) */
|
|
36
|
+
export declare const TRAE_DB_MAX_SESSIONS = 5000;
|
|
37
|
+
/** 解密/读表失败的**稳定码**(与 types.ts 的 ForeignSkipCode 一一对应) */
|
|
38
|
+
export type TraeDbProblemCode = 'trae-db-key-invalid' | 'trae-db-too-large' | 'trae-db-decrypt-failed' | 'trae-db-schema-mismatch';
|
|
39
|
+
/** 失败原因(`detail` 只放可枚举的短标签,绝不放密钥/明文片段) */
|
|
40
|
+
export interface TraeDbProblem {
|
|
41
|
+
readonly code: TraeDbProblemCode;
|
|
42
|
+
readonly detail: string;
|
|
43
|
+
readonly count?: number | undefined;
|
|
44
|
+
}
|
|
45
|
+
/** 读表交出的**中性**会话行(ID 校验与角色映射在 read-trae 里做,口径一处不改) */
|
|
46
|
+
export interface TraeDbSession {
|
|
47
|
+
readonly id: string;
|
|
48
|
+
readonly cwd?: string | undefined;
|
|
49
|
+
readonly title?: string | undefined;
|
|
50
|
+
readonly createdAt?: number | undefined;
|
|
51
|
+
readonly items: readonly unknown[];
|
|
52
|
+
}
|
|
53
|
+
/** 一次加密库读取的结果 */
|
|
54
|
+
export interface TraeDbReadOutcome {
|
|
55
|
+
readonly sessions: readonly TraeDbSession[];
|
|
56
|
+
readonly problem?: TraeDbProblem | undefined;
|
|
57
|
+
/** 解密出的页数(明文直读时为 undefined) */
|
|
58
|
+
readonly pages?: number | undefined;
|
|
59
|
+
/** `decrypted` = 走解密;`plaintext` = 库本身已是明文(旧版/已被解密的形态) */
|
|
60
|
+
readonly mode?: 'decrypted' | 'plaintext' | undefined;
|
|
61
|
+
/** 消息单元格解析不出的行数(如实计入,绝不伪造正文) */
|
|
62
|
+
readonly dropped?: number | undefined;
|
|
63
|
+
/** 缺 id 而无法建会话的行数 */
|
|
64
|
+
readonly skipped?: number | undefined;
|
|
65
|
+
/** 会话数触顶(调用方的 maxSessions) */
|
|
66
|
+
readonly truncated?: boolean | undefined;
|
|
67
|
+
}
|
|
68
|
+
/** 读表选项 */
|
|
69
|
+
export interface TraeDbReadOptions {
|
|
70
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
71
|
+
readonly platform: ForeignPlatform;
|
|
72
|
+
/** 体积上限(缺省 `TRAE_DB_MAX_BYTES`;单测用它造超限,不必造 2 GiB 文件) */
|
|
73
|
+
readonly maxBytes?: number | undefined;
|
|
74
|
+
/** 会话数上限(缺省 `TRAE_DB_MAX_SESSIONS`) */
|
|
75
|
+
readonly maxSessions?: number | undefined;
|
|
76
|
+
}
|
|
77
|
+
/** 密钥解析结果:要么给出 32 字节 raw key,要么给出可判定失败 */
|
|
78
|
+
export type TraeDbKeyResolution = {
|
|
79
|
+
readonly key: Buffer;
|
|
80
|
+
readonly source: 'default' | 'env';
|
|
81
|
+
} | {
|
|
82
|
+
readonly problem: TraeDbProblem;
|
|
83
|
+
};
|
|
84
|
+
/** 一个 `<User>` 根下的加密库位置(**绝不硬编码分隔符**) */
|
|
85
|
+
export declare function traeDbPathFor(userDir: string, platform: ForeignPlatform): string;
|
|
86
|
+
/**
|
|
87
|
+
* 解析密钥:环境变量优先,缺省内置常量。
|
|
88
|
+
*
|
|
89
|
+
* 环境变量**设了但不合法**时直接报 `trae-db-key-invalid`(detail=key-format),
|
|
90
|
+
* 绝不悄悄回落到内置 key —— 那会让「我换了密钥但没生效」变成静默 0 会话。
|
|
91
|
+
*/
|
|
92
|
+
export declare function resolveTraeDbKey(env: Readonly<Record<string, string | undefined>>): TraeDbKeyResolution;
|
|
93
|
+
/**
|
|
94
|
+
* 校验解密出的第 1 页明文(`plain` = 明文页的 `[16, 4016)`,即文件 offset 16 起的 4000 B)。
|
|
95
|
+
*
|
|
96
|
+
* 返回 null = 通过;返回字符串 = 可判定的失败 detail(一律映射成 `trae-db-key-invalid`)。
|
|
97
|
+
*/
|
|
98
|
+
export declare function validateTraePageOne(plain: Buffer, pages: number | null): string | null;
|
|
99
|
+
/**
|
|
100
|
+
* 把一个加密库逐页解密成明文库(**覆盖写 `destPath`**,目标不存在才写)。
|
|
101
|
+
*
|
|
102
|
+
* 只读源库;内存占用恒为一页;失败时返回稳定码,**不留半截明文**(由调用方的临时目录统一清理)。
|
|
103
|
+
*/
|
|
104
|
+
export declare function decryptTraeDatabase(sourcePath: string, destPath: string, key: Buffer): Promise<{
|
|
105
|
+
ok: true;
|
|
106
|
+
pages: number;
|
|
107
|
+
} | {
|
|
108
|
+
ok: false;
|
|
109
|
+
problem: TraeDbProblem;
|
|
110
|
+
}>;
|
|
111
|
+
/**
|
|
112
|
+
* 探测期的**单页**校验(detect 用):只解密第 1 页、只读 4 KB,用来抢在 build 之前把
|
|
113
|
+
* 「密钥错 / 截断 / 超限」这三类可判定失败摆到界面上(#134 的第二半)。
|
|
114
|
+
*
|
|
115
|
+
* 返回 null = 没发现问题(或库不存在 / 已是明文)。
|
|
116
|
+
*/
|
|
117
|
+
export declare function probeTraeEncryptedDatabase(sourcePath: string, options: Pick<TraeDbReadOptions, 'env' | 'maxBytes'>): Promise<TraeDbProblem | null>;
|
|
118
|
+
/** 正文容器 → 消息数组(`raw_messages` 第一顺位;数组本身也接受) */
|
|
119
|
+
export declare function messageItemsOf(value: unknown): unknown[] | null;
|
|
120
|
+
/**
|
|
121
|
+
* 读一个加密库:体积上限 → 密钥 → 解密(或明文直读)→ 只读读表 → 删临时明文。
|
|
122
|
+
*
|
|
123
|
+
* **绝不抛出**:所有失败都收成 `problem`(稳定码 + detail),调用方据此推 skip。
|
|
124
|
+
*/
|
|
125
|
+
export declare function readTraeEncryptedDatabase(sourcePath: string, options: TraeDbReadOptions): Promise<TraeDbReadOutcome>;
|
|
126
|
+
/** problem → skip(origin 固定 'trae';count 只在有意义时带上) */
|
|
127
|
+
export declare function traeDbSkipOf(problem: TraeDbProblem): ForeignSkip;
|