Skip to content

修复codex->dsh对话标题错误,增加目标模式双向保留,增加消息同步管理 - #13

Open
nlsp60 wants to merge 18 commits into
Walvez:mainfrom
nlsp60:main
Open

nlsp60 wants to merge 18 commits into
Walvez:mainfrom
nlsp60:main

Conversation

@nlsp60

@nlsp60 nlsp60 commented Nov 11, 2026 •

Copy link
Copy Markdown

一、读取与导入:现在能读到 Codex 的全部会话

项 之前 现在
.jsonl.zst 压缩会话 完全不支持(Codex Desktop 的默认格式) 用运行时自带的 node:zlib zstd 解码,零新依赖、不转换 Codex 数据
多帧 rollout 只读到第一帧 逐帧解码拼回完整内容
大文件 readFileSync 撞 Node 字符串上限,256 MiB 以上直接跳过 改为流式读取,默认上限提到 2 GiB
Windows 迁移包解析 找不到 @deepseek-ai/dsh-session-format-*,导入必失败 按 process.resourcesPath → app.asar/dsh/node_modules 解析
宿主版本 — 接受 host 0.2.2-rc.1
导入完成后 2.5 秒后整页刷新,打断阅读 只刷新插件自己的目录,侧边栏提供手动「刷新列表」

真实收益:本机两个会话(388 MB / 1.2 GB,6090 / 8882 条消息)此前根本不在列表里,现在可正常导入。

二、标题、项目与工作区命名

  • 标题与项目名改读 Codex 自己的数据库(~/.codex/state_5.sqlite):threads.name 才是侧边栏显示的名字(threads.title 常常是粘贴的原文),项目取 projects.name + project_roots.path。此前用 session_index.jsonl(缺约 25% 线程、可能过期)并按目录名猜项目,导致一个 Codex 项目被拆成多条。
  • 内部线程不再当聊天列出:guardian 审查({"subagent":{"other":"guardian"}},本机约 985 条)与 spawn 子代理按 threads.source 识别后隐藏,与 Codex 侧边栏一致;需要时用 --include-subagents。
  • 工作区按 Codex 项目命名,不再是路径:zbwx-frontend-v2 (~/…/zbwx-frontend-v2) → zbwx-v2。旧自动标题会在启动和每次挂载时迁移,你手动改过的标题不动。
  • 启动钩子修正:改听 agent/created(这个 DSH 版本没有 agent/session-start,导致 autoImport 与标题迁移一直是空转)。

三、机器包裹层过滤:聊天记录只剩真实内容

Codex 会把自己的工具上下文塞成用户消息。以下全部过滤(含带属性的变体):

<skill> / <skills>(整份 SKILL.md)、<codex_internal_context>、<guardian_tool_descriptions>、<external_codex_apps_*>、<in-app-browser-context>、<external_browser_tabs>、<node_repl_review_evidence>、<heartbeat>、<environment_context>、<turn_aborted>、<citation_entries>、<no retained transcript delta entries>,以及 <oai-mem-citation>(记忆引用块)。

<oai-mem-citation> 是特例:它追加在正文末尾,前导标签判定看不见,所以额外做了「从文本中间剪除 + 剪完为空则整块丢弃」。

刻意保留:<proposed_plan>(真实正文)与 <send_user_message_question_reply>(用户自己的回答)。

数据:本机 1134 个 rollout 里,泄漏的包裹层从约 8100 块降到 0;含记忆引用的 125 个 rollout 解析后残留 0。

四、会话模式:不再是「创造模式」

导入时把 agentPreset: 'cordis' 硬编码进会话头,而 cordis 正是 DSH 内置的创造模式(插件创作预设),于是每个同步来的对话都以创造模式打开。

  • 默认改为 standard(标准模式)
  • 可手动选择:配置 importAgentPreset,或 /import-codex --preset ptc(standard / ptc / minimal / cordis)

现场核对:5 个 codex-* 会话全部是 cordis,13 个原生会话全部是 standard —— 问题在导入逻辑,不在环境默认值。

五、目标模式(Goal):真正生效

