dsh-config-manager 0.1.69 → 0.1.71
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/README.md +59 -18
- package/README.zh-CN.md +29 -9
- package/lib/adapters/credentials.js +6 -3
- package/lib/adapters/file-collection.d.ts +21 -1
- package/lib/adapters/file-collection.js +32 -8
- package/lib/adapters/mcp.d.ts +12 -2
- package/lib/adapters/mcp.js +30 -13
- package/lib/adapters/plugin-files.d.ts +8 -0
- package/lib/adapters/plugin-files.js +36 -4
- package/lib/adapters/plugins.d.ts +28 -2
- package/lib/adapters/plugins.js +204 -55
- package/lib/adapters/prompts.d.ts +12 -2
- package/lib/adapters/prompts.js +34 -19
- package/lib/adapters/providers.js +5 -4
- package/lib/adapters/self.d.ts +20 -0
- package/lib/adapters/self.js +73 -0
- package/lib/adapters/sessions.d.ts +8 -0
- package/lib/adapters/sessions.js +47 -1
- package/lib/adapters/settings.d.ts +21 -3
- package/lib/adapters/settings.js +44 -7
- package/lib/adapters/skills.d.ts +36 -4
- package/lib/adapters/skills.js +222 -3
- package/lib/adapters/test-helpers.d.ts +31 -2
- package/lib/adapters/test-helpers.js +42 -5
- package/lib/adapters/workspaces.js +97 -5
- package/lib/cli/actions.d.ts +50 -3
- package/lib/cli/actions.js +103 -11
- package/lib/cli/help.d.ts +65 -0
- package/lib/cli/help.js +517 -0
- package/lib/cli/import-source.d.ts +32 -0
- package/lib/cli/import-source.js +178 -0
- package/lib/cli/index.d.ts +18 -2
- package/lib/cli/index.js +118 -90
- package/lib/cli/web/client-script.d.ts +8 -0
- package/lib/cli/web/client-script.js +11 -0
- package/lib/cli/web/http.d.ts +5 -0
- package/lib/cli/web/http.js +2 -1
- package/lib/cli/web/page.d.ts +16 -6
- package/lib/cli/web/page.js +102 -25
- package/lib/cli/web/routes.js +24 -5
- package/lib/cli/web/server.js +23 -2
- package/lib/client.d.ts +1019 -36
- package/lib/client.js +5522 -1564
- package/lib/core/analyzer.d.ts +15 -1
- package/lib/core/analyzer.js +114 -13
- package/lib/core/backup-plan.js +17 -1
- package/lib/core/backup.d.ts +8 -0
- package/lib/core/backup.js +28 -6
- package/lib/core/cache-cleaner.d.ts +10 -0
- package/lib/core/cache-cleaner.js +63 -22
- package/lib/core/checkpoint.d.ts +362 -0
- package/lib/core/checkpoint.js +1309 -0
- package/lib/core/journal.d.ts +37 -0
- package/lib/core/journal.js +69 -0
- package/lib/core/messages.d.ts +13 -0
- package/lib/core/messages.js +26 -0
- package/lib/core/model-tools.js +3 -0
- package/lib/core/patch-layers.d.ts +83 -0
- package/lib/core/patch-layers.js +110 -0
- package/lib/core/restore.d.ts +21 -0
- package/lib/core/restore.js +37 -3
- package/lib/core/rollback.js +6 -3
- package/lib/core/self-update.d.ts +52 -0
- package/lib/core/self-update.js +70 -0
- package/lib/core/session-health.d.ts +29 -5
- package/lib/core/session-health.js +28 -3
- package/lib/core/types.d.ts +126 -0
- package/lib/foreign/antigravity.d.ts +28 -0
- package/lib/foreign/antigravity.js +157 -0
- package/lib/foreign/bundle.d.ts +25 -0
- package/lib/foreign/bundle.js +79 -0
- package/lib/foreign/chatgpt.d.ts +6 -0
- package/lib/foreign/chatgpt.js +25 -0
- package/lib/foreign/claude-code.d.ts +3 -0
- package/lib/foreign/claude-code.js +85 -0
- package/lib/foreign/claude-sessions.d.ts +108 -0
- package/lib/foreign/claude-sessions.js +299 -0
- package/lib/foreign/cline.d.ts +6 -0
- package/lib/foreign/cline.js +27 -0
- package/lib/foreign/codex.d.ts +83 -0
- package/lib/foreign/codex.js +348 -0
- package/lib/foreign/continue.d.ts +9 -0
- package/lib/foreign/continue.js +65 -0
- package/lib/foreign/copilot.d.ts +39 -0
- package/lib/foreign/copilot.js +95 -0
- package/lib/foreign/crush.d.ts +11 -0
- package/lib/foreign/crush.js +57 -0
- package/lib/foreign/cursor.d.ts +87 -0
- package/lib/foreign/cursor.js +171 -0
- package/lib/foreign/dsh.d.ts +30 -0
- package/lib/foreign/dsh.js +101 -0
- package/lib/foreign/dsh4.d.ts +3 -0
- package/lib/foreign/dsh4.js +13 -0
- package/lib/foreign/gemini.d.ts +7 -0
- package/lib/foreign/gemini.js +44 -0
- package/lib/foreign/goose.d.ts +11 -0
- package/lib/foreign/goose.js +53 -0
- package/lib/foreign/grokbuild.d.ts +8 -0
- package/lib/foreign/grokbuild.js +25 -0
- package/lib/foreign/hermes.d.ts +2 -0
- package/lib/foreign/hermes.js +78 -0
- package/lib/foreign/kernel.d.ts +132 -0
- package/lib/foreign/kernel.js +569 -0
- package/lib/foreign/kilocode.d.ts +11 -0
- package/lib/foreign/kilocode.js +51 -0
- package/lib/foreign/kimi.d.ts +7 -0
- package/lib/foreign/kimi.js +47 -0
- package/lib/foreign/mimocode.d.ts +11 -0
- package/lib/foreign/mimocode.js +51 -0
- package/lib/foreign/openclaw.d.ts +7 -0
- package/lib/foreign/openclaw.js +46 -0
- package/lib/foreign/opencode.d.ts +11 -0
- package/lib/foreign/opencode.js +52 -0
- package/lib/foreign/pi.d.ts +7 -0
- package/lib/foreign/pi.js +48 -0
- package/lib/foreign/platform-paths.d.ts +66 -0
- package/lib/foreign/platform-paths.js +141 -0
- package/lib/foreign/qoder.d.ts +10 -0
- package/lib/foreign/qoder.js +49 -0
- package/lib/foreign/qwen.d.ts +7 -0
- package/lib/foreign/qwen.js +45 -0
- package/lib/foreign/read-antigravity.d.ts +57 -0
- package/lib/foreign/read-antigravity.js +504 -0
- package/lib/foreign/read-chatgpt.d.ts +20 -0
- package/lib/foreign/read-chatgpt.js +509 -0
- package/lib/foreign/read-claude-code.d.ts +24 -0
- package/lib/foreign/read-claude-code.js +234 -0
- package/lib/foreign/read-cline.d.ts +53 -0
- package/lib/foreign/read-cline.js +479 -0
- package/lib/foreign/read-codex.d.ts +75 -0
- package/lib/foreign/read-codex.js +842 -0
- package/lib/foreign/read-continue.d.ts +87 -0
- package/lib/foreign/read-continue.js +489 -0
- package/lib/foreign/read-copilot.d.ts +42 -0
- package/lib/foreign/read-copilot.js +267 -0
- package/lib/foreign/read-crush.d.ts +54 -0
- package/lib/foreign/read-crush.js +478 -0
- package/lib/foreign/read-cursor.d.ts +141 -0
- package/lib/foreign/read-cursor.js +705 -0
- package/lib/foreign/read-dsh.d.ts +43 -0
- package/lib/foreign/read-dsh.js +205 -0
- package/lib/foreign/read-dsh4.d.ts +14 -0
- package/lib/foreign/read-dsh4.js +27 -0
- package/lib/foreign/read-gemini.d.ts +55 -0
- package/lib/foreign/read-gemini.js +273 -0
- package/lib/foreign/read-goose.d.ts +25 -0
- package/lib/foreign/read-goose.js +322 -0
- package/lib/foreign/read-grokbuild.d.ts +34 -0
- package/lib/foreign/read-grokbuild.js +455 -0
- package/lib/foreign/read-hermes.d.ts +74 -0
- package/lib/foreign/read-hermes.js +690 -0
- package/lib/foreign/read-kilocode.d.ts +17 -0
- package/lib/foreign/read-kilocode.js +46 -0
- package/lib/foreign/read-kimi.d.ts +63 -0
- package/lib/foreign/read-kimi.js +719 -0
- package/lib/foreign/read-mimocode.d.ts +12 -0
- package/lib/foreign/read-mimocode.js +56 -0
- package/lib/foreign/read-openclaw.d.ts +51 -0
- package/lib/foreign/read-openclaw.js +445 -0
- package/lib/foreign/read-opencode.d.ts +150 -0
- package/lib/foreign/read-opencode.js +896 -0
- package/lib/foreign/read-pi.d.ts +56 -0
- package/lib/foreign/read-pi.js +411 -0
- package/lib/foreign/read-qoder.d.ts +54 -0
- package/lib/foreign/read-qoder.js +317 -0
- package/lib/foreign/read-qwen.d.ts +40 -0
- package/lib/foreign/read-qwen.js +326 -0
- package/lib/foreign/read-reasonix.d.ts +66 -0
- package/lib/foreign/read-reasonix.js +537 -0
- package/lib/foreign/read-teleagent.d.ts +15 -0
- package/lib/foreign/read-teleagent.js +68 -0
- package/lib/foreign/read-trae.d.ts +67 -0
- package/lib/foreign/read-trae.js +492 -0
- package/lib/foreign/read-vibe.d.ts +28 -0
- package/lib/foreign/read-vibe.js +364 -0
- package/lib/foreign/read-workbuddy.d.ts +49 -0
- package/lib/foreign/read-workbuddy.js +346 -0
- package/lib/foreign/read-zcode.d.ts +12 -0
- package/lib/foreign/read-zcode.js +38 -0
- package/lib/foreign/read-zed.d.ts +30 -0
- package/lib/foreign/read-zed.js +473 -0
- package/lib/foreign/reasonix.d.ts +6 -0
- package/lib/foreign/reasonix.js +20 -0
- package/lib/foreign/registry.d.ts +196 -0
- package/lib/foreign/registry.js +573 -0
- package/lib/foreign/session-ir.d.ts +186 -0
- package/lib/foreign/session-ir.js +427 -0
- package/lib/foreign/session-read.d.ts +102 -0
- package/lib/foreign/session-read.js +254 -0
- package/lib/foreign/session-source.d.ts +216 -0
- package/lib/foreign/session-source.js +453 -0
- package/lib/foreign/source-modules.d.ts +45 -0
- package/lib/foreign/source-modules.js +52 -0
- package/lib/foreign/sqlite.d.ts +61 -0
- package/lib/foreign/sqlite.js +404 -0
- package/lib/foreign/teleagent.d.ts +11 -0
- package/lib/foreign/teleagent.js +53 -0
- package/lib/foreign/trae.d.ts +6 -0
- package/lib/foreign/trae.js +20 -0
- package/lib/foreign/truth-table.d.ts +62 -0
- package/lib/foreign/truth-table.js +333 -0
- package/lib/foreign/types.d.ts +272 -0
- package/lib/foreign/types.js +2 -0
- package/lib/foreign/vibe.d.ts +6 -0
- package/lib/foreign/vibe.js +23 -0
- package/lib/foreign/workbuddy.d.ts +7 -0
- package/lib/foreign/workbuddy.js +45 -0
- package/lib/foreign/zcode.d.ts +11 -0
- package/lib/foreign/zcode.js +51 -0
- package/lib/foreign/zed.d.ts +11 -0
- package/lib/foreign/zed.js +53 -0
- package/lib/index.d.ts +154 -13
- package/lib/index.js +661 -84
- package/lib/market/github-repos.d.ts +28 -0
- package/lib/market/github-repos.js +43 -1
- package/lib/market/types.d.ts +1 -3
- package/lib/profiles/dsh-profile-manager.d.ts +54 -2
- package/lib/profiles/dsh-profile-manager.js +182 -11
- package/lib/profiles/dsh-profile-shared.d.ts +47 -0
- package/lib/profiles/dsh-profile-shared.js +15 -1
- package/lib/profiles/index.d.ts +1 -1
- package/lib/profiles/index.js +1 -1
- package/lib/routes/consult.js +51 -5
- package/lib/routes/foreign-context.d.ts +43 -0
- package/lib/routes/foreign-context.js +65 -0
- package/lib/routes/foreign.d.ts +11 -0
- package/lib/routes/foreign.js +208 -0
- package/lib/routes/import.d.ts +8 -0
- package/lib/routes/import.js +22 -1
- package/lib/routes/index.d.ts +2 -2
- package/lib/routes/index.js +4 -0
- package/lib/routes/kit.d.ts +4 -3
- package/lib/routes/market.js +0 -1
- package/lib/routes/prefs.d.ts +2 -1
- package/lib/routes/prefs.js +14 -2
- package/lib/routes/recovery.js +363 -3
- package/lib/routes/session-export.d.ts +117 -0
- package/lib/routes/session-export.js +270 -0
- package/lib/routes/snapshots.js +12 -2
- package/lib/routes/sync.js +82 -10
- package/lib/security/redaction.d.ts +14 -0
- package/lib/security/redaction.js +24 -9
- package/lib/security/secret-scanner.d.ts +27 -0
- package/lib/security/secret-scanner.js +54 -1
- package/lib/sync/autosync-scheduler.d.ts +13 -1
- package/lib/sync/autosync-scheduler.js +49 -26
- package/lib/sync/backup-files.js +6 -0
- package/lib/sync/gist/gist-transport.d.ts +91 -0
- package/lib/sync/gist/gist-transport.js +406 -0
- package/lib/sync/gist/messages.d.ts +22 -0
- package/lib/sync/gist/messages.js +46 -0
- package/lib/sync/s3/messages.d.ts +53 -0
- package/lib/sync/s3/messages.js +83 -0
- package/lib/sync/s3/s3-providers.d.ts +78 -0
- package/lib/sync/s3/s3-providers.js +156 -0
- package/lib/sync/s3/s3-transport.d.ts +126 -0
- package/lib/sync/s3/s3-transport.js +551 -0
- package/lib/sync/s3/sigv4.d.ts +107 -0
- package/lib/sync/s3/sigv4.js +196 -0
- package/lib/sync/sync-config.d.ts +250 -4
- package/lib/sync/sync-config.js +658 -57
- package/lib/sync/sync-engine.d.ts +1 -0
- package/lib/sync/sync-engine.js +4 -2
- package/lib/sync/sync-history.d.ts +1 -1
- package/lib/sync/webdav/webdav-transport.d.ts +31 -3
- package/lib/sync/webdav/webdav-transport.js +102 -18
- package/lib/ui/commands.d.ts +4 -3
- package/lib/ui/commands.js +41 -9
- package/lib/ui/disk-usage-view.d.ts +44 -0
- package/lib/ui/disk-usage-view.js +55 -1
- package/lib/ui/dsh-profiles-view.d.ts +53 -0
- package/lib/ui/dsh-profiles-view.js +56 -0
- package/lib/ui/foreign-view.d.ts +162 -0
- package/lib/ui/foreign-view.js +225 -0
- package/lib/ui/i18n.d.ts +77 -0
- package/lib/ui/i18n.js +164 -0
- package/lib/ui/session-inventory-view.d.ts +106 -0
- package/lib/ui/session-inventory-view.js +58 -0
- package/lib/ui/session-layout-view.d.ts +265 -0
- package/lib/ui/session-layout-view.js +271 -0
- package/lib/ui/sync-repository-picker.d.ts +98 -0
- package/lib/ui/sync-repository-picker.js +145 -0
- package/lib/ui/sync-settings-view.d.ts +143 -4
- package/lib/ui/sync-settings-view.js +231 -7
- package/lib/ui/types.d.ts +47 -0
- package/lib/utils/asar-read.d.ts +113 -0
- package/lib/utils/asar-read.js +523 -0
- package/lib/utils/env-lock.js +7 -2
- package/lib/utils/patch-yaml.d.ts +25 -0
- package/lib/utils/patch-yaml.js +62 -0
- package/lib/utils/paths.d.ts +10 -1
- package/lib/utils/paths.js +24 -3
- package/lib/utils/recursive-walk.js +12 -13
- package/lib/utils/session-format.d.ts +35 -2
- package/lib/utils/session-format.js +131 -5
- package/lib/utils/session-health-scan.d.ts +7 -1
- package/lib/utils/session-health-scan.js +369 -12
- package/lib/utils/session-layout-repair-service.d.ts +98 -0
- package/lib/utils/session-layout-repair-service.js +457 -0
- package/lib/utils/session-log-repair.d.ts +27 -0
- package/lib/utils/session-log-repair.js +233 -62
- package/lib/utils/session-repair-service.d.ts +32 -3
- package/lib/utils/session-repair-service.js +148 -9
- package/lib/utils/session-row-facts.d.ts +73 -0
- package/lib/utils/session-row-facts.js +182 -0
- package/lib/utils/session-verify.d.ts +118 -0
- package/lib/utils/session-verify.js +705 -0
- package/lib/utils/shared-constants.d.ts +59 -0
- package/lib/utils/shared-constants.js +71 -0
- package/package.json +1 -1
- package/src/adapters/credentials.test.ts +27 -0
- package/src/adapters/credentials.ts +6 -3
- package/src/adapters/file-collection.ts +33 -8
- package/src/adapters/files.test.ts +222 -0
- package/src/adapters/mcp.test.ts +43 -0
- package/src/adapters/mcp.ts +37 -14
- package/src/adapters/plugin-files.ts +34 -4
- package/src/adapters/plugins.test.ts +241 -0
- package/src/adapters/plugins.ts +201 -53
- package/src/adapters/prompts.test.ts +49 -0
- package/src/adapters/prompts.ts +41 -20
- package/src/adapters/providers.test.ts +16 -0
- package/src/adapters/providers.ts +4 -3
- package/src/adapters/self.test.ts +77 -0
- package/src/adapters/self.ts +75 -0
- package/src/adapters/sessions.test.ts +77 -0
- package/src/adapters/sessions.ts +47 -1
- package/src/adapters/settings.test.ts +78 -0
- package/src/adapters/settings.ts +42 -6
- package/src/adapters/skills.ts +221 -3
- package/src/adapters/test-helpers.ts +43 -5
- package/src/adapters/workspaces-dup-id.test.ts +144 -0
- package/src/adapters/workspaces.test.ts +10 -0
- package/src/adapters/workspaces.ts +97 -5
- package/src/cli/actions.test.ts +117 -2
- package/src/cli/actions.ts +132 -12
- package/src/cli/help.ts +570 -0
- package/src/cli/import-source.test.ts +193 -0
- package/src/cli/import-source.ts +229 -0
- package/src/cli/index.ts +129 -94
- package/src/cli/web/client-script.ts +12 -0
- package/src/cli/web/console-fixes.test.ts +36 -0
- package/src/cli/web/http.ts +7 -1
- package/src/cli/web/page.ts +108 -25
- package/src/cli/web/routes.ts +23 -4
- package/src/cli/web/script-anchor.test.ts +33 -0
- package/src/cli/web/server.ts +28 -2
- package/src/cli/web/web.test.ts +447 -4
- package/src/client/ConfigManagerSection.tsx +118 -63
- package/src/client/about/AboutPanel.tsx +42 -3
- package/src/client/about/PluginUpdateDialog.tsx +185 -0
- package/src/client/about/ReleaseBody.tsx +144 -0
- package/src/client/about/ReleaseNotesDialog.tsx +3 -130
- package/src/client/about/about-view.ts +7 -5
- package/src/client/about/plugin-update-view.test.ts +25 -0
- package/src/client/about/plugin-update-view.ts +26 -0
- package/src/client/about/release-notes-view.test.ts +33 -0
- package/src/client/about/release-notes-view.ts +34 -0
- package/src/client/api.ts +145 -1
- package/src/client/common/Icon.tsx +3 -0
- package/src/client/common/RunsCenter.tsx +8 -2
- package/src/client/common/Select.tsx +9 -2
- package/src/client/common/info-hint-guard.test.ts +63 -18
- package/src/client/common/plan-text-redaction.test.ts +193 -8
- package/src/client/common/routes.ts +15 -0
- package/src/client/config-manager.module.css +506 -354
- package/src/client/css-scale-guard.test.ts +122 -0
- package/src/client/css-token-guard.test.ts +82 -0
- package/src/client/environment/EnvironmentPanel.tsx +45 -16
- package/src/client/{snapshots → environment/maintenance}/DiskUsageCard.tsx +21 -17
- package/src/client/environment/profiles-incomplete-ui.test.ts +103 -0
- package/src/client/export/ExportView.tsx +9 -2
- package/src/client/{snapshots → home}/BackupScheduleCard.tsx +13 -4
- package/src/client/home/HomePanel.tsx +69 -157
- package/src/client/icon-layer-guard.test.ts +1 -1
- package/src/client/import/ForeignImportView.tsx +318 -0
- package/src/client/import/ImportWizardView.tsx +3 -1
- package/src/client/import/foreign-import-view-guard.test.ts +195 -0
- package/src/client/import/import-file-select.test.ts +6 -6
- package/src/client/import/import-wizard-steps.tsx +17 -1
- package/src/client/import/use-import-wizard-controller.ts +3 -3
- package/src/client/index.ts +1 -1
- package/src/client/library/LibraryActions.tsx +31 -34
- package/src/client/library/LibraryPanel.tsx +4 -1
- package/src/client/{snapshots → library}/RestorePlanView.tsx +1 -1
- package/src/client/{snapshots → library}/files-layout.test.ts +2 -2
- package/src/client/{snapshots → library}/report-dismiss.test.ts +26 -3
- package/src/client/library/task-panel-visibility.test.ts +25 -17
- package/src/client/locales.ts +278 -36
- package/src/client/lucide-icons.d.ts +1 -0
- package/src/client/market/MarketPanel.tsx +11 -2
- package/src/client/recovery/IncompleteCopiesSection.tsx +132 -0
- package/src/client/recovery/RecoveryPanel.tsx +486 -59
- package/src/client/recovery/recovery-api.ts +30 -0
- package/src/client/recovery/recovery-incomplete-copies.test.ts +151 -0
- package/src/client/recovery/recovery-locales.test.ts +88 -0
- package/src/client/recovery/recovery-locales.ts +321 -6
- package/src/client/recovery/recovery-panel-layout.test.ts +52 -0
- package/src/client/recovery/recovery-view.ts +92 -2
- package/src/client/run-store.test.ts +201 -89
- package/src/client/run-store.ts +114 -143
- package/src/client/session-export/session-export-view.test.ts +103 -0
- package/src/client/session-export/session-export-view.ts +118 -0
- package/src/client/sync/ChannelConfigDialog.tsx +219 -14
- package/src/client/sync/SyncChannelEntryCard.tsx +52 -4
- package/src/client/sync/SyncLogList.tsx +1 -1
- package/src/client/sync/SyncPanel.tsx +166 -102
- package/src/client/sync/SyncRepositoryPicker.tsx +216 -0
- package/src/client/sync/SyncSettingsView.test.ts +6 -1
- package/src/client/sync/history-model.test.ts +94 -57
- package/src/client/sync/history-model.ts +44 -25
- package/src/client/sync/sync-api.test.ts +56 -0
- package/src/client/sync/sync-api.ts +92 -0
- package/src/client/sync/sync-locales.ts +162 -2
- package/src/client/sync/sync-view.test.ts +3 -8
- package/src/client/sync/sync-view.ts +111 -21
- package/src/core/analyzer-cache.test.ts +47 -0
- package/src/core/analyzer.ts +115 -14
- package/src/core/backup-plan.test.ts +35 -0
- package/src/core/backup-plan.ts +19 -1
- package/src/core/backup.test.ts +37 -1
- package/src/core/backup.ts +27 -6
- package/src/core/cache-cleaner.test.ts +120 -1
- package/src/core/cache-cleaner.ts +59 -22
- package/src/core/checkpoint.test.ts +665 -0
- package/src/core/checkpoint.ts +1614 -0
- package/src/core/credential-plan-consistency.test.ts +93 -0
- package/src/core/incident-wiring.test.ts +6 -2
- package/src/core/journal.test.ts +70 -0
- package/src/core/journal.ts +68 -0
- package/src/core/messages.ts +26 -0
- package/src/core/model-tools.ts +3 -0
- package/src/core/patch-layers.test.ts +94 -0
- package/src/core/patch-layers.ts +150 -0
- package/src/core/restore.ts +59 -3
- package/src/core/rollback.ts +6 -3
- package/src/core/section-content-consistency.test.ts +185 -0
- package/src/core/self-update.test.ts +110 -0
- package/src/core/self-update.ts +118 -0
- package/src/core/session-health.test.ts +91 -1
- package/src/core/session-health.ts +56 -9
- package/src/core/types.ts +127 -1
- package/src/foreign/antigravity.test.ts +271 -0
- package/src/foreign/antigravity.ts +188 -0
- package/src/foreign/bundle.ts +108 -0
- package/src/foreign/chatgpt.test.ts +279 -0
- package/src/foreign/chatgpt.ts +30 -0
- package/src/foreign/claude-code.test.ts +234 -0
- package/src/foreign/claude-code.ts +106 -0
- package/src/foreign/claude-sessions-bytes.test.ts +227 -0
- package/src/foreign/claude-sessions.test.ts +180 -0
- package/src/foreign/claude-sessions.ts +461 -0
- package/src/foreign/cline.test.ts +274 -0
- package/src/foreign/cline.ts +32 -0
- package/src/foreign/codex.test.ts +585 -0
- package/src/foreign/codex.ts +409 -0
- package/src/foreign/continue.test.ts +365 -0
- package/src/foreign/continue.ts +73 -0
- package/src/foreign/copilot.test.ts +273 -0
- package/src/foreign/copilot.ts +133 -0
- package/src/foreign/crush.test.ts +234 -0
- package/src/foreign/crush.ts +66 -0
- package/src/foreign/cursor.test.ts +509 -0
- package/src/foreign/cursor.ts +259 -0
- package/src/foreign/dsh.test.ts +198 -0
- package/src/foreign/dsh.ts +117 -0
- package/src/foreign/dsh4.test.ts +127 -0
- package/src/foreign/dsh4.ts +15 -0
- package/src/foreign/file-budget.test.ts +256 -0
- package/src/foreign/fixtures/antigravity/README.md +18 -0
- package/src/foreign/fixtures/antigravity/basic/gemini/antigravity/mcp_config.json +13 -0
- package/src/foreign/fixtures/antigravity/basic/gemini/config/mcp_config.json +24 -0
- package/src/foreign/fixtures/antigravity/empty/gemini/antigravity/mcp_config.json +0 -0
- package/src/foreign/fixtures/antigravity/empty/gemini/antigravity/mcp_oauth_tokens.json +0 -0
- package/src/foreign/fixtures/antigravity/empty/gemini/config/mcp_config.json +0 -0
- package/src/foreign/fixtures/codex/README.md +31 -0
- package/src/foreign/fixtures/codex/basic/.agents/skills/hello/SKILL.md +6 -0
- package/src/foreign/fixtures/codex/basic/.agents/skills/wrapper/nested/SKILL.md +6 -0
- package/src/foreign/fixtures/codex/basic/.codex/AGENTS.md +4 -0
- package/src/foreign/fixtures/codex/basic/.codex/config.toml +28 -0
- package/src/foreign/fixtures/codex/malformed/.codex/config.toml +3 -0
- package/src/foreign/fixtures/codex/override/.codex/AGENTS.md +1 -0
- package/src/foreign/fixtures/codex/override/.codex/AGENTS.override.md +3 -0
- package/src/foreign/fixtures/codex/sessions/.codex/archived_sessions/rollout-2026-10-05T09-00-00-22222222-2222-4222-8222-222222222222.jsonl +2 -0
- package/src/foreign/fixtures/codex/sessions/.codex/sessions/2026/10/06/rollout-2026-10-06T10-00-00-11111111-1111-4111-8111-111111111111.jsonl +15 -0
- package/src/foreign/fixtures/codex/sessions/.codex/sessions/2026/10/06/rollout-2026-10-06T11-00-00-33333333-3333-4333-8333-333333333333.jsonl +2 -0
- package/src/foreign/fixtures/codex/sessions/.codex/sessions/2026/10/06/rollout-2026-10-06T11-30-00-55555555-5555-4555-8555-555555555555.jsonl +2 -0
- package/src/foreign/fixtures/codex/sessions/.codex/sessions/2026/10/06/rollout-2026-10-06T12-00-00-44444444-4444-4444-8444-444444444444.jsonl +2 -0
- package/src/foreign/fixtures/codex/sessions/.codex/sessions/notes.jsonl +1 -0
- package/src/foreign/fixtures/copilot/README.md +22 -0
- package/src/foreign/fixtures/copilot/basic/copilot-instructions.md +3 -0
- package/src/foreign/fixtures/copilot/basic/instructions/empty.instructions.md +1 -0
- package/src/foreign/fixtures/copilot/basic/instructions/repo.instructions.md +5 -0
- package/src/foreign/fixtures/copilot/basic/mcp-config.json +24 -0
- package/src/foreign/fixtures/copilot/basic/skills/hello/SKILL.md +6 -0
- package/src/foreign/fixtures/copilot/overridden/mcp-config.json +10 -0
- package/src/foreign/fixtures/cursor/README.md +17 -0
- package/src/foreign/fixtures/cursor/alt/.cursor/mcp.json +5 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/mcp.json +18 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/rules/agent.mdc +5 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/rules/always.mdc +6 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/rules/auto.mdc +7 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/rules/manual.mdc +3 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/skills/.hidden/SKILL.md +6 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/skills/hello/SKILL.md +6 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/skills/wrapper/nested/SKILL.md +6 -0
- package/src/foreign/fixtures/cursor/basic/.cursor/skills/wrapper/nested/notes.md +1 -0
- package/src/foreign/fixtures/cursor/basic/.cursorrules +1 -0
- package/src/foreign/fixtures/cursor/basic/project/.cursor/mcp.json +9 -0
- package/src/foreign/fixtures/cursor/basic/project/.cursor/rules/project-always.mdc +5 -0
- package/src/foreign/fixtures/cursor/basic/project/.cursor/skills/hello/SKILL.md +6 -0
- package/src/foreign/fixtures/cursor/basic/project/.cursorrules +1 -0
- package/src/foreign/fixtures/cursor/empty/.cursor/mcp.json +0 -0
- package/src/foreign/fixtures/cursor/malformed/.cursor/mcp.json +3 -0
- package/src/foreign/fixtures/cursor/malformed/.cursor/rules/broken.mdc +6 -0
- package/src/foreign/fixtures/cursor/shape/.cursor/mcp.json +3 -0
- package/src/foreign/fixtures/hermes/README.md +14 -0
- package/src/foreign/fixtures/hermes/basic/SOUL.md +3 -0
- package/src/foreign/fixtures/hermes/basic/config.yaml +48 -0
- package/src/foreign/fixtures/hermes/basic/dotenv.fixture +1 -0
- package/src/foreign/fixtures/hermes/basic/memories/MEMORY.md +1 -0
- package/src/foreign/fixtures/hermes/basic/memories/USER.md +1 -0
- package/src/foreign/fixtures/hermes/basic/skills/se-team-design/SKILL.md +6 -0
- package/src/foreign/fixtures/hermes/basic/skills/se-team-design/examples/usage.md +1 -0
- package/src/foreign/fixtures/hermes/basic/skills/software-development/dogfood/SKILL.md +6 -0
- package/src/foreign/fixtures/hermes/basic/skills/software-development/dogfood/notes.md +1 -0
- package/src/foreign/fixtures/hermes/basic/state.db +1 -0
- package/src/foreign/fixtures/hermes/empty/config.yaml +0 -0
- package/src/foreign/gemini.test.ts +291 -0
- package/src/foreign/gemini.ts +52 -0
- package/src/foreign/goose.test.ts +196 -0
- package/src/foreign/goose.ts +62 -0
- package/src/foreign/grokbuild.test.ts +246 -0
- package/src/foreign/grokbuild.ts +30 -0
- package/src/foreign/hermes.test.ts +545 -0
- package/src/foreign/hermes.ts +86 -0
- package/src/foreign/kernel-credentials.test.ts +88 -0
- package/src/foreign/kernel-workspaces.test.ts +88 -0
- package/src/foreign/kernel.ts +584 -0
- package/src/foreign/kilocode.test.ts +186 -0
- package/src/foreign/kilocode.ts +60 -0
- package/src/foreign/kimi.test.ts +259 -0
- package/src/foreign/kimi.ts +55 -0
- package/src/foreign/mcp-value-shape.test.ts +286 -0
- package/src/foreign/mimocode.test.ts +178 -0
- package/src/foreign/mimocode.ts +60 -0
- package/src/foreign/openclaw.test.ts +248 -0
- package/src/foreign/openclaw.ts +54 -0
- package/src/foreign/opencode.test.ts +376 -0
- package/src/foreign/opencode.ts +61 -0
- package/src/foreign/pi.test.ts +275 -0
- package/src/foreign/pi.ts +56 -0
- package/src/foreign/platform-paths.ts +156 -0
- package/src/foreign/qoder.test.ts +266 -0
- package/src/foreign/qoder.ts +57 -0
- package/src/foreign/qwen.test.ts +203 -0
- package/src/foreign/qwen.ts +53 -0
- package/src/foreign/read-antigravity.ts +569 -0
- package/src/foreign/read-chatgpt.ts +506 -0
- package/src/foreign/read-claude-code.ts +264 -0
- package/src/foreign/read-cline.ts +517 -0
- package/src/foreign/read-codex.ts +823 -0
- package/src/foreign/read-continue.ts +557 -0
- package/src/foreign/read-copilot.ts +304 -0
- package/src/foreign/read-crush.ts +503 -0
- package/src/foreign/read-cursor.ts +778 -0
- package/src/foreign/read-dsh.ts +215 -0
- package/src/foreign/read-dsh4.ts +35 -0
- package/src/foreign/read-gemini.ts +306 -0
- package/src/foreign/read-goose.ts +333 -0
- package/src/foreign/read-grokbuild.ts +475 -0
- package/src/foreign/read-hermes.ts +724 -0
- package/src/foreign/read-kilocode.ts +55 -0
- package/src/foreign/read-kimi.ts +768 -0
- package/src/foreign/read-mimocode.ts +66 -0
- package/src/foreign/read-openclaw.ts +505 -0
- package/src/foreign/read-opencode.ts +994 -0
- package/src/foreign/read-pi.ts +459 -0
- package/src/foreign/read-qoder.ts +351 -0
- package/src/foreign/read-qwen.ts +342 -0
- package/src/foreign/read-reasonix.ts +590 -0
- package/src/foreign/read-teleagent.ts +82 -0
- package/src/foreign/read-trae.ts +488 -0
- package/src/foreign/read-vibe.ts +353 -0
- package/src/foreign/read-workbuddy.ts +374 -0
- package/src/foreign/read-zcode.ts +48 -0
- package/src/foreign/read-zed.ts +479 -0
- package/src/foreign/reasonix.test.ts +336 -0
- package/src/foreign/reasonix.ts +25 -0
- package/src/foreign/registry.test.ts +377 -0
- package/src/foreign/registry.ts +750 -0
- package/src/foreign/session-ir.test.ts +189 -0
- package/src/foreign/session-ir.ts +614 -0
- package/src/foreign/session-read.ts +295 -0
- package/src/foreign/session-source.ts +625 -0
- package/src/foreign/skill-file-caps.test.ts +171 -0
- package/src/foreign/source-modules.ts +86 -0
- package/src/foreign/source-registry.test.ts +190 -0
- package/src/foreign/sqlite.test.ts +313 -0
- package/src/foreign/sqlite.ts +446 -0
- package/src/foreign/teleagent.test.ts +147 -0
- package/src/foreign/teleagent.ts +62 -0
- package/src/foreign/trae.test.ts +316 -0
- package/src/foreign/trae.ts +25 -0
- package/src/foreign/truncation-report.test.ts +238 -0
- package/src/foreign/truth-table.ts +453 -0
- package/src/foreign/types.ts +312 -0
- package/src/foreign/vibe.test.ts +209 -0
- package/src/foreign/vibe.ts +28 -0
- package/src/foreign/workbuddy.test.ts +207 -0
- package/src/foreign/workbuddy.ts +53 -0
- package/src/foreign/zcode.test.ts +224 -0
- package/src/foreign/zcode.ts +60 -0
- package/src/foreign/zed.test.ts +240 -0
- package/src/foreign/zed.ts +62 -0
- package/src/index.facade.test.ts +254 -16
- package/src/index.ts +704 -82
- package/src/market/github-repos.test.ts +98 -1
- package/src/market/github-repos.ts +63 -1
- package/src/market/types.ts +3 -3
- package/src/profiles/dsh-profile-incomplete-copy.test.ts +177 -0
- package/src/profiles/dsh-profile-manager.test.ts +37 -0
- package/src/profiles/dsh-profile-manager.ts +188 -13
- package/src/profiles/dsh-profile-shared.ts +55 -1
- package/src/profiles/index.ts +2 -1
- package/src/routes/consult.ts +53 -4
- package/src/routes/foreign-context.ts +89 -0
- package/src/routes/foreign.test.ts +443 -0
- package/src/routes/foreign.ts +226 -0
- package/src/routes/import.ts +23 -1
- package/src/routes/index.ts +6 -2
- package/src/routes/kit.ts +4 -3
- package/src/routes/market.ts +0 -1
- package/src/routes/prefs.ts +15 -1
- package/src/routes/recovery.test.ts +167 -0
- package/src/routes/recovery.ts +331 -1
- package/src/routes/session-export.ts +308 -0
- package/src/routes/snapshots.ts +12 -2
- package/src/routes/sync.ts +91 -7
- package/src/security/redaction.test.ts +149 -0
- package/src/security/redaction.ts +25 -9
- package/src/security/secret-scanner.test.ts +186 -0
- package/src/security/secret-scanner.ts +57 -1
- package/src/sync/autosync-risk-tier.test.ts +61 -0
- package/src/sync/autosync-scheduler.test.ts +48 -1
- package/src/sync/autosync-scheduler.ts +50 -26
- package/src/sync/backup-files.ts +5 -0
- package/src/sync/gist/gist-msgkeys-catalog.test.ts +33 -0
- package/src/sync/gist/gist-msgkeys.test.ts +71 -0
- package/src/sync/gist/gist-transport.test.ts +308 -0
- package/src/sync/gist/gist-transport.ts +550 -0
- package/src/sync/gist/messages.ts +49 -0
- package/src/sync/retention-prune-all-off.test.ts +50 -0
- package/src/sync/s3/cloud-config.test.ts +283 -0
- package/src/sync/s3/messages.ts +102 -0
- package/src/sync/s3/s3-delete-index-404.test.ts +170 -0
- package/src/sync/s3/s3-delete-index-unreadable.test.ts +141 -0
- package/src/sync/s3/s3-msgkeys.test.ts +101 -0
- package/src/sync/s3/s3-providers.ts +213 -0
- package/src/sync/s3/s3-transport.test.ts +394 -0
- package/src/sync/s3/s3-transport.ts +651 -0
- package/src/sync/s3/s3-upload-index-404.test.ts +171 -0
- package/src/sync/s3/sigv4.test.ts +219 -0
- package/src/sync/s3/sigv4.ts +283 -0
- package/src/sync/sync-config.test.ts +237 -5
- package/src/sync/sync-config.ts +841 -52
- package/src/sync/sync-engine-download-tombstone.test.ts +73 -0
- package/src/sync/sync-engine.ts +5 -3
- package/src/sync/sync-history.ts +1 -1
- package/src/sync/webdav/webdav-delete-index-404.test.ts +178 -0
- package/src/sync/webdav/webdav-delete-index-unreadable.test.ts +143 -0
- package/src/sync/webdav/webdav-msgkeys.test.ts +53 -0
- package/src/sync/webdav/webdav-transport.test.ts +9 -5
- package/src/sync/webdav/webdav-transport.ts +99 -17
- package/src/sync/webdav/webdav-upload-index-404.test.ts +177 -0
- package/src/ui/commands.test.ts +4 -1
- package/src/ui/commands.ts +46 -12
- package/src/ui/disk-usage-view.test.ts +63 -1
- package/src/ui/disk-usage-view.ts +93 -1
- package/src/ui/dsh-profiles-incomplete-view.test.ts +102 -0
- package/src/ui/dsh-profiles-view.ts +94 -0
- package/src/ui/foreign-view.test.ts +241 -0
- package/src/ui/foreign-view.ts +362 -0
- package/src/ui/i18n.ts +164 -0
- package/src/ui/mid-ellipsis.test.ts +5 -10
- package/src/ui/session-inventory-view.test.ts +142 -2
- package/src/ui/session-inventory-view.ts +127 -0
- package/src/ui/session-layout-view.test.ts +361 -0
- package/src/ui/session-layout-view.ts +444 -0
- package/src/ui/sync-repository-picker.test.ts +130 -0
- package/src/ui/sync-repository-picker.ts +180 -0
- package/src/ui/sync-settings-view.test.ts +166 -0
- package/src/ui/sync-settings-view.ts +319 -9
- package/src/ui/types.ts +42 -0
- package/src/utils/asar-read.test.ts +330 -0
- package/src/utils/asar-read.ts +606 -0
- package/src/utils/env-lock.test.ts +55 -0
- package/src/utils/env-lock.ts +6 -1
- package/src/utils/patch-yaml.test.ts +112 -0
- package/src/utils/patch-yaml.ts +72 -0
- package/src/utils/paths.test.ts +63 -0
- package/src/utils/paths.ts +25 -3
- package/src/utils/recursive-walk.test.ts +20 -0
- package/src/utils/recursive-walk.ts +12 -13
- package/src/utils/session-format.test.ts +113 -2
- package/src/utils/session-format.ts +127 -5
- package/src/utils/session-health-scan.test.ts +364 -1
- package/src/utils/session-health-scan.ts +434 -15
- package/src/utils/session-layout-repair-service.test.ts +362 -0
- package/src/utils/session-layout-repair-service.ts +568 -0
- package/src/utils/session-log-repair.test.ts +260 -1
- package/src/utils/session-log-repair.ts +294 -55
- package/src/utils/session-repair-service.test.ts +148 -1
- package/src/utils/session-repair-service.ts +165 -10
- package/src/utils/session-row-facts.test.ts +159 -0
- package/src/utils/session-row-facts.ts +187 -0
- package/src/utils/session-verify.test.ts +762 -0
- package/src/utils/session-verify.ts +784 -0
- package/src/utils/shared-constants.ts +82 -0
|
@@ -0,0 +1,768 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kimi(~\.kimi + ~/.kimi-code)用户目录的**读盘**层(宿主侧,node:fs)。
|
|
3
|
+
*
|
|
4
|
+
* 位置真值(read-chat-import.md §3.1 的 kimi 行 + §8.4;交叉核对 read-movein.md 附录 A 与
|
|
5
|
+
* read-vault.md §10.2 —— 三份报告都写明**双根**且根逐字一致):
|
|
6
|
+
* - 旧 Kimi CLI:<home>/.kimi/sessions/<md5(workdir)>/<session-id>/wire.jsonl
|
|
7
|
+
* (同目录还有 context.jsonl 与 state.json);workdir 映射表 <home>/.kimi/kimi.json
|
|
8
|
+
* (work_dirs[{path, kaos, last_session_id}];**目录名 = md5(path)**;kaos 非本地时前缀 <kaos>_)
|
|
9
|
+
* - 新 Kimi Code:<home>/.kimi-code/sessions/<workspace-id>/<session-id>/agents/main/wire.jsonl
|
|
10
|
+
* + 同级 state.json;缺 state.json 回退 <home>/.kimi-code/workspaces.json
|
|
11
|
+
* (条目形态:字符串,或 {root};对照 import-variants.mjs 的 kimiCodeWorkDirById)
|
|
12
|
+
* - **无环境变量覆盖**(两条根硬编码,chat-import §3.3 的 env 总表里没有 kimi)
|
|
13
|
+
*
|
|
14
|
+
* **两代 wire 的行形态完全不同**(chat-import §8.4 点名,是本来源最大的坑):
|
|
15
|
+
* - 旧 Kimi CLI:每行 {timestamp, message:{type, payload}},事件名 PascalCase
|
|
16
|
+
* (TurnBegin / SteerInput / StepBegin / TextPart / ThinkPart / ToolCall / ToolResult /
|
|
17
|
+
* CompactionBegin / CompactionEnd / SubagentEvent),载荷全在 message.payload;
|
|
18
|
+
* - 新 Kimi Code:每行直接 {type, time, …}(turn.prompt 的提问在 input;
|
|
19
|
+
* context.append_loop_event 的正文/思考在 event.part.text|think;工具结果在
|
|
20
|
+
* event.result.output + event.result.is_error)。
|
|
21
|
+
* 本层按「行里有 message.type」自动识别两代,**不看顶层 type 一个键**。
|
|
22
|
+
*
|
|
23
|
+
* 角色与提问(**不猜**):turn.prompt 恒为用户输入、旧代次 TurnBegin/SteerInput 的
|
|
24
|
+
* payload.user_input 是提问、TextPart/ThinkPart 恒为 agent 内容;其余判不出角色的
|
|
25
|
+
* 文本事件按类型计数(绝不默认成某一方)。context.append_message 与 turn.prompt
|
|
26
|
+
* 可能携带**同一段文本** → 只在这两种事件相邻且文本相同时去重(detail=duplicate-text)。
|
|
27
|
+
*
|
|
28
|
+
* 工具结果按 tool_call_id/toolCallId 挂回声明它的 assistant 记录,**未配对 / 重复**的
|
|
29
|
+
* 孤儿结果逐条计数(dropped-tool-result),绝不静默丢。
|
|
30
|
+
*
|
|
31
|
+
* cwd 的三档来源(都要求「有据」):状态文件字段(权威,cwd 或 workDir)→ 旧代次
|
|
32
|
+
* kimi.json 的 md5 反查 → 新代次 workspaces.json 反查(条目 path / root)。
|
|
33
|
+
* 标题:state.json 的 custom_title(或 isCustomTitle+title)> 首条 user 文本。
|
|
34
|
+
* 三档 cwd 都不成立就**不产出会话**(下游按 session-missing-cwd 跳过),绝不猜路径。
|
|
35
|
+
*
|
|
36
|
+
* 取证强度:**fixture**(真值表 truth-table.ts 的 kimi 行)。本机无 ~/.kimi 与 ~/.kimi-code,
|
|
37
|
+
* 夹具 + 单测端到端跑同一份布局 —— **真机未验证,不得标 measured**。
|
|
38
|
+
*
|
|
39
|
+
* 读盘纪律:只读固定位置、不跟随符号链接、单文件有字节上限(超限即不读并报码,绝不截断)、
|
|
40
|
+
* 读不到一律记账不抛、结果排序确定。路径函数**显式收 platform**(joinFor)。
|
|
41
|
+
*/
|
|
42
|
+
import { createHash } from 'node:crypto';
|
|
43
|
+
import fs from 'node:fs/promises';
|
|
44
|
+
|
|
45
|
+
import { isRecord } from '../utils/guards.ts';
|
|
46
|
+
import { joinFor, normalizePlatform } from './platform-paths.ts';
|
|
47
|
+
import {
|
|
48
|
+
irBump,
|
|
49
|
+
irEarlier,
|
|
50
|
+
irSafeTime,
|
|
51
|
+
irStr,
|
|
52
|
+
irTextBlock,
|
|
53
|
+
irToolCallBlock,
|
|
54
|
+
irToolResultBlock,
|
|
55
|
+
parseJsonlObjects,
|
|
56
|
+
} from './session-ir.ts';
|
|
57
|
+
import type { IrBlock, IrParseStats, IrTimeMs } from './session-ir.ts';
|
|
58
|
+
import { DEFAULT_MAX_FILE_BYTES, isDirectory, isFile, listDirNames, statOrNull } from './session-read.ts';
|
|
59
|
+
import { firstUserText, flattenText, genericBlocksOf } from './session-source.ts';
|
|
60
|
+
import type { ParsedTranscript, RootProbeOptions, SessionReadOutcome, TranscriptRecord } from './session-source.ts';
|
|
61
|
+
import type { ForeignSkip } from './types.ts';
|
|
62
|
+
|
|
63
|
+
/** 位置标签前缀(回给 GUI/CLI 的**只允许路径**) */
|
|
64
|
+
export const KIMI_SESSIONS_REL = '.kimi/sessions';
|
|
65
|
+
export const KIMI_CODE_SESSIONS_REL = '.kimi-code/sessions';
|
|
66
|
+
|
|
67
|
+
/** 伴生文件名(真值表 truth-table.ts 的 kimi 行里逐字列出) */
|
|
68
|
+
export const KIMI_WORK_DIRS_NAME = 'kimi.json';
|
|
69
|
+
export const KIMI_CODE_WORKSPACES_NAME = 'workspaces.json';
|
|
70
|
+
export const KIMI_WIRE_NAME = 'wire.jsonl';
|
|
71
|
+
export const KIMI_STATE_NAME = 'state.json';
|
|
72
|
+
|
|
73
|
+
/** 新代次的 wire 在会话目录下的相对路径(<session>/agents/main/wire.jsonl) */
|
|
74
|
+
const KIMI_CODE_WIRE_PARTS: readonly string[] = ['agents', 'main', KIMI_WIRE_NAME];
|
|
75
|
+
|
|
76
|
+
const MAX_SESSION_FILES = 500;
|
|
77
|
+
|
|
78
|
+
/** cwd 的候选键(保守:**不含** path/file 这类在工具参数里到处都是的键;workDir 是新代次写法) */
|
|
79
|
+
const CWD_KEYS: readonly string[] = [
|
|
80
|
+
'cwd', 'workDir', 'workdir', 'workingDirectory', 'working_directory', 'workspacePath', 'workspaceDir', 'projectPath',
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
/** 旧 Kimi CLI 的 sessions 根 */
|
|
84
|
+
export function kimiLegacySessionsDir(opts: RootProbeOptions): string {
|
|
85
|
+
return joinFor(normalizePlatform(opts.platform), opts.homeDir, '.kimi', 'sessions');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** 旧 Kimi CLI 的 workdir 映射表路径 */
|
|
89
|
+
export function kimiWorkDirsPath(opts: RootProbeOptions): string {
|
|
90
|
+
return joinFor(normalizePlatform(opts.platform), opts.homeDir, '.kimi', KIMI_WORK_DIRS_NAME);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** 新 Kimi Code 的 sessions 根 */
|
|
94
|
+
export function kimiCodeSessionsDir(opts: RootProbeOptions): string {
|
|
95
|
+
return joinFor(normalizePlatform(opts.platform), opts.homeDir, '.kimi-code', 'sessions');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** 新 Kimi Code 的 workspaces 表路径 */
|
|
99
|
+
export function kimiCodeWorkspacesPath(opts: RootProbeOptions): string {
|
|
100
|
+
return joinFor(normalizePlatform(opts.platform), opts.homeDir, '.kimi-code', KIMI_CODE_WORKSPACES_NAME);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** 一条已解析的 Kimi 会话 */
|
|
104
|
+
export interface KimiSessionFile {
|
|
105
|
+
readonly id: string;
|
|
106
|
+
readonly parsed: ParsedTranscript;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface KimiReadOptions extends RootProbeOptions {
|
|
110
|
+
readonly maxFileBytes?: number | undefined;
|
|
111
|
+
readonly maxSessionFiles?: number | undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** md5 十六进制(旧代次的目录名 = md5(workdir);这只是**反查用的哈希**,不是凭据) */
|
|
115
|
+
export function md5Hex(text: string): string {
|
|
116
|
+
return createHash('md5').update(text, 'utf8').digest('hex');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** 读一个文件(大小闸门在前,绝不截断);空文件 / 超限 / 读失败都变成稳定机器码 */
|
|
120
|
+
async function readTextGuarded(
|
|
121
|
+
p: string,
|
|
122
|
+
label: string,
|
|
123
|
+
maxBytes: number,
|
|
124
|
+
findings: ForeignSkip[],
|
|
125
|
+
): Promise<string | null> {
|
|
126
|
+
const st = await statOrNull(p);
|
|
127
|
+
if (st === null || !st.isFile()) return null;
|
|
128
|
+
if (st.size > maxBytes) {
|
|
129
|
+
findings.push({ code: 'source-unreadable', origin: label, detail: 'too-large' });
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
let text: string;
|
|
133
|
+
try {
|
|
134
|
+
text = await fs.readFile(p, 'utf8');
|
|
135
|
+
} catch {
|
|
136
|
+
findings.push({ code: 'source-unreadable', origin: label, detail: 'read-error' });
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
if (text.trim() === '') {
|
|
140
|
+
findings.push({ code: 'source-empty-file', origin: label });
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
return text;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** 静默读 JSON(读不到 / 畸形 = undefined;状态文件是**辅助**信息,不单独产码) */
|
|
147
|
+
async function readJsonSoft(p: string, maxBytes: number): Promise<unknown> {
|
|
148
|
+
const st = await statOrNull(p);
|
|
149
|
+
if (st === null || !st.isFile() || st.size === 0 || st.size > maxBytes) return undefined;
|
|
150
|
+
try {
|
|
151
|
+
return JSON.parse(await fs.readFile(p, 'utf8'));
|
|
152
|
+
} catch {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
/* ---------------- ① 目录名 → cwd 的两张反查表 ---------------- */
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* kimi.json 的 work_dirs[] → 目录名 → cwd。
|
|
162
|
+
*
|
|
163
|
+
* 目录名 = <kaos>_ + md5(path)(kaos 为**非本地**时才有前缀)。「本地」的判据是
|
|
164
|
+
* kaos 缺失 / 空串 / local(大小写不敏感);认不出的取值按**非本地**处理 —— 保守方向:
|
|
165
|
+
* 宁可不匹配,也不把远端前缀当成 md5 的一部分去反解。
|
|
166
|
+
*/
|
|
167
|
+
export function workDirMapOf(kimiJson: unknown): Map<string, string> {
|
|
168
|
+
const out = new Map<string, string>();
|
|
169
|
+
if (!isRecord(kimiJson)) return out;
|
|
170
|
+
const dirs = kimiJson['work_dirs'];
|
|
171
|
+
if (!Array.isArray(dirs)) return out;
|
|
172
|
+
for (const item of dirs) {
|
|
173
|
+
if (!isRecord(item)) continue;
|
|
174
|
+
const path = irStr(item['path']);
|
|
175
|
+
if (path === undefined) continue;
|
|
176
|
+
const kaos = irStr(item['kaos']);
|
|
177
|
+
const prefix = kaos === undefined || kaos.toLowerCase() === 'local' ? '' : kaos + '_';
|
|
178
|
+
out.set(prefix + md5Hex(path), path);
|
|
179
|
+
}
|
|
180
|
+
return out;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* workspaces.json → workspaceId → cwd(对象映射 / 数组两种形态都认;认不出就空表)。
|
|
185
|
+
*
|
|
186
|
+
* 条目形态:字符串,或 {path} / {root}(新代次真实写法是 root;对照
|
|
187
|
+
* import-variants.mjs 的 kimiCodeWorkDirById)。
|
|
188
|
+
*/
|
|
189
|
+
export function workspaceMapOf(workspacesJson: unknown): Map<string, string> {
|
|
190
|
+
const out = new Map<string, string>();
|
|
191
|
+
const pathOf = (raw: unknown): string | undefined => {
|
|
192
|
+
if (typeof raw === 'string' && raw !== '') return raw;
|
|
193
|
+
if (!isRecord(raw)) return undefined;
|
|
194
|
+
// 这里是**工作区注册表条目**(不是会话记录):path / root 就是它的规范键,可以放心收
|
|
195
|
+
for (const key of ['path', 'root', ...CWD_KEYS]) {
|
|
196
|
+
const v = irStr(raw[key]);
|
|
197
|
+
if (v !== undefined) return v;
|
|
198
|
+
}
|
|
199
|
+
return undefined;
|
|
200
|
+
};
|
|
201
|
+
if (Array.isArray(workspacesJson)) {
|
|
202
|
+
for (const item of workspacesJson) {
|
|
203
|
+
if (!isRecord(item)) continue;
|
|
204
|
+
const id = irStr(item['id']) ?? irStr(item['workspaceId']) ?? irStr(item['workspace_id']);
|
|
205
|
+
const path = pathOf(item);
|
|
206
|
+
if (id !== undefined && path !== undefined) out.set(id, path);
|
|
207
|
+
}
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
210
|
+
if (!isRecord(workspacesJson)) return out;
|
|
211
|
+
for (const [id, raw] of Object.entries(workspacesJson)) {
|
|
212
|
+
const path = pathOf(raw);
|
|
213
|
+
if (path !== undefined) out.set(id, path);
|
|
214
|
+
}
|
|
215
|
+
return out;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** 状态文件里的 cwd(cwd / workDir;**权威**优先于目录名反查) */
|
|
219
|
+
export function cwdOfState(stateJson: unknown): string | undefined {
|
|
220
|
+
if (!isRecord(stateJson)) return undefined;
|
|
221
|
+
for (const key of CWD_KEYS) {
|
|
222
|
+
const v = irStr(stateJson[key]);
|
|
223
|
+
if (v !== undefined) return v;
|
|
224
|
+
}
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* 状态文件里的权威标题:custom_title(重命名)> isCustomTitle === true 时的 title。
|
|
230
|
+
* 对照 import-variants.mjs 的 kimiDeriveArgs。
|
|
231
|
+
*/
|
|
232
|
+
export function titleOfState(stateJson: unknown): string | undefined {
|
|
233
|
+
if (!isRecord(stateJson)) return undefined;
|
|
234
|
+
const custom = irStr(stateJson['custom_title']);
|
|
235
|
+
if (custom !== undefined) return custom.trim();
|
|
236
|
+
if (stateJson['isCustomTitle'] === true) {
|
|
237
|
+
const title = irStr(stateJson['title']);
|
|
238
|
+
if (title !== undefined) return title.trim();
|
|
239
|
+
}
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/* ---------------- ② 两代 wire 事件 → 归一记录 ---------------- */
|
|
244
|
+
|
|
245
|
+
/** 归一化事件类型:小写、去掉 . 与 _(turn.prompt → turnprompt) */
|
|
246
|
+
export function normalizeEventType(raw: string): string {
|
|
247
|
+
return raw.toLowerCase().split('.').join('').split('_').join('');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** 秒/毫秒自动判定(两代 wire 的行时间都可能是 Unix 秒;< 1e11 视为秒) */
|
|
251
|
+
function kimiTimeOf(value: unknown): IrTimeMs | undefined {
|
|
252
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
253
|
+
const ms = Math.round(value < 1e11 ? value * 1000 : value);
|
|
254
|
+
return Number.isSafeInteger(ms) ? ms : undefined;
|
|
255
|
+
}
|
|
256
|
+
return irSafeTime(value);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* 用户输入 → 文本:字符串原样;ContentPart 数组取 text 片段**直接相接**(分隔符 ''),
|
|
261
|
+
* 结果去首尾空白。对照 convert/kimi.mjs 的 kimiUserInputText。
|
|
262
|
+
*/
|
|
263
|
+
export function kimiUserInputText(value: unknown): string {
|
|
264
|
+
if (typeof value === 'string') return value.trim();
|
|
265
|
+
if (Array.isArray(value)) {
|
|
266
|
+
const parts: string[] = [];
|
|
267
|
+
for (const p of value) {
|
|
268
|
+
if (typeof p === 'string') { parts.push(p); continue; }
|
|
269
|
+
if (!isRecord(p)) continue;
|
|
270
|
+
if (typeof p['text'] === 'string') { parts.push(p['text']); continue; }
|
|
271
|
+
if (typeof p['content'] === 'string') parts.push(p['content']);
|
|
272
|
+
}
|
|
273
|
+
return parts.join('').trim();
|
|
274
|
+
}
|
|
275
|
+
if (isRecord(value) && typeof value['text'] === 'string') return value['text'].trim();
|
|
276
|
+
return '';
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** 工具入参:字符串若是 JSON 就解析(旧代次 function.arguments 是 JSON 字符串) */
|
|
280
|
+
function kimiToolInput(raw: unknown): unknown {
|
|
281
|
+
if (typeof raw === 'string') {
|
|
282
|
+
const trimmed = raw.trim();
|
|
283
|
+
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
|
284
|
+
try {
|
|
285
|
+
return JSON.parse(trimmed);
|
|
286
|
+
} catch {
|
|
287
|
+
return raw;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return raw;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** 工具结果文本:output 优先;为空回退 message(对模型的说明文本),避免空结果吞信息 */
|
|
295
|
+
function kimiToolResultText(output: unknown, fallback: unknown, ignored: Record<string, number>): string {
|
|
296
|
+
const text = flattenText(output, ignored, 'toolResult');
|
|
297
|
+
return text !== '' ? text : flattenText(fallback, ignored, 'toolResult');
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const USER_VALUES: readonly string[] = ['user', 'human', 'prompt', 'usermessage', 'turnprompt'];
|
|
301
|
+
const ASSISTANT_VALUES: readonly string[] = ['assistant', 'ai', 'model', 'agent', 'bot', 'kimi', 'assistantmessage'];
|
|
302
|
+
|
|
303
|
+
/** 无内容的结构性事件:**不算未迁移**,也不产记录 */
|
|
304
|
+
const STRUCTURAL_TYPES: readonly string[] = [
|
|
305
|
+
'turnbegin', 'steerinput', 'turnstart', 'turnend', 'turnended', 'stepbegin', 'stepstart', 'stepend', 'stepended',
|
|
306
|
+
'contextappend', 'loopbegin', 'loopend', 'appendloopevent',
|
|
307
|
+
];
|
|
308
|
+
|
|
309
|
+
function eventTypeOf(obj: Record<string, unknown>): string {
|
|
310
|
+
return irStr(obj['type']) ?? irStr(obj['event']) ?? irStr(obj['kind']) ?? '';
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** 角色字段候选(事件本体与嵌套的 message 载荷都看;新代次的 role 在 message 里面) */
|
|
314
|
+
const ROLE_KEYS: readonly string[] = ['role', 'speaker', 'author', 'from', 'sender'];
|
|
315
|
+
|
|
316
|
+
function explicitRoleOf(obj: Record<string, unknown>): string | undefined {
|
|
317
|
+
for (const key of ROLE_KEYS) {
|
|
318
|
+
const v = irStr(obj[key]);
|
|
319
|
+
if (v !== undefined) return v;
|
|
320
|
+
}
|
|
321
|
+
return undefined;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function roleOfEvent(obj: Record<string, unknown>, normType: string): 'user' | 'assistant' | undefined {
|
|
325
|
+
const nested = isRecord(obj['message']) ? explicitRoleOf(obj['message']) : undefined;
|
|
326
|
+
const explicit = explicitRoleOf(obj) ?? nested;
|
|
327
|
+
if (explicit !== undefined) {
|
|
328
|
+
const lower = explicit.toLowerCase();
|
|
329
|
+
if (USER_VALUES.includes(lower)) return 'user';
|
|
330
|
+
if (ASSISTANT_VALUES.includes(lower)) return 'assistant';
|
|
331
|
+
}
|
|
332
|
+
// 两代词汇的既定语义(chat-import §8.4):新代次 turn.prompt = 用户输入;
|
|
333
|
+
// 旧代次 PascalCase 的 TextPart = agent 自己的文本流
|
|
334
|
+
if (normType === 'turnprompt') return 'user';
|
|
335
|
+
if (normType === 'textpart') return 'assistant';
|
|
336
|
+
return undefined;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** 文本载荷:text/content/message/delta/input;message.content 下钻一层 */
|
|
340
|
+
function textContentOf(obj: Record<string, unknown>): unknown {
|
|
341
|
+
for (const key of ['text', 'content', 'message', 'delta', 'input']) {
|
|
342
|
+
const v = obj[key];
|
|
343
|
+
if (v === undefined) continue;
|
|
344
|
+
if (isRecord(v) && v['content'] !== undefined) return v['content'];
|
|
345
|
+
return v;
|
|
346
|
+
}
|
|
347
|
+
return undefined;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** wire 解析的中间状态(**显式**状态对象,避免把归一逻辑写成闭包里的隐式状态) */
|
|
351
|
+
interface WireState {
|
|
352
|
+
readonly records: TranscriptRecord[];
|
|
353
|
+
readonly ignored: Record<string, number>;
|
|
354
|
+
createdAt: IrTimeMs | undefined;
|
|
355
|
+
textBuf: string[];
|
|
356
|
+
textTime: IrTimeMs | undefined;
|
|
357
|
+
textId: string | undefined;
|
|
358
|
+
pendingKind: 'prompt' | 'message' | undefined;
|
|
359
|
+
pendingText: string | undefined;
|
|
360
|
+
/** 已声明的工具调用 id(用于孤儿结果判定) */
|
|
361
|
+
readonly declaredCalls: Set<string>;
|
|
362
|
+
/** callId → 结果块(解析收尾时按 id 挂回 call 所在 assistant 记录) */
|
|
363
|
+
readonly toolResults: Map<string, { block: IrBlock; time: IrTimeMs | undefined }>;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function newWireState(): WireState {
|
|
367
|
+
return {
|
|
368
|
+
records: [], ignored: {}, createdAt: undefined, textBuf: [], textTime: undefined, textId: undefined,
|
|
369
|
+
pendingKind: undefined, pendingText: undefined, declaredCalls: new Set(), toolResults: new Map(),
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** 收口「相邻 assistant 文本→一条消息」(wire 是分片流,逐事件成消息会切碎一条回复) */
|
|
374
|
+
function flushText(st: WireState): void {
|
|
375
|
+
if (st.textBuf.length === 0) return;
|
|
376
|
+
st.records.push({
|
|
377
|
+
role: 'assistant',
|
|
378
|
+
blocks: [irTextBlock(st.textBuf.join(String.fromCharCode(10)))],
|
|
379
|
+
time: st.textTime,
|
|
380
|
+
id: st.textId,
|
|
381
|
+
});
|
|
382
|
+
st.textBuf = [];
|
|
383
|
+
st.textTime = undefined;
|
|
384
|
+
st.textId = undefined;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** 追加 assistant 文本(相邻分片合并;空串不产记录) */
|
|
388
|
+
function pushAssistantText(st: WireState, text: string, time: IrTimeMs | undefined, id: string | undefined): void {
|
|
389
|
+
if (text === '') return;
|
|
390
|
+
if (st.textBuf.length === 0) {
|
|
391
|
+
st.textTime = time;
|
|
392
|
+
st.textId = id;
|
|
393
|
+
}
|
|
394
|
+
st.textBuf.push(text);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* 推入一条 user 记录;context.append_message 与 turn.prompt 携带**同一段文本**且
|
|
399
|
+
* 相邻时去重(只这一对,绝不按「任意相邻同文本」去重)。
|
|
400
|
+
*/
|
|
401
|
+
function pushUserRecord(
|
|
402
|
+
st: WireState,
|
|
403
|
+
blocks: readonly IrBlock[],
|
|
404
|
+
time: IrTimeMs | undefined,
|
|
405
|
+
id: string | undefined,
|
|
406
|
+
kind: 'prompt' | 'message',
|
|
407
|
+
): void {
|
|
408
|
+
flushText(st);
|
|
409
|
+
const flat = blocks.filter((b) => b.type === 'text').map((b) => b.text).join(String.fromCharCode(10));
|
|
410
|
+
if (st.pendingText !== undefined && st.pendingKind !== undefined && st.pendingKind !== kind && st.pendingText === flat) {
|
|
411
|
+
irBump(st.ignored, 'duplicate-text');
|
|
412
|
+
st.pendingKind = kind;
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
st.records.push({ role: 'user', blocks, time, id });
|
|
416
|
+
st.pendingKind = kind;
|
|
417
|
+
st.pendingText = flat;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** 推入一条 assistant 工具调用记录(并登记 callId 供结果配对) */
|
|
421
|
+
function pushToolCall(
|
|
422
|
+
st: WireState,
|
|
423
|
+
callId: string,
|
|
424
|
+
name: string,
|
|
425
|
+
input: unknown,
|
|
426
|
+
time: IrTimeMs | undefined,
|
|
427
|
+
id: string | undefined,
|
|
428
|
+
): void {
|
|
429
|
+
flushText(st);
|
|
430
|
+
st.records.push({ role: 'assistant', blocks: [irToolCallBlock(callId, name, input)], time, id });
|
|
431
|
+
st.declaredCalls.add(callId);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** 登记工具结果:callId 未声明 / 重复 → 孤儿计数(绝不静默) */
|
|
435
|
+
function noteToolResult(st: WireState, callId: string, block: IrBlock, time: IrTimeMs | undefined): void {
|
|
436
|
+
if (callId === '' || !st.declaredCalls.has(callId) || st.toolResults.has(callId)) {
|
|
437
|
+
irBump(st.ignored, 'dropped-tool-result');
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
st.toolResults.set(callId, { block, time });
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/** 通用事件兜底(未在两代专用分支覆盖的文本事件;判不出角色就按类型计数) */
|
|
444
|
+
function handleWireEvent(
|
|
445
|
+
st: WireState,
|
|
446
|
+
obj: Record<string, unknown>,
|
|
447
|
+
normType: string,
|
|
448
|
+
outerTime: IrTimeMs | undefined,
|
|
449
|
+
): void {
|
|
450
|
+
const time = kimiTimeOf(obj['time']) ?? kimiTimeOf(obj['timestamp']) ?? outerTime;
|
|
451
|
+
st.createdAt = irEarlier(st.createdAt, time);
|
|
452
|
+
const id = irStr(obj['id']) ?? irStr(obj['messageId']) ?? irStr(obj['message_id']);
|
|
453
|
+
const isToolCall = normType.includes('toolcall') || normType.includes('tooluse');
|
|
454
|
+
const isToolResult = normType.includes('toolresult') || normType.includes('tooloutput') || normType.includes('toolresponse');
|
|
455
|
+
|
|
456
|
+
if (isToolCall) {
|
|
457
|
+
flushText(st);
|
|
458
|
+
const name = irStr(obj['name']) ?? irStr(obj['toolName']) ?? irStr(obj['tool']) ?? '';
|
|
459
|
+
const callId = irStr(obj['toolCallId']) ?? irStr(obj['callId']) ?? irStr(obj['id']) ?? '';
|
|
460
|
+
const input = obj['args'] ?? obj['arguments'] ?? obj['input'] ?? obj['parameters'];
|
|
461
|
+
st.records.push({ role: 'assistant', blocks: [irToolCallBlock(callId, name, input)], time, id });
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
if (isToolResult) {
|
|
465
|
+
flushText(st);
|
|
466
|
+
const callId = irStr(obj['toolCallId']) ?? irStr(obj['tool_call_id']) ?? irStr(obj['callId']) ?? irStr(obj['id']) ?? '';
|
|
467
|
+
const body = obj['content'] ?? obj['output'] ?? obj['result'];
|
|
468
|
+
const isError = obj['isError'] === true || obj['is_error'] === true || obj['error'] === true;
|
|
469
|
+
st.records.push({ role: 'user', blocks: [irToolResultBlock(callId, flattenText(body, st.ignored, 'toolResult'), isError)], time, id });
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const content = textContentOf(obj);
|
|
474
|
+
if (content === undefined) {
|
|
475
|
+
irBump(st.ignored, normType === '' ? 'unknown' : normType);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
const role = roleOfEvent(obj, normType);
|
|
479
|
+
if (role === undefined) {
|
|
480
|
+
// 判不出角色的文本事件:按类型计数(绝不默认成某一方)
|
|
481
|
+
irBump(st.ignored, normType === '' ? 'unknown' : normType);
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
const blocks = genericBlocksOf(content, st.ignored, 'block');
|
|
485
|
+
if (blocks.length === 0) {
|
|
486
|
+
irBump(st.ignored, normType + ':no-content');
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
const flat = blocks.filter((b) => b.type === 'text').map((b) => b.text).join(String.fromCharCode(10));
|
|
490
|
+
|
|
491
|
+
if (role === 'user') {
|
|
492
|
+
pushUserRecord(st, blocks, time, id, normType === 'turnprompt' ? 'prompt' : 'message');
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
pushAssistantText(st, flat, time, id);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/** 旧 Kimi CLI 事件(PascalCase;载荷在 message.payload) */
|
|
499
|
+
function handleOldEvent(
|
|
500
|
+
st: WireState,
|
|
501
|
+
type: string,
|
|
502
|
+
payload: Record<string, unknown>,
|
|
503
|
+
time: IrTimeMs | undefined,
|
|
504
|
+
): void {
|
|
505
|
+
const norm = normalizeEventType(type);
|
|
506
|
+
if (type === 'TurnBegin' || type === 'SteerInput') {
|
|
507
|
+
const prompt = kimiUserInputText(payload['user_input']);
|
|
508
|
+
if (prompt === '') { irBump(st.ignored, norm + ':no-input'); return; }
|
|
509
|
+
pushUserRecord(st, [irTextBlock(prompt)], time, undefined, 'prompt');
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
if (type === 'TextPart') {
|
|
513
|
+
if (typeof payload['text'] === 'string') pushAssistantText(st, payload['text'], time, undefined);
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
if (type === 'ThinkPart') {
|
|
517
|
+
// IR 无 reasoning 块(见 session-ir.ts 头注释)→ 不伪装成正文,逐类计数
|
|
518
|
+
if (typeof payload['think'] === 'string' && payload['think'] !== '') irBump(st.ignored, 'reasoning-block');
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
if (type === 'ToolCall') {
|
|
522
|
+
const fn = isRecord(payload['function']) ? payload['function'] : {};
|
|
523
|
+
const callId = irStr(payload['id']) ?? '';
|
|
524
|
+
const name = irStr(fn['name']) ?? '';
|
|
525
|
+
if (callId === '' || name === '') { irBump(st.ignored, 'toolcall:no-id-or-name'); return; }
|
|
526
|
+
pushToolCall(st, callId, name, kimiToolInput(fn['arguments']), time, undefined);
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
if (type === 'ToolResult') {
|
|
530
|
+
const callId = irStr(payload['tool_call_id']) ?? '';
|
|
531
|
+
const rv = isRecord(payload['return_value']) ? payload['return_value'] : {};
|
|
532
|
+
const body = kimiToolResultText(rv['output'], rv['message'], st.ignored);
|
|
533
|
+
noteToolResult(st, callId, irToolResultBlock(callId, body, rv['is_error'] === true), time);
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
if (type === 'ToolCallPart') return; // 流式参数分块:最终 ToolCall 已带完整参数(对照 convert/kimi.mjs)
|
|
537
|
+
if (type === 'CompactionBegin' || type === 'CompactionEnd') {
|
|
538
|
+
// 参考实现映射为 DSH 原生压缩检查点;本地合成器暂无此能力位(shared 层)→ 计数不静默
|
|
539
|
+
irBump(st.ignored, 'compaction');
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
if (type === 'SubagentEvent') {
|
|
543
|
+
irBump(st.ignored, 'subagent-event');
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
if (STRUCTURAL_TYPES.includes(norm)) return;
|
|
547
|
+
handleWireEvent(st, payload, norm, time);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/** 新 Kimi Code 事件(点分小写;每行直接是 {type,…}) */
|
|
551
|
+
function handleNewEvent(
|
|
552
|
+
st: WireState,
|
|
553
|
+
type: string,
|
|
554
|
+
rec: Record<string, unknown>,
|
|
555
|
+
time: IrTimeMs | undefined,
|
|
556
|
+
): void {
|
|
557
|
+
if (type === 'turn.prompt') {
|
|
558
|
+
// 提问在 input(ContentPart 数组);兼容历史顶层 text/content 写法
|
|
559
|
+
const raw = rec['input'] !== undefined ? rec['input'] : (rec['text'] !== undefined ? rec['text'] : rec['content']);
|
|
560
|
+
const prompt = kimiUserInputText(raw);
|
|
561
|
+
if (prompt === '') { irBump(st.ignored, 'turnprompt:no-input'); return; }
|
|
562
|
+
pushUserRecord(st, [irTextBlock(prompt)], time, irStr(rec['id']), 'prompt');
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
if (type === 'context.append_loop_event') {
|
|
566
|
+
const event = isRecord(rec['event']) ? rec['event'] : (isRecord(rec['payload']) ? rec['payload'] : undefined);
|
|
567
|
+
if (event === undefined) { irBump(st.ignored, 'contextappendloopevent:no-event'); return; }
|
|
568
|
+
const et = eventTypeOf(event);
|
|
569
|
+
const norm = normalizeEventType(et);
|
|
570
|
+
if (norm === 'stepbegin' || norm === 'stepend') return;
|
|
571
|
+
if (norm === 'contentpart') {
|
|
572
|
+
const part = isRecord(event['part']) ? event['part'] : undefined;
|
|
573
|
+
if (part === undefined) { irBump(st.ignored, 'contentpart:no-part'); return; }
|
|
574
|
+
const pt = typeof part['type'] === 'string' ? part['type'] : '';
|
|
575
|
+
if (pt === 'text') {
|
|
576
|
+
if (typeof part['text'] === 'string') pushAssistantText(st, part['text'], time, undefined);
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
if (pt === 'think') {
|
|
580
|
+
if (typeof part['think'] === 'string' && part['think'] !== '') irBump(st.ignored, 'reasoning-block');
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
if (pt === 'image_url' || pt === 'image' || pt === 'video_url' || pt === 'audio_url') {
|
|
584
|
+
irBump(st.ignored, 'image-block');
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
irBump(st.ignored, 'contentpart:' + (pt === '' ? 'unmapped' : pt));
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
if (norm === 'toolcall') {
|
|
591
|
+
const callId = irStr(event['toolCallId']) ?? '';
|
|
592
|
+
const name = irStr(event['name']) ?? '';
|
|
593
|
+
if (callId === '' || name === '') { irBump(st.ignored, 'toolcall:no-id-or-name'); return; }
|
|
594
|
+
pushToolCall(st, callId, name, kimiToolInput(event['args']), time, undefined);
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
if (norm === 'toolresult') {
|
|
598
|
+
const callId = irStr(event['toolCallId']) ?? '';
|
|
599
|
+
const rv = isRecord(event['result']) ? event['result'] : {};
|
|
600
|
+
const body = kimiToolResultText(rv['output'], rv['message'], st.ignored);
|
|
601
|
+
noteToolResult(st, callId, irToolResultBlock(callId, body, rv['is_error'] === true), time);
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
if (STRUCTURAL_TYPES.includes(norm)) return;
|
|
605
|
+
handleWireEvent(st, event, norm, time);
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
if (type === 'context.apply_compaction') {
|
|
609
|
+
// 参考实现把摘要落成压缩检查点;本地合成器暂无此能力位(shared 层)→ 计数不静默
|
|
610
|
+
irBump(st.ignored, 'compaction');
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
if (type === 'turn.ended') return;
|
|
614
|
+
if (STRUCTURAL_TYPES.includes(normalizeEventType(type))) return;
|
|
615
|
+
handleWireEvent(st, rec, normalizeEventType(type), time);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/** 把登记的 tool_result 块挂回声明它的 assistant 记录之后(合成器按位置收进同一 step) */
|
|
619
|
+
function applyToolResults(st: WireState): TranscriptRecord[] {
|
|
620
|
+
if (st.toolResults.size === 0) return st.records;
|
|
621
|
+
const out: TranscriptRecord[] = [];
|
|
622
|
+
for (const rec of st.records) {
|
|
623
|
+
out.push(rec);
|
|
624
|
+
if (rec.role !== 'assistant') continue;
|
|
625
|
+
const blocks: IrBlock[] = [];
|
|
626
|
+
let time: IrTimeMs | undefined;
|
|
627
|
+
for (const b of rec.blocks) {
|
|
628
|
+
if (b.type !== 'tool_call') continue;
|
|
629
|
+
const result = st.toolResults.get(b.id);
|
|
630
|
+
if (result === undefined) continue;
|
|
631
|
+
blocks.push(result.block);
|
|
632
|
+
if (time === undefined) time = result.time;
|
|
633
|
+
st.toolResults.delete(b.id);
|
|
634
|
+
}
|
|
635
|
+
if (blocks.length > 0) out.push({ role: 'user', blocks, time });
|
|
636
|
+
}
|
|
637
|
+
return out;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* wire.jsonl → 归一记录(**两代词汇共用一处**)。旧代次每行是
|
|
642
|
+
* {timestamp, message:{type,payload}}、新代次每行直接是 {type,…},按行自动识别。
|
|
643
|
+
*/
|
|
644
|
+
export function parseKimiWire(text: string): ParsedTranscript {
|
|
645
|
+
const stats: IrParseStats = { records: 0, unparsable: 0, issues: [] };
|
|
646
|
+
const objects = parseJsonlObjects(text, stats);
|
|
647
|
+
const st = newWireState();
|
|
648
|
+
|
|
649
|
+
for (const rec of objects) {
|
|
650
|
+
const msg = isRecord(rec['message']) ? rec['message'] : undefined;
|
|
651
|
+
const isOldWire = msg !== undefined && typeof msg['type'] === 'string';
|
|
652
|
+
if (isOldWire) {
|
|
653
|
+
const payload = isRecord(msg['payload']) ? msg['payload'] : {};
|
|
654
|
+
// 旧 wire 的行时间戳在**顶层**({timestamp, message:{…}}),载荷里没有
|
|
655
|
+
const outerTime = kimiTimeOf(rec['timestamp']);
|
|
656
|
+
st.createdAt = irEarlier(st.createdAt, outerTime);
|
|
657
|
+
handleOldEvent(st, msg['type'] as string, payload, outerTime);
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
const type = typeof rec['type'] === 'string' ? rec['type'] : '';
|
|
661
|
+
if (type === '') {
|
|
662
|
+
irBump(st.ignored, 'unknown');
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
const time = kimiTimeOf(rec['time'] ?? rec['created_at'] ?? rec['timestamp']);
|
|
666
|
+
st.createdAt = irEarlier(st.createdAt, time);
|
|
667
|
+
handleNewEvent(st, type, rec, time);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
flushText(st);
|
|
671
|
+
const records = applyToolResults(st);
|
|
672
|
+
return {
|
|
673
|
+
records,
|
|
674
|
+
createdAt: st.createdAt,
|
|
675
|
+
title: firstUserText(records),
|
|
676
|
+
raw: objects.length + stats.unparsable,
|
|
677
|
+
bad: stats.unparsable,
|
|
678
|
+
ignored: st.ignored,
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/* ---------------- ③ 入口 ---------------- */
|
|
683
|
+
|
|
684
|
+
export async function readKimiSessions(opts: KimiReadOptions): Promise<SessionReadOutcome<KimiSessionFile>> {
|
|
685
|
+
const platform = normalizePlatform(opts.platform);
|
|
686
|
+
const maxBytes = opts.maxFileBytes ?? DEFAULT_MAX_FILE_BYTES;
|
|
687
|
+
const maxFiles = opts.maxSessionFiles ?? MAX_SESSION_FILES;
|
|
688
|
+
const findings: ForeignSkip[] = [];
|
|
689
|
+
const files: KimiSessionFile[] = [];
|
|
690
|
+
|
|
691
|
+
const legacyRoot = kimiLegacySessionsDir(opts);
|
|
692
|
+
const codeRoot = kimiCodeSessionsDir(opts);
|
|
693
|
+
if (!(await isDirectory(legacyRoot)) && !(await isDirectory(codeRoot))) {
|
|
694
|
+
return { files, readFindings: findings, extraCounts: { 'sessions.candidates': 0 } };
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
const workDirs = workDirMapOf(await readJsonSoft(kimiWorkDirsPath(opts), maxBytes));
|
|
698
|
+
const workspaces = workspaceMapOf(await readJsonSoft(kimiCodeWorkspacesPath(opts), maxBytes));
|
|
699
|
+
|
|
700
|
+
/** 两个代次共用的一条会话:wire 位置 + 状态文件位置 + cwd/标题的反查结果 */
|
|
701
|
+
const addSession = async (input: {
|
|
702
|
+
id: string;
|
|
703
|
+
label: string;
|
|
704
|
+
wirePath: string;
|
|
705
|
+
statePath: string;
|
|
706
|
+
cwdFromMapping: string | undefined;
|
|
707
|
+
}): Promise<void> => {
|
|
708
|
+
const text = await readTextGuarded(input.wirePath, input.label, maxBytes, findings);
|
|
709
|
+
if (text === null) return;
|
|
710
|
+
const state = await readJsonSoft(input.statePath, maxBytes);
|
|
711
|
+
const cwd = cwdOfState(state) ?? input.cwdFromMapping;
|
|
712
|
+
const title = titleOfState(state);
|
|
713
|
+
const parsed = parseKimiWire(text);
|
|
714
|
+
files.push({
|
|
715
|
+
id: input.id,
|
|
716
|
+
parsed: {
|
|
717
|
+
...parsed,
|
|
718
|
+
...(cwd === undefined ? {} : { cwd }),
|
|
719
|
+
...(title === undefined ? {} : { title }),
|
|
720
|
+
},
|
|
721
|
+
});
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
// 触顶必须**可见**(audit-foreign F4):两个代次共同一个上限,任一 break 都置标志。
|
|
725
|
+
let truncated = false;
|
|
726
|
+
/* 旧 Kimi CLI:<root>/<md5(workdir)>/<sid>/{wire.jsonl,state.json} */
|
|
727
|
+
if (await isDirectory(legacyRoot)) {
|
|
728
|
+
for (const workDirName of await listDirNames(legacyRoot)) {
|
|
729
|
+
const workDir = joinFor(platform, legacyRoot, workDirName);
|
|
730
|
+
for (const sid of await listDirNames(workDir)) {
|
|
731
|
+
if (files.length >= maxFiles) { truncated = true; break; }
|
|
732
|
+
const sessionDir = joinFor(platform, workDir, sid);
|
|
733
|
+
const wirePath = joinFor(platform, sessionDir, KIMI_WIRE_NAME);
|
|
734
|
+
if (!(await isFile(wirePath))) continue;
|
|
735
|
+
await addSession({
|
|
736
|
+
id: sid,
|
|
737
|
+
label: KIMI_SESSIONS_REL + '/' + workDirName + '/' + sid + '/' + KIMI_WIRE_NAME,
|
|
738
|
+
wirePath,
|
|
739
|
+
statePath: joinFor(platform, sessionDir, KIMI_STATE_NAME),
|
|
740
|
+
cwdFromMapping: workDirs.get(workDirName),
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
/* 新 Kimi Code:<root>/<workspaceId>/<sid>/agents/main/wire.jsonl + 同级 state.json */
|
|
747
|
+
if (await isDirectory(codeRoot)) {
|
|
748
|
+
for (const workspaceId of await listDirNames(codeRoot)) {
|
|
749
|
+
const workspaceDir = joinFor(platform, codeRoot, workspaceId);
|
|
750
|
+
for (const sid of await listDirNames(workspaceDir)) {
|
|
751
|
+
if (files.length >= maxFiles) { truncated = true; break; }
|
|
752
|
+
const sessionDir = joinFor(platform, workspaceDir, sid);
|
|
753
|
+
const wirePath = joinFor(platform, sessionDir, ...KIMI_CODE_WIRE_PARTS);
|
|
754
|
+
if (!(await isFile(wirePath))) continue;
|
|
755
|
+
await addSession({
|
|
756
|
+
id: sid,
|
|
757
|
+
label: KIMI_CODE_SESSIONS_REL + '/' + workspaceId + '/' + sid + '/agents/main/' + KIMI_WIRE_NAME,
|
|
758
|
+
wirePath,
|
|
759
|
+
statePath: joinFor(platform, sessionDir, KIMI_STATE_NAME),
|
|
760
|
+
cwdFromMapping: workspaces.get(workspaceId),
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
if (truncated) findings.push({ code: 'source-unreadable', origin: 'kimi', detail: 'max-sessions-reached', count: maxFiles });
|
|
767
|
+
return { files, readFindings: findings, extraCounts: { 'sessions.candidates': files.length } };
|
|
768
|
+
}
|