将 dsh 会话事件镜像到 MySQL、PostgreSQL、SQLite 或 SQL Server,同时保留本地会话文件。
安装
# npm 包(预构建)
dsh plugin --profile web add @amaster.ai/dsh-storage
# GitHub 源码(首次需按提示配置 allowBuilds 构建授权后重试)
dsh plugin --profile web add github:TGYD-helige/dsh-plugins#path:/packages/dsh-storage
装任何插件都等于在你的机器上跑第三方代码,权限和你本人一样大——能读你的文件、用你的凭据、访问网络,工具审批管不到它。GitHub 来源的插件还会在安装时执行构建脚本——pnpm 默认拦截,所以安装可能停在 ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED 或 ERR_PNPM_IGNORED_BUILDS;dsh 会打印出需要添加的确切键名,把它加进该 profile 的 pnpm-workspace.yaml 的 allowBuilds 下,重跑一次即可装上。放行构建本身就是一次信任判断:请只安装可信来源,并尽量锁定 commit(github:owner/repo#sha)。
README
该插件的 README 只有英文版本。

Session storage mirror for DeepSeek Harness (dsh): projects the session/event stream into MySQL/PostgreSQL/SQLite/SQL Server (ai_messages / ai_chat_histories, same tables as the source project) without replacing dsh's local persistence — local files stay authoritative, this is a mirror.
Use it when a dsh profile needs durable, queryable session data in an existing relational database while preserving the runtime's local session store as the source of truth.
Install
dsh plugin --profile my-agent add @amaster.ai/dsh-storage
Runtime peers: @prisma/client (Prisma 7) plus the driver adapter for your database:
| Provider | Adapter peer |
|---|---|
mysql |
@prisma/adapter-mariadb |
postgresql |
@prisma/adapter-pg |
sqlite |
@prisma/adapter-libsql |
sqlserver |
@prisma/adapter-mssql |
The PrismaClient is pre-generated per provider and shipped in the package — no prisma generate step for consumers.
Configuration
Disabled by default. Configure via the profile's cordis.patch.yml:
- insert:
- id: storage-mirror
name: '@amaster.ai/dsh-storage'
config:
enabled: true
database:
enabled: true
provider: mysql # mysql | postgresql | sqlite | sqlserver
url: mysql://user:pass@host:3306/agent
Create or upgrade the tables with the shipped schema variant:
npx prisma db push --schema node_modules/@amaster.ai/dsh-storage/prisma/schema.mysql.prisma --url "mysql://user:pass@host:3306/agent"
# schema.postgresql.prisma / schema.sqlite.prisma / schema.sqlserver.prisma work the same way
Only message, tool-result, assistant-attempt, turn-end, title, and successful compaction events enter the mirror queue; unrelated lifecycle records do not trigger database reads or retries. Failed initialization retries share a one-second delay across sessions. Valid queued events wait through that delay, and session flush/unload still drain their ordered work. Database operation failures continue to be logged and swallowed; local DSH persistence remains authoritative.
Adjacent queued tool results for the same assistant row are merged before writing, with at most 32 events per batch and no debounce timer. Different messages and intervening mirrored events preserve queue order. Session flush, archive, disposal, and plugin unload seal and drain earlier batches. Full result rows are not kept in a new persistent cache. This reduces repeated reads/writes; the queue can still grow when incoming data outpaces the database.
Data model
ai_messages— user and model rows, withthoughts,tokens,tool_calls,agent_id,metadataJSON columns and soft-delete. Atool/resultupdates the matching model row'stool_callsentry by call ID; it does not create atype=toolrow.agent_idismainfor top-level sessions and the child session id for subagent sessions.ai_chat_histories— per-session rollup (message count, total tokens, first/last message timestamps). A subagent child session records its creator under thedsh-storage:parentSessionIdmetadata key.
The logical message id rides in metadata.id; message rows use a deterministic hash of (session_id, message id) as their primary key, so re-projected events upsert in place rather than duplicate — on every connector. Session rows are matched by session_id and keep their cuid primary keys. One deviation from the source project: no user_id column — tenancy rides on session_id.
For user/message rows, content remains the text projection, while metadata.message retains the original user message as received, including source and ordered content blocks. Image/file blocks keep whatever attachment reference, path, URL, or inline data the incoming message actually contains; this mirror does not fetch or rewrite attachments. Re-projection writes the same raw message into the existing row.
The tool_calls array retains dsh's tool-call blocks (id, name, arguments); the matching entry gains the structured result block and, on failure, an error identity. Live call IDs are cached, and restored calls can resolve their message ID from the model surface: both paths read one message primary key. Older calls are searched in keyset pages of at most 100 ID/tool-call candidates, matched in the plugin and discarded before fetching the next page. Tool-result lookup SQL does not search JSON, join tables, or nest SELECT statements. Duplicate results update the same row and do not increment message counts. Existing historical type=tool rows are left intact.
When an assistant message contains dsh reasoning blocks, thoughts is an array of { content } entries in block order. If the adapter supplies a matching signature in the message's source.replayState.blocks, that entry also carries thoughtSignature. The full model source, including opaque replayState, is preserved in row metadata for lossless provider replay. The backend's readMessages() also accepts older { description } entries and JSON string thoughts, returning them as { content }. subject and a per-thought timestamp are not invented when the upstream message does not supply them.
SQL Server note: Prisma's sqlserver connector has no Json type, so its variant maps the JSON columns to text — the backend serializes them on write automatically (SQL Server's ISJSON / JSON_VALUE still query the text as JSON).
Mirroring is a no-throw seam: backend errors are logged with a [dsh-storage] prefix and never escape into the agent loop.
Successful native compaction/end events also write a utility_compressor message. Its
content is the source-compatible Content[] JSON array of the complete surviving
conversation: summary plus retained tail, with tool calls/results paired by ID. System
prompts are excluded. The surface is captured at the event, before asynchronous database
writes; failed/canceled compactions leave the previous snapshot intact. Snapshot rows do
not increment the visible message count. Adjacent messages with the same role merge their
ordered parts, since the legacy reader would otherwise skip the retained tail.
Consumers can resume from the latest active compression snapshot plus later message rows.
Snapshots and newly mirrored rows include metadata.sessionCreatedAt and metadata.seq
to distinguish resumed session generations and messages in the same database second.
Older snapshots without this metadata retain their creation-time boundary. The mirror
does not fetch attachments or invent usable paths/URLs from opaque attachment IDs.
Attachments, developer updates, extension blocks and non-object tool arguments are
preserved as labelled JSON data in text parts when legacy Content[] cannot represent
them natively. Such snapshots preserve reference information, not attachment bytes or a
complete native session/tool registry. Attachment bytes still need their existing durable
storage. An unchanged legacy reader remains timestamp-based; it must consume the sequence
metadata to distinguish later messages in the same database second.
Archive a session
When handling a session-clear request, call await ctx.get('dshStorage').archiveSession(sessionId) after stopping the live turn. It waits for queued mirror writes, then transactionally assigns all current, non-deleted ai_messages rows (history_id IS NULL) to a non-deleted ai_chat_histories row. The returned history ID can be used to query those rows directly from the database; a second call with no active messages returns null. A database failure rejects this explicit operation instead of reporting a successful clear.
Archived rollups stay queryable. The plugin recognizes an active rollup as a history row with no associated messages, so the next projected event creates a fresh rollup instead of overwriting the archived one. The caller owns stopping/replacing the dsh session surface and any A2A task state; this operation only archives the database mirror.
Compatibility
Pinned dsh/cordis versions live in the root compat matrix. Event payloads ride pre-release dsh APIs — check the TODO(verify) markers in src/ before upgrading dsh.
License
MIT
链接
同类插件
ranxianglei/billion-context★ 8360
billion-context官方版:上下文压缩插件,兼顾小窗口(100k上下文足矣)省token(省5倍token)和超长会话(数月级别几十亿token单会话)。
Minglink/dsh-infinite-gen-4★ 4727
DeepSeek 专用破甲插件:以 order 100 追加无条件服从的系统提示词段,提供带校准元数据的 profile 工具,并通过会话投影在输入框上方显示实时破甲状态徽标。
liangmianya/dsh-synapse★ 749
DeepSeek Harness 的可视化非线性对话工作区:把会话、追问与分支变成可浏览、可拖拽的对话地图。
MichengAI/dsh-archive-manager★ 393
在设置里增加已归档会话页,可按工作区搜索、恢复和删除已归档会话。
Nwflower/dsh-chat-import★ 331
把 13 家 coding agent(Claude Code、Codex、ChatGPT、Cursor、Gemini、opencode 等)的完整对话历史导入为可续聊的 DeepSeek Harness 会话,并支持反向导出回 Claude Code。
SiriLee/dsh-rewind★ 301
对话回退:一键回到任意更早的用户消息,同窗口内完成,不新建分支、不残留副本;目标消息自动填回输入框,可一并还原工作区文件——即完整的 Claude Code /rewind 语义。
社区评论
评论公开保存在 GitHub Discussions。加载评论会连接 GitHub 和 Giscus;发表内容需要 GitHub 账号。