@deepseek-ai/dsh-goal 的规约很严格:create 必须 revision 1 / active / 0 rounds;之后每次变更恰好 revision+1 且保留 createdAt、roundsStarted;pause/block 只能从 active;回到 active 只能靠 resume;同一 goal id 在一个会话里只能创建一次。

  • 1.9.0:读取 Codex 的 thread_goal_updated(最后一次快照生效)并重放为 DSH 的 goal/change;未完成的目标导入后仍是 active,暂停的仍是 paused。导出时反向写回 Codex 快照(active/paused 直映;blocked → paused;complete 不作为活动目标导出)。
  • 1.9.3:修掉两处违反「只能创建一次」的写法——重导时尾片把 goal create 又带上一遍、以及目标变回 active 时写成第二个 create 而不是 resume。现在 goal 事件不走 diff 路径,重导从会话日志读回已存目标并续接。

验证:测试直接调用真实 foldGoal 折叠产出事件(create → pause → blocked → resume 全链通过);此前报错的 rollout 重导后 phase=active, revision=1。

六、待同步列表:重复行与侧边聊天

  • 同一对话重复出现:Codex 把一个线程分页写成多个 rollout(…-<uuid>.jsonl 加 …-<uuid>_<fork> 分段,共用同一 session_meta.id),而目录是「一个文件一行」。现在按会话 id 折叠,lastTime 取最新分段(否则「有更新」判定会漏)。本机 6 个线程、多出 8 行 → 0 重复标题。
  • 侧边聊天不再同步、也不展示:Codex 桌面版「在侧边继续这个对话」会把会话 fork 成新线程(forked_from_id,同名同历史前缀),列表里于是出现两条同名对话。现在识别 forked_from_id 并在导入与列表中都跳过;分页分段的 history_base 指向自己,不会被误判。本机 27 个 fork 线程全部命中过滤。

七、管理已同步:真正的删除(新增)

DSH 没有删除 Session 的接口(只有 archive / unarchive / pin / unpin),归档后文件仍在、重导仍判为已存在。

新增面板 Sync → 管理已同步:按项目分组、搜索、三态勾选,底部红色「删除 N」,二次确认。

  • 只删 codex-*(你在 DSH 里自建的对话永远删不到)
  • 正在打开的对话拒绝删除,并说明原因
  • 先清归档标记,再删目录与投影缓存(SQLite 索引按「索引有、磁盘无」自行收敛)
  • 删除结果如实回显:逐条 [deleted] / [refused],全是拒绝时标题显示「没有删除任何会话」(此前 200 响应被当成成功,看起来像按钮没反应)
  • 列出范围补全:侧边聊天、以及「Codex 侧已不存在」的孤儿导入也会列出(标题取自 DSH 会话日志),保证没有已同步会话变得不可删

八、问答卡片:双向映射

Codex 把用户回答存成 markup:<send_user_message_question_reply>[{questionItemId, question, answer}],DSH 里没有任何代码认识它,只能当源码打印。

  • Codex → DSH:导入时识别该信封,发出 DSH 需要的 user/message(source.kind = 'user-question-reply'、surfaceOp = 'append'、正文为 {questions, answers} JSON),渲染成「已回答」卡片;callId 从 questionItemId 解出,跳过的问题 selected: []。真实会话实测 48 张卡片。
  • DSH → Codex:导出时反向翻译回 Codex 信封,questionItemId 重建为 ["request_user_input_async","call_…",<index>],往返 callId / 问题 id / 问题 / 答案逐字段一致。
  • 迁移兼容:v2→v3 迁移级的 source.kind 是封闭白名单(不含 user-question-reply),直接写会报 cannot safely transform unclassified message source 并中断整批。现在迁移期降级为 user、迁移后按消息 id 恢复(当前 v4 写入校验接受该 kind)。

九、结果反馈:部分成功不再伪装成成功

情况 之前 现在
某个会话迁移失败 整批抛错,什么都不写 逐条 [skipped-migration] <id>: <原因> + migration-failed N,其余照常导入
会话正在打开(写句柄被占) 整批中断 重试一次后跳过,[busy] … + busy N
挂工作区失败 静默(attachSession 被过滤时不报错),表现为「导入成功但侧边栏找不到」 校验 sessionIds、重试一次,仍失败输出 [ungrouped] … 并提示运行 /attach-workspaces
结果页 一律绿勾「导入完成」 migration-failed > 0 → ⚠️「部分会话未导入」;busy > 0 → ⚠️「部分会话未更新」,明细逐条列出

十、验证

  • 13 个套件 / 100 项测试全绿
  • 真实数据:1275 个 rollout;目录 11 个项目 / 82 个会话;重复标题 0
  • 端到端:6262 条消息 → 60893 事件的大型会话,通过当前格式写入与还原校验
  • 所有导入结果都过真实 sessionFormatCatalog.encodeCurrentEvent + restoreReleasedV4Artifact

十一、升级

装完完整退出并重启 DSH Desktop(只刷新页面不够)。

⚠️ 已导入的旧会话不会自动变好:模式、目标、问答卡片、包裹层过滤都写进了会话日志。要生效:管理已同步 → 删除 → 重新导入。

十二、已知限制

  • Codex 侧删除/归档的会话不会从 DSH 删除(可在管理面板手动删)
  • 重命名标题不会在重导时同步(标题只在创建时写入)
  • 导出到 Codex 一律新建副本,不覆盖原线程
  • blocked 目标导出为 paused;complete 的目标不作为活动目标导出
  • Codex 的 tokensUsed / timeUsedSeconds 不换算成 DSH 的 roundsStarted(含义不同)
  • DSH 允许不同路径的工作区重名;一个 Codex 项目含多个仓库根时会显示成多个同名分组

English summary

Reading & import — zstd rollouts are decoded with the runtime's own node:zlib, multi-frame files frame by frame; reading is streamed with a 2 GiB ceiling (two local sessions of 388 MB / 1.2 GB were invisible before); the session-format migration packages resolve inside the Desktop app.asar on Windows; host 0.2.2-rc.1 is accepted; a successful import no longer reloads the page.

Titles, projects, workspaces — titles and projects come from ~/.codex/state_5.sqlite (threads.name, projects.name, project_roots.path); guardian reviews and spawned sub-agents are hidden like the Codex sidebar; workspaces are named after the Codex project, never a path; startup hooks listen to agent/created (the old event name never fired).

Envelope filtering — <skill>, <codex_internal_context>, <guardian_tool_descriptions>, <external_codex_apps_*>, <in-app-browser-context>, <heartbeat>, <oai-mem-citation> (appended to real text, cut out mid-block) and friends are dropped; <proposed_plan> and <send_user_message_question_reply> are kept on purpose.

Session preset — imports hardcoded agentPreset: 'cordis' (创造模式); they now default to standard, overridable via config.importAgentPreset or /import-codex --preset.

Goal mode — Codex goal snapshots are replayed as goal/change and exported back as thread_goal_updated; the strict fold only allows one create per goal id, so re-imports now continue the stored goal (resume/pause/block/complete) instead of re-creating it. Verified with the real foldGoal.

Catalog — paginated continuation segments fold into one row; Codex side chats (forked_from_id) are neither imported nor listed.

Manage synced (new) — DSH has no delete-Session API, so archive kept the artifact and blocked a clean re-import. The new panel lists every chat this plugin wrote (including side chats and orphaned imports), grouped by project, with checkbox deletion that only accepts codex-* ids, refuses a chat that is open, clears the archive flag, and removes the artifact plus its projection cache.

Question answers — imported as DSH's answered-question card and exported back as the Codex envelope (questionItemId rebuilt identically, round trip verified); the v2→v3 migration's closed source.kind whitelist is worked around by downgrading during the chain and restoring afterwards.

Feedback — a session the migration cannot transform is skipped and reported ([skipped-migration], migration-failed N) instead of aborting the batch; a chat left untouched because it is open is reported as [busy]; unattached workspaces are reported as [ungrouped]; the result page turns into a warning state (「部分会话未导入」 / 「部分会话未更新」) whenever a batch is only partially done.

Verification — 13 suites / 100 tests green; 1275 real rollouts, 11 projects / 82 chats, no duplicate titles.

Upgrade — install from GitHub, fully quit and restart DSH Desktop; chats imported by an older build must be deleted and re-imported to pick up presets, goals, answer cards and the new filters.

neo added 18 commits November 11, 2026 19:39
Import fidelity
- read `rollout-*.jsonl.zst` with the runtime's own node:zlib zstd decoder
  (no new dependency, no conversion of Codex data); multi-frame rollouts are
  decoded frame by frame instead of stopping at frame one
- stream rollouts instead of `readFileSync`, so the 256 MiB guard no longer
  hides real conversations (default cap now 2 GiB); two sessions here
  (388 MiB and 1.2 GB) were previously invisible
- drop the Codex desktop envelopes that leaked into transcripts as user
  messages: `<skill>` (whole SKILL.md), `<codex_internal_context>`,
  `<guardian_tool_descriptions>`, `<external_codex_apps_*>`,
  `<in-app-browser-context>`, `<heartbeat>`, `<no retained transcript delta
  entries>`; `<proposed_plan>` and `<send_user_message_question_reply>` stay
- carry goal mode across: read `event_msg/thread_goal_updated` and replay it as
  the `goal/change` events DSH derives goals from (create + transition); on
  re-import append only a changed phase

Catalog fidelity
- new `lib/codex-index.mjs`: titles and projects come from
  `~/.codex/state_5.sqlite` (`threads.name`, `projects.name`,
  `project_roots.path`), with `session_index.jsonl` and the rollout as
  fallbacks
- group the picker by Codex project (one project owns several repo roots) and
  hide guardian reviews / spawned sub-agents by default, matching the sidebar
- workspace titles are the Codex project name, never a path; auto-generated
  `base (path)` titles are migrated at startup and on attach
- export writes `thread_goal_updated` so a DSH goal reappears in Codex

Compatibility
- resolve `@deepseek-ai/dsh-session-format-*` inside the Desktop app on Windows
  (`process.resourcesPath` → `app.asar/dsh/node_modules`), which the v0→v4
  migration needs on that platform
- accept host 0.2.2-rc.1; listen to `agent/created` (the old
  `agent/session-start` name does not exist, so autoImport never ran)
- importing no longer reloads the page; the result panel offers a manual
  refresh instead
- test harness: Windows-safe ESM imports (`pathToFileURL`), zstd/native
  decoding in tests, new suites for the Codex index and workspace titles

Verification: 12 suites / 77 tests green; `node --check` clean on lib+bin;
`npm pack --dry-run` still ships cordis.patch.yml and lib/client.js.
DSH's JSONL backend keeps one write handle per Session id and refuses a second
(`session "…" is already owned by an active write handle`), which is exactly the
state of a chat that is open in the GUI while it is being re-imported.

- survive the busy case: one retry after 300 ms (the handle is released when the
  view switches away), then skip that session with a [busy] hint instead of
  failing the whole batch; every other append error still fails loud
- report `busy N` in the result line plus an actionable hint
- lib/persistence-facade.mjs exports isSessionBusyError (by name or message)
- tests: a busy session is skipped while its siblings still update; other append
  errors still reject
The importer hardcoded `agentPreset: 'cordis'` in the Session header, and
`cordis` is the built-in 创造模式 (plugin-authoring) preset, so every chat
synced from Codex opened in it. DSH fixes a session's preset at creation
(`agentPresetProjectionDefinition.init` reads the header; later changes need an
`agent-preset/selected` event and are only allowed while the session is blank).

- default imported sessions to `standard` (标准模式)
  (`DEFAULT_IMPORT_AGENT_PRESET` in lib/import-service.js)
- keep it selectable: `config.importAgentPreset`, or `/import-codex --preset ptc`
- lib/dsh-writer.mjs writes the same default
- tests: default is `standard`; an explicit preset wins
`@deepseek-ai/dsh-goal` validates a goal log strictly: `create` must be revision
1, phase active, zero rounds; every later change is exactly revision+1 and keeps
`createdAt` and `roundsStarted`; `pause`/`block` only apply to an active goal;
`resume` is the only path back to active; and a goal id may be created ONCE per
session (`seenGoalIds`). The importer broke the last rule in two ways, so the
goal projection on re-imported chats failed with "goal create requires a fresh
active revision-one goal with zero rounds" and goal mode never took effect:

- `diffImportEvents` slices the rebuilt log up to its end, so the trailing goal
  `create` came back with every re-imported turn → duplicate create. Goal events
  are now filtered out of the diffed suffix (they are appended only by the goal
  helper).
- a Codex goal that moved back to active was written as a second `create`
  instead of `resume`. Re-imports now read the stored goal (phase, revision,
  createdAt, updatedAt) back from the log and continue it with the transitions
  the fold admits; an impossible move out of `complete` appends nothing.

Tests exercise the real fold: create → pause → blocked → resume must stay
admissible (operations and revisions asserted), and a re-imported turn must not
duplicate the create. Verified on the real rollout that failed before: one
`create#1:active`, `foldGoal` accepts it.
DSH 没有删除 Session 的接口(workspace 控制器只有 archive/unarchive/pin/unpin),
所以「归档」之后会话文件仍在,重新导入仍会被判定为已存在。新增面板把这件事做对:

- client: ImportPicker 增加 manage 模式(同步设置 → 管理已同步),复用导入视图的
  项目分组/搜索/三态勾选框,底部按钮换成红色「删除 N」,删前二次确认;行内不再重复
  标注「已导入」,只保留「有更新」。
- host: GET /dsh-codex-sync/catalog?only=imported 只返回已导入线程
  (listImportCatalog 新增 onlyImported),POST /dsh-codex-sync/delete 走
  lib/delete-imported.mjs。
- lib/delete-imported.mjs: 删除会话目录 + projection 缓存,并在删除前通过
  workspaceRegistry.unarchiveSession 清掉归档标记(否则同 id 重导会被隐藏;
  SQLite 索引按「索引有、磁盘无」自行收敛)。只允许 codex- 前缀;正在 DSH 中打开的
  会话拒绝删除;不在存储里的 id 记为 missing;dryRun 只报告不动手;Codex 原始对话
  永不触碰。
- tests: 6 个新用例(删除产物+缓存+归档标记、拒绝原生会话、拒绝正在打开的会话、
  missing、dryRun、路径定位),全套 88 项。
Codex 会把一个线程分页写成多个 rollout 文件:基础 `rollout-<ts>-<uuid>.jsonl[.zst]`
加上后续 `rollout-<ts>-<uuid>_<fork>` 分段,它们带着同一个
`session_meta.payload.id`,只包含增量轮次。导入器早已按 id 合并,但
`listImportCatalog` 是「一个文件一行」,于是这些线程在导入/管理面板里按分段数重复
出现(本机 6 个线程、多出 8 行)。

- lib/import-service.js: 目录按会话 id 折叠——同一 id 只产出一行,`createdAt` 取最早、
  `lastTime` 取最新(保证「有更新」判定正确),并补齐 cwd/parentRawId。
- test: 新增「分段线程只出现一行」用例,断言 lastTime 覆盖最新分段。
- 实机验证:目录从 87 行降到 79 行,重复 id 为 0。
`workspace.attachSession()` 在注册表把 id 过滤掉时(归档会话永远进不了
`workspace.sessionIds`)会**正常返回、不报错**,导入器把它当成成功,于是会话既不在任何
工作区、侧边栏也就没有位置显示——表现就是「导入成功但对应项目下找不到」。

- lib/attach-workspaces.mjs: attach 后用 `workspace.sessionIds.includes(id)` 校验;
  失败先重试一次(写入后 header 索引可能滞后 300ms);仍未挂上则输出
  `[ungrouped] <id> → <工作区>: <原因>`,并追加提示「关闭该对话后运行 /attach-workspaces」。
- test: 新增「注册表静默不收(归档)时报告 ungrouped」用例;fake registry 补
  sessionIds,便于断言。
- 现场核对(本机):`codex-01a1c47b…` 会话文件确实写入
  `...\ZBWX\2.0\zbwx-frontend-v2`,live host 的 persistence.list() 也能看到它,但
  `workspace.json` 里没有任何工作区收录它 → 正是上面的静默失败。
@nlsp60 nlsp60 changed the title 适配dshV0.2.2-rc.1,修复codex->dsh对话标题错误,增加目标模式双向保留 修复codex->dsh对话标题错误,增加目标模式双向保留,增加消息同步管理 Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant